Skip to content

Commit

Permalink
fix dialog token update, use dialog token for kick
Browse files Browse the repository at this point in the history
bugfix

Delete naf-dialog-adapter-copy.js

Update hub-channel.js
  • Loading branch information
yakyouk committed Jul 18, 2021
1 parent 066f4c2 commit 16e67dd
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/hub.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
);
Expand Down
4 changes: 2 additions & 2 deletions src/naf-dialog-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 } }));
Expand Down
13 changes: 5 additions & 8 deletions src/utils/hub-channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 });
};

Expand Down

0 comments on commit 16e67dd

Please sign in to comment.