token session added
This commit is contained in:
@@ -216,6 +216,14 @@
|
||||
<script>
|
||||
(function() {
|
||||
var PARALLEL_GLOBE_URL = 'https://parallelglobe.io';
|
||||
var restoredMeetingToken = restoreMeetingTokenFromSession();
|
||||
|
||||
if (restoredMeetingToken) {
|
||||
return;
|
||||
}
|
||||
|
||||
rememberMeetingToken();
|
||||
|
||||
var directAccessBlocked = isDirectRoomAccess();
|
||||
|
||||
if (directAccessBlocked) {
|
||||
@@ -223,20 +231,116 @@
|
||||
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);
|
||||
|
||||
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() {
|
||||
var path = window.location.pathname.replace(/\/+$/, '');
|
||||
var path = getRoomPath();
|
||||
|
||||
if (!path || path === '/') {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (/^\/(?:static|images|libs|css|sounds|fonts|transcripts)\//.test(path)) {
|
||||
if (isIgnoredJitsiPath(path)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -261,13 +365,11 @@
|
||||
}
|
||||
|
||||
function getMeetingToken() {
|
||||
return new URLSearchParams(window.location.search).get('jwt') || '';
|
||||
return getMeetingTokenFromUrl() || getStoredMeetingToken() || '';
|
||||
}
|
||||
|
||||
function getPoliticTalkJwtPayload() {
|
||||
function getPoliticTalkJwtPayloadFromToken(token) {
|
||||
try {
|
||||
var token = getMeetingToken();
|
||||
|
||||
if (!token) {
|
||||
return null;
|
||||
}
|
||||
@@ -278,9 +380,11 @@
|
||||
}
|
||||
}
|
||||
|
||||
function getPoliticTalkMeetingTitle() {
|
||||
var payload = getPoliticTalkJwtPayload();
|
||||
function getPoliticTalkJwtPayload() {
|
||||
return getPoliticTalkJwtPayloadFromToken(getMeetingToken());
|
||||
}
|
||||
|
||||
function getPoliticTalkMeetingTitleFromPayload(payload) {
|
||||
if (!payload) {
|
||||
return '';
|
||||
}
|
||||
@@ -296,6 +400,11 @@
|
||||
return title.trim() ? title : '';
|
||||
}
|
||||
|
||||
function getPoliticTalkMeetingTitle() {
|
||||
return getPoliticTalkMeetingTitleFromPayload(getPoliticTalkJwtPayload())
|
||||
|| readRoomSessionValue('title');
|
||||
}
|
||||
|
||||
function isPoliticTalkHost() {
|
||||
var payload = getPoliticTalkJwtPayload();
|
||||
var user = payload && payload.context && payload.context.user;
|
||||
@@ -340,6 +449,25 @@
|
||||
characterData: 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() {
|
||||
@@ -475,9 +603,7 @@
|
||||
button.className = 'politictalk-direct-access__button';
|
||||
button.textContent = 'OK';
|
||||
button.type = 'button';
|
||||
button.addEventListener('click', function() {
|
||||
window.location.href = PARALLEL_GLOBE_URL;
|
||||
});
|
||||
button.addEventListener('click', redirectToParallelGlobe);
|
||||
|
||||
actions.appendChild(button);
|
||||
dialog.appendChild(title);
|
||||
|
||||
Reference in New Issue
Block a user