token session added

This commit is contained in:
2026-05-26 22:25:26 +05:30
parent 0e34b3701c
commit afffe831e4

View File

@@ -216,6 +216,14 @@
<script> <script>
(function() { (function() {
var PARALLEL_GLOBE_URL = 'https://parallelglobe.io'; var PARALLEL_GLOBE_URL = 'https://parallelglobe.io';
var restoredMeetingToken = restoreMeetingTokenFromSession();
if (restoredMeetingToken) {
return;
}
rememberMeetingToken();
var directAccessBlocked = isDirectRoomAccess(); var directAccessBlocked = isDirectRoomAccess();
if (directAccessBlocked) { if (directAccessBlocked) {
@@ -223,20 +231,116 @@
document.title = 'Access required - PoliticTalk'; document.title = 'Access required - PoliticTalk';
} }
function hasMeetingToken() { function getRoomPath() {
return window.location.pathname.replace(/\/+$/, '');
}
function isIgnoredJitsiPath(path) {
return /^\/(?:static|images|libs|css|sounds|fonts|transcripts)\//.test(path);
}
function getMeetingTokenFromUrl() {
var params = new URLSearchParams(window.location.search); var params = new URLSearchParams(window.location.search);
return Boolean(params.get('jwt') || params.get('token')); return params.get('jwt') || params.get('token') || '';
}
function hasMeetingToken() {
return Boolean(getMeetingTokenFromUrl());
}
function getRoomSessionKey(name) {
var path = getRoomPath() || '/';
return 'politictalk:' + path + ':' + name;
}
function readRoomSessionValue(name) {
try {
return window.sessionStorage.getItem(getRoomSessionKey(name)) || '';
} catch (error) {
return '';
}
}
function writeRoomSessionValue(name, value) {
try {
window.sessionStorage.setItem(getRoomSessionKey(name), value);
} catch (error) {
// Ignore storage failures. The direct-access guard still works.
}
}
function removeRoomSessionValue(name) {
try {
window.sessionStorage.removeItem(getRoomSessionKey(name));
} catch (error) {
// Ignore storage failures.
}
}
function getStoredMeetingToken() {
return readRoomSessionValue('jwt');
}
function isJwtUsable(token) {
try {
var payload = JSON.parse(decodeBase64Url((token || '').split('.')[1] || ''));
var expiresAt = Number(payload.exp || 0);
return !expiresAt || expiresAt > Math.floor(Date.now() / 1000) + 10;
} catch (error) {
return false;
}
}
function rememberMeetingToken() {
var token = getMeetingTokenFromUrl();
if (!token || !isJwtUsable(token)) {
return;
}
writeRoomSessionValue('jwt', token);
var payload = getPoliticTalkJwtPayloadFromToken(token);
var meetingTitle = getPoliticTalkMeetingTitleFromPayload(payload);
if (meetingTitle) {
writeRoomSessionValue('title', meetingTitle);
}
}
function restoreMeetingTokenFromSession() {
var path = getRoomPath();
if (!path || path === '/' || isIgnoredJitsiPath(path) || hasMeetingToken()) {
return false;
}
var token = getStoredMeetingToken();
if (!token || !isJwtUsable(token)) {
removeRoomSessionValue('jwt');
removeRoomSessionValue('title');
return false;
}
var params = new URLSearchParams(window.location.search);
params.set('jwt', token);
window.location.replace(path + '?' + params.toString() + window.location.hash);
return true;
} }
function isDirectRoomAccess() { function isDirectRoomAccess() {
var path = window.location.pathname.replace(/\/+$/, ''); var path = getRoomPath();
if (!path || path === '/') { if (!path || path === '/') {
return false; return false;
} }
if (/^\/(?:static|images|libs|css|sounds|fonts|transcripts)\//.test(path)) { if (isIgnoredJitsiPath(path)) {
return false; return false;
} }
@@ -261,13 +365,11 @@
} }
function getMeetingToken() { function getMeetingToken() {
return new URLSearchParams(window.location.search).get('jwt') || ''; return getMeetingTokenFromUrl() || getStoredMeetingToken() || '';
} }
function getPoliticTalkJwtPayload() { function getPoliticTalkJwtPayloadFromToken(token) {
try { try {
var token = getMeetingToken();
if (!token) { if (!token) {
return null; return null;
} }
@@ -278,9 +380,11 @@
} }
} }
function getPoliticTalkMeetingTitle() { function getPoliticTalkJwtPayload() {
var payload = getPoliticTalkJwtPayload(); return getPoliticTalkJwtPayloadFromToken(getMeetingToken());
}
function getPoliticTalkMeetingTitleFromPayload(payload) {
if (!payload) { if (!payload) {
return ''; return '';
} }
@@ -296,6 +400,11 @@
return title.trim() ? title : ''; return title.trim() ? title : '';
} }
function getPoliticTalkMeetingTitle() {
return getPoliticTalkMeetingTitleFromPayload(getPoliticTalkJwtPayload())
|| readRoomSessionValue('title');
}
function isPoliticTalkHost() { function isPoliticTalkHost() {
var payload = getPoliticTalkJwtPayload(); var payload = getPoliticTalkJwtPayload();
var user = payload && payload.context && payload.context.user; var user = payload && payload.context && payload.context.user;
@@ -340,6 +449,25 @@
characterData: true, characterData: true,
subtree: true subtree: true
}); });
window.clearInterval(window.politicTalkTitleInterval);
window.politicTalkTitleInterval = window.setInterval(function() {
if (document.title !== pageTitle) {
document.title = pageTitle;
}
}, 1000);
}
function redirectToParallelGlobe() {
try {
window.location.assign(PARALLEL_GLOBE_URL);
} catch (error) {
window.location.href = PARALLEL_GLOBE_URL;
}
window.setTimeout(function() {
window.location.href = PARALLEL_GLOBE_URL;
}, 250);
} }
function preventHostLeaveButtonExecution() { function preventHostLeaveButtonExecution() {
@@ -475,9 +603,7 @@
button.className = 'politictalk-direct-access__button'; button.className = 'politictalk-direct-access__button';
button.textContent = 'OK'; button.textContent = 'OK';
button.type = 'button'; button.type = 'button';
button.addEventListener('click', function() { button.addEventListener('click', redirectToParallelGlobe);
window.location.href = PARALLEL_GLOBE_URL;
});
actions.appendChild(button); actions.appendChild(button);
dialog.appendChild(title); dialog.appendChild(title);