@@ -84,7 +84,7 @@ export class RoomState extends TypedEventEmitter<EmittedEvents, EventHandlerMap>
8484 public paginationToken : string = null ;
8585
8686 public readonly beacons = new Map < BeaconIdentifier , Beacon > ( ) ;
87- private liveBeaconIds : BeaconIdentifier [ ] = [ ] ;
87+ private _liveBeaconIds : BeaconIdentifier [ ] = [ ] ;
8888
8989 /**
9090 * Construct room state.
@@ -251,6 +251,10 @@ export class RoomState extends TypedEventEmitter<EmittedEvents, EventHandlerMap>
251251 return ! ! this . liveBeaconIds ?. length ;
252252 }
253253
254+ public get liveBeaconIds ( ) : BeaconIdentifier [ ] {
255+ return this . _liveBeaconIds ;
256+ }
257+
254258 /**
255259 * Creates a copy of this room state so that mutations to either won't affect the other.
256260 * @return {RoomState } the copy of the room state
@@ -502,26 +506,22 @@ export class RoomState extends TypedEventEmitter<EmittedEvents, EventHandlerMap>
502506
503507 this . emit ( BeaconEvent . New , event , beacon ) ;
504508 beacon . on ( BeaconEvent . LivenessChange , this . onBeaconLivenessChange . bind ( this ) ) ;
509+ beacon . on ( BeaconEvent . Destroy , this . onBeaconLivenessChange . bind ( this ) ) ;
505510
506511 this . beacons . set ( beacon . identifier , beacon ) ;
507512 }
508513
509514 /**
510515 * @experimental
511516 * Check liveness of room beacons
512- * emit RoomStateEvent.BeaconLiveness when
513- * roomstate.hasLiveBeacons has changed
517+ * emit RoomStateEvent.BeaconLiveness event
514518 */
515519 private onBeaconLivenessChange ( ) : void {
516- const prevHasLiveBeacons = ! ! this . liveBeaconIds ?. length ;
517- this . liveBeaconIds = Array . from ( this . beacons . values ( ) )
520+ this . _liveBeaconIds = Array . from ( this . beacons . values ( ) )
518521 . filter ( beacon => beacon . isLive )
519522 . map ( beacon => beacon . identifier ) ;
520523
521- const hasLiveBeacons = ! ! this . liveBeaconIds . length ;
522- if ( prevHasLiveBeacons !== hasLiveBeacons ) {
523- this . emit ( RoomStateEvent . BeaconLiveness , this , hasLiveBeacons ) ;
524- }
524+ this . emit ( RoomStateEvent . BeaconLiveness , this , this . hasLiveBeacons ) ;
525525 }
526526
527527 private getStateEventMatching ( event : MatrixEvent ) : MatrixEvent | null {
0 commit comments