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

Commit f34b4f1

Browse files
authored
Disconnect from video rooms when leaving (#8500)
* Disconnect from video rooms when leaving * Listen on the specific room * Fix lints
1 parent 658ff4d commit f34b4f1

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/stores/VideoChannelStore.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ limitations under the License.
1515
*/
1616

1717
import EventEmitter from "events";
18+
import { Room, RoomEvent } from "matrix-js-sdk/src/models/room";
1819
import { ClientWidgetApi, IWidgetApiRequest } from "matrix-widget-api";
1920

2021
import defaultDispatcher from "../dispatcher/dispatcher";
@@ -193,6 +194,7 @@ export default class VideoChannelStore extends AsyncStoreWithClient<null> {
193194

194195
this.connected = true;
195196
messaging.once(`action:${ElementWidgetActions.HangupCall}`, this.onHangup);
197+
this.matrixClient.getRoom(roomId).on(RoomEvent.MyMembership, this.onMyMembership);
196198
window.addEventListener("beforeunload", this.setDisconnected);
197199

198200
this.emit(VideoChannelEvent.Connect, roomId);
@@ -214,11 +216,13 @@ export default class VideoChannelStore extends AsyncStoreWithClient<null> {
214216
};
215217

216218
public setDisconnected = async () => {
219+
const roomId = this.roomId;
220+
217221
this.activeChannel.off(`action:${ElementWidgetActions.HangupCall}`, this.onHangup);
218222
this.activeChannel.off(`action:${ElementWidgetActions.CallParticipants}`, this.onParticipants);
223+
this.matrixClient.getRoom(roomId).off(RoomEvent.MyMembership, this.onMyMembership);
219224
window.removeEventListener("beforeunload", this.setDisconnected);
220225

221-
const roomId = this.roomId;
222226
this.activeChannel = null;
223227
this.roomId = null;
224228
this.connected = false;
@@ -242,6 +246,8 @@ export default class VideoChannelStore extends AsyncStoreWithClient<null> {
242246

243247
private updateDevices = async (roomId: string, fn: (devices: string[]) => string[]) => {
244248
const room = this.matrixClient.getRoom(roomId);
249+
if (room.getMyMembership() !== "join") return;
250+
245251
const devicesState = room.currentState.getStateEvents(VIDEO_CHANNEL_MEMBER, this.matrixClient.getUserId());
246252
const devices = devicesState?.getContent<IVideoChannelMemberContent>()?.devices ?? [];
247253

@@ -280,4 +286,8 @@ export default class VideoChannelStore extends AsyncStoreWithClient<null> {
280286
this.videoMuted = false;
281287
this.ack(ev);
282288
};
289+
290+
private onMyMembership = (room: Room, membership: string) => {
291+
if (membership !== "join") this.setDisconnected();
292+
};
283293
}

0 commit comments

Comments
 (0)