@fluidframework/presence 2.80.0 → 2.81.0-374083
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/getPresence.js +2 -2
- package/dist/getPresence.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.d.ts.map +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/presenceDatastoreManager.d.ts.map +1 -1
- package/dist/presenceDatastoreManager.js +6 -5
- package/dist/presenceDatastoreManager.js.map +1 -1
- package/dist/presenceManager.js +1 -1
- package/dist/presenceManager.js.map +1 -1
- package/dist/systemWorkspace.js +1 -1
- package/dist/systemWorkspace.js.map +1 -1
- package/lib/getPresence.js +2 -2
- package/lib/getPresence.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.d.ts.map +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/presenceDatastoreManager.d.ts.map +1 -1
- package/lib/presenceDatastoreManager.js +6 -5
- package/lib/presenceDatastoreManager.js.map +1 -1
- package/lib/presenceManager.js +1 -1
- package/lib/presenceManager.js.map +1 -1
- package/lib/systemWorkspace.js +1 -1
- package/lib/systemWorkspace.js.map +1 -1
- package/package.json +21 -21
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"systemWorkspace.js","sourceRoot":"","sources":["../src/systemWorkspace.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAIH,kEAA6D;AAK7D,yDAAsD;AAEtD,+CAA+C;AAE/C,uDAAiD;AAsBjD,MAAM,aAAa;IAGlB,YACiB,UAAsB;IACtC;;;OAGG;IACI,QAAgB,CAAC,EACjB,eAA+C,SAAS;QAN/C,eAAU,GAAV,UAAU,CAAY;QAK/B,UAAK,GAAL,KAAK,CAAY;QACjB,iBAAY,GAAZ,YAAY,CAA4C;QATxD,qBAAgB,GAAmB,4BAAc,CAAC,YAAY,C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,CACpC,UAAsB,EACtB,SAAmC,EACnC,MAA+D,EAC/D,QAAmB;IAQnB,MAAM,SAAS,GAAG,IAAI,mBAAmB,CAAC,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;IACnF,OAAO;QACN,SAAS;QACT,WAAW,EAAE;YACZ,QAAQ,EAAE,SAAS;YACnB,MAAM,EAAE,SAA2D;SACnE;KACD,CAAC;AACH,CAAC;AApBD,sDAoBC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { IAudience } from \"@fluidframework/container-definitions\";\nimport type { IEmitter, Listenable } from \"@fluidframework/core-interfaces/internal\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\n\nimport type { ClientConnectionId } from \"./baseTypes.js\";\nimport type { InternalTypes } from \"./exposedInternalTypes.js\";\nimport type { PostUpdateAction } from \"./internalTypes.js\";\nimport { revealOpaqueJson } from \"./internalUtils.js\";\nimport type { Attendee, AttendeesEvents, AttendeeId, Presence } from \"./presence.js\";\nimport { AttendeeStatus } from \"./presence.js\";\nimport type { PresenceStatesInternal } from \"./presenceStates.js\";\nimport { TimerManager } from \"./timerManager.js\";\nimport type { AnyWorkspace, StatesWorkspaceSchema } from \"./types.js\";\n\n/**\n * `ConnectionValueState` is known value state for `clientToSessionId` data.\n *\n * @remarks\n * It is {@link InternalTypes.ValueRequiredState} with a known value type.\n */\ninterface ConnectionValueState extends InternalTypes.ValueStateMetadata {\n\tvalue: AttendeeId;\n}\n\n/**\n * The system workspace's datastore structure.\n */\nexport interface SystemWorkspaceDatastore {\n\tclientToSessionId: {\n\t\t[ConnectionId: ClientConnectionId]: ConnectionValueState;\n\t};\n}\n\nclass SessionClient implements Attendee {\n\tprivate connectionStatus: AttendeeStatus = AttendeeStatus.Disconnected;\n\n\tpublic constructor(\n\t\tpublic readonly attendeeId: AttendeeId,\n\t\t/**\n\t\t * Order is used to track the most recent client connection\n\t\t * during a session.\n\t\t */\n\t\tpublic order: number = 0,\n\t\tpublic connectionId: ClientConnectionId | undefined = undefined,\n\t) {}\n\n\tpublic getConnectionId(): ClientConnectionId {\n\t\tif (this.connectionId === undefined) {\n\t\t\tthrow new Error(\"Client has never been connected\");\n\t\t}\n\t\treturn this.connectionId;\n\t}\n\n\tpublic getConnectionStatus(): AttendeeStatus {\n\t\treturn this.connectionStatus;\n\t}\n\n\tpublic setConnected(): void {\n\t\tthis.connectionStatus = AttendeeStatus.Connected;\n\t}\n\n\tpublic setDisconnected(): void {\n\t\tthis.connectionStatus = AttendeeStatus.Disconnected;\n\t}\n}\n\n/**\n * Internal workspace that manages metadata for session attendees.\n */\nexport interface SystemWorkspace\n\t// Portion of Presence that is handled by SystemWorkspace along with\n\t// responsibility for emitting \"attendeeConnected\" events.\n\textends Exclude<Presence[\"attendees\"], never> {\n\t/**\n\t * Must be called when the current client acquires a new connection.\n\t *\n\t * @param clientConnectionId - The new client connection ID.\n\t * @param audienceOutOfDate - When true, audience cannot be used as authoritative.\n\t */\n\tonConnectionAdded(clientConnectionId: ClientConnectionId, audienceOutOfDate: boolean): void;\n\n\t/**\n\t * Removes the client connection ID from the system workspace.\n\t *\n\t * @param clientConnectionId - The client connection ID to remove.\n\t */\n\tremoveClientConnectionId(clientConnectionId: ClientConnectionId): void;\n}\n\nclass SystemWorkspaceImpl implements PresenceStatesInternal, SystemWorkspace {\n\tprivate readonly selfAttendee: SessionClient;\n\t/**\n\t * `attendees` is this client's understanding of the attendees in the\n\t * session. The map covers entries for both session ids and connection\n\t * ids, which are never expected to collide, but if they did for same\n\t * client that would be fine.\n\t * An entry is for session ID if the value's `attendeeId` matches the key.\n\t */\n\tprivate readonly attendees = new Map<ClientConnectionId | AttendeeId, SessionClient>();\n\n\t// When local client disconnects, we lose the connectivity status updates for remote attendees in the session.\n\t// Upon reconnect, we mark all other attendees connections as stale and update their status to disconnected after 30 seconds of inactivity.\n\tprivate readonly staleConnectionClients = new Set<SessionClient>();\n\n\tprivate readonly staleConnectionTimer = new TimerManager();\n\n\tpublic constructor(\n\t\tattendeeId: AttendeeId,\n\t\tprivate readonly datastore: SystemWorkspaceDatastore,\n\t\tpublic readonly events: Listenable<AttendeesEvents> & IEmitter<AttendeesEvents>,\n\t\tprivate readonly audience: IAudience,\n\t) {\n\t\tthis.selfAttendee = new SessionClient(attendeeId);\n\t\tthis.attendees.set(attendeeId, this.selfAttendee);\n\t}\n\n\tpublic ensureContent<TSchemaAdditional extends StatesWorkspaceSchema>(\n\t\t_content: TSchemaAdditional,\n\t): never {\n\t\tthrow new Error(\"Method not implemented.\");\n\t}\n\n\tpublic processUpdate(\n\t\t_received: number,\n\t\t_timeModifier: number,\n\t\t/**\n\t\t * Remote datastore typed to match {@link PresenceStatesInternal.processUpdate}'s\n\t\t * `ValueUpdateRecord` type that uses {@link InternalTypes.ValueRequiredState}\n\t\t * and expects an Opaque JSON type. (We get away with a non-`unknown` value type\n\t\t * per TypeScript's method parameter bivariance.) Proper type would be\n\t\t * {@link ConnectionValueState} directly.\n\t\t * {@link ClientConnectionId} use for index is also a deviation, but conveniently\n\t\t * the accurate {@link AttendeeId} type is just a branded string, and\n\t\t * {@link ClientConnectionId} is just `string`.\n\t\t */\n\t\tremoteDatastore: {\n\t\t\tclientToSessionId: {\n\t\t\t\t[ConnectionId: ClientConnectionId]: InternalTypes.ValueRequiredState<\n\t\t\t\t\tConnectionValueState[\"value\"]\n\t\t\t\t>;\n\t\t\t};\n\t\t},\n\t\tsenderConnectionId: ClientConnectionId,\n\t): PostUpdateAction[] {\n\t\tconst audienceMembers = this.audience.getMembers();\n\t\tconst postUpdateActions: PostUpdateAction[] = [];\n\t\tfor (const [clientConnectionId, value] of Object.entries(\n\t\t\trevealOpaqueJson(remoteDatastore.clientToSessionId),\n\t\t)) {\n\t\t\tconst attendeeId = value.value;\n\t\t\tconst { attendee, isJoining } = this.ensureAttendee({\n\t\t\t\tattendeeId,\n\t\t\t\tclientConnectionId,\n\t\t\t\torder: value.rev,\n\t\t\t\tisSender: senderConnectionId === clientConnectionId,\n\t\t\t\tisInAudience: audienceMembers.has(clientConnectionId),\n\t\t\t});\n\t\t\t// If the attendee is joining the session, add them to the list of joining attendees to be announced later.\n\t\t\tif (isJoining) {\n\t\t\t\tpostUpdateActions.push(() => this.events.emit(\"attendeeConnected\", attendee));\n\t\t\t}\n\n\t\t\tconst knownSessionId = this.datastore.clientToSessionId[clientConnectionId];\n\t\t\tif (knownSessionId === undefined) {\n\t\t\t\tthis.datastore.clientToSessionId[clientConnectionId] = value;\n\t\t\t} else {\n\t\t\t\tassert(knownSessionId.value === value.value, 0xa5a /* Mismatched SessionId */);\n\t\t\t}\n\t\t}\n\n\t\treturn postUpdateActions;\n\t}\n\n\tpublic onConnectionAdded(\n\t\tclientConnectionId: ClientConnectionId,\n\t\taudienceOutOfDate: boolean,\n\t): void {\n\t\tassert(\n\t\t\tthis.selfAttendee.getConnectionStatus() === AttendeeStatus.Disconnected,\n\t\t\t0xaad /* Local client should be 'Disconnected' before adding new connection. */,\n\t\t);\n\n\t\tconst selfInAudience = this.audience.getMember(clientConnectionId) !== undefined;\n\t\tassert(\n\t\t\tselfInAudience || audienceOutOfDate,\n\t\t\t\"Local client must be in audience for presence to handle added connection.\",\n\t\t);\n\n\t\tif (!(clientConnectionId in this.datastore.clientToSessionId)) {\n\t\t\tthis.datastore.clientToSessionId[clientConnectionId] = {\n\t\t\t\trev: this.selfAttendee.order++,\n\t\t\t\ttimestamp: Date.now(),\n\t\t\t\tvalue: this.selfAttendee.attendeeId,\n\t\t\t};\n\t\t}\n\n\t\t// Update the self attendee connection information, but not connection\n\t\t// status yet. Connection status is updated once self is in audience -\n\t\t// see later. It is only once our connection is known to audience that\n\t\t// audience can be used to track other attendees' connection statuses\n\t\t// and we seek to present a consistent view locally.\n\t\tthis.selfAttendee.connectionId = clientConnectionId;\n\t\tthis.attendees.set(clientConnectionId, this.selfAttendee);\n\n\t\tif (selfInAudience) {\n\t\t\t// Mark 'Connected' remote attendees connections as stale\n\t\t\t// Performance note: This will visit attendees multiple times as the\n\t\t\t// attendee map has attendeeIds and connectionIds entries that point to\n\t\t\t// the same attendee. But the getConnectionStatus check is cheap and\n\t\t\t// staleConnectionClients.add will handle duplicates.\n\t\t\tthis.staleConnectionClients.clear();\n\t\t\tfor (const staleConnectionClient of this.attendees.values()) {\n\t\t\t\tif (staleConnectionClient.getConnectionStatus() === AttendeeStatus.Connected) {\n\t\t\t\t\tthis.staleConnectionClients.add(staleConnectionClient);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tthis.staleConnectionTimer.setTimeout(this.resolveStaleConnections.bind(this), 30_000);\n\n\t\t\tthis.selfAttendee.setConnected();\n\t\t\t// TODO: AB#56686: self-Attendee never announced as Connected - Emit this event once there are tests in place\n\t\t\t// this.events.emit(\"attendeeConnected\", this.selfAttendee);\n\t\t}\n\t}\n\n\tprivate resolveStaleConnections(): void {\n\t\tconst consideredDisconnected = [];\n\t\tfor (const client of this.staleConnectionClients) {\n\t\t\t// Confirm that audience no longer has connection. It is possible\n\t\t\t// but unlikely that no one mentioned the attendee in this period\n\t\t\t// and that they were never disconnected.\n\t\t\tif (this.audience.getMember(client.getConnectionId()) === undefined) {\n\t\t\t\tconsideredDisconnected.push(client);\n\t\t\t\tclient.setDisconnected();\n\t\t\t}\n\t\t}\n\t\tfor (const client of consideredDisconnected) {\n\t\t\tthis.events.emit(\"attendeeDisconnected\", client);\n\t\t}\n\t\tthis.staleConnectionClients.clear();\n\t}\n\n\tpublic removeClientConnectionId(clientConnectionId: ClientConnectionId): void {\n\t\tconst attendee = this.attendees.get(clientConnectionId);\n\t\tif (!attendee) {\n\t\t\treturn;\n\t\t}\n\n\t\t// If the local connection is being removed, clear the stale connection timer\n\t\tif (attendee === this.selfAttendee) {\n\t\t\tthis.staleConnectionTimer.clearTimeout();\n\t\t} else {\n\t\t\t// When self is not connected, audience may go through a refresh that\n\t\t\t// removes members and adds them back. Defer any removals until self\n\t\t\t// is connected implying audience is stable.\n\t\t\tif (this.selfAttendee.getConnectionStatus() !== AttendeeStatus.Connected) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\t// If the last known connectionID is different from the connection ID being removed, the attendee has reconnected,\n\t\t// therefore we should not change the attendee connection status or emit a disconnect event.\n\t\tconst attendeeReconnected = attendee.getConnectionId() !== clientConnectionId;\n\t\tconst connected = attendee.getConnectionStatus() === AttendeeStatus.Connected;\n\t\tif (!attendeeReconnected && connected) {\n\t\t\tattendee.setDisconnected();\n\t\t\tthis.events.emit(\"attendeeDisconnected\", attendee);\n\t\t\tthis.staleConnectionClients.delete(attendee);\n\t\t}\n\t}\n\n\tpublic getAttendees(): ReadonlySet<Attendee> {\n\t\treturn new Set(this.attendees.values());\n\t}\n\n\tpublic getAttendee(clientId: ClientConnectionId | AttendeeId): Attendee {\n\t\tconst attendee = this.attendees.get(clientId);\n\t\tif (attendee) {\n\t\t\treturn attendee;\n\t\t}\n\n\t\t// TODO: Restore option to add attendee on demand to handle internal\n\t\t// lookup cases that must come from internal data.\n\t\t// There aren't any resiliency mechanisms in place to handle a missed\n\t\t// ClientJoin right now.\n\t\tthrow new Error(\"Attendee not found\");\n\t}\n\n\tpublic getMyself(): Attendee {\n\t\treturn this.selfAttendee;\n\t}\n\n\t/**\n\t * Make sure the given client session and connection ID pair are represented\n\t * in the attendee map. If not present, SessionClient is created and added\n\t * to map. If present, make sure the current connection ID is updated.\n\t */\n\tprivate ensureAttendee({\n\t\tattendeeId,\n\t\tclientConnectionId,\n\t\torder,\n\t\tisSender,\n\t\tisInAudience,\n\t}: {\n\t\tattendeeId: AttendeeId;\n\t\tclientConnectionId: ClientConnectionId;\n\t\torder: number;\n\t\tisSender: boolean;\n\t\tisInAudience: boolean;\n\t}): { attendee: SessionClient; isJoining: boolean } {\n\t\tlet attendee = this.attendees.get(attendeeId);\n\t\tlet isConnected = false;\n\t\tlet isJoining = false;\n\n\t\tif (attendee === undefined) {\n\t\t\t// New attendee. Create SessionClient and add session ID based\n\t\t\t// entry to map.\n\t\t\tattendee = new SessionClient(attendeeId, order, clientConnectionId);\n\t\t\tthis.attendees.set(attendeeId, attendee);\n\t\t\t// If the attendee update is from the sending remote client itself\n\t\t\t// OR if the attendee is present in audience,\n\t\t\t// then the attendee is considered connected. (Otherwise, leave\n\t\t\t// state as disconnected - default.)\n\t\t\tif (isSender || isInAudience) {\n\t\t\t\tisConnected = true;\n\t\t\t\tattendee.setConnected();\n\t\t\t\tisJoining = true;\n\t\t\t}\n\t\t} else {\n\t\t\t// Known attendee is considered connected if\n\t\t\tisConnected =\n\t\t\t\t// this information is at least up to date with current knowledge\n\t\t\t\torder >= attendee.order &&\n\t\t\t\t// AND in the audience OR\n\t\t\t\t(isInAudience ||\n\t\t\t\t\t// not in audience, but client is the sender and has newer\n\t\t\t\t\t// info. (Assume that audience is out of date and attendee\n\t\t\t\t\t// is joining.)\n\t\t\t\t\t(isSender && order > attendee.order));\n\n\t\t\tif (order > attendee.order) {\n\t\t\t\t// The given association is newer than the one we have.\n\t\t\t\t// Update the order and current connection ID.\n\t\t\t\tattendee.order = order;\n\t\t\t\tattendee.connectionId = clientConnectionId;\n\t\t\t}\n\n\t\t\t// Known attendee is joining the session if they are currently disconnected.\n\t\t\tif (isConnected && attendee.getConnectionStatus() === AttendeeStatus.Disconnected) {\n\t\t\t\tattendee.setConnected();\n\t\t\t\tisJoining = true;\n\t\t\t}\n\t\t}\n\n\t\tif (isConnected) {\n\t\t\t// If the attendee is connected, remove them from the stale connection set\n\t\t\tthis.staleConnectionClients.delete(attendee);\n\t\t}\n\n\t\t// Always update entry for the connection ID. (Okay if already set.)\n\t\tthis.attendees.set(clientConnectionId, attendee);\n\n\t\treturn { attendee, isJoining };\n\t}\n}\n\n/**\n * Instantiates the system workspace.\n */\nexport function createSystemWorkspace(\n\tattendeeId: AttendeeId,\n\tdatastore: SystemWorkspaceDatastore,\n\tevents: Listenable<AttendeesEvents> & IEmitter<AttendeesEvents>,\n\taudience: IAudience,\n): {\n\tworkspace: SystemWorkspace;\n\tstatesEntry: {\n\t\tinternal: PresenceStatesInternal;\n\t\tpublic: AnyWorkspace<StatesWorkspaceSchema>;\n\t};\n} {\n\tconst workspace = new SystemWorkspaceImpl(attendeeId, datastore, events, audience);\n\treturn {\n\t\tworkspace,\n\t\tstatesEntry: {\n\t\t\tinternal: workspace,\n\t\t\tpublic: undefined as unknown as AnyWorkspace<StatesWorkspaceSchema>,\n\t\t},\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"systemWorkspace.js","sourceRoot":"","sources":["../src/systemWorkspace.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAIH,kEAA6D;AAK7D,yDAAsD;AAEtD,+CAA+C;AAE/C,uDAAiD;AAsBjD,MAAM,aAAa;IAGlB,YACiB,UAAsB;IACtC;;;OAGG;IACI,QAAgB,CAAC,EACjB,eAA+C,SAAS;QAN/C,eAAU,GAAV,UAAU,CAAY;QAK/B,UAAK,GAAL,KAAK,CAAY;QACjB,iBAAY,GAAZ,YAAY,CAA4C;QATxD,qBAAgB,GAAmB,4BAAc,CAAC,YAAY,CAAC;IAUpE,CAAC;IAEG,eAAe;QACrB,IAAI,IAAI,CAAC,YAAY,KAAK,SAAS,EAAE,CAAC;YACrC,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;QACpD,CAAC;QACD,OAAO,IAAI,CAAC,YAAY,CAAC;IAC1B,CAAC;IAEM,mBAAmB;QACzB,OAAO,IAAI,CAAC,gBAAgB,CAAC;IAC9B,CAAC;IAEM,YAAY;QAClB,IAAI,CAAC,gBAAgB,GAAG,4BAAc,CAAC,SAAS,CAAC;IAClD,CAAC;IAEM,eAAe;QACrB,IAAI,CAAC,gBAAgB,GAAG,4BAAc,CAAC,YAAY,CAAC;IACrD,CAAC;CACD;AAyBD,MAAM,mBAAmB;IAiBxB,YACC,UAAsB,EACL,SAAmC,EACpC,MAA+D,EAC9D,QAAmB;QAFnB,cAAS,GAAT,SAAS,CAA0B;QACp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C,IAAI,KAAK,GAAG,QAAQ,CAAC,KAAK,EAAE,CAAC;gBAC5B,uDAAuD;gBACvD,8CAA8C;gBAC9C,QAAQ,CAAC,KAAK,GAAG,KAAK,CAAC;gBACvB,QAAQ,CAAC,YAAY,GAAG,kBAAkB,CAAC;YAC5C,CAAC;YAED,4EAA4E;YAC5E,IAAI,WAAW,IAAI,QAAQ,CAAC,mBAAmB,EAAE,KAAK,4BAAc,CAAC,YAAY,EAAE,CAAC;gBACnF,QAAQ,CAAC,YAAY,EAAE,CAAC;gBACxB,SAAS,GAAG,IAAI,CAAC;YAClB,CAAC;QACF,CAAC;QAED,IAAI,WAAW,EAAE,CAAC;YACjB,0EAA0E;YAC1E,IAAI,CAAC,sBAAsB,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAC9C,CAAC;QAED,oEAAoE;QACpE,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,kBAAkB,EAAE,QAAQ,CAAC,CAAC;QAEjD,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC;IAChC,CAAC;CACD;AAED;;GAEG;AACH,SAAgB,qBAAqB,CACpC,UAAsB,EACtB,SAAmC,EACnC,MAA+D,EAC/D,QAAmB;IAQnB,MAAM,SAAS,GAAG,IAAI,mBAAmB,CAAC,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;IACnF,OAAO;QACN,SAAS;QACT,WAAW,EAAE;YACZ,QAAQ,EAAE,SAAS;YACnB,MAAM,EAAE,SAA2D;SACnE;KACD,CAAC;AACH,CAAC;AApBD,sDAoBC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { IAudience } from \"@fluidframework/container-definitions\";\nimport type { IEmitter, Listenable } from \"@fluidframework/core-interfaces/internal\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\n\nimport type { ClientConnectionId } from \"./baseTypes.js\";\nimport type { InternalTypes } from \"./exposedInternalTypes.js\";\nimport type { PostUpdateAction } from \"./internalTypes.js\";\nimport { revealOpaqueJson } from \"./internalUtils.js\";\nimport type { Attendee, AttendeesEvents, AttendeeId, Presence } from \"./presence.js\";\nimport { AttendeeStatus } from \"./presence.js\";\nimport type { PresenceStatesInternal } from \"./presenceStates.js\";\nimport { TimerManager } from \"./timerManager.js\";\nimport type { AnyWorkspace, StatesWorkspaceSchema } from \"./types.js\";\n\n/**\n * `ConnectionValueState` is known value state for `clientToSessionId` data.\n *\n * @remarks\n * It is {@link InternalTypes.ValueRequiredState} with a known value type.\n */\ninterface ConnectionValueState extends InternalTypes.ValueStateMetadata {\n\tvalue: AttendeeId;\n}\n\n/**\n * The system workspace's datastore structure.\n */\nexport interface SystemWorkspaceDatastore {\n\tclientToSessionId: {\n\t\t[ConnectionId: ClientConnectionId]: ConnectionValueState;\n\t};\n}\n\nclass SessionClient implements Attendee {\n\tprivate connectionStatus: AttendeeStatus = AttendeeStatus.Disconnected;\n\n\tpublic constructor(\n\t\tpublic readonly attendeeId: AttendeeId,\n\t\t/**\n\t\t * Order is used to track the most recent client connection\n\t\t * during a session.\n\t\t */\n\t\tpublic order: number = 0,\n\t\tpublic connectionId: ClientConnectionId | undefined = undefined,\n\t) {}\n\n\tpublic getConnectionId(): ClientConnectionId {\n\t\tif (this.connectionId === undefined) {\n\t\t\tthrow new Error(\"Client has never been connected\");\n\t\t}\n\t\treturn this.connectionId;\n\t}\n\n\tpublic getConnectionStatus(): AttendeeStatus {\n\t\treturn this.connectionStatus;\n\t}\n\n\tpublic setConnected(): void {\n\t\tthis.connectionStatus = AttendeeStatus.Connected;\n\t}\n\n\tpublic setDisconnected(): void {\n\t\tthis.connectionStatus = AttendeeStatus.Disconnected;\n\t}\n}\n\n/**\n * Internal workspace that manages metadata for session attendees.\n */\nexport interface SystemWorkspace\n\t// Portion of Presence that is handled by SystemWorkspace along with\n\t// responsibility for emitting \"attendeeConnected\" events.\n\textends Exclude<Presence[\"attendees\"], never> {\n\t/**\n\t * Must be called when the current client acquires a new connection.\n\t *\n\t * @param clientConnectionId - The new client connection ID.\n\t * @param audienceOutOfDate - When true, audience cannot be used as authoritative.\n\t */\n\tonConnectionAdded(clientConnectionId: ClientConnectionId, audienceOutOfDate: boolean): void;\n\n\t/**\n\t * Removes the client connection ID from the system workspace.\n\t *\n\t * @param clientConnectionId - The client connection ID to remove.\n\t */\n\tremoveClientConnectionId(clientConnectionId: ClientConnectionId): void;\n}\n\nclass SystemWorkspaceImpl implements PresenceStatesInternal, SystemWorkspace {\n\tprivate readonly selfAttendee: SessionClient;\n\t/**\n\t * `attendees` is this client's understanding of the attendees in the\n\t * session. The map covers entries for both session ids and connection\n\t * ids, which are never expected to collide, but if they did for same\n\t * client that would be fine.\n\t * An entry is for session ID if the value's `attendeeId` matches the key.\n\t */\n\tprivate readonly attendees = new Map<ClientConnectionId | AttendeeId, SessionClient>();\n\n\t// When local client disconnects, we lose the connectivity status updates for remote attendees in the session.\n\t// Upon reconnect, we mark all other attendees connections as stale and update their status to disconnected after 30 seconds of inactivity.\n\tprivate readonly staleConnectionClients = new Set<SessionClient>();\n\n\tprivate readonly staleConnectionTimer = new TimerManager();\n\n\tpublic constructor(\n\t\tattendeeId: AttendeeId,\n\t\tprivate readonly datastore: SystemWorkspaceDatastore,\n\t\tpublic readonly events: Listenable<AttendeesEvents> & IEmitter<AttendeesEvents>,\n\t\tprivate readonly audience: IAudience,\n\t) {\n\t\tthis.selfAttendee = new SessionClient(attendeeId);\n\t\tthis.attendees.set(attendeeId, this.selfAttendee);\n\t}\n\n\tpublic ensureContent<TSchemaAdditional extends StatesWorkspaceSchema>(\n\t\t_content: TSchemaAdditional,\n\t): never {\n\t\tthrow new Error(\"Method not implemented.\");\n\t}\n\n\tpublic processUpdate(\n\t\t_received: number,\n\t\t_timeModifier: number,\n\t\t/**\n\t\t * Remote datastore typed to match {@link PresenceStatesInternal.processUpdate}'s\n\t\t * `ValueUpdateRecord` type that uses {@link InternalTypes.ValueRequiredState}\n\t\t * and expects an Opaque JSON type. (We get away with a non-`unknown` value type\n\t\t * per TypeScript's method parameter bivariance.) Proper type would be\n\t\t * {@link ConnectionValueState} directly.\n\t\t * {@link ClientConnectionId} use for index is also a deviation, but conveniently\n\t\t * the accurate {@link AttendeeId} type is just a branded string, and\n\t\t * {@link ClientConnectionId} is just `string`.\n\t\t */\n\t\tremoteDatastore: {\n\t\t\tclientToSessionId: {\n\t\t\t\t[ConnectionId: ClientConnectionId]: InternalTypes.ValueRequiredState<\n\t\t\t\t\tConnectionValueState[\"value\"]\n\t\t\t\t>;\n\t\t\t};\n\t\t},\n\t\tsenderConnectionId: ClientConnectionId,\n\t): PostUpdateAction[] {\n\t\tconst audienceMembers = this.audience.getMembers();\n\t\tconst postUpdateActions: PostUpdateAction[] = [];\n\t\tfor (const [clientConnectionId, value] of Object.entries(\n\t\t\trevealOpaqueJson(remoteDatastore.clientToSessionId),\n\t\t)) {\n\t\t\tconst attendeeId = value.value;\n\t\t\tconst { attendee, isJoining } = this.ensureAttendee({\n\t\t\t\tattendeeId,\n\t\t\t\tclientConnectionId,\n\t\t\t\torder: value.rev,\n\t\t\t\tisSender: senderConnectionId === clientConnectionId,\n\t\t\t\tisInAudience: audienceMembers.has(clientConnectionId),\n\t\t\t});\n\t\t\t// If the attendee is joining the session, add them to the list of joining attendees to be announced later.\n\t\t\tif (isJoining) {\n\t\t\t\tpostUpdateActions.push(() => this.events.emit(\"attendeeConnected\", attendee));\n\t\t\t}\n\n\t\t\tconst knownSessionId = this.datastore.clientToSessionId[clientConnectionId];\n\t\t\tif (knownSessionId === undefined) {\n\t\t\t\tthis.datastore.clientToSessionId[clientConnectionId] = value;\n\t\t\t} else {\n\t\t\t\tassert(knownSessionId.value === value.value, 0xa5a /* Mismatched SessionId */);\n\t\t\t}\n\t\t}\n\n\t\treturn postUpdateActions;\n\t}\n\n\tpublic onConnectionAdded(\n\t\tclientConnectionId: ClientConnectionId,\n\t\taudienceOutOfDate: boolean,\n\t): void {\n\t\tassert(\n\t\t\tthis.selfAttendee.getConnectionStatus() === AttendeeStatus.Disconnected,\n\t\t\t0xaad /* Local client should be 'Disconnected' before adding new connection. */,\n\t\t);\n\n\t\tconst selfInAudience = this.audience.getMember(clientConnectionId) !== undefined;\n\t\tassert(\n\t\t\tselfInAudience || audienceOutOfDate,\n\t\t\t0xcc0 /* Local client must be in audience for presence to handle added connection. */,\n\t\t);\n\n\t\tif (!(clientConnectionId in this.datastore.clientToSessionId)) {\n\t\t\tthis.datastore.clientToSessionId[clientConnectionId] = {\n\t\t\t\trev: this.selfAttendee.order++,\n\t\t\t\ttimestamp: Date.now(),\n\t\t\t\tvalue: this.selfAttendee.attendeeId,\n\t\t\t};\n\t\t}\n\n\t\t// Update the self attendee connection information, but not connection\n\t\t// status yet. Connection status is updated once self is in audience -\n\t\t// see later. It is only once our connection is known to audience that\n\t\t// audience can be used to track other attendees' connection statuses\n\t\t// and we seek to present a consistent view locally.\n\t\tthis.selfAttendee.connectionId = clientConnectionId;\n\t\tthis.attendees.set(clientConnectionId, this.selfAttendee);\n\n\t\tif (selfInAudience) {\n\t\t\t// Mark 'Connected' remote attendees connections as stale\n\t\t\t// Performance note: This will visit attendees multiple times as the\n\t\t\t// attendee map has attendeeIds and connectionIds entries that point to\n\t\t\t// the same attendee. But the getConnectionStatus check is cheap and\n\t\t\t// staleConnectionClients.add will handle duplicates.\n\t\t\tthis.staleConnectionClients.clear();\n\t\t\tfor (const staleConnectionClient of this.attendees.values()) {\n\t\t\t\tif (staleConnectionClient.getConnectionStatus() === AttendeeStatus.Connected) {\n\t\t\t\t\tthis.staleConnectionClients.add(staleConnectionClient);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tthis.staleConnectionTimer.setTimeout(this.resolveStaleConnections.bind(this), 30_000);\n\n\t\t\tthis.selfAttendee.setConnected();\n\t\t\t// TODO: AB#56686: self-Attendee never announced as Connected - Emit this event once there are tests in place\n\t\t\t// this.events.emit(\"attendeeConnected\", this.selfAttendee);\n\t\t}\n\t}\n\n\tprivate resolveStaleConnections(): void {\n\t\tconst consideredDisconnected = [];\n\t\tfor (const client of this.staleConnectionClients) {\n\t\t\t// Confirm that audience no longer has connection. It is possible\n\t\t\t// but unlikely that no one mentioned the attendee in this period\n\t\t\t// and that they were never disconnected.\n\t\t\tif (this.audience.getMember(client.getConnectionId()) === undefined) {\n\t\t\t\tconsideredDisconnected.push(client);\n\t\t\t\tclient.setDisconnected();\n\t\t\t}\n\t\t}\n\t\tfor (const client of consideredDisconnected) {\n\t\t\tthis.events.emit(\"attendeeDisconnected\", client);\n\t\t}\n\t\tthis.staleConnectionClients.clear();\n\t}\n\n\tpublic removeClientConnectionId(clientConnectionId: ClientConnectionId): void {\n\t\tconst attendee = this.attendees.get(clientConnectionId);\n\t\tif (!attendee) {\n\t\t\treturn;\n\t\t}\n\n\t\t// If the local connection is being removed, clear the stale connection timer\n\t\tif (attendee === this.selfAttendee) {\n\t\t\tthis.staleConnectionTimer.clearTimeout();\n\t\t} else {\n\t\t\t// When self is not connected, audience may go through a refresh that\n\t\t\t// removes members and adds them back. Defer any removals until self\n\t\t\t// is connected implying audience is stable.\n\t\t\tif (this.selfAttendee.getConnectionStatus() !== AttendeeStatus.Connected) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\t// If the last known connectionID is different from the connection ID being removed, the attendee has reconnected,\n\t\t// therefore we should not change the attendee connection status or emit a disconnect event.\n\t\tconst attendeeReconnected = attendee.getConnectionId() !== clientConnectionId;\n\t\tconst connected = attendee.getConnectionStatus() === AttendeeStatus.Connected;\n\t\tif (!attendeeReconnected && connected) {\n\t\t\tattendee.setDisconnected();\n\t\t\tthis.events.emit(\"attendeeDisconnected\", attendee);\n\t\t\tthis.staleConnectionClients.delete(attendee);\n\t\t}\n\t}\n\n\tpublic getAttendees(): ReadonlySet<Attendee> {\n\t\treturn new Set(this.attendees.values());\n\t}\n\n\tpublic getAttendee(clientId: ClientConnectionId | AttendeeId): Attendee {\n\t\tconst attendee = this.attendees.get(clientId);\n\t\tif (attendee) {\n\t\t\treturn attendee;\n\t\t}\n\n\t\t// TODO: Restore option to add attendee on demand to handle internal\n\t\t// lookup cases that must come from internal data.\n\t\t// There aren't any resiliency mechanisms in place to handle a missed\n\t\t// ClientJoin right now.\n\t\tthrow new Error(\"Attendee not found\");\n\t}\n\n\tpublic getMyself(): Attendee {\n\t\treturn this.selfAttendee;\n\t}\n\n\t/**\n\t * Make sure the given client session and connection ID pair are represented\n\t * in the attendee map. If not present, SessionClient is created and added\n\t * to map. If present, make sure the current connection ID is updated.\n\t */\n\tprivate ensureAttendee({\n\t\tattendeeId,\n\t\tclientConnectionId,\n\t\torder,\n\t\tisSender,\n\t\tisInAudience,\n\t}: {\n\t\tattendeeId: AttendeeId;\n\t\tclientConnectionId: ClientConnectionId;\n\t\torder: number;\n\t\tisSender: boolean;\n\t\tisInAudience: boolean;\n\t}): { attendee: SessionClient; isJoining: boolean } {\n\t\tlet attendee = this.attendees.get(attendeeId);\n\t\tlet isConnected = false;\n\t\tlet isJoining = false;\n\n\t\tif (attendee === undefined) {\n\t\t\t// New attendee. Create SessionClient and add session ID based\n\t\t\t// entry to map.\n\t\t\tattendee = new SessionClient(attendeeId, order, clientConnectionId);\n\t\t\tthis.attendees.set(attendeeId, attendee);\n\t\t\t// If the attendee update is from the sending remote client itself\n\t\t\t// OR if the attendee is present in audience,\n\t\t\t// then the attendee is considered connected. (Otherwise, leave\n\t\t\t// state as disconnected - default.)\n\t\t\tif (isSender || isInAudience) {\n\t\t\t\tisConnected = true;\n\t\t\t\tattendee.setConnected();\n\t\t\t\tisJoining = true;\n\t\t\t}\n\t\t} else {\n\t\t\t// Known attendee is considered connected if\n\t\t\tisConnected =\n\t\t\t\t// this information is at least up to date with current knowledge\n\t\t\t\torder >= attendee.order &&\n\t\t\t\t// AND in the audience OR\n\t\t\t\t(isInAudience ||\n\t\t\t\t\t// not in audience, but client is the sender and has newer\n\t\t\t\t\t// info. (Assume that audience is out of date and attendee\n\t\t\t\t\t// is joining.)\n\t\t\t\t\t(isSender && order > attendee.order));\n\n\t\t\tif (order > attendee.order) {\n\t\t\t\t// The given association is newer than the one we have.\n\t\t\t\t// Update the order and current connection ID.\n\t\t\t\tattendee.order = order;\n\t\t\t\tattendee.connectionId = clientConnectionId;\n\t\t\t}\n\n\t\t\t// Known attendee is joining the session if they are currently disconnected.\n\t\t\tif (isConnected && attendee.getConnectionStatus() === AttendeeStatus.Disconnected) {\n\t\t\t\tattendee.setConnected();\n\t\t\t\tisJoining = true;\n\t\t\t}\n\t\t}\n\n\t\tif (isConnected) {\n\t\t\t// If the attendee is connected, remove them from the stale connection set\n\t\t\tthis.staleConnectionClients.delete(attendee);\n\t\t}\n\n\t\t// Always update entry for the connection ID. (Okay if already set.)\n\t\tthis.attendees.set(clientConnectionId, attendee);\n\n\t\treturn { attendee, isJoining };\n\t}\n}\n\n/**\n * Instantiates the system workspace.\n */\nexport function createSystemWorkspace(\n\tattendeeId: AttendeeId,\n\tdatastore: SystemWorkspaceDatastore,\n\tevents: Listenable<AttendeesEvents> & IEmitter<AttendeesEvents>,\n\taudience: IAudience,\n): {\n\tworkspace: SystemWorkspace;\n\tstatesEntry: {\n\t\tinternal: PresenceStatesInternal;\n\t\tpublic: AnyWorkspace<StatesWorkspaceSchema>;\n\t};\n} {\n\tconst workspace = new SystemWorkspaceImpl(attendeeId, datastore, events, audience);\n\treturn {\n\t\tworkspace,\n\t\tstatesEntry: {\n\t\t\tinternal: workspace,\n\t\t\tpublic: undefined as unknown as AnyWorkspace<StatesWorkspaceSchema>,\n\t\t},\n\t};\n}\n"]}
|
package/lib/getPresence.js
CHANGED
|
@@ -45,7 +45,7 @@ class ContainerPresenceManager {
|
|
|
45
45
|
assertCompatibilityInvariants(newCompatibilityRequest);
|
|
46
46
|
// There have not yet been any changes that would require action to upgrade.
|
|
47
47
|
// But also mixed runtime versions are not yet expected.
|
|
48
|
-
fail(
|
|
48
|
+
fail(0xcb1 /* Presence is only expected to be accessed with a single version. */);
|
|
49
49
|
}
|
|
50
50
|
onNewUse() {
|
|
51
51
|
// No-op
|
|
@@ -66,7 +66,7 @@ const ContainerPresenceFactory = {
|
|
|
66
66
|
assertCompatibilityInvariants(existingInstantiation.compatibility);
|
|
67
67
|
// There have not yet been any changes that would require action to upgrade.
|
|
68
68
|
// But also mixed runtime versions are not yet expected.
|
|
69
|
-
fail(
|
|
69
|
+
fail(0xcb2 /* Presence is only expected to be accessed with a single version. */);
|
|
70
70
|
},
|
|
71
71
|
instantiateExtension(host) {
|
|
72
72
|
return new ContainerPresenceManager(host);
|
package/lib/getPresence.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getPresence.js","sourceRoot":"","sources":["../src/getPresence.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAUH,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,qCAAqC,CAAC;AAEnE,OAAO,EAAE,wBAAwB,EAAE,MAAM,uCAAuC,CAAC;AAQjF,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAGjD,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAG7D,MAAM,qBAAqB,GAAG;IAC7B,UAAU,EAAE,CAAC;IACb,OAAO,EAAE,UAAU;IACnB,YAAY,EAAE,IAAI,GAAG,CAAC,EAAE,CAAC;CACwB,CAAC;AAEnD;;;;;GAKG;AACH,MAAM,+BAA+B,GAAG,QAAQ,CAAC;AAEjD,SAAS,6BAA6B,CAAC,aAA4C;IAClF,MAAM,CACL,aAAa,CAAC,UAAU,KAAK,qBAAqB,CAAC,UAAU,EAC7D,KAAK,CAAC,iDAAiD,CACvD,CAAC;IACF,MAAM,CACL,aAAa,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,EACtC,KAAK,CAAC,gDAAgD,CACtD,CAAC;IACF,MAAM,CACL,MAAM,CAAC,UAAU,CAAC,aAAa,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,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;AAED,SAAS,iCAAiC,CACzC,OAA+B;IAE/B,MAAM,CACL,cAAc,IAAI,OAAO,EACzB,KAAK,CAAC,sEAAsE,CAC5E,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,+BAA+B,CAAC,OAA+B;IAC9E,iCAAiC,CAAC,OAAO,CAAC,CAAC;IAC3C,OAAO,OAAO,CAAC,YAAY,CAAC,WAAW,EAAE,wBAAwB,CAAC,CAAC;AACpE,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { ILayerCompatSupportRequirements } from \"@fluid-internal/client-utils\";\nimport type {\n\tContainerExtension,\n\tContainerExtensionFactory,\n\tExtensionInstantiationResult,\n\tExtensionRuntimeProperties as GenericExtensionRuntimeProperties,\n\tInboundExtensionMessage,\n} from \"@fluidframework/container-runtime-definitions/internal\";\nimport { assert, fail } from \"@fluidframework/core-utils/internal\";\nimport type { IFluidContainer } from \"@fluidframework/fluid-static\";\nimport { isInternalFluidContainer } from \"@fluidframework/fluid-static/internal\";\nimport type {\n\tExtensionCompatibilityDetails,\n\tFluidDataStoreContextInternal,\n\tIFluidDataStoreContext,\n} from \"@fluidframework/runtime-definitions/internal\";\n\nimport type { ExtensionHost, ExtensionRuntimeProperties } from \"./internalTypes.js\";\nimport { pkgVersion } from \"./packageVersion.js\";\nimport type { Presence, PresenceWithNotifications } from \"./presence.js\";\nimport type { PresenceExtensionInterface } from \"./presenceManager.js\";\nimport { createPresenceManager } from \"./presenceManager.js\";\nimport type { SignalMessages } from \"./protocol.js\";\n\nconst presenceCompatibility = {\n\tgeneration: 1,\n\tversion: pkgVersion,\n\tcapabilities: new Set([]),\n} as const satisfies ExtensionCompatibilityDetails;\n\n/**\n * Minimal compatible package version.\n * If an existing presence extension is registered with this version or higher,\n * it can be used instead of instantiating new instance from this version of\n * the package (assuming also capabilities are compatible).\n */\nconst minimalCompatiblePackageVersion = \"2.71.0\";\n\nfunction assertCompatibilityInvariants(compatibility: ExtensionCompatibilityDetails): void {\n\tassert(\n\t\tcompatibility.generation === presenceCompatibility.generation,\n\t\t0xc97 /* Presence compatibility generation mismatch. */,\n\t);\n\tassert(\n\t\tcompatibility.version.startsWith(\"2.\"),\n\t\t0xc98 /* Registered version is not major version 2. */,\n\t);\n\tassert(\n\t\tNumber.parseFloat(compatibility.version.slice(2)) <\n\t\t\tNumber.parseFloat(presenceCompatibility.version.slice(2)),\n\t\t0xc99 /* Registered version is not less than the current version. */,\n\t);\n\tassert(\n\t\tpresenceCompatibility.capabilities.size === 0,\n\t\t0xc9a /* Presence capabilities should be empty. */,\n\t);\n}\n\n/**\n * Common Presence manager for a container\n */\nclass ContainerPresenceManager\n\timplements\n\t\tContainerExtension<ExtensionRuntimeProperties>,\n\t\tReturnType<\n\t\t\tContainerExtensionFactory<\n\t\t\t\tPresenceWithNotifications,\n\t\t\t\tExtensionRuntimeProperties\n\t\t\t>[\"instantiateExtension\"]\n\t\t>\n{\n\t// ContainerExtensionFactory return elements\n\tpublic readonly compatibility = presenceCompatibility;\n\tpublic readonly interface: PresenceWithNotifications;\n\tpublic readonly extension = this;\n\n\tprivate readonly manager: PresenceExtensionInterface;\n\n\tpublic constructor(host: ExtensionHost) {\n\t\tthis.interface = this.manager = createPresenceManager({\n\t\t\t...host,\n\t\t\tsubmitSignal: (message) => {\n\t\t\t\thost.submitAddressedSignal([], message);\n\t\t\t},\n\t\t});\n\t}\n\n\tpublic handleVersionOrCapabilitiesMismatch<_TRequestedInterface>(\n\t\tourExistingInstantiation: Readonly<\n\t\t\tExtensionInstantiationResult<PresenceWithNotifications, ExtensionRuntimeProperties, []>\n\t\t>,\n\t\tnewCompatibilityRequest: ExtensionCompatibilityDetails,\n\t): never {\n\t\tassert(\n\t\t\tourExistingInstantiation.compatibility === presenceCompatibility,\n\t\t\t0xc9b /* Presence extension called without own compatibility details */,\n\t\t);\n\t\tassertCompatibilityInvariants(newCompatibilityRequest);\n\t\t// There have not yet been any changes that would require action to upgrade.\n\t\t// But also mixed runtime versions are not yet expected.\n\t\tfail(0xcb1 /* Presence is only expected to be accessed with a single version. */);\n\t}\n\n\tpublic onNewUse(): void {\n\t\t// No-op\n\t}\n\n\tpublic processSignal(\n\t\taddressChain: string[],\n\t\tmessage: InboundExtensionMessage<SignalMessages>,\n\t\tlocal: boolean,\n\t): void {\n\t\tthis.manager.processSignal(addressChain, message, local);\n\t}\n}\n\nconst extensionId = \"dis:bb89f4c0-80fd-4f0c-8469-4f2848ee7f4a\";\n\nconst ContainerPresenceFactory = {\n\thostRequirements: {\n\t\tminSupportedGeneration: 1,\n\t\trequiredFeatures: [],\n\t} as const satisfies ILayerCompatSupportRequirements,\n\n\tinstanceExpectations: { ...presenceCompatibility, version: minimalCompatiblePackageVersion },\n\n\tresolvePriorInstantiation(\n\t\texistingInstantiation: ExtensionInstantiationResult<\n\t\t\tunknown,\n\t\t\tGenericExtensionRuntimeProperties,\n\t\t\tunknown[]\n\t\t>,\n\t): never {\n\t\t// Validate assumptions about existing instance\n\t\tassertCompatibilityInvariants(existingInstantiation.compatibility);\n\t\t// There have not yet been any changes that would require action to upgrade.\n\t\t// But also mixed runtime versions are not yet expected.\n\t\tfail(0xcb2 /* Presence is only expected to be accessed with a single version. */);\n\t},\n\n\tinstantiateExtension(host: ExtensionHost): ContainerPresenceManager {\n\t\treturn new ContainerPresenceManager(host);\n\t},\n\n\t[Symbol.hasInstance]: (instance: unknown): instance is ContainerPresenceManager => {\n\t\treturn instance instanceof ContainerPresenceManager;\n\t},\n} as const satisfies ContainerExtensionFactory<\n\tPresenceWithNotifications,\n\tExtensionRuntimeProperties\n>;\n\n/**\n * Acquire a {@link Presence} from a Fluid Container\n * @param fluidContainer - Fluid Container to acquire the map from\n * @returns the {@link Presence}\n *\n * @beta\n */\nexport const getPresence: (fluidContainer: IFluidContainer) => Presence = getPresenceAlpha;\n\n/**\n * Acquire a {@link PresenceWithNotifications} from a Fluid Container\n * @param fluidContainer - Fluid Container to acquire the map from\n * @returns the {@link PresenceWithNotifications}\n *\n * @alpha\n */\nexport function getPresenceAlpha(fluidContainer: IFluidContainer): PresenceWithNotifications {\n\tassert(\n\t\tisInternalFluidContainer(fluidContainer),\n\t\t0xa2f /* IFluidContainer was not recognized. Only Containers generated by the Fluid Framework are supported. */,\n\t);\n\tconst presence = fluidContainer.acquireExtension(extensionId, ContainerPresenceFactory);\n\treturn presence;\n}\n\nfunction assertContextHasExtensionProvider(\n\tcontext: IFluidDataStoreContext,\n): asserts context is FluidDataStoreContextInternal {\n\tassert(\n\t\t\"getExtension\" in context,\n\t\t0xc9c /* Data store context does not implement ContainerExtensionProvider */,\n\t);\n}\n\n/**\n * Get {@link Presence} from a Fluid Data Store Context\n *\n * @legacy @alpha\n */\nexport function getPresenceFromDataStoreContext(context: IFluidDataStoreContext): Presence {\n\tassertContextHasExtensionProvider(context);\n\treturn context.getExtension(extensionId, ContainerPresenceFactory);\n}\n"]}
|
package/lib/packageVersion.d.ts
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
|
|
6
6
|
*/
|
|
7
7
|
export declare const pkgName = "@fluidframework/presence";
|
|
8
|
-
export declare const pkgVersion = "2.
|
|
8
|
+
export declare const pkgVersion = "2.81.0-374083";
|
|
9
9
|
//# sourceMappingURL=packageVersion.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,6BAA6B,CAAC;AAClD,eAAO,MAAM,UAAU,
|
|
1
|
+
{"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,6BAA6B,CAAC;AAClD,eAAO,MAAM,UAAU,kBAAkB,CAAC"}
|
package/lib/packageVersion.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,0BAA0B,CAAC;AAClD,MAAM,CAAC,MAAM,UAAU,GAAG,
|
|
1
|
+
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,0BAA0B,CAAC;AAClD,MAAM,CAAC,MAAM,UAAU,GAAG,eAAe,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/presence\";\nexport const pkgVersion = \"2.81.0-374083\";\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"presenceDatastoreManager.d.ts","sourceRoot":"","sources":["../src/presenceDatastoreManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,wDAAwD,CAAC;AACtG,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0CAA0C,CAAC;AAEzE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0CAA0C,CAAC;AAEpF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAEvE,OAAO,KAAK,EACX,iBAAiB,EAEjB,wBAAwB,EACxB,yBAAyB,EAEzB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,KAAK,EACX,UAAU,EACV,yBAAyB,IAAI,QAAQ,EACrC,cAAc,EACd,MAAM,eAAe,CAAC;AAC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AK,EAAE,OAAO,EACd,QAAQ,EAAE,OAAO,GACf,IAAI;IAyJP;;;OAGG;IACH,OAAO,CAAC,QAAQ,CAAC,6BAA6B,CAsB5C;IAEF;;;;;;;;;;OAUG;IACH,OAAO,CAAC,mBAAmB;CAqG3B"}
|
|
@@ -184,7 +184,7 @@ export class PresenceDatastoreManagerImpl {
|
|
|
184
184
|
// When self is not represented, audience is an unreliable state,
|
|
185
185
|
// especially during a reconnect. An alternateProvider is expected
|
|
186
186
|
// to have been provided for this call to be useful (efficient).
|
|
187
|
-
assert(alternateProvider !== undefined,
|
|
187
|
+
assert(alternateProvider !== undefined, 0xcba /* Self is not in audience and no alternateProvider given */);
|
|
188
188
|
}
|
|
189
189
|
// Broadcast join message to all clients
|
|
190
190
|
// Select primary update providers
|
|
@@ -232,6 +232,7 @@ export class PresenceDatastoreManagerImpl {
|
|
|
232
232
|
return existing.internal.ensureContent(requestedContent, controls);
|
|
233
233
|
}
|
|
234
234
|
let workspaceDatastore = this.datastore[internalWorkspaceAddress];
|
|
235
|
+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- using ??= could change behavior if value is falsy
|
|
235
236
|
if (workspaceDatastore === undefined) {
|
|
236
237
|
workspaceDatastore = this.datastore[internalWorkspaceAddress] = {};
|
|
237
238
|
}
|
|
@@ -319,7 +320,7 @@ export class PresenceDatastoreManagerImpl {
|
|
|
319
320
|
const currentClientToSessionValueState =
|
|
320
321
|
// When connected, `clientToSessionId` must always have current connection entry.
|
|
321
322
|
this.datastore["system:presence"].clientToSessionId[clientConnectionId];
|
|
322
|
-
assert(currentClientToSessionValueState !== undefined,
|
|
323
|
+
assert(currentClientToSessionValueState !== undefined, 0xcbb /* Client connection update missing */);
|
|
323
324
|
const newMessage = {
|
|
324
325
|
sendTimestamp: Date.now(),
|
|
325
326
|
avgLatency: this.averageLatency,
|
|
@@ -440,7 +441,7 @@ export class PresenceDatastoreManagerImpl {
|
|
|
440
441
|
processSignal(message, local, optional) {
|
|
441
442
|
const received = Date.now();
|
|
442
443
|
if (!isPresenceMessage(message)) {
|
|
443
|
-
assert(optional,
|
|
444
|
+
assert(optional, 0xcbc /* Unrecognized message type in critical message */);
|
|
444
445
|
return;
|
|
445
446
|
}
|
|
446
447
|
if (local) {
|
|
@@ -473,7 +474,7 @@ export class PresenceDatastoreManagerImpl {
|
|
|
473
474
|
const joinResponseFor = message.content.joinResponseFor;
|
|
474
475
|
if (joinResponseFor) {
|
|
475
476
|
const selfClientId = this.runtime.getClientId();
|
|
476
|
-
assert(selfClientId !== undefined,
|
|
477
|
+
assert(selfClientId !== undefined, 0xcbd /* Received signal without clientId */);
|
|
477
478
|
let justGainedCompleteSnapshot = false;
|
|
478
479
|
if (joinResponseFor.includes(selfClientId)) {
|
|
479
480
|
if (this.reasonForCompleteSnapshot) {
|
|
@@ -516,7 +517,7 @@ export class PresenceDatastoreManagerImpl {
|
|
|
516
517
|
}
|
|
517
518
|
// If the message requests an acknowledgement, we will send a targeted acknowledgement message back to just the requestor.
|
|
518
519
|
if (message.content.acknowledgementId !== undefined) {
|
|
519
|
-
assert(this.targetedSignalSupport,
|
|
520
|
+
assert(this.targetedSignalSupport, 0xcbe /* Acknowledgment message was requested while targeted signal capability is not supported */);
|
|
520
521
|
this.runtime.submitSignal({
|
|
521
522
|
type: acknowledgementMessageType,
|
|
522
523
|
content: { id: message.content.acknowledgementId },
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"presenceDatastoreManager.js","sourceRoot":"","sources":["../src/presenceDatastoreManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAa7D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAYnD,OAAO,EACN,oBAAoB,EACpB,uBAAuB,EACvB,mBAAmB,GACnB,MAAM,qBAAqB,CAAC;AAW7B,OAAO,EACN,0BAA0B,EAC1B,0BAA0B,EAC1B,eAAe,GACf,MAAM,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AC;QAED,qEAAqE;QACrE,sEAAsE;QACtE,sEAAsE;QACtE,sDAAsD;QACtD,IAAI,IAAI,CAAC,yBAAyB,IAAI,eAAe,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC;YAC9E,+DAA+D;YAC/D,mEAAmE;YACnE,wEAAwE;YACxE,oEAAoE;YACpE,IAAI,CAAC,cAAc,CAAC,SAAS,EAAE;gBAC9B,wBAAwB,EAAE,mBAAmB;aAC7C,CAAC,CAAC;QACJ,CAAC;aAAM,CAAC;YACP,gEAAgE;YAChE,4CAA4C;YAC5C,IACC,IAAI,CAAC,sBAAsB,CAAC,UAAU,EAAE;gBACxC,YAAY,GAAG,IAAI,CAAC,sBAAsB,CAAC,UAAU,EACpD,CAAC;gBACF,2BAA2B;gBAC3B,IAAI,CAAC,sBAAsB,CAAC,UAAU,CACrC,IAAI,CAAC,6BAA6B,EAClC,mBAAmB,CACnB,CAAC;YACH,CAAC;QACF,CAAC;IACF,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { InboundExtensionMessage } from \"@fluidframework/container-runtime-definitions/internal\";\nimport type { IEmitter } from \"@fluidframework/core-interfaces/internal\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport type { ITelemetryLoggerExt } from \"@fluidframework/telemetry-utils/internal\";\n\nimport type { ClientConnectionId } from \"./baseTypes.js\";\nimport type { BroadcastControlSettings } from \"./broadcastControls.js\";\nimport type { InternalTypes } from \"./exposedInternalTypes.js\";\nimport type {\n\tIEphemeralRuntime,\n\tPostUpdateAction,\n\tValidatableOptionalState,\n\tValidatableValueDirectory,\n\tValidatableValueStructure,\n} from \"./internalTypes.js\";\nimport { objectEntries } from \"./internalUtils.js\";\nimport type {\n\tAttendeeId,\n\tPresenceWithNotifications as Presence,\n\tPresenceEvents,\n} from \"./presence.js\";\nimport type {\n\tClientUpdateEntry,\n\tRuntimeLocalUpdateOptions,\n\tPresenceStatesInternal,\n\tValueElementMap,\n} from \"./presenceStates.js\";\nimport {\n\tcreatePresenceStates,\n\tmergeUntrackedDatastore,\n\tmergeValueDirectory,\n} from \"./presenceStates.js\";\nimport type {\n\tDatastoreMessageContent,\n\tGeneralDatastoreMessageContent,\n\tInboundClientJoinMessage,\n\tInboundDatastoreUpdateMessage,\n\tInternalWorkspaceAddress,\n\tOutboundDatastoreUpdateMessage,\n\tSignalMessages,\n\tSystemDatastore,\n} from \"./protocol.js\";\nimport {\n\tacknowledgementMessageType,\n\tdatastoreUpdateMessageType,\n\tjoinMessageType,\n} from \"./protocol.js\";\nimport type { SystemWorkspaceDatastore } from \"./systemWorkspace.js\";\nimport { TimerManager } from \"./timerManager.js\";\nimport type {\n\tAnyWorkspace,\n\tNotificationsWorkspace,\n\tNotificationsWorkspaceSchema,\n\tStatesWorkspace,\n\tStatesWorkspaceSchema,\n\tWorkspaceAddress,\n} from \"./types.js\";\n\ninterface AnyWorkspaceEntry<TSchema extends StatesWorkspaceSchema> {\n\tpublic: AnyWorkspace<TSchema>;\n\tinternal: PresenceStatesInternal;\n}\n\n/**\n * Datastore structure used for broadcasting to other clients.\n * Validation metadata is stripped before transmission.\n */\ntype PresenceDatastore = SystemDatastore & {\n\t[WorkspaceAddress: InternalWorkspaceAddress]: ValueElementMap<StatesWorkspaceSchema>;\n};\n\nconst internalWorkspaceTypes: Readonly<Record<string, \"States\" | \"Notifications\">> = {\n\ts: \"States\",\n\tn: \"Notifications\",\n} as const;\n\nconst knownMessageTypes = new Set([\n\tjoinMessageType,\n\tdatastoreUpdateMessageType,\n\tacknowledgementMessageType,\n]);\nfunction isPresenceMessage(\n\tmessage: InboundExtensionMessage<SignalMessages>,\n): message is InboundDatastoreUpdateMessage | InboundClientJoinMessage {\n\treturn knownMessageTypes.has(message.type);\n}\n\n/**\n * Type guard to check if a value hierarchy object is a directory (has \"items\"\n * property).\n *\n * @param obj - The object to check\n * @returns True if the object is a {@link ValidatableValueDirectory}\n */\nexport function isValueDirectory<T>(\n\tobj: ValidatableValueDirectory<T> | ValidatableOptionalState<T>,\n): obj is ValidatableValueDirectory<T> {\n\treturn \"items\" in obj;\n}\n\n/**\n * High-level contract for manager of singleton Presence datastore\n */\nexport interface PresenceDatastoreManager {\n\tjoinSession(\n\t\tclientId: ClientConnectionId,\n\t\talternateProvider: ClientConnectionId | undefined,\n\t): void;\n\tonDisconnected(): void;\n\tgetWorkspace<TSchema extends StatesWorkspaceSchema>(\n\t\tinternalWorkspaceAddress: `s:${WorkspaceAddress}`,\n\t\trequestedContent: TSchema,\n\t\tcontrols?: BroadcastControlSettings,\n\t): StatesWorkspace<TSchema>;\n\tgetWorkspace<TSchema extends NotificationsWorkspaceSchema>(\n\t\tinternalWorkspaceAddress: `n:${WorkspaceAddress}`,\n\t\trequestedContent: TSchema,\n\t): NotificationsWorkspace<TSchema>;\n\tprocessSignal(\n\t\tmessage: InboundExtensionMessage<SignalMessages> & { clientId: ClientConnectionId },\n\t\tlocal: boolean,\n\t\toptional: boolean,\n\t): void;\n}\n\nfunction mergeGeneralDatastoreMessageContent(\n\tbase: GeneralDatastoreMessageContent | undefined,\n\tnewData: GeneralDatastoreMessageContent,\n): GeneralDatastoreMessageContent {\n\t// This function-local \"datastore\" will hold the merged message data.\n\tconst queueDatastore = base ?? {};\n\n\t// Merge the current data with the existing data, if any exists.\n\t// Iterate over the current message data; individual items are workspaces.\n\tfor (const [workspaceName, workspaceData] of objectEntries(newData)) {\n\t\t// Initialize the merged data as the queued datastore entry for the workspace.\n\t\t// Since the key might not exist, create an empty object in that case. It will\n\t\t// be set explicitly after the loop.\n\t\tconst mergedData = queueDatastore[workspaceName] ?? {};\n\n\t\t// Iterate over each value manager and its data, merging it as needed.\n\t\tfor (const [valueManagerKey, valueManagerValue] of objectEntries(workspaceData)) {\n\t\t\tfor (const [attendeeId, value] of objectEntries(valueManagerValue)) {\n\t\t\t\tconst mergeObject = (mergedData[valueManagerKey] ??= {});\n\t\t\t\tconst oldData = mergeObject[attendeeId];\n\t\t\t\tmergeObject[attendeeId] = mergeValueDirectory(\n\t\t\t\t\toldData,\n\t\t\t\t\tvalue,\n\t\t\t\t\t0, // local values do not need a time shift\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\t// Store the merged data in the function-local queue workspace. The whole contents of this\n\t\t// datastore will be sent as the message data.\n\t\tqueueDatastore[workspaceName] = mergedData;\n\t}\n\treturn queueDatastore;\n}\n\n/**\n * Delays used for broadcasting join responses to clients.\n *\n * @remarks\n * Exported for test coordination.\n * These could be made customizable in the future to accommodate different\n * session configurations.\n */\nexport const broadcastJoinResponseDelaysMs = {\n\t/**\n\t * The delay in milliseconds before a join response is sent to any client.\n\t * This is used to accumulate other join response requests and reduce\n\t * network traffic.\n\t */\n\tnamedResponder: 200,\n\t/**\n\t * The additional delay in milliseconds a backup responder waits before sending\n\t * a join response to allow others to respond first.\n\t */\n\tbackupResponderIncrement: 40,\n} as const;\n\n/**\n * Manages singleton datastore for all Presence.\n */\nexport class PresenceDatastoreManagerImpl implements PresenceDatastoreManager {\n\tprivate readonly datastore: PresenceDatastore;\n\tprivate averageLatency = 0;\n\tprivate returnedMessages = 0;\n\tprivate readonly sendMessageTimer = new TimerManager();\n\tprivate readonly workspaces = new Map<string, AnyWorkspaceEntry<StatesWorkspaceSchema>>();\n\tprivate readonly targetedSignalSupport: boolean;\n\n\t/**\n\t * Tracks whether this client has complete snapshot level knowledge and\n\t * how that determination was reached.\n\t * - \"alone\": no other audience members detected at join\n\t * - \"join response\": another client has responded to our join request\n\t * - \"full requests\": all others have requested response from us\n\t *\n\t * @remarks\n\t * Only applies when not using targeted join responses.\n\t *\n\t * Without a complete snapshot, we cannot fully onboard any other clients.\n\t * One exception to this is if this client is the only participant in the\n\t * session. In such a case, there is no one to respond to the join request.\n\t * Another exception is multiple clients attempting to join at the same\n\t * time and thus expecting that someone has full knowledge, yet none have\n\t * received a complete update to think they are qualified to respond.\n\t * Generically if the number of outstanding requestors meets or exceeds the\n\t * count of other audience members, then we can consider the snapshot\n\t * complete (as all will have provided their own complete information in\n\t * their join responses).\n\t */\n\tprivate reasonForCompleteSnapshot?: \"alone\" | \"join response\" | \"full requests\";\n\n\t/**\n\t * Map of outstanding broadcast (join response) requests.\n\t */\n\tprivate readonly broadcastRequests = new Map<\n\t\tClientConnectionId,\n\t\t{ deadlineTime: number; responseOrder?: number | undefined }\n\t>();\n\t/**\n\t * Timer for managing broadcast (join response) request timing.\n\t */\n\tprivate readonly broadcastRequestsTimer = new TimerManager();\n\n\tpublic constructor(\n\t\tprivate readonly attendeeId: AttendeeId,\n\t\tprivate readonly runtime: IEphemeralRuntime,\n\t\tprivate readonly logger: ITelemetryLoggerExt | undefined,\n\t\tprivate readonly events: IEmitter<PresenceEvents>,\n\t\tprivate readonly presence: Presence,\n\t\tsystemWorkspaceDatastore: SystemWorkspaceDatastore,\n\t\tsystemWorkspace: AnyWorkspaceEntry<StatesWorkspaceSchema>,\n\t) {\n\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\tthis.datastore = { \"system:presence\": systemWorkspaceDatastore } as PresenceDatastore;\n\t\tthis.workspaces.set(\"system:presence\", systemWorkspace);\n\t\tthis.targetedSignalSupport = this.runtime.supportedFeatures.has(\"submit_signals_v2\");\n\t\t// If audience member is removed, they won't need a broadcast response.\n\t\tthis.runtime.getAudience().on(\"removeMember\", (clientId) => {\n\t\t\tthis.broadcastRequests.delete(clientId);\n\t\t});\n\t}\n\n\tprivate getAudienceInformation(selfClientId: ClientConnectionId): {\n\t\tselfPresent: boolean;\n\t\tinteractiveMembersExcludingSelf: {\n\t\t\tall: Set<ClientConnectionId>;\n\t\t\twriters: Set<ClientConnectionId>;\n\t\t};\n\t} {\n\t\tconst audience = this.runtime.getAudience();\n\t\tconst members = audience.getMembers();\n\t\tconst all = new Set<ClientConnectionId>();\n\t\tconst writers = new Set<ClientConnectionId>();\n\t\tconst selfPresent = members.has(selfClientId);\n\t\tif (selfPresent) {\n\t\t\t// Remove self\n\t\t\tmembers.delete(selfClientId);\n\t\t}\n\t\t// Gather interactive client IDs\n\t\tfor (const [id, client] of members) {\n\t\t\tif (client.details.capabilities.interactive) {\n\t\t\t\tall.add(id);\n\t\t\t\tif (client.mode === \"write\") {\n\t\t\t\t\twriters.add(id);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn {\n\t\t\tselfPresent,\n\t\t\tinteractiveMembersExcludingSelf: {\n\t\t\t\tall,\n\t\t\t\twriters,\n\t\t\t},\n\t\t};\n\t}\n\n\tpublic joinSession(\n\t\tselfClientId: ClientConnectionId,\n\t\talternateProvider: ClientConnectionId | undefined = undefined,\n\t): void {\n\t\t// Before broadcasting the join message, check that there is at least\n\t\t// one audience member present (self or another). This is useful to\n\t\t// optimize join messages while not using targeted join responses.\n\t\t// (We need at least one other to be able to elect them as update\n\t\t// provider.)\n\t\t// Lack of anyone likely means that this client is very freshly joined\n\t\t// and has not received any Join Signals (type=\"join\") from the service\n\t\t// yet.\n\t\tconst { selfPresent, interactiveMembersExcludingSelf } =\n\t\t\tthis.getAudienceInformation(selfClientId);\n\n\t\tif (selfPresent) {\n\t\t\tif (interactiveMembersExcludingSelf.all.size === 0) {\n\t\t\t\t// If there aren't any members connected except self, then this client\n\t\t\t\t// must have complete information.\n\t\t\t\tthis.reasonForCompleteSnapshot = \"alone\";\n\t\t\t\t// It would be possible to return at this time and skip ClientJoin\n\t\t\t\t// signal. Instead continue in case audience information is\n\t\t\t\t// inaccurate. This client might temporarily erroneously believe it\n\t\t\t\t// has complete information, but the other(s) should respond to\n\t\t\t\t// ClientJoin soon rectifying that and covering for bad incomplete\n\t\t\t\t// responses this client sent in the meantime.\n\t\t\t}\n\t\t} else {\n\t\t\t// When self is not represented, audience is an unreliable state,\n\t\t\t// especially during a reconnect. An alternateProvider is expected\n\t\t\t// to have been provided for this call to be useful (efficient).\n\t\t\tassert(\n\t\t\t\talternateProvider !== undefined,\n\t\t\t\t\"Self is not in audience and no alternateProvider given\",\n\t\t\t);\n\t\t}\n\n\t\t// Broadcast join message to all clients\n\t\t// Select primary update providers\n\t\t// Use write members if any, then fallback to read-only members.\n\t\tconst updateProviders = [\n\t\t\t...(interactiveMembersExcludingSelf.writers.size > 0\n\t\t\t\t? interactiveMembersExcludingSelf.writers\n\t\t\t\t: interactiveMembersExcludingSelf.all),\n\t\t];\n\t\t// Limit to three providers to prevent flooding the network.\n\t\t// If none respond, others present will (should) after a delay.\n\t\tif (updateProviders.length > 3) {\n\t\t\tupdateProviders.length = 3;\n\t\t} else if (updateProviders.length === 0 && alternateProvider !== undefined) {\n\t\t\tupdateProviders.push(alternateProvider);\n\t\t}\n\t\tthis.runtime.submitSignal({\n\t\t\ttype: joinMessageType,\n\t\t\tcontent: {\n\t\t\t\tsendTimestamp: Date.now(),\n\t\t\t\tavgLatency: this.averageLatency,\n\t\t\t\tdata: this.stripValidationMetadata(this.datastore),\n\t\t\t\tupdateProviders,\n\t\t\t},\n\t\t});\n\t\tthis.logger?.sendTelemetryEvent({\n\t\t\teventName: \"JoinRequested\",\n\t\t\tdetails: {\n\t\t\t\tattendeeId: this.attendeeId,\n\t\t\t\tconnectionId: selfClientId,\n\t\t\t\t// Empty updateProviders is indicative of join when alone.\n\t\t\t\tupdateProviders: JSON.stringify(updateProviders),\n\t\t\t\t// If false and providers is single entry, then join was probably forced.\n\t\t\t\tselfPresent,\n\t\t\t},\n\t\t});\n\t}\n\n\tpublic onDisconnected(): void {\n\t\tdelete this.reasonForCompleteSnapshot;\n\t}\n\n\tpublic getWorkspace<TSchema extends StatesWorkspaceSchema>(\n\t\tinternalWorkspaceAddress: InternalWorkspaceAddress,\n\t\trequestedContent: TSchema,\n\t\tcontrols?: BroadcastControlSettings,\n\t): AnyWorkspace<TSchema> {\n\t\tconst existing = this.workspaces.get(internalWorkspaceAddress);\n\t\tif (existing) {\n\t\t\treturn existing.internal.ensureContent(requestedContent, controls);\n\t\t}\n\n\t\tlet workspaceDatastore: ValueElementMap<StatesWorkspaceSchema> | undefined =\n\t\t\tthis.datastore[internalWorkspaceAddress];\n\t\tif (workspaceDatastore === undefined) {\n\t\t\tworkspaceDatastore = this.datastore[internalWorkspaceAddress] = {};\n\t\t}\n\n\t\tconst localUpdate = (\n\t\t\tstates: { [key: string]: ClientUpdateEntry },\n\t\t\toptions: RuntimeLocalUpdateOptions,\n\t\t): void => {\n\t\t\t// Check for connectivity before sending updates.\n\t\t\tif (this.runtime.getJoinedStatus() === \"disconnected\") {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst updates: GeneralDatastoreMessageContent[InternalWorkspaceAddress] = {};\n\t\t\tfor (const [key, value] of Object.entries(states)) {\n\t\t\t\tupdates[key] = { [this.attendeeId]: value };\n\t\t\t}\n\n\t\t\tthis.enqueueMessage(\n\t\t\t\t{\n\t\t\t\t\t[internalWorkspaceAddress]: updates,\n\t\t\t\t},\n\t\t\t\toptions,\n\t\t\t);\n\t\t};\n\n\t\tconst entry = createPresenceStates(\n\t\t\t{\n\t\t\t\tpresence: this.presence,\n\t\t\t\tattendeeId: this.attendeeId,\n\t\t\t\tlocalUpdate,\n\t\t\t},\n\t\t\tworkspaceDatastore,\n\t\t\trequestedContent,\n\t\t\tcontrols,\n\t\t);\n\n\t\tthis.workspaces.set(internalWorkspaceAddress, entry);\n\t\treturn entry.public;\n\t}\n\n\t/**\n\t * The combined contents of all queued updates. Will be `\"sendAll\"` when a\n\t * full broadcast is pending or `undefined` when no messages are queued.\n\t */\n\tprivate queuedData: GeneralDatastoreMessageContent | \"sendAll\" | undefined;\n\n\t/**\n\t * Enqueues a new message to be sent. The message may be queued or may be sent immediately depending on the state of\n\t * the send timer, other messages in the queue, the configured allowed latency, etc.\n\t */\n\tprivate enqueueMessage(\n\t\tdata: GeneralDatastoreMessageContent | \"sendAll\",\n\t\toptions: RuntimeLocalUpdateOptions,\n\t): void {\n\t\tif (this.queuedData !== \"sendAll\") {\n\t\t\tthis.queuedData =\n\t\t\t\tdata === \"sendAll\"\n\t\t\t\t\t? \"sendAll\"\n\t\t\t\t\t: // Merging the message with any queued messages effectively queues the message.\n\t\t\t\t\t\t// It is OK to queue all incoming messages as long as when we send, we send the queued data.\n\t\t\t\t\t\tmergeGeneralDatastoreMessageContent(this.queuedData, data);\n\t\t}\n\n\t\tconst { allowableUpdateLatencyMs } = options;\n\t\tconst now = Date.now();\n\t\tconst thisMessageDeadline = now + allowableUpdateLatencyMs;\n\n\t\tif (\n\t\t\t// If the timer has not expired, we can short-circuit because the timer will fire\n\t\t\t// and cover this update. In other words, queuing this will be fast enough to\n\t\t\t// meet its deadline, because a timer is already scheduled to fire before its deadline.\n\t\t\t!this.sendMessageTimer.hasExpired() &&\n\t\t\t// If the deadline for this message is later than the overall send deadline, then\n\t\t\t// we can exit early since a timer will take care of sending it.\n\t\t\tthisMessageDeadline >= this.sendMessageTimer.expireTime\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Either we need to send this message immediately, or we need to schedule a timer\n\t\t// to fire at the send deadline that will take care of it.\n\n\t\t// Note that timeoutInMs === allowableUpdateLatencyMs, but the calculation is done this way for clarity.\n\t\tconst timeoutInMs = thisMessageDeadline - now;\n\t\tconst scheduleForLater = timeoutInMs > 0;\n\n\t\tif (scheduleForLater) {\n\t\t\t// Schedule the queued messages to be sent at the updateDeadline\n\t\t\tthis.sendMessageTimer.setTimeout(this.sendQueuedMessage.bind(this), timeoutInMs);\n\t\t} else {\n\t\t\tthis.sendQueuedMessage();\n\t\t}\n\t}\n\n\t/**\n\t * Send any queued signal immediately. Does nothing if no message is queued.\n\t */\n\tprivate sendQueuedMessage(): void {\n\t\tthis.sendMessageTimer.clearTimeout();\n\n\t\tif (this.queuedData === undefined) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Check for connectivity before sending updates.\n\t\tif (this.runtime.getJoinedStatus() === \"disconnected\") {\n\t\t\t// Clear the queued data since we're disconnected. We don't want messages\n\t\t\t// to queue infinitely while disconnected.\n\t\t\tthis.queuedData = undefined;\n\t\t\treturn;\n\t\t}\n\n\t\tif (this.queuedData === \"sendAll\") {\n\t\t\tthis.broadcastAllKnownState();\n\t\t\treturn;\n\t\t}\n\n\t\tconst clientConnectionId = this.runtime.getClientId();\n\t\tassert(clientConnectionId !== undefined, 0xa59 /* Client connected without clientId */);\n\t\tconst currentClientToSessionValueState =\n\t\t\t// When connected, `clientToSessionId` must always have current connection entry.\n\t\t\tthis.datastore[\"system:presence\"].clientToSessionId[clientConnectionId];\n\t\tassert(currentClientToSessionValueState !== undefined, \"Client connection update missing\");\n\n\t\tconst newMessage = {\n\t\t\tsendTimestamp: Date.now(),\n\t\t\tavgLatency: this.averageLatency,\n\t\t\t// isComplete: false,\n\t\t\tdata: {\n\t\t\t\t// Always send current connection mapping for some resiliency against\n\t\t\t\t// lost signals. This ensures that client session id found in `updates`\n\t\t\t\t// (which is this client's client session id) is always represented in\n\t\t\t\t// system workspace of recipient clients.\n\t\t\t\t\"system:presence\": {\n\t\t\t\t\tclientToSessionId: {\n\t\t\t\t\t\t[clientConnectionId]: { ...currentClientToSessionValueState },\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t...this.queuedData,\n\t\t\t},\n\t\t} satisfies OutboundDatastoreUpdateMessage[\"content\"];\n\t\tthis.queuedData = undefined;\n\t\tthis.runtime.submitSignal({ type: datastoreUpdateMessageType, content: newMessage });\n\t}\n\n\t/**\n\t * Recursively strips validation metadata (validatedValue) from datastore before broadcasting.\n\t * This ensures that validation metadata doesn't leak into signals sent to other clients.\n\t */\n\tprivate stripValidationMetadata(datastore: PresenceDatastore): DatastoreMessageContent {\n\t\tconst messageContent: DatastoreMessageContent = {\n\t\t\t[\"system:presence\"]: datastore[\"system:presence\"],\n\t\t};\n\n\t\tfor (const [workspaceAddress, workspace] of objectEntries(datastore)) {\n\t\t\t// System workspace has no validation metadata and is already\n\t\t\t// set in messageContent; so, it can be skipped.\n\t\t\tif (workspaceAddress === \"system:presence\") continue;\n\n\t\t\tconst workspaceData: GeneralDatastoreMessageContent[typeof workspaceAddress] = {};\n\n\t\t\tfor (const [stateName, clientRecord] of objectEntries(workspace)) {\n\t\t\t\tconst cleanClientRecord: GeneralDatastoreMessageContent[typeof workspaceAddress][typeof stateName] =\n\t\t\t\t\t{};\n\n\t\t\t\tfor (const [attendeeId, valueData] of objectEntries(clientRecord)) {\n\t\t\t\t\tcleanClientRecord[attendeeId] = this.stripValidationFromValueData(valueData);\n\t\t\t\t}\n\n\t\t\t\tworkspaceData[stateName] = cleanClientRecord;\n\t\t\t}\n\n\t\t\tmessageContent[workspaceAddress] = workspaceData;\n\t\t}\n\n\t\treturn messageContent;\n\t}\n\n\t/**\n\t * Strips validation metadata from individual value data entries.\n\t */\n\tprivate stripValidationFromValueData<\n\t\tT extends\n\t\t\t| InternalTypes.ValueDirectory<unknown>\n\t\t\t| InternalTypes.ValueRequiredState<unknown>\n\t\t\t| InternalTypes.ValueOptionalState<unknown>,\n\t>(valueDataIn: ValidatableValueStructure<T>): T {\n\t\t// Clone the input object since we may mutate it\n\t\tconst valueData = { ...valueDataIn };\n\n\t\t// Handle directory structures (with \"items\" property)\n\t\tif (isValueDirectory(valueData)) {\n\t\t\tfor (const [key, item] of Object.entries(valueData.items)) {\n\t\t\t\tvalueData.items[key] = this.stripValidationFromValueData(item);\n\t\t\t}\n\n\t\t\t// This `satisfies` test is rather weak while ValidatableValueDirectory\n\t\t\t// only has optional properties over InternalTypes.ValueDirectory and\n\t\t\t// thus readily does satisfy. If `validatedValue?: never` is uncommented\n\t\t\t// in Value*State then this will fail.\n\t\t\tvalueData satisfies InternalTypes.ValueDirectory<unknown>;\n\t\t\treturn valueData as T;\n\t\t}\n\n\t\tdelete valueData.validatedValue;\n\t\t// This `satisfies` test is rather weak while Validatable*State\n\t\t// only has optional properties over InternalTypes.Value*State and\n\t\t// thus readily does satisfy. If `validatedValue?: never` is uncommented\n\t\t// in Value*State then this will fail.\n\t\tvalueData satisfies\n\t\t\t| InternalTypes.ValueRequiredState<unknown>\n\t\t\t| InternalTypes.ValueOptionalState<unknown>;\n\t\treturn valueData as T;\n\t}\n\n\tprivate broadcastAllKnownState(): void {\n\t\tconst content: OutboundDatastoreUpdateMessage[\"content\"] = {\n\t\t\tsendTimestamp: Date.now(),\n\t\t\tavgLatency: this.averageLatency,\n\t\t\tisComplete: true,\n\t\t\tdata: this.stripValidationMetadata(this.datastore),\n\t\t};\n\n\t\tconst primaryRequestors: ClientConnectionId[] = [];\n\t\tconst secondaryRequestors: [ClientConnectionId, number][] = [];\n\t\tif (this.broadcastRequests.size > 0) {\n\t\t\tcontent.joinResponseFor = [...this.broadcastRequests.keys()];\n\t\t\tif (this.logger) {\n\t\t\t\t// Build telemetry data\n\t\t\t\tfor (const [requestor, { responseOrder }] of this.broadcastRequests.entries()) {\n\t\t\t\t\tif (responseOrder === undefined) {\n\t\t\t\t\t\tprimaryRequestors.push(requestor);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tsecondaryRequestors.push([requestor, responseOrder]);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tthis.broadcastRequests.clear();\n\t\t}\n\n\t\t// This broadcast will satisfy all requests; clear any remaining timer.\n\t\tthis.broadcastRequestsTimer.clearTimeout();\n\t\tthis.sendMessageTimer.clearTimeout();\n\n\t\tthis.runtime.submitSignal({\n\t\t\ttype: datastoreUpdateMessageType,\n\t\t\tcontent,\n\t\t});\n\t\tif (content.joinResponseFor) {\n\t\t\tthis.logger?.sendTelemetryEvent({\n\t\t\t\teventName: \"JoinResponse\",\n\t\t\t\tdetails: {\n\t\t\t\t\ttype: \"broadcastAll\",\n\t\t\t\t\tattendeeId: this.attendeeId,\n\t\t\t\t\tconnectionId: this.runtime.getClientId(),\n\t\t\t\t\tprimaryResponses: JSON.stringify(primaryRequestors),\n\t\t\t\t\tsecondaryResponses: JSON.stringify(secondaryRequestors),\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\n\t\t// Sending all must account for anything queued before.\n\t\tthis.queuedData = undefined;\n\t}\n\n\tpublic processSignal(\n\t\tmessage: InboundExtensionMessage<SignalMessages> & { clientId: ClientConnectionId },\n\t\tlocal: boolean,\n\t\toptional: boolean,\n\t): void {\n\t\tconst received = Date.now();\n\t\tif (!isPresenceMessage(message)) {\n\t\t\tassert(optional, \"Unrecognized message type in critical message\");\n\t\t\treturn;\n\t\t}\n\n\t\tif (local) {\n\t\t\tconst deliveryDelta = received - message.content.sendTimestamp;\n\t\t\t// Limit returnedMessages count to 256 such that newest message\n\t\t\t// always contributes at least 1/256th to the average. Older\n\t\t\t// messages have more weight, but that diminishes as new messages\n\t\t\t// contribute.\n\t\t\tthis.returnedMessages = Math.min(this.returnedMessages + 1, 256);\n\t\t\tthis.averageLatency =\n\t\t\t\t(this.averageLatency * (this.returnedMessages - 1) + deliveryDelta) /\n\t\t\t\tthis.returnedMessages;\n\t\t\treturn;\n\t\t}\n\n\t\tconst timeModifier =\n\t\t\treceived -\n\t\t\t(this.averageLatency + message.content.avgLatency + message.content.sendTimestamp);\n\n\t\tconst postUpdateActions: PostUpdateAction[] = [];\n\n\t\tif (message.type === joinMessageType) {\n\t\t\t// It is possible for some signals to come in while client is not connected due\n\t\t\t// to how work is scheduled. If we are not connected, we can't respond to the\n\t\t\t// join request. We will make our own Join request once we are connected.\n\t\t\tif (this.runtime.getJoinedStatus() !== \"disconnected\") {\n\t\t\t\tthis.prepareJoinResponse(message.content.updateProviders, message.clientId);\n\t\t\t}\n\t\t\t// It is okay to continue processing the contained updates even if we are not\n\t\t\t// connected.\n\t\t} else {\n\t\t\t// Update join response requests that are now satisfied.\n\t\t\tconst joinResponseFor = message.content.joinResponseFor;\n\t\t\tif (joinResponseFor) {\n\t\t\t\tconst selfClientId = this.runtime.getClientId();\n\t\t\t\tassert(selfClientId !== undefined, \"Received signal without clientId\");\n\n\t\t\t\tlet justGainedCompleteSnapshot = false;\n\t\t\t\tif (joinResponseFor.includes(selfClientId)) {\n\t\t\t\t\tif (this.reasonForCompleteSnapshot) {\n\t\t\t\t\t\tif (this.reasonForCompleteSnapshot === \"alone\") {\n\t\t\t\t\t\t\t// No response was expected. This might happen when\n\t\t\t\t\t\t\t// either cautionary ClientJoin signal is received\n\t\t\t\t\t\t\t// by audience member that was unknown.\n\t\t\t\t\t\t\tthis.logger?.sendTelemetryEvent({\n\t\t\t\t\t\t\t\teventName: \"JoinResponseWhenAlone\",\n\t\t\t\t\t\t\t\tdetails: {\n\t\t\t\t\t\t\t\t\tattendeeId: this.attendeeId,\n\t\t\t\t\t\t\t\t\tconnectionId: this.runtime.getClientId(),\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// If we are the intended recipient of the join response,\n\t\t\t\t\t\t// we can consider our knowledge complete and can respond\n\t\t\t\t\t\t// to others join requests.\n\t\t\t\t\t\tjustGainedCompleteSnapshot = true;\n\t\t\t\t\t}\n\t\t\t\t\tthis.reasonForCompleteSnapshot = \"join response\";\n\t\t\t\t}\n\t\t\t\tif (this.broadcastRequests.size > 0) {\n\t\t\t\t\tfor (const responseFor of joinResponseFor) {\n\t\t\t\t\t\tthis.broadcastRequests.delete(responseFor);\n\t\t\t\t\t}\n\t\t\t\t\tif (this.broadcastRequests.size === 0) {\n\t\t\t\t\t\t// If no more requests are pending, clear any timer.\n\t\t\t\t\t\tthis.broadcastRequestsTimer.clearTimeout();\n\t\t\t\t\t} else if (justGainedCompleteSnapshot) {\n\t\t\t\t\t\t// May or may not be time to respond to remaining requests.\n\t\t\t\t\t\t// Clear the timer and recheck after processing.\n\t\t\t\t\t\tthis.broadcastRequestsTimer.clearTimeout();\n\t\t\t\t\t\tpostUpdateActions.push(this.sendJoinResponseIfStillNeeded);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// If the message requests an acknowledgement, we will send a targeted acknowledgement message back to just the requestor.\n\t\t\tif (message.content.acknowledgementId !== undefined) {\n\t\t\t\tassert(\n\t\t\t\t\tthis.targetedSignalSupport,\n\t\t\t\t\t\"Acknowledgment message was requested while targeted signal capability is not supported\",\n\t\t\t\t);\n\t\t\t\tthis.runtime.submitSignal({\n\t\t\t\t\ttype: acknowledgementMessageType,\n\t\t\t\t\tcontent: { id: message.content.acknowledgementId },\n\t\t\t\t\ttargetClientId: message.clientId,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\t// Handle activation of unregistered workspaces before processing updates.\n\t\tfor (const [workspaceAddress] of objectEntries(message.content.data)) {\n\t\t\t// The first part of OR condition checks if workspace is already registered.\n\t\t\t// The second part checks if the workspace has already been seen before.\n\t\t\t// In either case we can skip emitting 'workspaceActivated' event.\n\t\t\tif (this.workspaces.has(workspaceAddress) || this.datastore[workspaceAddress]) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// Separate internal type prefix from public workspace address\n\t\t\tconst match = /^([^:]):([^:]+:.+)$/.exec(workspaceAddress) as\n\t\t\t\t| null\n\t\t\t\t| [string, string, WorkspaceAddress];\n\n\t\t\tif (match === null) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst prefix = match[1];\n\t\t\tconst publicWorkspaceAddress = match[2];\n\n\t\t\tconst internalWorkspaceType = internalWorkspaceTypes[prefix] ?? \"Unknown\";\n\n\t\t\tthis.events.emit(\"workspaceActivated\", publicWorkspaceAddress, internalWorkspaceType);\n\t\t}\n\n\t\t// While the system workspace is processed here too, it is declared as\n\t\t// conforming to the general schema. So drop its override.\n\t\tconst data = message.content.data as Omit<typeof message.content.data, \"system:presence\">;\n\t\tfor (const [workspaceAddress, remoteDatastore] of objectEntries(data)) {\n\t\t\t// Direct to the appropriate Presence Workspace, if present.\n\t\t\tconst workspace = this.workspaces.get(workspaceAddress);\n\t\t\tif (workspace) {\n\t\t\t\tpostUpdateActions.push(\n\t\t\t\t\t...workspace.internal.processUpdate(\n\t\t\t\t\t\treceived,\n\t\t\t\t\t\ttimeModifier,\n\t\t\t\t\t\tremoteDatastore,\n\t\t\t\t\t\tmessage.clientId,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\t// All broadcast state is kept even if not currently registered, unless a value\n\t\t\t\t// notes itself to be ignored.\n\n\t\t\t\t// Ensure there is a datastore at this address and get it.\n\t\t\t\tconst workspaceDatastore = (this.datastore[workspaceAddress] ??= {});\n\t\t\t\tfor (const [key, remoteAllKnownState] of Object.entries(remoteDatastore)) {\n\t\t\t\t\tmergeUntrackedDatastore(key, remoteAllKnownState, workspaceDatastore, timeModifier);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tfor (const action of postUpdateActions) {\n\t\t\taction();\n\t\t}\n\t}\n\n\t/**\n\t * Broadcasts a join response (complete datastore update message)\n\t * if there is an outstanding join response request.\n\t */\n\tprivate readonly sendJoinResponseIfStillNeeded = (): void => {\n\t\t// Make sure we are currently connected and a broadcast is still needed.\n\t\t// If not connected, nothing we can do.\n\t\tif (this.runtime.getJoinedStatus() !== \"disconnected\" && this.broadcastRequests.size > 0) {\n\t\t\t// Confirm that of remaining requests, now is the time to respond.\n\t\t\tconst now = Date.now();\n\t\t\tlet minResponseTime = Number.POSITIVE_INFINITY;\n\t\t\tfor (const { deadlineTime } of this.broadcastRequests.values()) {\n\t\t\t\tminResponseTime = Math.min(minResponseTime, deadlineTime);\n\t\t\t}\n\t\t\tif (minResponseTime <= now) {\n\t\t\t\tif (this.reasonForCompleteSnapshot) {\n\t\t\t\t\tthis.broadcastAllKnownState();\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// No response needed yet - schedule a later attempt\n\t\t\t\tthis.broadcastRequestsTimer.setTimeout(\n\t\t\t\t\tthis.sendJoinResponseIfStillNeeded,\n\t\t\t\t\tminResponseTime - now,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t};\n\n\t/**\n\t * Handles responding to another client joining the session.\n\t *\n\t * @param updateProviders - list of client connection id's that requestor selected\n\t * to provide response\n\t * @param requestor - `requestor` is only used in telemetry. While it is the requestor's\n\t * client connection id, that is not most important. It is important that this is a\n\t * unique shared id across all clients that might respond as we want to monitor the\n\t * response patterns. The convenience of being client connection id will allow\n\t * correlation with other telemetry where it is often called just `clientId`.\n\t */\n\tprivate prepareJoinResponse(\n\t\tupdateProviders: ClientConnectionId[],\n\t\trequestor: ClientConnectionId,\n\t): void {\n\t\t// We must be connected to receive this message, so clientId should be defined.\n\t\t// If it isn't then, not really a problem; just won't be in provider or audience list.\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\tconst selfClientId = this.runtime.getClientId()!;\n\t\tlet joinResponseDelayMs = broadcastJoinResponseDelaysMs.namedResponder;\n\t\tlet relativeResponseOrder: number | undefined;\n\t\tif (!updateProviders.includes(selfClientId)) {\n\t\t\t// Schedule a broadcast to the new client after a delay only to send if\n\t\t\t// another broadcast satisfying the request hasn't been seen in the\n\t\t\t// meantime. The delay is based on the position in the quorum list. It\n\t\t\t// doesn't have to be a stable list across all clients. We need\n\t\t\t// something to provide suggested order to prevent a flood of broadcasts.\n\t\t\tconst quorumMembers = this.runtime.getQuorum().getMembers();\n\t\t\tconst self = quorumMembers.get(selfClientId);\n\t\t\tif (self) {\n\t\t\t\t// Compute order quorum join order (indicated by sequenceNumber)\n\t\t\t\trelativeResponseOrder = 0;\n\t\t\t\tfor (const { client, sequenceNumber } of quorumMembers.values()) {\n\t\t\t\t\tif (\n\t\t\t\t\t\tsequenceNumber < self.sequenceNumber &&\n\t\t\t\t\t\tclient.details.capabilities.interactive\n\t\t\t\t\t) {\n\t\t\t\t\t\trelativeResponseOrder++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// Order past quorum members + arbitrary additional offset up to 10\n\t\t\t\tlet possibleQuorumRespondents = 0;\n\t\t\t\tfor (const { client } of quorumMembers.values()) {\n\t\t\t\t\tif (client.details.capabilities.interactive) {\n\t\t\t\t\t\tpossibleQuorumRespondents++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\trelativeResponseOrder = possibleQuorumRespondents + Math.random() * 10;\n\t\t\t}\n\t\t\t// When not named to provide update, wait an additional amount\n\t\t\t// of time for those named or others to respond.\n\t\t\tjoinResponseDelayMs +=\n\t\t\t\tbroadcastJoinResponseDelaysMs.backupResponderIncrement *\n\t\t\t\t(3 * updateProviders.length + relativeResponseOrder);\n\t\t}\n\n\t\t// Add the requestor to the list of clients that will receive the broadcast.\n\t\tconst deadlineTime = Date.now() + joinResponseDelayMs;\n\t\tthis.broadcastRequests.set(requestor, {\n\t\t\tdeadlineTime,\n\t\t\tresponseOrder: relativeResponseOrder,\n\t\t});\n\n\t\tif (!this.reasonForCompleteSnapshot) {\n\t\t\t// Check if requestor count meets or exceeds count of other audience\n\t\t\t// members indicating that we effectively have a complete snapshot\n\t\t\t// (once the current message being processed is processed).\n\t\t\tconst { selfPresent, interactiveMembersExcludingSelf } =\n\t\t\t\tthis.getAudienceInformation(selfClientId);\n\t\t\tif (\n\t\t\t\t// Self-present check is done to help ensure that audience\n\t\t\t\t// information is accurate. If self is not present, audience\n\t\t\t\t// information might be incomplete.\n\t\t\t\tselfPresent &&\n\t\t\t\tthis.broadcastRequests.size >= interactiveMembersExcludingSelf.all.size\n\t\t\t) {\n\t\t\t\t// Note that no action is taken here specifically.\n\t\t\t\t// We want action to be queued so that it takes place after\n\t\t\t\t// current message is completely processed. All of the actions\n\t\t\t\t// below should be delayed (not immediate).\n\t\t\t\tthis.reasonForCompleteSnapshot = \"full requests\";\n\t\t\t}\n\t\t}\n\n\t\t// Check if capable of full primary response. If requested to provide\n\t\t// primary response, but do not yet have complete snapshot, we need to\n\t\t// delay a full response, until we think we have complete snapshot. In\n\t\t// the meantime we will send partial updates as usual.\n\t\tif (this.reasonForCompleteSnapshot && updateProviders.includes(selfClientId)) {\n\t\t\t// Use regular message queue to handle timing of the broadcast.\n\t\t\t// Any more immediate broadcasts will accelerate the response time.\n\t\t\t// As a primary responder, it is expected that broadcast will happen and\n\t\t\t// using the regular queue allows other updates to avoid merge work.\n\t\t\tthis.enqueueMessage(\"sendAll\", {\n\t\t\t\tallowableUpdateLatencyMs: joinResponseDelayMs,\n\t\t\t});\n\t\t} else {\n\t\t\t// Check if there isn't already a timer scheduled to send a join\n\t\t\t// response with in this request's deadline.\n\t\t\tif (\n\t\t\t\tthis.broadcastRequestsTimer.hasExpired() ||\n\t\t\t\tdeadlineTime < this.broadcastRequestsTimer.expireTime\n\t\t\t) {\n\t\t\t\t// Set or update the timer.\n\t\t\t\tthis.broadcastRequestsTimer.setTimeout(\n\t\t\t\t\tthis.sendJoinResponseIfStillNeeded,\n\t\t\t\t\tjoinResponseDelayMs,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"presenceDatastoreManager.js","sourceRoot":"","sources":["../src/presenceDatastoreManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAa7D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAYnD,OAAO,EACN,oBAAoB,EACpB,uBAAuB,EACvB,mBAAmB,GACnB,MAAM,qBAAqB,CAAC;AAW7B,OAAO,EACN,0BAA0B,EAC1B,0BAA0B,EAC1B,eAAe,GACf,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAuBjD,MAAM,sBAAsB,GAAyD;IACpF,CAAC,EAAE,QAAQ;IACX,CAAC,EAAE,eAAe;CACT,CAAC;AAEX,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAC;IACjC,eAAe;IACf,0BAA0B;IAC1B,0BAA0B;CAC1B,CAAC,CAAC;AACH,SAAS,iBAAiB,CACzB,OAAgD;IAEhD,OAAO,iBAAiB,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AAC5C,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAC/B,GAA+D;IAE/D,OAAO,OAA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,CAAC,sBAAsB,CAAC,UAAU,EAAE;gBACxC,YAAY,GAAG,IAAI,CAAC,sBAAsB,CAAC,UAAU,EACpD,CAAC;gBACF,2BAA2B;gBAC3B,IAAI,CAAC,sBAAsB,CAAC,UAAU,CACrC,IAAI,CAAC,6BAA6B,EAClC,mBAAmB,CACnB,CAAC;YACH,CAAC;QACF,CAAC;IACF,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { InboundExtensionMessage } from \"@fluidframework/container-runtime-definitions/internal\";\nimport type { IEmitter } from \"@fluidframework/core-interfaces/internal\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport type { ITelemetryLoggerExt } from \"@fluidframework/telemetry-utils/internal\";\n\nimport type { ClientConnectionId } from \"./baseTypes.js\";\nimport type { BroadcastControlSettings } from \"./broadcastControls.js\";\nimport type { InternalTypes } from \"./exposedInternalTypes.js\";\nimport type {\n\tIEphemeralRuntime,\n\tPostUpdateAction,\n\tValidatableOptionalState,\n\tValidatableValueDirectory,\n\tValidatableValueStructure,\n} from \"./internalTypes.js\";\nimport { objectEntries } from \"./internalUtils.js\";\nimport type {\n\tAttendeeId,\n\tPresenceWithNotifications as Presence,\n\tPresenceEvents,\n} from \"./presence.js\";\nimport type {\n\tClientUpdateEntry,\n\tRuntimeLocalUpdateOptions,\n\tPresenceStatesInternal,\n\tValueElementMap,\n} from \"./presenceStates.js\";\nimport {\n\tcreatePresenceStates,\n\tmergeUntrackedDatastore,\n\tmergeValueDirectory,\n} from \"./presenceStates.js\";\nimport type {\n\tDatastoreMessageContent,\n\tGeneralDatastoreMessageContent,\n\tInboundClientJoinMessage,\n\tInboundDatastoreUpdateMessage,\n\tInternalWorkspaceAddress,\n\tOutboundDatastoreUpdateMessage,\n\tSignalMessages,\n\tSystemDatastore,\n} from \"./protocol.js\";\nimport {\n\tacknowledgementMessageType,\n\tdatastoreUpdateMessageType,\n\tjoinMessageType,\n} from \"./protocol.js\";\nimport type { SystemWorkspaceDatastore } from \"./systemWorkspace.js\";\nimport { TimerManager } from \"./timerManager.js\";\nimport type {\n\tAnyWorkspace,\n\tNotificationsWorkspace,\n\tNotificationsWorkspaceSchema,\n\tStatesWorkspace,\n\tStatesWorkspaceSchema,\n\tWorkspaceAddress,\n} from \"./types.js\";\n\ninterface AnyWorkspaceEntry<TSchema extends StatesWorkspaceSchema> {\n\tpublic: AnyWorkspace<TSchema>;\n\tinternal: PresenceStatesInternal;\n}\n\n/**\n * Datastore structure used for broadcasting to other clients.\n * Validation metadata is stripped before transmission.\n */\ntype PresenceDatastore = SystemDatastore & {\n\t[WorkspaceAddress: InternalWorkspaceAddress]: ValueElementMap<StatesWorkspaceSchema>;\n};\n\nconst internalWorkspaceTypes: Readonly<Record<string, \"States\" | \"Notifications\">> = {\n\ts: \"States\",\n\tn: \"Notifications\",\n} as const;\n\nconst knownMessageTypes = new Set([\n\tjoinMessageType,\n\tdatastoreUpdateMessageType,\n\tacknowledgementMessageType,\n]);\nfunction isPresenceMessage(\n\tmessage: InboundExtensionMessage<SignalMessages>,\n): message is InboundDatastoreUpdateMessage | InboundClientJoinMessage {\n\treturn knownMessageTypes.has(message.type);\n}\n\n/**\n * Type guard to check if a value hierarchy object is a directory (has \"items\"\n * property).\n *\n * @param obj - The object to check\n * @returns True if the object is a {@link ValidatableValueDirectory}\n */\nexport function isValueDirectory<T>(\n\tobj: ValidatableValueDirectory<T> | ValidatableOptionalState<T>,\n): obj is ValidatableValueDirectory<T> {\n\treturn \"items\" in obj;\n}\n\n/**\n * High-level contract for manager of singleton Presence datastore\n */\nexport interface PresenceDatastoreManager {\n\tjoinSession(\n\t\tclientId: ClientConnectionId,\n\t\talternateProvider: ClientConnectionId | undefined,\n\t): void;\n\tonDisconnected(): void;\n\tgetWorkspace<TSchema extends StatesWorkspaceSchema>(\n\t\tinternalWorkspaceAddress: `s:${WorkspaceAddress}`,\n\t\trequestedContent: TSchema,\n\t\tcontrols?: BroadcastControlSettings,\n\t): StatesWorkspace<TSchema>;\n\tgetWorkspace<TSchema extends NotificationsWorkspaceSchema>(\n\t\tinternalWorkspaceAddress: `n:${WorkspaceAddress}`,\n\t\trequestedContent: TSchema,\n\t): NotificationsWorkspace<TSchema>;\n\tprocessSignal(\n\t\tmessage: InboundExtensionMessage<SignalMessages> & { clientId: ClientConnectionId },\n\t\tlocal: boolean,\n\t\toptional: boolean,\n\t): void;\n}\n\nfunction mergeGeneralDatastoreMessageContent(\n\tbase: GeneralDatastoreMessageContent | undefined,\n\tnewData: GeneralDatastoreMessageContent,\n): GeneralDatastoreMessageContent {\n\t// This function-local \"datastore\" will hold the merged message data.\n\tconst queueDatastore = base ?? {};\n\n\t// Merge the current data with the existing data, if any exists.\n\t// Iterate over the current message data; individual items are workspaces.\n\tfor (const [workspaceName, workspaceData] of objectEntries(newData)) {\n\t\t// Initialize the merged data as the queued datastore entry for the workspace.\n\t\t// Since the key might not exist, create an empty object in that case. It will\n\t\t// be set explicitly after the loop.\n\t\tconst mergedData = queueDatastore[workspaceName] ?? {};\n\n\t\t// Iterate over each value manager and its data, merging it as needed.\n\t\tfor (const [valueManagerKey, valueManagerValue] of objectEntries(workspaceData)) {\n\t\t\tfor (const [attendeeId, value] of objectEntries(valueManagerValue)) {\n\t\t\t\tconst mergeObject = (mergedData[valueManagerKey] ??= {});\n\t\t\t\tconst oldData = mergeObject[attendeeId];\n\t\t\t\tmergeObject[attendeeId] = mergeValueDirectory(\n\t\t\t\t\toldData,\n\t\t\t\t\tvalue,\n\t\t\t\t\t0, // local values do not need a time shift\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\t// Store the merged data in the function-local queue workspace. The whole contents of this\n\t\t// datastore will be sent as the message data.\n\t\tqueueDatastore[workspaceName] = mergedData;\n\t}\n\treturn queueDatastore;\n}\n\n/**\n * Delays used for broadcasting join responses to clients.\n *\n * @remarks\n * Exported for test coordination.\n * These could be made customizable in the future to accommodate different\n * session configurations.\n */\nexport const broadcastJoinResponseDelaysMs = {\n\t/**\n\t * The delay in milliseconds before a join response is sent to any client.\n\t * This is used to accumulate other join response requests and reduce\n\t * network traffic.\n\t */\n\tnamedResponder: 200,\n\t/**\n\t * The additional delay in milliseconds a backup responder waits before sending\n\t * a join response to allow others to respond first.\n\t */\n\tbackupResponderIncrement: 40,\n} as const;\n\n/**\n * Manages singleton datastore for all Presence.\n */\nexport class PresenceDatastoreManagerImpl implements PresenceDatastoreManager {\n\tprivate readonly datastore: PresenceDatastore;\n\tprivate averageLatency = 0;\n\tprivate returnedMessages = 0;\n\tprivate readonly sendMessageTimer = new TimerManager();\n\tprivate readonly workspaces = new Map<string, AnyWorkspaceEntry<StatesWorkspaceSchema>>();\n\tprivate readonly targetedSignalSupport: boolean;\n\n\t/**\n\t * Tracks whether this client has complete snapshot level knowledge and\n\t * how that determination was reached.\n\t * - \"alone\": no other audience members detected at join\n\t * - \"join response\": another client has responded to our join request\n\t * - \"full requests\": all others have requested response from us\n\t *\n\t * @remarks\n\t * Only applies when not using targeted join responses.\n\t *\n\t * Without a complete snapshot, we cannot fully onboard any other clients.\n\t * One exception to this is if this client is the only participant in the\n\t * session. In such a case, there is no one to respond to the join request.\n\t * Another exception is multiple clients attempting to join at the same\n\t * time and thus expecting that someone has full knowledge, yet none have\n\t * received a complete update to think they are qualified to respond.\n\t * Generically if the number of outstanding requestors meets or exceeds the\n\t * count of other audience members, then we can consider the snapshot\n\t * complete (as all will have provided their own complete information in\n\t * their join responses).\n\t */\n\tprivate reasonForCompleteSnapshot?: \"alone\" | \"join response\" | \"full requests\";\n\n\t/**\n\t * Map of outstanding broadcast (join response) requests.\n\t */\n\tprivate readonly broadcastRequests = new Map<\n\t\tClientConnectionId,\n\t\t{ deadlineTime: number; responseOrder?: number | undefined }\n\t>();\n\t/**\n\t * Timer for managing broadcast (join response) request timing.\n\t */\n\tprivate readonly broadcastRequestsTimer = new TimerManager();\n\n\tpublic constructor(\n\t\tprivate readonly attendeeId: AttendeeId,\n\t\tprivate readonly runtime: IEphemeralRuntime,\n\t\tprivate readonly logger: ITelemetryLoggerExt | undefined,\n\t\tprivate readonly events: IEmitter<PresenceEvents>,\n\t\tprivate readonly presence: Presence,\n\t\tsystemWorkspaceDatastore: SystemWorkspaceDatastore,\n\t\tsystemWorkspace: AnyWorkspaceEntry<StatesWorkspaceSchema>,\n\t) {\n\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\tthis.datastore = { \"system:presence\": systemWorkspaceDatastore } as PresenceDatastore;\n\t\tthis.workspaces.set(\"system:presence\", systemWorkspace);\n\t\tthis.targetedSignalSupport = this.runtime.supportedFeatures.has(\"submit_signals_v2\");\n\t\t// If audience member is removed, they won't need a broadcast response.\n\t\tthis.runtime.getAudience().on(\"removeMember\", (clientId) => {\n\t\t\tthis.broadcastRequests.delete(clientId);\n\t\t});\n\t}\n\n\tprivate getAudienceInformation(selfClientId: ClientConnectionId): {\n\t\tselfPresent: boolean;\n\t\tinteractiveMembersExcludingSelf: {\n\t\t\tall: Set<ClientConnectionId>;\n\t\t\twriters: Set<ClientConnectionId>;\n\t\t};\n\t} {\n\t\tconst audience = this.runtime.getAudience();\n\t\tconst members = audience.getMembers();\n\t\tconst all = new Set<ClientConnectionId>();\n\t\tconst writers = new Set<ClientConnectionId>();\n\t\tconst selfPresent = members.has(selfClientId);\n\t\tif (selfPresent) {\n\t\t\t// Remove self\n\t\t\tmembers.delete(selfClientId);\n\t\t}\n\t\t// Gather interactive client IDs\n\t\tfor (const [id, client] of members) {\n\t\t\tif (client.details.capabilities.interactive) {\n\t\t\t\tall.add(id);\n\t\t\t\tif (client.mode === \"write\") {\n\t\t\t\t\twriters.add(id);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn {\n\t\t\tselfPresent,\n\t\t\tinteractiveMembersExcludingSelf: {\n\t\t\t\tall,\n\t\t\t\twriters,\n\t\t\t},\n\t\t};\n\t}\n\n\tpublic joinSession(\n\t\tselfClientId: ClientConnectionId,\n\t\talternateProvider: ClientConnectionId | undefined = undefined,\n\t): void {\n\t\t// Before broadcasting the join message, check that there is at least\n\t\t// one audience member present (self or another). This is useful to\n\t\t// optimize join messages while not using targeted join responses.\n\t\t// (We need at least one other to be able to elect them as update\n\t\t// provider.)\n\t\t// Lack of anyone likely means that this client is very freshly joined\n\t\t// and has not received any Join Signals (type=\"join\") from the service\n\t\t// yet.\n\t\tconst { selfPresent, interactiveMembersExcludingSelf } =\n\t\t\tthis.getAudienceInformation(selfClientId);\n\n\t\tif (selfPresent) {\n\t\t\tif (interactiveMembersExcludingSelf.all.size === 0) {\n\t\t\t\t// If there aren't any members connected except self, then this client\n\t\t\t\t// must have complete information.\n\t\t\t\tthis.reasonForCompleteSnapshot = \"alone\";\n\t\t\t\t// It would be possible to return at this time and skip ClientJoin\n\t\t\t\t// signal. Instead continue in case audience information is\n\t\t\t\t// inaccurate. This client might temporarily erroneously believe it\n\t\t\t\t// has complete information, but the other(s) should respond to\n\t\t\t\t// ClientJoin soon rectifying that and covering for bad incomplete\n\t\t\t\t// responses this client sent in the meantime.\n\t\t\t}\n\t\t} else {\n\t\t\t// When self is not represented, audience is an unreliable state,\n\t\t\t// especially during a reconnect. An alternateProvider is expected\n\t\t\t// to have been provided for this call to be useful (efficient).\n\t\t\tassert(\n\t\t\t\talternateProvider !== undefined,\n\t\t\t\t0xcba /* Self is not in audience and no alternateProvider given */,\n\t\t\t);\n\t\t}\n\n\t\t// Broadcast join message to all clients\n\t\t// Select primary update providers\n\t\t// Use write members if any, then fallback to read-only members.\n\t\tconst updateProviders = [\n\t\t\t...(interactiveMembersExcludingSelf.writers.size > 0\n\t\t\t\t? interactiveMembersExcludingSelf.writers\n\t\t\t\t: interactiveMembersExcludingSelf.all),\n\t\t];\n\t\t// Limit to three providers to prevent flooding the network.\n\t\t// If none respond, others present will (should) after a delay.\n\t\tif (updateProviders.length > 3) {\n\t\t\tupdateProviders.length = 3;\n\t\t} else if (updateProviders.length === 0 && alternateProvider !== undefined) {\n\t\t\tupdateProviders.push(alternateProvider);\n\t\t}\n\t\tthis.runtime.submitSignal({\n\t\t\ttype: joinMessageType,\n\t\t\tcontent: {\n\t\t\t\tsendTimestamp: Date.now(),\n\t\t\t\tavgLatency: this.averageLatency,\n\t\t\t\tdata: this.stripValidationMetadata(this.datastore),\n\t\t\t\tupdateProviders,\n\t\t\t},\n\t\t});\n\t\tthis.logger?.sendTelemetryEvent({\n\t\t\teventName: \"JoinRequested\",\n\t\t\tdetails: {\n\t\t\t\tattendeeId: this.attendeeId,\n\t\t\t\tconnectionId: selfClientId,\n\t\t\t\t// Empty updateProviders is indicative of join when alone.\n\t\t\t\tupdateProviders: JSON.stringify(updateProviders),\n\t\t\t\t// If false and providers is single entry, then join was probably forced.\n\t\t\t\tselfPresent,\n\t\t\t},\n\t\t});\n\t}\n\n\tpublic onDisconnected(): void {\n\t\tdelete this.reasonForCompleteSnapshot;\n\t}\n\n\tpublic getWorkspace<TSchema extends StatesWorkspaceSchema>(\n\t\tinternalWorkspaceAddress: InternalWorkspaceAddress,\n\t\trequestedContent: TSchema,\n\t\tcontrols?: BroadcastControlSettings,\n\t): AnyWorkspace<TSchema> {\n\t\tconst existing = this.workspaces.get(internalWorkspaceAddress);\n\t\tif (existing) {\n\t\t\treturn existing.internal.ensureContent(requestedContent, controls);\n\t\t}\n\n\t\tlet workspaceDatastore: ValueElementMap<StatesWorkspaceSchema> | undefined =\n\t\t\tthis.datastore[internalWorkspaceAddress];\n\t\t// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- using ??= could change behavior if value is falsy\n\t\tif (workspaceDatastore === undefined) {\n\t\t\tworkspaceDatastore = this.datastore[internalWorkspaceAddress] = {};\n\t\t}\n\n\t\tconst localUpdate = (\n\t\t\tstates: { [key: string]: ClientUpdateEntry },\n\t\t\toptions: RuntimeLocalUpdateOptions,\n\t\t): void => {\n\t\t\t// Check for connectivity before sending updates.\n\t\t\tif (this.runtime.getJoinedStatus() === \"disconnected\") {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst updates: GeneralDatastoreMessageContent[InternalWorkspaceAddress] = {};\n\t\t\tfor (const [key, value] of Object.entries(states)) {\n\t\t\t\tupdates[key] = { [this.attendeeId]: value };\n\t\t\t}\n\n\t\t\tthis.enqueueMessage(\n\t\t\t\t{\n\t\t\t\t\t[internalWorkspaceAddress]: updates,\n\t\t\t\t},\n\t\t\t\toptions,\n\t\t\t);\n\t\t};\n\n\t\tconst entry = createPresenceStates(\n\t\t\t{\n\t\t\t\tpresence: this.presence,\n\t\t\t\tattendeeId: this.attendeeId,\n\t\t\t\tlocalUpdate,\n\t\t\t},\n\t\t\tworkspaceDatastore,\n\t\t\trequestedContent,\n\t\t\tcontrols,\n\t\t);\n\n\t\tthis.workspaces.set(internalWorkspaceAddress, entry);\n\t\treturn entry.public;\n\t}\n\n\t/**\n\t * The combined contents of all queued updates. Will be `\"sendAll\"` when a\n\t * full broadcast is pending or `undefined` when no messages are queued.\n\t */\n\tprivate queuedData: GeneralDatastoreMessageContent | \"sendAll\" | undefined;\n\n\t/**\n\t * Enqueues a new message to be sent. The message may be queued or may be sent immediately depending on the state of\n\t * the send timer, other messages in the queue, the configured allowed latency, etc.\n\t */\n\tprivate enqueueMessage(\n\t\tdata: GeneralDatastoreMessageContent | \"sendAll\",\n\t\toptions: RuntimeLocalUpdateOptions,\n\t): void {\n\t\tif (this.queuedData !== \"sendAll\") {\n\t\t\tthis.queuedData =\n\t\t\t\tdata === \"sendAll\"\n\t\t\t\t\t? \"sendAll\"\n\t\t\t\t\t: // Merging the message with any queued messages effectively queues the message.\n\t\t\t\t\t\t// It is OK to queue all incoming messages as long as when we send, we send the queued data.\n\t\t\t\t\t\tmergeGeneralDatastoreMessageContent(this.queuedData, data);\n\t\t}\n\n\t\tconst { allowableUpdateLatencyMs } = options;\n\t\tconst now = Date.now();\n\t\tconst thisMessageDeadline = now + allowableUpdateLatencyMs;\n\n\t\tif (\n\t\t\t// If the timer has not expired, we can short-circuit because the timer will fire\n\t\t\t// and cover this update. In other words, queuing this will be fast enough to\n\t\t\t// meet its deadline, because a timer is already scheduled to fire before its deadline.\n\t\t\t!this.sendMessageTimer.hasExpired() &&\n\t\t\t// If the deadline for this message is later than the overall send deadline, then\n\t\t\t// we can exit early since a timer will take care of sending it.\n\t\t\tthisMessageDeadline >= this.sendMessageTimer.expireTime\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Either we need to send this message immediately, or we need to schedule a timer\n\t\t// to fire at the send deadline that will take care of it.\n\n\t\t// Note that timeoutInMs === allowableUpdateLatencyMs, but the calculation is done this way for clarity.\n\t\tconst timeoutInMs = thisMessageDeadline - now;\n\t\tconst scheduleForLater = timeoutInMs > 0;\n\n\t\tif (scheduleForLater) {\n\t\t\t// Schedule the queued messages to be sent at the updateDeadline\n\t\t\tthis.sendMessageTimer.setTimeout(this.sendQueuedMessage.bind(this), timeoutInMs);\n\t\t} else {\n\t\t\tthis.sendQueuedMessage();\n\t\t}\n\t}\n\n\t/**\n\t * Send any queued signal immediately. Does nothing if no message is queued.\n\t */\n\tprivate sendQueuedMessage(): void {\n\t\tthis.sendMessageTimer.clearTimeout();\n\n\t\tif (this.queuedData === undefined) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Check for connectivity before sending updates.\n\t\tif (this.runtime.getJoinedStatus() === \"disconnected\") {\n\t\t\t// Clear the queued data since we're disconnected. We don't want messages\n\t\t\t// to queue infinitely while disconnected.\n\t\t\tthis.queuedData = undefined;\n\t\t\treturn;\n\t\t}\n\n\t\tif (this.queuedData === \"sendAll\") {\n\t\t\tthis.broadcastAllKnownState();\n\t\t\treturn;\n\t\t}\n\n\t\tconst clientConnectionId = this.runtime.getClientId();\n\t\tassert(clientConnectionId !== undefined, 0xa59 /* Client connected without clientId */);\n\t\tconst currentClientToSessionValueState =\n\t\t\t// When connected, `clientToSessionId` must always have current connection entry.\n\t\t\tthis.datastore[\"system:presence\"].clientToSessionId[clientConnectionId];\n\t\tassert(\n\t\t\tcurrentClientToSessionValueState !== undefined,\n\t\t\t0xcbb /* Client connection update missing */,\n\t\t);\n\n\t\tconst newMessage = {\n\t\t\tsendTimestamp: Date.now(),\n\t\t\tavgLatency: this.averageLatency,\n\t\t\t// isComplete: false,\n\t\t\tdata: {\n\t\t\t\t// Always send current connection mapping for some resiliency against\n\t\t\t\t// lost signals. This ensures that client session id found in `updates`\n\t\t\t\t// (which is this client's client session id) is always represented in\n\t\t\t\t// system workspace of recipient clients.\n\t\t\t\t\"system:presence\": {\n\t\t\t\t\tclientToSessionId: {\n\t\t\t\t\t\t[clientConnectionId]: { ...currentClientToSessionValueState },\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t...this.queuedData,\n\t\t\t},\n\t\t} satisfies OutboundDatastoreUpdateMessage[\"content\"];\n\t\tthis.queuedData = undefined;\n\t\tthis.runtime.submitSignal({ type: datastoreUpdateMessageType, content: newMessage });\n\t}\n\n\t/**\n\t * Recursively strips validation metadata (validatedValue) from datastore before broadcasting.\n\t * This ensures that validation metadata doesn't leak into signals sent to other clients.\n\t */\n\tprivate stripValidationMetadata(datastore: PresenceDatastore): DatastoreMessageContent {\n\t\tconst messageContent: DatastoreMessageContent = {\n\t\t\t[\"system:presence\"]: datastore[\"system:presence\"],\n\t\t};\n\n\t\tfor (const [workspaceAddress, workspace] of objectEntries(datastore)) {\n\t\t\t// System workspace has no validation metadata and is already\n\t\t\t// set in messageContent; so, it can be skipped.\n\t\t\tif (workspaceAddress === \"system:presence\") continue;\n\n\t\t\tconst workspaceData: GeneralDatastoreMessageContent[typeof workspaceAddress] = {};\n\n\t\t\tfor (const [stateName, clientRecord] of objectEntries(workspace)) {\n\t\t\t\tconst cleanClientRecord: GeneralDatastoreMessageContent[typeof workspaceAddress][typeof stateName] =\n\t\t\t\t\t{};\n\n\t\t\t\tfor (const [attendeeId, valueData] of objectEntries(clientRecord)) {\n\t\t\t\t\tcleanClientRecord[attendeeId] = this.stripValidationFromValueData(valueData);\n\t\t\t\t}\n\n\t\t\t\tworkspaceData[stateName] = cleanClientRecord;\n\t\t\t}\n\n\t\t\tmessageContent[workspaceAddress] = workspaceData;\n\t\t}\n\n\t\treturn messageContent;\n\t}\n\n\t/**\n\t * Strips validation metadata from individual value data entries.\n\t */\n\tprivate stripValidationFromValueData<\n\t\tT extends\n\t\t\t| InternalTypes.ValueDirectory<unknown>\n\t\t\t| InternalTypes.ValueRequiredState<unknown>\n\t\t\t| InternalTypes.ValueOptionalState<unknown>,\n\t>(valueDataIn: ValidatableValueStructure<T>): T {\n\t\t// Clone the input object since we may mutate it\n\t\tconst valueData = { ...valueDataIn };\n\n\t\t// Handle directory structures (with \"items\" property)\n\t\tif (isValueDirectory(valueData)) {\n\t\t\tfor (const [key, item] of Object.entries(valueData.items)) {\n\t\t\t\tvalueData.items[key] = this.stripValidationFromValueData(item);\n\t\t\t}\n\n\t\t\t// This `satisfies` test is rather weak while ValidatableValueDirectory\n\t\t\t// only has optional properties over InternalTypes.ValueDirectory and\n\t\t\t// thus readily does satisfy. If `validatedValue?: never` is uncommented\n\t\t\t// in Value*State then this will fail.\n\t\t\tvalueData satisfies InternalTypes.ValueDirectory<unknown>;\n\t\t\treturn valueData as T;\n\t\t}\n\n\t\tdelete valueData.validatedValue;\n\t\t// This `satisfies` test is rather weak while Validatable*State\n\t\t// only has optional properties over InternalTypes.Value*State and\n\t\t// thus readily does satisfy. If `validatedValue?: never` is uncommented\n\t\t// in Value*State then this will fail.\n\t\tvalueData satisfies\n\t\t\t| InternalTypes.ValueRequiredState<unknown>\n\t\t\t| InternalTypes.ValueOptionalState<unknown>;\n\t\treturn valueData as T;\n\t}\n\n\tprivate broadcastAllKnownState(): void {\n\t\tconst content: OutboundDatastoreUpdateMessage[\"content\"] = {\n\t\t\tsendTimestamp: Date.now(),\n\t\t\tavgLatency: this.averageLatency,\n\t\t\tisComplete: true,\n\t\t\tdata: this.stripValidationMetadata(this.datastore),\n\t\t};\n\n\t\tconst primaryRequestors: ClientConnectionId[] = [];\n\t\tconst secondaryRequestors: [ClientConnectionId, number][] = [];\n\t\tif (this.broadcastRequests.size > 0) {\n\t\t\tcontent.joinResponseFor = [...this.broadcastRequests.keys()];\n\t\t\tif (this.logger) {\n\t\t\t\t// Build telemetry data\n\t\t\t\tfor (const [requestor, { responseOrder }] of this.broadcastRequests.entries()) {\n\t\t\t\t\tif (responseOrder === undefined) {\n\t\t\t\t\t\tprimaryRequestors.push(requestor);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tsecondaryRequestors.push([requestor, responseOrder]);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tthis.broadcastRequests.clear();\n\t\t}\n\n\t\t// This broadcast will satisfy all requests; clear any remaining timer.\n\t\tthis.broadcastRequestsTimer.clearTimeout();\n\t\tthis.sendMessageTimer.clearTimeout();\n\n\t\tthis.runtime.submitSignal({\n\t\t\ttype: datastoreUpdateMessageType,\n\t\t\tcontent,\n\t\t});\n\t\tif (content.joinResponseFor) {\n\t\t\tthis.logger?.sendTelemetryEvent({\n\t\t\t\teventName: \"JoinResponse\",\n\t\t\t\tdetails: {\n\t\t\t\t\ttype: \"broadcastAll\",\n\t\t\t\t\tattendeeId: this.attendeeId,\n\t\t\t\t\tconnectionId: this.runtime.getClientId(),\n\t\t\t\t\tprimaryResponses: JSON.stringify(primaryRequestors),\n\t\t\t\t\tsecondaryResponses: JSON.stringify(secondaryRequestors),\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\n\t\t// Sending all must account for anything queued before.\n\t\tthis.queuedData = undefined;\n\t}\n\n\tpublic processSignal(\n\t\tmessage: InboundExtensionMessage<SignalMessages> & { clientId: ClientConnectionId },\n\t\tlocal: boolean,\n\t\toptional: boolean,\n\t): void {\n\t\tconst received = Date.now();\n\t\tif (!isPresenceMessage(message)) {\n\t\t\tassert(optional, 0xcbc /* Unrecognized message type in critical message */);\n\t\t\treturn;\n\t\t}\n\n\t\tif (local) {\n\t\t\tconst deliveryDelta = received - message.content.sendTimestamp;\n\t\t\t// Limit returnedMessages count to 256 such that newest message\n\t\t\t// always contributes at least 1/256th to the average. Older\n\t\t\t// messages have more weight, but that diminishes as new messages\n\t\t\t// contribute.\n\t\t\tthis.returnedMessages = Math.min(this.returnedMessages + 1, 256);\n\t\t\tthis.averageLatency =\n\t\t\t\t(this.averageLatency * (this.returnedMessages - 1) + deliveryDelta) /\n\t\t\t\tthis.returnedMessages;\n\t\t\treturn;\n\t\t}\n\n\t\tconst timeModifier =\n\t\t\treceived -\n\t\t\t(this.averageLatency + message.content.avgLatency + message.content.sendTimestamp);\n\n\t\tconst postUpdateActions: PostUpdateAction[] = [];\n\n\t\tif (message.type === joinMessageType) {\n\t\t\t// It is possible for some signals to come in while client is not connected due\n\t\t\t// to how work is scheduled. If we are not connected, we can't respond to the\n\t\t\t// join request. We will make our own Join request once we are connected.\n\t\t\tif (this.runtime.getJoinedStatus() !== \"disconnected\") {\n\t\t\t\tthis.prepareJoinResponse(message.content.updateProviders, message.clientId);\n\t\t\t}\n\t\t\t// It is okay to continue processing the contained updates even if we are not\n\t\t\t// connected.\n\t\t} else {\n\t\t\t// Update join response requests that are now satisfied.\n\t\t\tconst joinResponseFor = message.content.joinResponseFor;\n\t\t\tif (joinResponseFor) {\n\t\t\t\tconst selfClientId = this.runtime.getClientId();\n\t\t\t\tassert(selfClientId !== undefined, 0xcbd /* Received signal without clientId */);\n\n\t\t\t\tlet justGainedCompleteSnapshot = false;\n\t\t\t\tif (joinResponseFor.includes(selfClientId)) {\n\t\t\t\t\tif (this.reasonForCompleteSnapshot) {\n\t\t\t\t\t\tif (this.reasonForCompleteSnapshot === \"alone\") {\n\t\t\t\t\t\t\t// No response was expected. This might happen when\n\t\t\t\t\t\t\t// either cautionary ClientJoin signal is received\n\t\t\t\t\t\t\t// by audience member that was unknown.\n\t\t\t\t\t\t\tthis.logger?.sendTelemetryEvent({\n\t\t\t\t\t\t\t\teventName: \"JoinResponseWhenAlone\",\n\t\t\t\t\t\t\t\tdetails: {\n\t\t\t\t\t\t\t\t\tattendeeId: this.attendeeId,\n\t\t\t\t\t\t\t\t\tconnectionId: this.runtime.getClientId(),\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// If we are the intended recipient of the join response,\n\t\t\t\t\t\t// we can consider our knowledge complete and can respond\n\t\t\t\t\t\t// to others join requests.\n\t\t\t\t\t\tjustGainedCompleteSnapshot = true;\n\t\t\t\t\t}\n\t\t\t\t\tthis.reasonForCompleteSnapshot = \"join response\";\n\t\t\t\t}\n\t\t\t\tif (this.broadcastRequests.size > 0) {\n\t\t\t\t\tfor (const responseFor of joinResponseFor) {\n\t\t\t\t\t\tthis.broadcastRequests.delete(responseFor);\n\t\t\t\t\t}\n\t\t\t\t\tif (this.broadcastRequests.size === 0) {\n\t\t\t\t\t\t// If no more requests are pending, clear any timer.\n\t\t\t\t\t\tthis.broadcastRequestsTimer.clearTimeout();\n\t\t\t\t\t} else if (justGainedCompleteSnapshot) {\n\t\t\t\t\t\t// May or may not be time to respond to remaining requests.\n\t\t\t\t\t\t// Clear the timer and recheck after processing.\n\t\t\t\t\t\tthis.broadcastRequestsTimer.clearTimeout();\n\t\t\t\t\t\tpostUpdateActions.push(this.sendJoinResponseIfStillNeeded);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// If the message requests an acknowledgement, we will send a targeted acknowledgement message back to just the requestor.\n\t\t\tif (message.content.acknowledgementId !== undefined) {\n\t\t\t\tassert(\n\t\t\t\t\tthis.targetedSignalSupport,\n\t\t\t\t\t0xcbe /* Acknowledgment message was requested while targeted signal capability is not supported */,\n\t\t\t\t);\n\t\t\t\tthis.runtime.submitSignal({\n\t\t\t\t\ttype: acknowledgementMessageType,\n\t\t\t\t\tcontent: { id: message.content.acknowledgementId },\n\t\t\t\t\ttargetClientId: message.clientId,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\t// Handle activation of unregistered workspaces before processing updates.\n\t\tfor (const [workspaceAddress] of objectEntries(message.content.data)) {\n\t\t\t// The first part of OR condition checks if workspace is already registered.\n\t\t\t// The second part checks if the workspace has already been seen before.\n\t\t\t// In either case we can skip emitting 'workspaceActivated' event.\n\t\t\tif (this.workspaces.has(workspaceAddress) || this.datastore[workspaceAddress]) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// Separate internal type prefix from public workspace address\n\t\t\tconst match = /^([^:]):([^:]+:.+)$/.exec(workspaceAddress) as\n\t\t\t\t| null\n\t\t\t\t| [string, string, WorkspaceAddress];\n\n\t\t\tif (match === null) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst prefix = match[1];\n\t\t\tconst publicWorkspaceAddress = match[2];\n\n\t\t\tconst internalWorkspaceType = internalWorkspaceTypes[prefix] ?? \"Unknown\";\n\n\t\t\tthis.events.emit(\"workspaceActivated\", publicWorkspaceAddress, internalWorkspaceType);\n\t\t}\n\n\t\t// While the system workspace is processed here too, it is declared as\n\t\t// conforming to the general schema. So drop its override.\n\t\tconst data = message.content.data as Omit<typeof message.content.data, \"system:presence\">;\n\t\tfor (const [workspaceAddress, remoteDatastore] of objectEntries(data)) {\n\t\t\t// Direct to the appropriate Presence Workspace, if present.\n\t\t\tconst workspace = this.workspaces.get(workspaceAddress);\n\t\t\tif (workspace) {\n\t\t\t\tpostUpdateActions.push(\n\t\t\t\t\t...workspace.internal.processUpdate(\n\t\t\t\t\t\treceived,\n\t\t\t\t\t\ttimeModifier,\n\t\t\t\t\t\tremoteDatastore,\n\t\t\t\t\t\tmessage.clientId,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\t// All broadcast state is kept even if not currently registered, unless a value\n\t\t\t\t// notes itself to be ignored.\n\n\t\t\t\t// Ensure there is a datastore at this address and get it.\n\t\t\t\tconst workspaceDatastore = (this.datastore[workspaceAddress] ??= {});\n\t\t\t\tfor (const [key, remoteAllKnownState] of Object.entries(remoteDatastore)) {\n\t\t\t\t\tmergeUntrackedDatastore(key, remoteAllKnownState, workspaceDatastore, timeModifier);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tfor (const action of postUpdateActions) {\n\t\t\taction();\n\t\t}\n\t}\n\n\t/**\n\t * Broadcasts a join response (complete datastore update message)\n\t * if there is an outstanding join response request.\n\t */\n\tprivate readonly sendJoinResponseIfStillNeeded = (): void => {\n\t\t// Make sure we are currently connected and a broadcast is still needed.\n\t\t// If not connected, nothing we can do.\n\t\tif (this.runtime.getJoinedStatus() !== \"disconnected\" && this.broadcastRequests.size > 0) {\n\t\t\t// Confirm that of remaining requests, now is the time to respond.\n\t\t\tconst now = Date.now();\n\t\t\tlet minResponseTime = Number.POSITIVE_INFINITY;\n\t\t\tfor (const { deadlineTime } of this.broadcastRequests.values()) {\n\t\t\t\tminResponseTime = Math.min(minResponseTime, deadlineTime);\n\t\t\t}\n\t\t\tif (minResponseTime <= now) {\n\t\t\t\tif (this.reasonForCompleteSnapshot) {\n\t\t\t\t\tthis.broadcastAllKnownState();\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// No response needed yet - schedule a later attempt\n\t\t\t\tthis.broadcastRequestsTimer.setTimeout(\n\t\t\t\t\tthis.sendJoinResponseIfStillNeeded,\n\t\t\t\t\tminResponseTime - now,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t};\n\n\t/**\n\t * Handles responding to another client joining the session.\n\t *\n\t * @param updateProviders - list of client connection id's that requestor selected\n\t * to provide response\n\t * @param requestor - `requestor` is only used in telemetry. While it is the requestor's\n\t * client connection id, that is not most important. It is important that this is a\n\t * unique shared id across all clients that might respond as we want to monitor the\n\t * response patterns. The convenience of being client connection id will allow\n\t * correlation with other telemetry where it is often called just `clientId`.\n\t */\n\tprivate prepareJoinResponse(\n\t\tupdateProviders: ClientConnectionId[],\n\t\trequestor: ClientConnectionId,\n\t): void {\n\t\t// We must be connected to receive this message, so clientId should be defined.\n\t\t// If it isn't then, not really a problem; just won't be in provider or audience list.\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\tconst selfClientId = this.runtime.getClientId()!;\n\t\tlet joinResponseDelayMs = broadcastJoinResponseDelaysMs.namedResponder;\n\t\tlet relativeResponseOrder: number | undefined;\n\t\tif (!updateProviders.includes(selfClientId)) {\n\t\t\t// Schedule a broadcast to the new client after a delay only to send if\n\t\t\t// another broadcast satisfying the request hasn't been seen in the\n\t\t\t// meantime. The delay is based on the position in the quorum list. It\n\t\t\t// doesn't have to be a stable list across all clients. We need\n\t\t\t// something to provide suggested order to prevent a flood of broadcasts.\n\t\t\tconst quorumMembers = this.runtime.getQuorum().getMembers();\n\t\t\tconst self = quorumMembers.get(selfClientId);\n\t\t\tif (self) {\n\t\t\t\t// Compute order quorum join order (indicated by sequenceNumber)\n\t\t\t\trelativeResponseOrder = 0;\n\t\t\t\tfor (const { client, sequenceNumber } of quorumMembers.values()) {\n\t\t\t\t\tif (\n\t\t\t\t\t\tsequenceNumber < self.sequenceNumber &&\n\t\t\t\t\t\tclient.details.capabilities.interactive\n\t\t\t\t\t) {\n\t\t\t\t\t\trelativeResponseOrder++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// Order past quorum members + arbitrary additional offset up to 10\n\t\t\t\tlet possibleQuorumRespondents = 0;\n\t\t\t\tfor (const { client } of quorumMembers.values()) {\n\t\t\t\t\tif (client.details.capabilities.interactive) {\n\t\t\t\t\t\tpossibleQuorumRespondents++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\trelativeResponseOrder = possibleQuorumRespondents + Math.random() * 10;\n\t\t\t}\n\t\t\t// When not named to provide update, wait an additional amount\n\t\t\t// of time for those named or others to respond.\n\t\t\tjoinResponseDelayMs +=\n\t\t\t\tbroadcastJoinResponseDelaysMs.backupResponderIncrement *\n\t\t\t\t(3 * updateProviders.length + relativeResponseOrder);\n\t\t}\n\n\t\t// Add the requestor to the list of clients that will receive the broadcast.\n\t\tconst deadlineTime = Date.now() + joinResponseDelayMs;\n\t\tthis.broadcastRequests.set(requestor, {\n\t\t\tdeadlineTime,\n\t\t\tresponseOrder: relativeResponseOrder,\n\t\t});\n\n\t\tif (!this.reasonForCompleteSnapshot) {\n\t\t\t// Check if requestor count meets or exceeds count of other audience\n\t\t\t// members indicating that we effectively have a complete snapshot\n\t\t\t// (once the current message being processed is processed).\n\t\t\tconst { selfPresent, interactiveMembersExcludingSelf } =\n\t\t\t\tthis.getAudienceInformation(selfClientId);\n\t\t\tif (\n\t\t\t\t// Self-present check is done to help ensure that audience\n\t\t\t\t// information is accurate. If self is not present, audience\n\t\t\t\t// information might be incomplete.\n\t\t\t\tselfPresent &&\n\t\t\t\tthis.broadcastRequests.size >= interactiveMembersExcludingSelf.all.size\n\t\t\t) {\n\t\t\t\t// Note that no action is taken here specifically.\n\t\t\t\t// We want action to be queued so that it takes place after\n\t\t\t\t// current message is completely processed. All of the actions\n\t\t\t\t// below should be delayed (not immediate).\n\t\t\t\tthis.reasonForCompleteSnapshot = \"full requests\";\n\t\t\t}\n\t\t}\n\n\t\t// Check if capable of full primary response. If requested to provide\n\t\t// primary response, but do not yet have complete snapshot, we need to\n\t\t// delay a full response, until we think we have complete snapshot. In\n\t\t// the meantime we will send partial updates as usual.\n\t\tif (this.reasonForCompleteSnapshot && updateProviders.includes(selfClientId)) {\n\t\t\t// Use regular message queue to handle timing of the broadcast.\n\t\t\t// Any more immediate broadcasts will accelerate the response time.\n\t\t\t// As a primary responder, it is expected that broadcast will happen and\n\t\t\t// using the regular queue allows other updates to avoid merge work.\n\t\t\tthis.enqueueMessage(\"sendAll\", {\n\t\t\t\tallowableUpdateLatencyMs: joinResponseDelayMs,\n\t\t\t});\n\t\t} else {\n\t\t\t// Check if there isn't already a timer scheduled to send a join\n\t\t\t// response with in this request's deadline.\n\t\t\tif (\n\t\t\t\tthis.broadcastRequestsTimer.hasExpired() ||\n\t\t\t\tdeadlineTime < this.broadcastRequestsTimer.expireTime\n\t\t\t) {\n\t\t\t\t// Set or update the timer.\n\t\t\t\tthis.broadcastRequestsTimer.setTimeout(\n\t\t\t\t\tthis.sendJoinResponseIfStillNeeded,\n\t\t\t\t\tjoinResponseDelayMs,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
|
package/lib/presenceManager.js
CHANGED
|
@@ -106,7 +106,7 @@ class PresenceManager {
|
|
|
106
106
|
// rolling.
|
|
107
107
|
if (!local && !this.joined) {
|
|
108
108
|
const selfClientId = this.runtime.getClientId();
|
|
109
|
-
assert(selfClientId !== undefined,
|
|
109
|
+
assert(selfClientId !== undefined, 0xcbf /* Received signal without clientId */);
|
|
110
110
|
this.onJoin(selfClientId, /* alternateUpdateProvider */ message.clientId);
|
|
111
111
|
}
|
|
112
112
|
this.datastoreManager.processSignal(message, local,
|