Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Forcefully disconnect from video rooms on logout
Browse files Browse the repository at this point in the history
  • Loading branch information
robintown committed Apr 20, 2022
1 parent 6e86a14 commit b57c64e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
2 changes: 2 additions & 0 deletions src/components/structures/MatrixChat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ import { IConfigOptions } from "../../IConfigOptions";
import { SnakedObject } from "../../utils/SnakedObject";
import InfoDialog from '../views/dialogs/InfoDialog';
import { leaveRoomBehaviour } from "../../utils/leave-behaviour";
import VideoChannelStore from "../../stores/VideoChannelStore";

// legacy export
export { default as Views } from "../../Views";
Expand Down Expand Up @@ -576,6 +577,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
break;
case 'logout':
CallHandler.instance.hangupAllCalls();
if (VideoChannelStore.instance.connected) VideoChannelStore.instance.setDisconnected();
Lifecycle.logout();
break;
case 'require_registration':
Expand Down
39 changes: 21 additions & 18 deletions src/stores/VideoChannelStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,26 @@ export default class VideoChannelStore extends AsyncStoreWithClient<null> {
}
};

public setDisconnected = async () => {
this.activeChannel.off(`action:${ElementWidgetActions.HangupCall}`, this.onHangup);
this.activeChannel.off(`action:${ElementWidgetActions.CallParticipants}`, this.onParticipants);

const roomId = this.roomId;
this.activeChannel = null;
this.roomId = null;
this.connected = false;
this.participants = [];

this.emit(VideoChannelEvent.Disconnect, roomId);

// Tell others that we're disconnected, by removing our device from room state
await this.updateDevices(roomId, devices => {
const devicesSet = new Set(devices);
devicesSet.delete(this.matrixClient.getDeviceId());
return Array.from(devicesSet);
});
};

private ack = (ev: CustomEvent<IWidgetApiRequest>) => {
// Even if we don't have a reply to a given widget action, we still need
// to give the widget API something to acknowledge receipt
Expand All @@ -208,24 +228,7 @@ export default class VideoChannelStore extends AsyncStoreWithClient<null> {

private onHangup = async (ev: CustomEvent<IWidgetApiRequest>) => {
this.ack(ev);

this.activeChannel.off(`action:${ElementWidgetActions.HangupCall}`, this.onHangup);
this.activeChannel.off(`action:${ElementWidgetActions.CallParticipants}`, this.onParticipants);

const roomId = this.roomId;
this.activeChannel = null;
this.roomId = null;
this.connected = false;
this.participants = [];

this.emit(VideoChannelEvent.Disconnect, roomId);

// Tell others that we're disconnected, by removing our device from room state
await this.updateDevices(roomId, devices => {
const devicesSet = new Set(devices);
devicesSet.delete(this.matrixClient.getDeviceId());
return Array.from(devicesSet);
});
await this.setDisconnected();
};

private onParticipants = (ev: CustomEvent<IWidgetApiRequest>) => {
Expand Down

0 comments on commit b57c64e

Please sign in to comment.