@@ -15,6 +15,7 @@ limitations under the License.
15
15
*/
16
16
17
17
import EventEmitter from "events" ;
18
+ import { Room , RoomEvent } from "matrix-js-sdk/src/models/room" ;
18
19
import { ClientWidgetApi , IWidgetApiRequest } from "matrix-widget-api" ;
19
20
20
21
import defaultDispatcher from "../dispatcher/dispatcher" ;
@@ -193,6 +194,7 @@ export default class VideoChannelStore extends AsyncStoreWithClient<null> {
193
194
194
195
this . connected = true ;
195
196
messaging . once ( `action:${ ElementWidgetActions . HangupCall } ` , this . onHangup ) ;
197
+ this . matrixClient . getRoom ( roomId ) . on ( RoomEvent . MyMembership , this . onMyMembership ) ;
196
198
window . addEventListener ( "beforeunload" , this . setDisconnected ) ;
197
199
198
200
this . emit ( VideoChannelEvent . Connect , roomId ) ;
@@ -214,11 +216,13 @@ export default class VideoChannelStore extends AsyncStoreWithClient<null> {
214
216
} ;
215
217
216
218
public setDisconnected = async ( ) => {
219
+ const roomId = this . roomId ;
220
+
217
221
this . activeChannel . off ( `action:${ ElementWidgetActions . HangupCall } ` , this . onHangup ) ;
218
222
this . activeChannel . off ( `action:${ ElementWidgetActions . CallParticipants } ` , this . onParticipants ) ;
223
+ this . matrixClient . getRoom ( roomId ) . off ( RoomEvent . MyMembership , this . onMyMembership ) ;
219
224
window . removeEventListener ( "beforeunload" , this . setDisconnected ) ;
220
225
221
- const roomId = this . roomId ;
222
226
this . activeChannel = null ;
223
227
this . roomId = null ;
224
228
this . connected = false ;
@@ -242,6 +246,8 @@ export default class VideoChannelStore extends AsyncStoreWithClient<null> {
242
246
243
247
private updateDevices = async ( roomId : string , fn : ( devices : string [ ] ) => string [ ] ) => {
244
248
const room = this . matrixClient . getRoom ( roomId ) ;
249
+ if ( room . getMyMembership ( ) !== "join" ) return ;
250
+
245
251
const devicesState = room . currentState . getStateEvents ( VIDEO_CHANNEL_MEMBER , this . matrixClient . getUserId ( ) ) ;
246
252
const devices = devicesState ?. getContent < IVideoChannelMemberContent > ( ) ?. devices ?? [ ] ;
247
253
@@ -280,4 +286,8 @@ export default class VideoChannelStore extends AsyncStoreWithClient<null> {
280
286
this . videoMuted = false ;
281
287
this . ack ( ev ) ;
282
288
} ;
289
+
290
+ private onMyMembership = ( room : Room , membership : string ) => {
291
+ if ( membership !== "join" ) this . setDisconnected ( ) ;
292
+ } ;
283
293
}
0 commit comments