diff --git a/src/hub.js b/src/hub.js index f921fa96ab1..58e5ced676d 100644 --- a/src/hub.js +++ b/src/hub.js @@ -1429,7 +1429,7 @@ document.addEventListener("DOMContentLoaded", async () => { setupPeerConnectionConfig(adapter); - hubChannel.addEventListener("permissions-refreshed", e => adapter.setJoinToken(e.detail.permsToken)); + hubChannel.addEventListener("permissions_updated", e => adapter.setJoinToken(e.detail.permsToken)); }, { once: true } ); diff --git a/src/naf-dialog-adapter.js b/src/naf-dialog-adapter.js index 7d942b9be1f..d3a5aafbeb6 100644 --- a/src/naf-dialog-adapter.js +++ b/src/naf-dialog-adapter.js @@ -1104,12 +1104,12 @@ export default class DialogAdapter extends EventEmitter { }, timeout); } - kick(clientId, permsToken) { + kick(clientId) { return this._protoo .request("kick", { room_id: this.room, user_id: clientId, - token: permsToken + token: this._joinToken }) .then(() => { document.body.dispatchEvent(new CustomEvent("kicked", { detail: { clientId: clientId } })); diff --git a/src/utils/hub-channel.js b/src/utils/hub-channel.js index c46a30c6e22..f853221dd95 100644 --- a/src/utils/hub-channel.js +++ b/src/utils/hub-channel.js @@ -145,14 +145,12 @@ export default class HubChannel extends EventTarget { // Note: token is not verified. this._permissions = jwtDecode(token); configs.setIsAdmin(this._permissions.postgrest_role === "ret_admin"); - this.dispatchEvent(new CustomEvent("permissions_updated")); + this.dispatchEvent(new CustomEvent("permissions_updated", { detail: { permsToken: token } })); // Refresh the token 1 minute before it expires. - const nextRefresh = new Date(this._permissions.exp * 1000 - 60 * 1000) - new Date(); - setTimeout(async () => { - const result = await this.fetchPermissions(); - this.dispatchEvent(new CustomEvent("permissions-refreshed", { detail: result })); - }, nextRefresh); + const nextRefresh = new Date(this._permissions.exp * 1000 - 60000) - new Date(); + if (this._refreshTimer) clearTimeout(this._refreshTimer); + this._refreshTimer = setTimeout(this.fetchPermissions, nextRefresh); }; sendEnteringEvent = async () => { @@ -427,8 +425,7 @@ export default class HubChannel extends EventTarget { isHidden = sessionId => this._blockedSessionIds.has(sessionId); kick = async sessionId => { - const permsToken = await this.fetchPermissions(); - NAF.connection.adapter.kick(sessionId, permsToken); + NAF.connection.adapter.kick(sessionId); this.channel.push("kick", { session_id: sessionId }); };