You've already forked matrix-react-sdk
							
							
				mirror of
				https://github.com/matrix-org/matrix-react-sdk.git
				synced 2025-11-03 00:33:22 +03:00 
			
		
		
		
	Disconnect from video rooms when leaving (#8500)
* Disconnect from video rooms when leaving * Listen on the specific room * Fix lints
This commit is contained in:
		@@ -15,6 +15,7 @@ limitations under the License.
 | 
				
			|||||||
*/
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import EventEmitter from "events";
 | 
					import EventEmitter from "events";
 | 
				
			||||||
 | 
					import { Room, RoomEvent } from "matrix-js-sdk/src/models/room";
 | 
				
			||||||
import { ClientWidgetApi, IWidgetApiRequest } from "matrix-widget-api";
 | 
					import { ClientWidgetApi, IWidgetApiRequest } from "matrix-widget-api";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import defaultDispatcher from "../dispatcher/dispatcher";
 | 
					import defaultDispatcher from "../dispatcher/dispatcher";
 | 
				
			||||||
@@ -193,6 +194,7 @@ export default class VideoChannelStore extends AsyncStoreWithClient<null> {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        this.connected = true;
 | 
					        this.connected = true;
 | 
				
			||||||
        messaging.once(`action:${ElementWidgetActions.HangupCall}`, this.onHangup);
 | 
					        messaging.once(`action:${ElementWidgetActions.HangupCall}`, this.onHangup);
 | 
				
			||||||
 | 
					        this.matrixClient.getRoom(roomId).on(RoomEvent.MyMembership, this.onMyMembership);
 | 
				
			||||||
        window.addEventListener("beforeunload", this.setDisconnected);
 | 
					        window.addEventListener("beforeunload", this.setDisconnected);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.emit(VideoChannelEvent.Connect, roomId);
 | 
					        this.emit(VideoChannelEvent.Connect, roomId);
 | 
				
			||||||
@@ -214,11 +216,13 @@ export default class VideoChannelStore extends AsyncStoreWithClient<null> {
 | 
				
			|||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public setDisconnected = async () => {
 | 
					    public setDisconnected = async () => {
 | 
				
			||||||
 | 
					        const roomId = this.roomId;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.activeChannel.off(`action:${ElementWidgetActions.HangupCall}`, this.onHangup);
 | 
					        this.activeChannel.off(`action:${ElementWidgetActions.HangupCall}`, this.onHangup);
 | 
				
			||||||
        this.activeChannel.off(`action:${ElementWidgetActions.CallParticipants}`, this.onParticipants);
 | 
					        this.activeChannel.off(`action:${ElementWidgetActions.CallParticipants}`, this.onParticipants);
 | 
				
			||||||
 | 
					        this.matrixClient.getRoom(roomId).off(RoomEvent.MyMembership, this.onMyMembership);
 | 
				
			||||||
        window.removeEventListener("beforeunload", this.setDisconnected);
 | 
					        window.removeEventListener("beforeunload", this.setDisconnected);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const roomId = this.roomId;
 | 
					 | 
				
			||||||
        this.activeChannel = null;
 | 
					        this.activeChannel = null;
 | 
				
			||||||
        this.roomId = null;
 | 
					        this.roomId = null;
 | 
				
			||||||
        this.connected = false;
 | 
					        this.connected = false;
 | 
				
			||||||
@@ -242,6 +246,8 @@ export default class VideoChannelStore extends AsyncStoreWithClient<null> {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    private updateDevices = async (roomId: string, fn: (devices: string[]) => string[]) => {
 | 
					    private updateDevices = async (roomId: string, fn: (devices: string[]) => string[]) => {
 | 
				
			||||||
        const room = this.matrixClient.getRoom(roomId);
 | 
					        const room = this.matrixClient.getRoom(roomId);
 | 
				
			||||||
 | 
					        if (room.getMyMembership() !== "join") return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const devicesState = room.currentState.getStateEvents(VIDEO_CHANNEL_MEMBER, this.matrixClient.getUserId());
 | 
					        const devicesState = room.currentState.getStateEvents(VIDEO_CHANNEL_MEMBER, this.matrixClient.getUserId());
 | 
				
			||||||
        const devices = devicesState?.getContent<IVideoChannelMemberContent>()?.devices ?? [];
 | 
					        const devices = devicesState?.getContent<IVideoChannelMemberContent>()?.devices ?? [];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -280,4 +286,8 @@ export default class VideoChannelStore extends AsyncStoreWithClient<null> {
 | 
				
			|||||||
        this.videoMuted = false;
 | 
					        this.videoMuted = false;
 | 
				
			||||||
        this.ack(ev);
 | 
					        this.ack(ev);
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private onMyMembership = (room: Room, membership: string) => {
 | 
				
			||||||
 | 
					        if (membership !== "join") this.setDisconnected();
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user