@@ -25,6 +25,7 @@ import {
2525 BeaconInfoState , makeBeaconContent , makeBeaconInfoContent ,
2626} from "matrix-js-sdk/src/content-helpers" ;
2727import { M_BEACON } from "matrix-js-sdk/src/@types/beacon" ;
28+ import { logger } from "matrix-js-sdk/src/logger" ;
2829
2930import defaultDispatcher from "../dispatcher/dispatcher" ;
3031import { ActionPayload } from "../dispatcher/payloads" ;
@@ -63,10 +64,11 @@ export class OwnBeaconStore extends AsyncStoreWithClient<OwnBeaconStoreState> {
6364 private geolocationError : GeolocationError | undefined ;
6465 private clearPositionWatch : ClearWatchCallback | undefined ;
6566 /**
66- * Track the last published position and when it was published
67- * so it can be republished while the user is static
67+ * Track when the last position was published
68+ * So we can manually get position on slow interval
69+ * when the target is status
6870 */
69- private lastPublishedPosition : { position : TimedGeoUri , publishedTimestamp : number } | undefined ;
71+ private lastPublishedPositionTimestamp : number | undefined ;
7072
7173 public constructor ( ) {
7274 super ( defaultDispatcher ) ;
@@ -241,13 +243,12 @@ export class OwnBeaconStore extends AsyncStoreWithClient<OwnBeaconStoreState> {
241243 this . clearPositionWatch = await watchPosition ( this . onWatchedPosition , this . onWatchedPositionError ) ;
242244
243245 this . locationInterval = setInterval ( ( ) => {
244- if ( ! this . lastPublishedPosition ) {
246+ if ( ! this . lastPublishedPositionTimestamp ) {
245247 return ;
246248 }
247- const { publishedTimestamp } = this . lastPublishedPosition ;
248249 // if position was last updated STATIC_UPDATE_INTERVAL ms ago or more
249250 // get our position and publish it
250- if ( publishedTimestamp <= Date . now ( ) - STATIC_UPDATE_INTERVAL ) {
251+ if ( this . lastPublishedPositionTimestamp <= Date . now ( ) - STATIC_UPDATE_INTERVAL ) {
251252 this . publishCurrentLocationToBeacons ( ) ;
252253 }
253254 } , STATIC_UPDATE_INTERVAL ) ;
@@ -257,7 +258,7 @@ export class OwnBeaconStore extends AsyncStoreWithClient<OwnBeaconStoreState> {
257258 const timedGeoPosition = mapGeolocationPositionToTimedGeo ( position ) ;
258259
259260 // if this is our first position, publish immediateley
260- if ( ! this . lastPublishedPosition ) {
261+ if ( ! this . lastPublishedPositionTimestamp ) {
261262 this . publishLocationToBeacons ( timedGeoPosition ) ;
262263 } else {
263264 this . debouncedPublishLocationToBeacons ( timedGeoPosition ) ;
@@ -266,13 +267,13 @@ export class OwnBeaconStore extends AsyncStoreWithClient<OwnBeaconStoreState> {
266267
267268 private onWatchedPositionError = ( error : GeolocationError ) => {
268269 this . geolocationError = error ;
269- console . log ( this . geolocationError ) ;
270+ logger . error ( this . geolocationError ) ;
270271 } ;
271272
272273 private stopPollingLocation = ( ) => {
273274 clearInterval ( this . locationInterval ) ;
274275 this . locationInterval = undefined ;
275- this . lastPublishedPosition = undefined ;
276+ this . lastPublishedPositionTimestamp = undefined ;
276277 this . geolocationError = undefined ;
277278
278279 if ( this . clearPositionWatch ) {
@@ -286,7 +287,7 @@ export class OwnBeaconStore extends AsyncStoreWithClient<OwnBeaconStoreState> {
286287 * Sets last published beacon
287288 */
288289 private publishLocationToBeacons = async ( position : TimedGeoUri ) => {
289- this . lastPublishedPosition = { position , publishedTimestamp : Date . now ( ) } ;
290+ this . lastPublishedPositionTimestamp = Date . now ( ) ;
290291 // TODO handle failure in individual beacon without rejecting rest
291292 await Promise . all ( this . liveBeaconIds . map ( beaconId =>
292293 this . sendLocationToBeacon ( this . beacons . get ( beaconId ) , position ) ) ,
0 commit comments