@@ -26,7 +26,6 @@ export enum BeaconEvent {
2626}
2727
2828export type BeaconEventHandlerMap = {
29- [ BeaconEvent . New ] : ( event : MatrixEvent , beacon : Beacon ) => void ;
3029 [ BeaconEvent . Update ] : ( event : MatrixEvent , beacon : Beacon ) => void ;
3130 [ BeaconEvent . LivenessChange ] : ( isLive : boolean , beacon : Beacon ) => void ;
3231} ;
@@ -42,9 +41,9 @@ export const isBeaconInfoEventType = (type: string) =>
4241 type . startsWith ( M_BEACON_INFO . altName ) ;
4342
4443// https://github.com/matrix-org/matrix-spec-proposals/pull/3489
45- export class Beacon extends TypedEventEmitter < BeaconEvent , BeaconEventHandlerMap > {
44+ export class Beacon extends TypedEventEmitter < Exclude < BeaconEvent , BeaconEvent . New > , BeaconEventHandlerMap > {
4645 public readonly roomId : string ;
47- private beaconInfo : BeaconInfoState ;
46+ private _beaconInfo : BeaconInfoState ;
4847 private _isLive : boolean ;
4948 private livenessWatchInterval : number ;
5049
@@ -54,7 +53,6 @@ export class Beacon extends TypedEventEmitter<BeaconEvent, BeaconEventHandlerMap
5453 super ( ) ;
5554 this . setBeaconInfo ( this . rootEvent ) ;
5655 this . roomId = this . rootEvent . getRoomId ( ) ;
57- this . emit ( BeaconEvent . New , this . rootEvent , this ) ;
5856 }
5957
6058 public get isLive ( ) : boolean {
@@ -69,6 +67,14 @@ export class Beacon extends TypedEventEmitter<BeaconEvent, BeaconEventHandlerMap
6967 return this . rootEvent . getStateKey ( ) ;
7068 }
7169
70+ public get beaconInfoEventType ( ) : string {
71+ return this . rootEvent . getType ( ) ;
72+ }
73+
74+ public get beaconInfo ( ) : BeaconInfoState {
75+ return this . _beaconInfo ;
76+ }
77+
7278 public update ( beaconInfoEvent : MatrixEvent ) : void {
7379 if ( beaconInfoEvent . getId ( ) !== this . beaconInfoId ) {
7480 throw new Error ( 'Invalid updating event' ) ;
@@ -95,22 +101,22 @@ export class Beacon extends TypedEventEmitter<BeaconEvent, BeaconEventHandlerMap
95101 }
96102
97103 if ( this . isLive ) {
98- const expiryInMs = ( this . beaconInfo ?. timestamp + this . beaconInfo ?. timeout + 1 ) - Date . now ( ) ;
104+ const expiryInMs = ( this . _beaconInfo ?. timestamp + this . _beaconInfo ?. timeout + 1 ) - Date . now ( ) ;
99105 if ( expiryInMs > 1 ) {
100106 this . livenessWatchInterval = setInterval ( this . checkLiveness . bind ( this ) , expiryInMs ) ;
101107 }
102108 }
103109 }
104110
105111 private setBeaconInfo ( event : MatrixEvent ) : void {
106- this . beaconInfo = parseBeaconInfoContent ( event . getContent ( ) ) ;
112+ this . _beaconInfo = parseBeaconInfoContent ( event . getContent ( ) ) ;
107113 this . checkLiveness ( ) ;
108114 }
109115
110116 private checkLiveness ( ) : void {
111117 const prevLiveness = this . isLive ;
112- this . _isLive = this . beaconInfo ?. live &&
113- isTimestampInDuration ( this . beaconInfo ?. timestamp , this . beaconInfo ?. timeout , Date . now ( ) ) ;
118+ this . _isLive = this . _beaconInfo ?. live &&
119+ isTimestampInDuration ( this . _beaconInfo ?. timestamp , this . _beaconInfo ?. timeout , Date . now ( ) ) ;
114120
115121 if ( prevLiveness !== this . isLive ) {
116122 this . emit ( BeaconEvent . LivenessChange , this . isLive , this ) ;
0 commit comments