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 Sep 4, 2021
1 parent 07d9ccd commit 68a1c24
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/naf-dialog-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -944,12 +944,12 @@ export class DialogAdapter extends EventEmitter {
}
}

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
10 changes: 3 additions & 7 deletions src/utils/hub-channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,17 +143,14 @@ export default class HubChannel extends EventTarget {
this.token = token;
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();
if (this.fetchPermissionsTimeout) {
clearTimeout(this.fetchPermissionsTimeout);
}
this.fetchPermissionsTimeout = setTimeout(async () => {
const result = await this.fetchPermissions();
this.dispatchEvent(new CustomEvent("permissions-refreshed", { detail: result }));
}, nextRefresh);
this.fetchPermissionsTimeout = setTimeout(this.fetchPermissions, nextRefresh);
};

sendEnteringEvent = async () => {
Expand Down Expand Up @@ -430,8 +427,7 @@ export default class HubChannel extends EventTarget {
isHidden = sessionId => this._blockedSessionIds.has(sessionId);

kick = async sessionId => {
const permsToken = await this.fetchPermissions();
APP.dialog.kick(sessionId, permsToken);
APP.dialog.kick(sessionId);
this.channel.push("kick", { session_id: sessionId });
};

Expand Down

0 comments on commit 68a1c24

Please sign in to comment.