@@ -48,15 +48,17 @@ export const getBeaconInfoIdentifier = (event: MatrixEvent): BeaconIdentifier =>
48
48
// https://github.com/matrix-org/matrix-spec-proposals/pull/3672
49
49
export class Beacon extends TypedEventEmitter < Exclude < BeaconEvent , BeaconEvent . New > , BeaconEventHandlerMap > {
50
50
public readonly roomId : string ;
51
- private _beaconInfo ?: BeaconInfoState ;
51
+ // beaconInfo is assigned by setBeaconInfo in the constructor
52
+ // ! to make tsc believe it is definitely assigned
53
+ private _beaconInfo ! : BeaconInfoState ;
52
54
private _isLive ?: boolean ;
53
55
private livenessWatchTimeout ?: ReturnType < typeof setTimeout > ;
54
56
private _latestLocationEvent ?: MatrixEvent ;
55
57
56
58
public constructor ( private rootEvent : MatrixEvent ) {
57
59
super ( ) ;
58
- this . setBeaconInfo ( this . rootEvent ) ;
59
60
this . roomId = this . rootEvent . getRoomId ( ) ! ;
61
+ this . setBeaconInfo ( this . rootEvent ) ;
60
62
}
61
63
62
64
public get isLive ( ) : boolean {
@@ -79,7 +81,7 @@ export class Beacon extends TypedEventEmitter<Exclude<BeaconEvent, BeaconEvent.N
79
81
return this . rootEvent . getType ( ) ;
80
82
}
81
83
82
- public get beaconInfo ( ) : BeaconInfoState | undefined {
84
+ public get beaconInfo ( ) : BeaconInfoState {
83
85
return this . _beaconInfo ;
84
86
}
85
87
@@ -158,9 +160,9 @@ export class Beacon extends TypedEventEmitter<Exclude<BeaconEvent, BeaconEvent.N
158
160
if ( ! parsed . uri || ! parsed . timestamp ) return false ; // we won't be able to process these
159
161
const { timestamp } = parsed ;
160
162
return (
161
- this . _beaconInfo ! . timestamp &&
163
+ this . _beaconInfo . timestamp &&
162
164
// only include positions that were taken inside the beacon's live period
163
- isTimestampInDuration ( this . _beaconInfo ! . timestamp , this . _beaconInfo ! . timeout , timestamp ) &&
165
+ isTimestampInDuration ( this . _beaconInfo . timestamp , this . _beaconInfo . timeout , timestamp ) &&
164
166
// ignore positions older than our current latest location
165
167
( ! this . latestLocationState || timestamp > this . latestLocationState . timestamp ! )
166
168
) ;
@@ -196,9 +198,9 @@ export class Beacon extends TypedEventEmitter<Exclude<BeaconEvent, BeaconEvent.N
196
198
? this . beaconInfo . timestamp ! - 360000 /* 6min */
197
199
: this . beaconInfo . timestamp ;
198
200
this . _isLive =
199
- ! ! this . _beaconInfo ? .live &&
201
+ ! ! this . _beaconInfo . live &&
200
202
! ! startTimestamp &&
201
- isTimestampInDuration ( startTimestamp , this . _beaconInfo ? .timeout , Date . now ( ) ) ;
203
+ isTimestampInDuration ( startTimestamp , this . _beaconInfo . timeout , Date . now ( ) ) ;
202
204
203
205
if ( prevLiveness !== this . isLive ) {
204
206
this . emit ( BeaconEvent . LivenessChange , this . isLive , this ) ;
0 commit comments