diff options
Diffstat (limited to 'includes/external/matrix/node_modules/matrix-js-sdk/lib/models/beacon.js.map')
-rw-r--r-- | includes/external/matrix/node_modules/matrix-js-sdk/lib/models/beacon.js.map | 1 |
1 files changed, 0 insertions, 1 deletions
diff --git a/includes/external/matrix/node_modules/matrix-js-sdk/lib/models/beacon.js.map b/includes/external/matrix/node_modules/matrix-js-sdk/lib/models/beacon.js.map deleted file mode 100644 index 15062fb..0000000 --- a/includes/external/matrix/node_modules/matrix-js-sdk/lib/models/beacon.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"beacon.js","names":["_contentHelpers","require","_utils","_typedEventEmitter","BeaconEvent","exports","isTimestampInDuration","startTimestamp","durationMs","timestamp","getBeaconInfoIdentifier","event","getRoomId","getStateKey","Beacon","TypedEventEmitter","constructor","rootEvent","_defineProperty2","default","_latestLocationEvent","undefined","emit","LocationUpdate","latestLocationState","roomId","setBeaconInfo","isLive","_isLive","identifier","beaconInfoId","getId","beaconInfoOwner","beaconInfoEventType","getType","beaconInfo","_beaconInfo","parseBeaconContent","getContent","latestLocationEvent","update","beaconInfoEvent","Error","getTs","Update","clearLatestLocation","destroy","livenessWatchTimeout","clearTimeout","Destroy","monitorLiveness","checkLiveness","expiryInMs","timeout","Date","now","setTimeout","addLocations","beaconLocationEvents","_validLocationEvents$","validLocationEvents","filter","content","parsed","uri","sort","sortEventsByLatestContentTimestamp","parseBeaconInfoContent","prevLiveness","live","LivenessChange"],"sources":["../../src/models/beacon.ts"],"sourcesContent":["/*\nCopyright 2022 The Matrix.org Foundation C.I.C.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport { MBeaconEventContent } from \"../@types/beacon\";\nimport { BeaconInfoState, BeaconLocationState, parseBeaconContent, parseBeaconInfoContent } from \"../content-helpers\";\nimport { MatrixEvent } from \"./event\";\nimport { sortEventsByLatestContentTimestamp } from \"../utils\";\nimport { TypedEventEmitter } from \"./typed-event-emitter\";\n\nexport enum BeaconEvent {\n New = \"Beacon.new\",\n Update = \"Beacon.update\",\n LivenessChange = \"Beacon.LivenessChange\",\n Destroy = \"Beacon.Destroy\",\n LocationUpdate = \"Beacon.LocationUpdate\",\n}\n\nexport type BeaconEventHandlerMap = {\n [BeaconEvent.Update]: (event: MatrixEvent, beacon: Beacon) => void;\n [BeaconEvent.LivenessChange]: (isLive: boolean, beacon: Beacon) => void;\n [BeaconEvent.Destroy]: (beaconIdentifier: string) => void;\n [BeaconEvent.LocationUpdate]: (locationState: BeaconLocationState) => void;\n [BeaconEvent.Destroy]: (beaconIdentifier: string) => void;\n};\n\nexport const isTimestampInDuration = (startTimestamp: number, durationMs: number, timestamp: number): boolean =>\n timestamp >= startTimestamp && startTimestamp + durationMs >= timestamp;\n\n// beacon info events are uniquely identified by\n// `<roomId>_<state_key>`\nexport type BeaconIdentifier = string;\nexport const getBeaconInfoIdentifier = (event: MatrixEvent): BeaconIdentifier =>\n `${event.getRoomId()}_${event.getStateKey()}`;\n\n// https://github.com/matrix-org/matrix-spec-proposals/pull/3672\nexport class Beacon extends TypedEventEmitter<Exclude<BeaconEvent, BeaconEvent.New>, BeaconEventHandlerMap> {\n public readonly roomId: string;\n // beaconInfo is assigned by setBeaconInfo in the constructor\n // ! to make tsc believe it is definitely assigned\n private _beaconInfo!: BeaconInfoState;\n private _isLive?: boolean;\n private livenessWatchTimeout?: ReturnType<typeof setTimeout>;\n private _latestLocationEvent?: MatrixEvent;\n\n public constructor(private rootEvent: MatrixEvent) {\n super();\n this.roomId = this.rootEvent.getRoomId()!;\n this.setBeaconInfo(this.rootEvent);\n }\n\n public get isLive(): boolean {\n return !!this._isLive;\n }\n\n public get identifier(): BeaconIdentifier {\n return getBeaconInfoIdentifier(this.rootEvent);\n }\n\n public get beaconInfoId(): string {\n return this.rootEvent.getId()!;\n }\n\n public get beaconInfoOwner(): string {\n return this.rootEvent.getStateKey()!;\n }\n\n public get beaconInfoEventType(): string {\n return this.rootEvent.getType();\n }\n\n public get beaconInfo(): BeaconInfoState {\n return this._beaconInfo;\n }\n\n public get latestLocationState(): BeaconLocationState | undefined {\n return this._latestLocationEvent && parseBeaconContent(this._latestLocationEvent.getContent());\n }\n\n public get latestLocationEvent(): MatrixEvent | undefined {\n return this._latestLocationEvent;\n }\n\n public update(beaconInfoEvent: MatrixEvent): void {\n if (getBeaconInfoIdentifier(beaconInfoEvent) !== this.identifier) {\n throw new Error(\"Invalid updating event\");\n }\n // don't update beacon with an older event\n if (beaconInfoEvent.getTs() < this.rootEvent.getTs()) {\n return;\n }\n this.rootEvent = beaconInfoEvent;\n this.setBeaconInfo(this.rootEvent);\n\n this.emit(BeaconEvent.Update, beaconInfoEvent, this);\n this.clearLatestLocation();\n }\n\n public destroy(): void {\n if (this.livenessWatchTimeout) {\n clearTimeout(this.livenessWatchTimeout);\n }\n\n this._isLive = false;\n this.emit(BeaconEvent.Destroy, this.identifier);\n }\n\n /**\n * Monitor liveness of a beacon\n * Emits BeaconEvent.LivenessChange when beacon expires\n */\n public monitorLiveness(): void {\n if (this.livenessWatchTimeout) {\n clearTimeout(this.livenessWatchTimeout);\n }\n\n this.checkLiveness();\n if (!this.beaconInfo) return;\n if (this.isLive) {\n const expiryInMs = this.beaconInfo.timestamp! + this.beaconInfo.timeout - Date.now();\n if (expiryInMs > 1) {\n this.livenessWatchTimeout = setTimeout(() => {\n this.monitorLiveness();\n }, expiryInMs);\n }\n } else if (this.beaconInfo.timestamp! > Date.now()) {\n // beacon start timestamp is in the future\n // check liveness again then\n this.livenessWatchTimeout = setTimeout(() => {\n this.monitorLiveness();\n }, this.beaconInfo.timestamp! - Date.now());\n }\n }\n\n /**\n * Process Beacon locations\n * Emits BeaconEvent.LocationUpdate\n */\n public addLocations(beaconLocationEvents: MatrixEvent[]): void {\n // discard locations for beacons that are not live\n if (!this.isLive) {\n return;\n }\n\n const validLocationEvents = beaconLocationEvents.filter((event) => {\n const content = event.getContent<MBeaconEventContent>();\n const parsed = parseBeaconContent(content);\n if (!parsed.uri || !parsed.timestamp) return false; // we won't be able to process these\n const { timestamp } = parsed;\n return (\n this._beaconInfo.timestamp &&\n // only include positions that were taken inside the beacon's live period\n isTimestampInDuration(this._beaconInfo.timestamp, this._beaconInfo.timeout, timestamp) &&\n // ignore positions older than our current latest location\n (!this.latestLocationState || timestamp > this.latestLocationState.timestamp!)\n );\n });\n const latestLocationEvent = validLocationEvents.sort(sortEventsByLatestContentTimestamp)?.[0];\n\n if (latestLocationEvent) {\n this._latestLocationEvent = latestLocationEvent;\n this.emit(BeaconEvent.LocationUpdate, this.latestLocationState!);\n }\n }\n\n private clearLatestLocation = (): void => {\n this._latestLocationEvent = undefined;\n this.emit(BeaconEvent.LocationUpdate, this.latestLocationState!);\n };\n\n private setBeaconInfo(event: MatrixEvent): void {\n this._beaconInfo = parseBeaconInfoContent(event.getContent());\n this.checkLiveness();\n }\n\n private checkLiveness(): void {\n const prevLiveness = this.isLive;\n\n // element web sets a beacon's start timestamp to the senders local current time\n // when Alice's system clock deviates slightly from Bob's a beacon Alice intended to be live\n // may have a start timestamp in the future from Bob's POV\n // handle this by adding 6min of leniency to the start timestamp when it is in the future\n if (!this.beaconInfo) return;\n const startTimestamp =\n this.beaconInfo.timestamp! > Date.now()\n ? this.beaconInfo.timestamp! - 360000 /* 6min */\n : this.beaconInfo.timestamp;\n this._isLive =\n !!this._beaconInfo.live &&\n !!startTimestamp &&\n isTimestampInDuration(startTimestamp, this._beaconInfo.timeout, Date.now());\n\n if (prevLiveness !== this.isLive) {\n this.emit(BeaconEvent.LivenessChange, this.isLive, this);\n }\n }\n}\n"],"mappings":";;;;;;;;AAiBA,IAAAA,eAAA,GAAAC,OAAA;AAEA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