@fluidframework/presence 2.74.0-370705 → 2.80.0
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/alpha.d.ts +1 -0
- package/dist/beta.d.ts +1 -0
- package/dist/exposedInternalTypes.d.ts +1 -1
- package/dist/exposedInternalTypes.d.ts.map +1 -1
- package/dist/exposedInternalTypes.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/internalTypes.d.ts +6 -0
- package/dist/internalTypes.d.ts.map +1 -1
- package/dist/internalTypes.js.map +1 -1
- package/dist/latestMapValueManager.d.ts +33 -14
- package/dist/latestMapValueManager.d.ts.map +1 -1
- package/dist/latestMapValueManager.js +33 -16
- package/dist/latestMapValueManager.js.map +1 -1
- package/dist/legacy.alpha.d.ts +1 -0
- 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 +7 -11
- package/dist/presenceDatastoreManager.d.ts.map +1 -1
- package/dist/presenceDatastoreManager.js +11 -62
- package/dist/presenceDatastoreManager.js.map +1 -1
- package/dist/presenceManager.d.ts.map +1 -1
- package/dist/presenceManager.js +68 -23
- package/dist/presenceManager.js.map +1 -1
- package/dist/stateDatastore.d.ts +2 -2
- package/dist/stateDatastore.d.ts.map +1 -1
- package/dist/stateDatastore.js.map +1 -1
- package/dist/systemWorkspace.d.ts +2 -1
- package/dist/systemWorkspace.d.ts.map +1 -1
- package/dist/systemWorkspace.js +95 -42
- package/dist/systemWorkspace.js.map +1 -1
- package/lib/alpha.d.ts +1 -0
- package/lib/beta.d.ts +1 -0
- package/lib/exposedInternalTypes.d.ts +1 -1
- package/lib/exposedInternalTypes.d.ts.map +1 -1
- package/lib/exposedInternalTypes.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/internalTypes.d.ts +6 -0
- package/lib/internalTypes.d.ts.map +1 -1
- package/lib/internalTypes.js.map +1 -1
- package/lib/latestMapValueManager.d.ts +33 -14
- package/lib/latestMapValueManager.d.ts.map +1 -1
- package/lib/latestMapValueManager.js +33 -16
- package/lib/latestMapValueManager.js.map +1 -1
- package/lib/legacy.alpha.d.ts +1 -0
- 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 +7 -11
- package/lib/presenceDatastoreManager.d.ts.map +1 -1
- package/lib/presenceDatastoreManager.js +11 -62
- package/lib/presenceDatastoreManager.js.map +1 -1
- package/lib/presenceManager.d.ts.map +1 -1
- package/lib/presenceManager.js +64 -19
- package/lib/presenceManager.js.map +1 -1
- package/lib/stateDatastore.d.ts +2 -2
- package/lib/stateDatastore.d.ts.map +1 -1
- package/lib/stateDatastore.js.map +1 -1
- package/lib/systemWorkspace.d.ts +2 -1
- package/lib/systemWorkspace.d.ts.map +1 -1
- package/lib/systemWorkspace.js +95 -42
- package/lib/systemWorkspace.js.map +1 -1
- package/package.json +25 -24
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"presenceDatastoreManager.js","sourceRoot":"","sources":["../src/presenceDatastoreManager.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAKH,kEAA6D;AAa7D,yDAAmD;AAYnD,2DAI6B;AAW7B,+CAIuB;AAEvB,uDAAiD;AAuBjD,MAAM,sBAAsB,GAAyD;IACpF,CAAC,EAAE,QAAQ;IACX,CAAC,EAAE,eAAe;CACT,CAAC;AAEX,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAC;IACjC,6BAAe;IACf,wCAA0B;IAC1B,wCAA0B;CAC1B,CAAC,CAAC;AACH,SAAS,iBAAiB,CACzB,OAAgD;IAEhD,OAAO,iBAAiB,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,CAAC;gBACF,kDAAkD;gBAClD,2DAA2D;gBAC3D,8DAA8D;gBAC9D,2CAA2C;gBAC3C,IAAI,CAAC,yBAAyB,GAAG,eAAe,CAAC;YAClD,CAAC;QACF,CAAC;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;AA5yBD,oEA4yBC","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 { 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(clientId: ClientConnectionId): 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>,\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 * When defined, this client is not recognized in the session.\n\t * Call when no longer caring about that condition. That way listeners are\n\t * cleaned up.\n\t */\n\tprivate stopWaitingForSelfInAudience: undefined | (() => void);\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\taudience: IAudience;\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\taudience,\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 { audience, selfPresent, interactiveMembersExcludingSelf } =\n\t\t\tthis.getAudienceInformation(selfClientId);\n\n\t\tif (interactiveMembersExcludingSelf.all.size === 0 && alternateProvider !== undefined) {\n\t\t\tif (selfPresent) {\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} else {\n\t\t\t\t// No one is known. Not even self. Defer judgement on\n\t\t\t\t// complete snapshot until at least self is known to be present.\n\t\t\t\tthis.listenForSelfInAudience(selfClientId, audience);\n\t\t\t\treturn;\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\tprivate listenForSelfInAudience(selfClientId: string, audience: IAudience): void {\n\t\tthis.logger?.sendTelemetryEvent({\n\t\t\teventName: \"JoinDeferred\",\n\t\t\tdetails: {\n\t\t\t\tattendeeId: this.attendeeId,\n\t\t\t\tconnectionId: selfClientId,\n\t\t\t},\n\t\t});\n\t\t// Prepare to join once self audience member joins.\n\t\t// Alternatively, processSignal may force a join when a presence\n\t\t// signal is received even without audience members (assumes\n\t\t// audience signals were lost).\n\t\tconst joinWhenSelfAudienceMemberAdded = (addedClientId: ClientConnectionId): void => {\n\t\t\tif (addedClientId !== selfClientId) {\n\t\t\t\t// Keep listening\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// No need to force here by providing alternate provider as self is\n\t\t\t// now present.\n\t\t\t// Do avoid forcing so that reasonForCompleteSnapshot is set correctly\n\t\t\t// if no others have been added.\n\t\t\tthis.stopWaitingAndJoin(selfClientId, /* alternateProvider */ undefined);\n\t\t};\n\t\taudience.on(\"addMember\", joinWhenSelfAudienceMemberAdded);\n\t\tthis.stopWaitingForSelfInAudience = () => {\n\t\t\taudience.off(\"addMember\", joinWhenSelfAudienceMemberAdded);\n\t\t};\n\t}\n\n\tprivate stopWaitingAndJoin(\n\t\tselfClientId: ClientConnectionId,\n\t\talternateProvider: ClientConnectionId | undefined,\n\t): void {\n\t\tthis.stopWaitingForSelfInAudience?.();\n\t\tthis.stopWaitingForSelfInAudience = undefined;\n\t\t// Confirm not currently disconnected\n\t\tif (this.runtime.getJoinedStatus() !== \"disconnected\") {\n\t\t\tthis.joinSession(selfClientId, alternateProvider);\n\t\t}\n\t}\n\n\tpublic onDisconnected(): void {\n\t\tdelete this.reasonForCompleteSnapshot;\n\t\tthis.stopWaitingForSelfInAudience?.();\n\t\tthis.stopWaitingForSelfInAudience = undefined;\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>,\n\t\tlocal: boolean,\n\t\toptional: boolean,\n\t): void {\n\t\tconst received = Date.now();\n\t\tassert(message.clientId !== null, 0xa3a /* Map received signal without clientId */);\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 selfClientId = this.runtime.getClientId();\n\t\tassert(selfClientId !== undefined, \"Received signal without clientId\");\n\n\t\t// Check for undesired case of receiving a remote presence signal\n\t\t// without having been alerted to self audience join. (Perhaps join\n\t\t// signal was dropped.)\n\t\t// In practice it is commonly observed that local signals can be\n\t\t// returned ahead of audience join notification. So, it is reasonable\n\t\t// to expect that audience join notification may be delayed until after\n\t\t// other presence signals are received. One is enough to get things\n\t\t// rolling.\n\t\tif (this.stopWaitingForSelfInAudience !== undefined) {\n\t\t\tthis.stopWaitingAndJoin(selfClientId, /* alternateProvider */ message.clientId);\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\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,kEAA6D;AAa7D,yDAAmD;AAYnD,2DAI6B;AAW7B,+CAIuB;AAEvB,uDAAiD;AAuBjD,MAAM,sBAAsB,GAAyD;IACpF,CAAC,EAAE,QAAQ;IACX,CAAC,EAAE,eAAe;CACT,CAAC;AAEX,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAC;IACjC,6BAAe;IACf,wCAA0B;IAC1B,wCAA0B;CAC1B,CAAC,CAAC;AACH,SAAS,iBAAiB,CACzB,OAA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EAAmE;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;AA7uBD,oEA6uBC","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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"presenceManager.d.ts","sourceRoot":"","sources":["../src/presenceManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EACX,kBAAkB,EAElB,MAAM,wDAAwD,CAAC;
|
|
1
|
+
{"version":3,"file":"presenceManager.d.ts","sourceRoot":"","sources":["../src/presenceManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EACX,kBAAkB,EAElB,MAAM,wDAAwD,CAAC;AAYhE,OAAO,KAAK,EAAE,0BAA0B,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACxF,OAAO,KAAK,EAEX,UAAU,EACV,yBAAyB,IAAI,QAAQ,EAErC,MAAM,eAAe,CAAC;AAcvB;;GAEG;AACH,MAAM,MAAM,0BAA0B,GAAG,QAAQ,CAChD,IAAI,CAAC,kBAAkB,CAAC,0BAA0B,CAAC,EAAE,eAAe,CAAC,CACrE,CAAC;AA0MF;;GAEG;AACH,wBAAgB,qBAAqB,CACpC,OAAO,EAAE,iBAAiB,EAC1B,UAAU,GAAE,UAA4C,GACtD,QAAQ,GAAG,0BAA0B,CAEvC"}
|
package/dist/presenceManager.js
CHANGED
|
@@ -6,15 +6,25 @@
|
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.createPresenceManager = void 0;
|
|
8
8
|
const client_utils_1 = require("@fluid-internal/client-utils");
|
|
9
|
-
const internal_1 = require("@fluidframework/
|
|
10
|
-
const internal_2 = require("@fluidframework/
|
|
9
|
+
const internal_1 = require("@fluidframework/core-utils/internal");
|
|
10
|
+
const internal_2 = require("@fluidframework/id-compressor/internal");
|
|
11
|
+
const internal_3 = require("@fluidframework/telemetry-utils/internal");
|
|
11
12
|
const presenceDatastoreManager_js_1 = require("./presenceDatastoreManager.js");
|
|
12
13
|
const systemWorkspace_js_1 = require("./systemWorkspace.js");
|
|
14
|
+
/**
|
|
15
|
+
* Confirms that the message is from a client and has a clientId
|
|
16
|
+
* versus from the system which specifies `null` for clientId.
|
|
17
|
+
*/
|
|
18
|
+
function assertMessageIsFromAClient(message) {
|
|
19
|
+
(0, internal_1.assert)(message.clientId !== null, 0xa3a /* Presence received signal without clientId */);
|
|
20
|
+
}
|
|
13
21
|
/**
|
|
14
22
|
* The Presence manager
|
|
15
23
|
*/
|
|
16
24
|
class PresenceManager {
|
|
17
25
|
constructor(runtime, attendeeId) {
|
|
26
|
+
this.runtime = runtime;
|
|
27
|
+
this.joined = false;
|
|
18
28
|
this.events = (0, client_utils_1.createEmitter)();
|
|
19
29
|
this.states = {
|
|
20
30
|
getWorkspace: (workspaceAddress, requestedContent, settings) => this.datastoreManager.getWorkspace(`s:${workspaceAddress}`, requestedContent, settings),
|
|
@@ -25,40 +35,61 @@ class PresenceManager {
|
|
|
25
35
|
this.mc = undefined;
|
|
26
36
|
const logger = runtime.logger;
|
|
27
37
|
if (logger) {
|
|
28
|
-
this.mc = (0,
|
|
38
|
+
this.mc = (0, internal_3.createChildMonitoringContext)({ logger, namespace: "Presence" });
|
|
29
39
|
this.mc.logger.sendTelemetryEvent({ eventName: "PresenceInstantiated" });
|
|
30
40
|
}
|
|
31
41
|
[this.datastoreManager, this.systemWorkspace] = setupSubComponents(attendeeId, runtime, this.events, this.mc?.logger, this);
|
|
32
42
|
this.attendees = this.systemWorkspace;
|
|
33
|
-
runtime.events.on("
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
this.datastoreManager.onDisconnected();
|
|
42
|
-
});
|
|
43
|
-
runtime.getAudience().on("removeMember", this.removeClientConnectionId.bind(this));
|
|
44
|
-
// Check if already connected (can send signals) at the time of construction.
|
|
43
|
+
runtime.events.on("disconnected", this.onDisconnected.bind(this));
|
|
44
|
+
const audience = runtime.getAudience();
|
|
45
|
+
// Listen for self add to Audience to indicate join (with a stable
|
|
46
|
+
// audience population).
|
|
47
|
+
audience.on("addMember", this.addClientConnectionId.bind(this));
|
|
48
|
+
audience.on("removeMember", this.removeClientConnectionId.bind(this));
|
|
49
|
+
// Check if already connected (can send signals and complete audience)
|
|
50
|
+
// at the time of construction.
|
|
45
51
|
// If constructed during data store load, the runtime may already be connected
|
|
46
|
-
// and the "
|
|
47
|
-
// delayed we expect that "
|
|
52
|
+
// and the self-"addMember" event will be raised during completion. With
|
|
53
|
+
// construction delayed we expect that self-"addMember" event has passed.
|
|
48
54
|
// Note: In some manual testing, this does not appear to be enough to
|
|
49
55
|
// always trigger an initial connect.
|
|
50
56
|
const clientId = runtime.getClientId();
|
|
51
|
-
if (clientId !== undefined &&
|
|
52
|
-
|
|
57
|
+
if (clientId !== undefined &&
|
|
58
|
+
runtime.getJoinedStatus() !== "disconnected" &&
|
|
59
|
+
audience.getMember(clientId) !== undefined) {
|
|
60
|
+
this.onJoin(clientId, /* alternateUpdateProvider */ undefined);
|
|
53
61
|
}
|
|
54
62
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
63
|
+
addClientConnectionId(clientConnectionId) {
|
|
64
|
+
// Check specifically for self join that indicates stable audience
|
|
65
|
+
// and is preferred trigger for presence join.
|
|
66
|
+
if (clientConnectionId === this.runtime.getClientId()) {
|
|
67
|
+
this.onJoin(clientConnectionId, /* alternateUpdateProvider */ undefined);
|
|
68
|
+
}
|
|
58
69
|
}
|
|
59
70
|
removeClientConnectionId(clientConnectionId) {
|
|
60
71
|
this.systemWorkspace.removeClientConnectionId(clientConnectionId);
|
|
61
72
|
}
|
|
73
|
+
onJoin(clientConnectionId, alternateUpdateProvider) {
|
|
74
|
+
// System workspace is notified even if already "joined", to handle the
|
|
75
|
+
// audience -> attendee status updates.
|
|
76
|
+
this.systemWorkspace.onConnectionAdded(clientConnectionId,
|
|
77
|
+
// audienceOutOfDate - out of date when onJoin is forced by receiving
|
|
78
|
+
// a signal (which calls with alternateUpdateProvider defined).
|
|
79
|
+
alternateUpdateProvider !== undefined);
|
|
80
|
+
if (!this.joined) {
|
|
81
|
+
this.datastoreManager.joinSession(clientConnectionId, alternateUpdateProvider);
|
|
82
|
+
this.joined = true;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
onDisconnected() {
|
|
86
|
+
this.joined = false;
|
|
87
|
+
const currentClientId = this.runtime.getClientId();
|
|
88
|
+
if (currentClientId !== undefined) {
|
|
89
|
+
this.removeClientConnectionId(currentClientId);
|
|
90
|
+
}
|
|
91
|
+
this.datastoreManager.onDisconnected();
|
|
92
|
+
}
|
|
62
93
|
/**
|
|
63
94
|
* Check for Presence message and process it.
|
|
64
95
|
*
|
|
@@ -67,6 +98,20 @@ class PresenceManager {
|
|
|
67
98
|
* @param local - Whether the message originated locally (`true`) or remotely (`false`)
|
|
68
99
|
*/
|
|
69
100
|
processSignal(addressChain, message, local) {
|
|
101
|
+
assertMessageIsFromAClient(message);
|
|
102
|
+
// Check for undesired case of receiving a remote presence signal
|
|
103
|
+
// without having been alerted to self audience join that is preferred
|
|
104
|
+
// trigger for join. (Perhaps join signal was dropped.)
|
|
105
|
+
// In practice it is commonly observed that local signals can be
|
|
106
|
+
// returned ahead of audience join notification. So, it is reasonable
|
|
107
|
+
// to expect that audience join notification may be delayed until after
|
|
108
|
+
// other presence signals are received. One is enough to get things
|
|
109
|
+
// rolling.
|
|
110
|
+
if (!local && !this.joined) {
|
|
111
|
+
const selfClientId = this.runtime.getClientId();
|
|
112
|
+
(0, internal_1.assert)(selfClientId !== undefined, "Received signal without clientId");
|
|
113
|
+
this.onJoin(selfClientId, /* alternateUpdateProvider */ message.clientId);
|
|
114
|
+
}
|
|
70
115
|
this.datastoreManager.processSignal(message, local,
|
|
71
116
|
/* optional */ addressChain[0] === "?");
|
|
72
117
|
}
|
|
@@ -92,7 +137,7 @@ function setupSubComponents(attendeeId, runtime, events, logger, presence) {
|
|
|
92
137
|
/**
|
|
93
138
|
* Instantiates Presence Manager
|
|
94
139
|
*/
|
|
95
|
-
function createPresenceManager(runtime, attendeeId = (0,
|
|
140
|
+
function createPresenceManager(runtime, attendeeId = (0, internal_2.createSessionId)()) {
|
|
96
141
|
return new PresenceManager(runtime, attendeeId);
|
|
97
142
|
}
|
|
98
143
|
exports.createPresenceManager = createPresenceManager;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"presenceManager.js","sourceRoot":"","sources":["../src/presenceManager.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAA6D;AAM7D,qEAAyE;AAKzE,uEAAwF;AAYxF,+EAA6E;AAG7E,6DAA6D;AAgB7D;;GAEG;AACH,MAAM,eAAe;IA0BpB,YAAmB,OAA0B,EAAE,UAAsB;QAtBrD,WAAM,GAAG,IAAA,4BAAa,GAAoC,CAAC;QAI3D,WAAM,GAAG;YACxB,YAAY,EAAE,CACb,gBAAkC,EAClC,gBAAyB,EACzB,QAAmC,EACR,EAAE,CAC7B,IAAI,CAAC,gBAAgB,CAAC,YAAY,CAAC,KAAK,gBAAgB,EAAE,EAAE,gBAAgB,EAAE,QAAQ,CAAC;SACxF,CAAC;QACc,kBAAa,GAAG;YAC/B,YAAY,EAAE,CACb,gBAAkC,EAClC,gBAAyB,EACS,EAAE,CACpC,IAAI,CAAC,gBAAgB,CAAC,YAAY,CAAC,KAAK,gBAAgB,EAAE,EAAE,gBAAgB,CAAC;SAC9E,CAAC;QAEe,OAAE,GAAkC,SAAS,CAAC;QAG9D,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC9B,IAAI,MAAM,EA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O,IAAI,eAAe,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;AACjD,CAAC;AALD,sDAKC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { createEmitter } from \"@fluid-internal/client-utils\";\nimport type {\n\tContainerExtension,\n\tInboundExtensionMessage,\n} from \"@fluidframework/container-runtime-definitions/internal\";\nimport type { IEmitter, Listenable } from \"@fluidframework/core-interfaces/internal\";\nimport { createSessionId } from \"@fluidframework/id-compressor/internal\";\nimport type {\n\tITelemetryLoggerExt,\n\tMonitoringContext,\n} from \"@fluidframework/telemetry-utils/internal\";\nimport { createChildMonitoringContext } from \"@fluidframework/telemetry-utils/internal\";\n\nimport type { ClientConnectionId } from \"./baseTypes.js\";\nimport type { BroadcastControlSettings } from \"./broadcastControls.js\";\nimport type { ExtensionRuntimeProperties, IEphemeralRuntime } from \"./internalTypes.js\";\nimport type {\n\tAttendeesEvents,\n\tAttendeeId,\n\tPresenceWithNotifications as Presence,\n\tPresenceEvents,\n} from \"./presence.js\";\nimport type { PresenceDatastoreManager } from \"./presenceDatastoreManager.js\";\nimport { PresenceDatastoreManagerImpl } from \"./presenceDatastoreManager.js\";\nimport type { SignalMessages } from \"./protocol.js\";\nimport type { SystemWorkspace, SystemWorkspaceDatastore } from \"./systemWorkspace.js\";\nimport { createSystemWorkspace } from \"./systemWorkspace.js\";\nimport type {\n\tNotificationsWorkspace,\n\tNotificationsWorkspaceSchema,\n\tStatesWorkspace,\n\tStatesWorkspaceSchema,\n\tWorkspaceAddress,\n} from \"./types.js\";\n\n/**\n * Portion of the container extension requirements ({@link ContainerExtension}) that are delegated to presence manager.\n */\nexport type PresenceExtensionInterface = Required<\n\tPick<ContainerExtension<ExtensionRuntimeProperties>, \"processSignal\">\n>;\n\n/**\n * The Presence manager\n */\nclass PresenceManager implements Presence, PresenceExtensionInterface {\n\tprivate readonly datastoreManager: PresenceDatastoreManager;\n\tprivate readonly systemWorkspace: SystemWorkspace;\n\n\tpublic readonly events = createEmitter<PresenceEvents & AttendeesEvents>();\n\n\tpublic readonly attendees: Presence[\"attendees\"];\n\n\tpublic readonly states = {\n\t\tgetWorkspace: <TSchema extends StatesWorkspaceSchema>(\n\t\t\tworkspaceAddress: WorkspaceAddress,\n\t\t\trequestedContent: TSchema,\n\t\t\tsettings?: BroadcastControlSettings,\n\t\t): StatesWorkspace<TSchema> =>\n\t\t\tthis.datastoreManager.getWorkspace(`s:${workspaceAddress}`, requestedContent, settings),\n\t};\n\tpublic readonly notifications = {\n\t\tgetWorkspace: <TSchema extends NotificationsWorkspaceSchema>(\n\t\t\tworkspaceAddress: WorkspaceAddress,\n\t\t\trequestedContent: TSchema,\n\t\t): NotificationsWorkspace<TSchema> =>\n\t\t\tthis.datastoreManager.getWorkspace(`n:${workspaceAddress}`, requestedContent),\n\t};\n\n\tprivate readonly mc: MonitoringContext | undefined = undefined;\n\n\tpublic constructor(runtime: IEphemeralRuntime, attendeeId: AttendeeId) {\n\t\tconst logger = runtime.logger;\n\t\tif (logger) {\n\t\t\tthis.mc = createChildMonitoringContext({ logger, namespace: \"Presence\" });\n\t\t\tthis.mc.logger.sendTelemetryEvent({ eventName: \"PresenceInstantiated\" });\n\t\t}\n\n\t\t[this.datastoreManager, this.systemWorkspace] = setupSubComponents(\n\t\t\tattendeeId,\n\t\t\truntime,\n\t\t\tthis.events,\n\t\t\tthis.mc?.logger,\n\t\t\tthis,\n\t\t);\n\t\tthis.attendees = this.systemWorkspace;\n\n\t\truntime.events.on(\"joined\", ({ clientId: joinedClientId }: { clientId: string }) => {\n\t\t\tthis.onJoin(joinedClientId);\n\t\t});\n\n\t\truntime.events.on(\"disconnected\", () => {\n\t\t\tconst currentClientId = runtime.getClientId();\n\t\t\tif (currentClientId !== undefined) {\n\t\t\t\tthis.removeClientConnectionId(currentClientId);\n\t\t\t}\n\t\t\tthis.datastoreManager.onDisconnected();\n\t\t});\n\n\t\truntime.getAudience().on(\"removeMember\", this.removeClientConnectionId.bind(this));\n\n\t\t// Check if already connected (can send signals) at the time of construction.\n\t\t// If constructed during data store load, the runtime may already be connected\n\t\t// and the \"joined\" event will be raised during completion. With construction\n\t\t// delayed we expect that \"joined\" event has passed.\n\t\t// Note: In some manual testing, this does not appear to be enough to\n\t\t// always trigger an initial connect.\n\t\tconst clientId = runtime.getClientId();\n\t\tif (clientId !== undefined && runtime.getJoinedStatus() !== \"disconnected\") {\n\t\t\tthis.onJoin(clientId);\n\t\t}\n\t}\n\n\tprivate onJoin(clientConnectionId: ClientConnectionId): void {\n\t\tthis.systemWorkspace.onConnectionAdded(clientConnectionId);\n\t\tthis.datastoreManager.joinSession(clientConnectionId);\n\t}\n\n\tprivate removeClientConnectionId(clientConnectionId: ClientConnectionId): void {\n\t\tthis.systemWorkspace.removeClientConnectionId(clientConnectionId);\n\t}\n\t/**\n\t * Check for Presence message and process it.\n\t *\n\t * @param addressChain - Address chain of the message\n\t * @param message - Unverified message to be processed\n\t * @param local - Whether the message originated locally (`true`) or remotely (`false`)\n\t */\n\tpublic processSignal(\n\t\taddressChain: string[],\n\t\tmessage: InboundExtensionMessage<SignalMessages>,\n\t\tlocal: boolean,\n\t): void {\n\t\tthis.datastoreManager.processSignal(\n\t\t\tmessage,\n\t\t\tlocal,\n\t\t\t/* optional */ addressChain[0] === \"?\",\n\t\t);\n\t}\n}\n\n/**\n * Helper for Presence Manager setup\n *\n * Presence Manager is outermost layer of the presence system and has two main\n * sub-components:\n * 1. PresenceDatastoreManager: Manages the unified general data for states and\n * registry for workspaces.\n * 2. SystemWorkspace: Custom internal workspace for system states including\n * attendee management. It is registered with the PresenceDatastoreManager.\n */\nfunction setupSubComponents(\n\tattendeeId: AttendeeId,\n\truntime: IEphemeralRuntime,\n\tevents: Listenable<PresenceEvents & AttendeesEvents> &\n\t\tIEmitter<PresenceEvents & AttendeesEvents>,\n\tlogger: ITelemetryLoggerExt | undefined,\n\tpresence: Presence,\n): [PresenceDatastoreManager, SystemWorkspace] {\n\tconst systemWorkspaceDatastore: SystemWorkspaceDatastore = {\n\t\tclientToSessionId: {},\n\t};\n\tconst systemWorkspaceConfig = createSystemWorkspace(\n\t\tattendeeId,\n\t\tsystemWorkspaceDatastore,\n\t\tevents,\n\t\truntime.getAudience(),\n\t);\n\tconst datastoreManager = new PresenceDatastoreManagerImpl(\n\t\tattendeeId,\n\t\truntime,\n\t\tlogger,\n\t\tevents,\n\t\tpresence,\n\t\tsystemWorkspaceDatastore,\n\t\tsystemWorkspaceConfig.statesEntry,\n\t);\n\treturn [datastoreManager, systemWorkspaceConfig.workspace];\n}\n\n/**\n * Instantiates Presence Manager\n */\nexport function createPresenceManager(\n\truntime: IEphemeralRuntime,\n\tattendeeId: AttendeeId = createSessionId() as AttendeeId,\n): Presence & PresenceExtensionInterface {\n\treturn new PresenceManager(runtime, attendeeId);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"presenceManager.js","sourceRoot":"","sources":["../src/presenceManager.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAA6D;AAM7D,kEAA6D;AAC7D,qEAAyE;AAKzE,uEAAwF;AAYxF,+EAA6E;AAG7E,6DAA6D;AAgB7D;;;GAGG;AACH,SAAS,0BAA0B,CAClC,OAAgD;IAIhD,IAAA,iBAAM,EAAC,OAAO,CAAC,QAAQ,KAAK,IAAI,EAAE,KAAK,CAAC,+CAA+C,CAAC,CAAC;AAC1F,CAAC;AAED;;GAEG;AACH,MAAM,eAAe;IA2BpB,YACkB,OAA0B,EAC3C,UAAsB;QADL,YAAO,GAAP,OAAO,CAAmB;QA3BpC,WAAM,GAAG,KAAK,CAAC;QAIP,WAAM,GAAG,IAAA,4BAAa,GAAoC,CAAC;QAI3D,WAAM,GAAG;YACxB,YAAY,EAAE,CACb,gBAAkC,EAClC,gBAAyB,EACzB,QAAmC,EACR,EAAE,CAC7B,IAAI,CAAC,gBAAgB,CAAC,YAAY,CAAC,KAAK,gBAAgB,EAAE,EAAE,gBAAgB,EAAE,QA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O,CAAC,gBAAgB,EAAE,qBAAqB,CAAC,SAAS,CAAC,CAAC;AAC5D,CAAC;AAED;;GAEG;AACH,SAAgB,qBAAqB,CACpC,OAA0B,EAC1B,aAAyB,IAAA,0BAAe,GAAgB;IAExD,OAAO,IAAI,eAAe,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;AACjD,CAAC;AALD,sDAKC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { createEmitter } from \"@fluid-internal/client-utils\";\nimport type {\n\tContainerExtension,\n\tInboundExtensionMessage,\n} from \"@fluidframework/container-runtime-definitions/internal\";\nimport type { IEmitter, Listenable } from \"@fluidframework/core-interfaces/internal\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport { createSessionId } from \"@fluidframework/id-compressor/internal\";\nimport type {\n\tITelemetryLoggerExt,\n\tMonitoringContext,\n} from \"@fluidframework/telemetry-utils/internal\";\nimport { createChildMonitoringContext } from \"@fluidframework/telemetry-utils/internal\";\n\nimport type { ClientConnectionId } from \"./baseTypes.js\";\nimport type { BroadcastControlSettings } from \"./broadcastControls.js\";\nimport type { ExtensionRuntimeProperties, IEphemeralRuntime } from \"./internalTypes.js\";\nimport type {\n\tAttendeesEvents,\n\tAttendeeId,\n\tPresenceWithNotifications as Presence,\n\tPresenceEvents,\n} from \"./presence.js\";\nimport type { PresenceDatastoreManager } from \"./presenceDatastoreManager.js\";\nimport { PresenceDatastoreManagerImpl } from \"./presenceDatastoreManager.js\";\nimport type { SignalMessages } from \"./protocol.js\";\nimport type { SystemWorkspace, SystemWorkspaceDatastore } from \"./systemWorkspace.js\";\nimport { createSystemWorkspace } from \"./systemWorkspace.js\";\nimport type {\n\tNotificationsWorkspace,\n\tNotificationsWorkspaceSchema,\n\tStatesWorkspace,\n\tStatesWorkspaceSchema,\n\tWorkspaceAddress,\n} from \"./types.js\";\n\n/**\n * Portion of the container extension requirements ({@link ContainerExtension}) that are delegated to presence manager.\n */\nexport type PresenceExtensionInterface = Required<\n\tPick<ContainerExtension<ExtensionRuntimeProperties>, \"processSignal\">\n>;\n\n/**\n * Confirms that the message is from a client and has a clientId\n * versus from the system which specifies `null` for clientId.\n */\nfunction assertMessageIsFromAClient(\n\tmessage: InboundExtensionMessage<SignalMessages>,\n): asserts message is InboundExtensionMessage<SignalMessages> & {\n\tclientId: ClientConnectionId;\n} {\n\tassert(message.clientId !== null, 0xa3a /* Presence received signal without clientId */);\n}\n\n/**\n * The Presence manager\n */\nclass PresenceManager implements Presence, PresenceExtensionInterface {\n\tprivate joined = false;\n\tprivate readonly datastoreManager: PresenceDatastoreManager;\n\tprivate readonly systemWorkspace: SystemWorkspace;\n\n\tpublic readonly events = createEmitter<PresenceEvents & AttendeesEvents>();\n\n\tpublic readonly attendees: Presence[\"attendees\"];\n\n\tpublic readonly states = {\n\t\tgetWorkspace: <TSchema extends StatesWorkspaceSchema>(\n\t\t\tworkspaceAddress: WorkspaceAddress,\n\t\t\trequestedContent: TSchema,\n\t\t\tsettings?: BroadcastControlSettings,\n\t\t): StatesWorkspace<TSchema> =>\n\t\t\tthis.datastoreManager.getWorkspace(`s:${workspaceAddress}`, requestedContent, settings),\n\t};\n\tpublic readonly notifications = {\n\t\tgetWorkspace: <TSchema extends NotificationsWorkspaceSchema>(\n\t\t\tworkspaceAddress: WorkspaceAddress,\n\t\t\trequestedContent: TSchema,\n\t\t): NotificationsWorkspace<TSchema> =>\n\t\t\tthis.datastoreManager.getWorkspace(`n:${workspaceAddress}`, requestedContent),\n\t};\n\n\tprivate readonly mc: MonitoringContext | undefined = undefined;\n\n\tpublic constructor(\n\t\tprivate readonly runtime: IEphemeralRuntime,\n\t\tattendeeId: AttendeeId,\n\t) {\n\t\tconst logger = runtime.logger;\n\t\tif (logger) {\n\t\t\tthis.mc = createChildMonitoringContext({ logger, namespace: \"Presence\" });\n\t\t\tthis.mc.logger.sendTelemetryEvent({ eventName: \"PresenceInstantiated\" });\n\t\t}\n\n\t\t[this.datastoreManager, this.systemWorkspace] = setupSubComponents(\n\t\t\tattendeeId,\n\t\t\truntime,\n\t\t\tthis.events,\n\t\t\tthis.mc?.logger,\n\t\t\tthis,\n\t\t);\n\t\tthis.attendees = this.systemWorkspace;\n\n\t\truntime.events.on(\"disconnected\", this.onDisconnected.bind(this));\n\n\t\tconst audience = runtime.getAudience();\n\t\t// Listen for self add to Audience to indicate join (with a stable\n\t\t// audience population).\n\t\taudience.on(\"addMember\", this.addClientConnectionId.bind(this));\n\t\taudience.on(\"removeMember\", this.removeClientConnectionId.bind(this));\n\n\t\t// Check if already connected (can send signals and complete audience)\n\t\t// at the time of construction.\n\t\t// If constructed during data store load, the runtime may already be connected\n\t\t// and the self-\"addMember\" event will be raised during completion. With\n\t\t// construction delayed we expect that self-\"addMember\" event has passed.\n\t\t// Note: In some manual testing, this does not appear to be enough to\n\t\t// always trigger an initial connect.\n\t\tconst clientId = runtime.getClientId();\n\t\tif (\n\t\t\tclientId !== undefined &&\n\t\t\truntime.getJoinedStatus() !== \"disconnected\" &&\n\t\t\taudience.getMember(clientId) !== undefined\n\t\t) {\n\t\t\tthis.onJoin(clientId, /* alternateUpdateProvider */ undefined);\n\t\t}\n\t}\n\n\tprivate addClientConnectionId(clientConnectionId: ClientConnectionId): void {\n\t\t// Check specifically for self join that indicates stable audience\n\t\t// and is preferred trigger for presence join.\n\t\tif (clientConnectionId === this.runtime.getClientId()) {\n\t\t\tthis.onJoin(clientConnectionId, /* alternateUpdateProvider */ undefined);\n\t\t}\n\t}\n\n\tprivate removeClientConnectionId(clientConnectionId: ClientConnectionId): void {\n\t\tthis.systemWorkspace.removeClientConnectionId(clientConnectionId);\n\t}\n\n\tprivate onJoin(\n\t\tclientConnectionId: ClientConnectionId,\n\t\talternateUpdateProvider: ClientConnectionId | undefined,\n\t): void {\n\t\t// System workspace is notified even if already \"joined\", to handle the\n\t\t// audience -> attendee status updates.\n\t\tthis.systemWorkspace.onConnectionAdded(\n\t\t\tclientConnectionId,\n\t\t\t// audienceOutOfDate - out of date when onJoin is forced by receiving\n\t\t\t// a signal (which calls with alternateUpdateProvider defined).\n\t\t\talternateUpdateProvider !== undefined,\n\t\t);\n\t\tif (!this.joined) {\n\t\t\tthis.datastoreManager.joinSession(clientConnectionId, alternateUpdateProvider);\n\t\t\tthis.joined = true;\n\t\t}\n\t}\n\n\tprivate onDisconnected(): void {\n\t\tthis.joined = false;\n\t\tconst currentClientId = this.runtime.getClientId();\n\t\tif (currentClientId !== undefined) {\n\t\t\tthis.removeClientConnectionId(currentClientId);\n\t\t}\n\t\tthis.datastoreManager.onDisconnected();\n\t}\n\n\t/**\n\t * Check for Presence message and process it.\n\t *\n\t * @param addressChain - Address chain of the message\n\t * @param message - Unverified message to be processed\n\t * @param local - Whether the message originated locally (`true`) or remotely (`false`)\n\t */\n\tpublic processSignal(\n\t\taddressChain: string[],\n\t\tmessage: InboundExtensionMessage<SignalMessages>,\n\t\tlocal: boolean,\n\t): void {\n\t\tassertMessageIsFromAClient(message);\n\n\t\t// Check for undesired case of receiving a remote presence signal\n\t\t// without having been alerted to self audience join that is preferred\n\t\t// trigger for join. (Perhaps join signal was dropped.)\n\t\t// In practice it is commonly observed that local signals can be\n\t\t// returned ahead of audience join notification. So, it is reasonable\n\t\t// to expect that audience join notification may be delayed until after\n\t\t// other presence signals are received. One is enough to get things\n\t\t// rolling.\n\t\tif (!local && !this.joined) {\n\t\t\tconst selfClientId = this.runtime.getClientId();\n\t\t\tassert(selfClientId !== undefined, \"Received signal without clientId\");\n\t\t\tthis.onJoin(selfClientId, /* alternateUpdateProvider */ message.clientId);\n\t\t}\n\n\t\tthis.datastoreManager.processSignal(\n\t\t\tmessage,\n\t\t\tlocal,\n\t\t\t/* optional */ addressChain[0] === \"?\",\n\t\t);\n\t}\n}\n\n/**\n * Helper for Presence Manager setup\n *\n * Presence Manager is outermost layer of the presence system and has two main\n * sub-components:\n * 1. PresenceDatastoreManager: Manages the unified general data for states and\n * registry for workspaces.\n * 2. SystemWorkspace: Custom internal workspace for system states including\n * attendee management. It is registered with the PresenceDatastoreManager.\n */\nfunction setupSubComponents(\n\tattendeeId: AttendeeId,\n\truntime: IEphemeralRuntime,\n\tevents: Listenable<PresenceEvents & AttendeesEvents> &\n\t\tIEmitter<PresenceEvents & AttendeesEvents>,\n\tlogger: ITelemetryLoggerExt | undefined,\n\tpresence: Presence,\n): [PresenceDatastoreManager, SystemWorkspace] {\n\tconst systemWorkspaceDatastore: SystemWorkspaceDatastore = {\n\t\tclientToSessionId: {},\n\t};\n\tconst systemWorkspaceConfig = createSystemWorkspace(\n\t\tattendeeId,\n\t\tsystemWorkspaceDatastore,\n\t\tevents,\n\t\truntime.getAudience(),\n\t);\n\tconst datastoreManager = new PresenceDatastoreManagerImpl(\n\t\tattendeeId,\n\t\truntime,\n\t\tlogger,\n\t\tevents,\n\t\tpresence,\n\t\tsystemWorkspaceDatastore,\n\t\tsystemWorkspaceConfig.statesEntry,\n\t);\n\treturn [datastoreManager, systemWorkspaceConfig.workspace];\n}\n\n/**\n * Instantiates Presence Manager\n */\nexport function createPresenceManager(\n\truntime: IEphemeralRuntime,\n\tattendeeId: AttendeeId = createSessionId() as AttendeeId,\n): Presence & PresenceExtensionInterface {\n\treturn new PresenceManager(runtime, attendeeId);\n}\n"]}
|
package/dist/stateDatastore.d.ts
CHANGED
|
@@ -25,9 +25,9 @@ export interface LocalStateUpdateOptions {
|
|
|
25
25
|
* Contract for States Workspace to support State Manager access to
|
|
26
26
|
* datastore and general internal presence knowledge.
|
|
27
27
|
*/
|
|
28
|
-
export interface StateDatastore<TKey extends string,
|
|
28
|
+
export interface StateDatastore<TKey extends string, TLocalUpdateValue extends InternalTypes.ValueDirectoryOrState<unknown>, TStoredValue extends ValidatableValueDirectoryOrState<unknown> = ValidatableValueStructure<TLocalUpdateValue>> {
|
|
29
29
|
readonly presence: Presence;
|
|
30
|
-
localUpdate(key: TKey, value:
|
|
30
|
+
localUpdate(key: TKey, value: TLocalUpdateValue & {
|
|
31
31
|
ignoreUnmonitored?: true;
|
|
32
32
|
}, options: LocalStateUpdateOptions): void;
|
|
33
33
|
update(key: TKey, attendeeId: AttendeeId, value: TStoredValue): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stateDatastore.d.ts","sourceRoot":"","sources":["../src/stateDatastore.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,KAAK,EACX,YAAY,EACZ,gCAAgC,EAChC,yBAAyB,EACzB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,UAAU,EAAE,yBAAyB,IAAI,QAAQ,EAAE,MAAM,eAAe,CAAC;AAcvF;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACvC;;;;OAIG;IACH,wBAAwB,EAAE,MAAM,GAAG,SAAS,CAAC;IAE7C;;OAEG;IACH,cAAc,CAAC,EAAE,kBAAkB,CAAC;CACpC;AAED;;;GAGG;AACH,MAAM,WAAW,cAAc,CAC9B,IAAI,SAAS,MAAM,EACnB,
|
|
1
|
+
{"version":3,"file":"stateDatastore.d.ts","sourceRoot":"","sources":["../src/stateDatastore.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,KAAK,EACX,YAAY,EACZ,gCAAgC,EAChC,yBAAyB,EACzB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,UAAU,EAAE,yBAAyB,IAAI,QAAQ,EAAE,MAAM,eAAe,CAAC;AAcvF;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACvC;;;;OAIG;IACH,wBAAwB,EAAE,MAAM,GAAG,SAAS,CAAC;IAE7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1
|
-
{"version":3,"file":"stateDatastore.js","sourceRoot":"","sources":["../src/stateDatastore.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAiEH;;GAEG;AACH,SAAgB,mBAAmB,CAOlC,SAAuC;IAEvC,OAAO,SAGN,CAAC;AACH,CAAC;AAbD,kDAaC;AAED;;GAEG;AACH,SAAgB,mBAAmB,CAGjC,MAAwD;IACzD,OAAO,MAAiD,CAAC;AAC1D,CAAC;AALD,kDAKC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { ClientConnectionId } from \"./baseTypes.js\";\nimport type { InternalTypes } from \"./exposedInternalTypes.js\";\nimport type {\n\tClientRecord,\n\tValidatableValueDirectoryOrState,\n\tValidatableValueStructure,\n} from \"./internalTypes.js\";\nimport type { AttendeeId, PresenceWithNotifications as Presence } from \"./presence.js\";\n\n// type StateDatastoreSchemaNode<\n// \tTValue extends InternalTypes.ValueDirectoryOrState<any> = InternalTypes.ValueDirectoryOrState<unknown>,\n// > = TValue extends InternalTypes.ValueDirectoryOrState<infer T> ? InternalTypes.ValueDirectoryOrState<T> : never;\n\n// export interface StateDatastoreSchema {\n// \t// This type is not precise. It may\n// \t// need to be replaced with StatesWorkspace schema pattern\n// \t// similar to what is commented out.\n// \t[key: string]: InternalTypes.ValueDirectoryOrState<unknown>;\n// \t// [key: string]: StateDatastoreSchemaNode;\n// }\n\n/**\n * Miscellaneous options for local state updates\n */\nexport interface LocalStateUpdateOptions {\n\t/**\n\t * When defined, this is the maximum time in milliseconds that this\n\t * update is allowed to be delayed before it must be sent to service.\n\t * When `undefined`, the callee may determine maximum delay.\n\t */\n\tallowableUpdateLatencyMs: number | undefined;\n\n\t/**\n\t * Special option allowed for unicast notifications.\n\t */\n\ttargetClientId?: ClientConnectionId;\n}\n\n/**\n * Contract for States Workspace to support State Manager access to\n * datastore and general internal presence knowledge.\n */\nexport interface StateDatastore<\n\tTKey extends string,\n\
|
|
1
|
+
{"version":3,"file":"stateDatastore.js","sourceRoot":"","sources":["../src/stateDatastore.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAiEH;;GAEG;AACH,SAAgB,mBAAmB,CAOlC,SAAuC;IAEvC,OAAO,SAGN,CAAC;AACH,CAAC;AAbD,kDAaC;AAED;;GAEG;AACH,SAAgB,mBAAmB,CAGjC,MAAwD;IACzD,OAAO,MAAiD,CAAC;AAC1D,CAAC;AALD,kDAKC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { ClientConnectionId } from \"./baseTypes.js\";\nimport type { InternalTypes } from \"./exposedInternalTypes.js\";\nimport type {\n\tClientRecord,\n\tValidatableValueDirectoryOrState,\n\tValidatableValueStructure,\n} from \"./internalTypes.js\";\nimport type { AttendeeId, PresenceWithNotifications as Presence } from \"./presence.js\";\n\n// type StateDatastoreSchemaNode<\n// \tTValue extends InternalTypes.ValueDirectoryOrState<any> = InternalTypes.ValueDirectoryOrState<unknown>,\n// > = TValue extends InternalTypes.ValueDirectoryOrState<infer T> ? InternalTypes.ValueDirectoryOrState<T> : never;\n\n// export interface StateDatastoreSchema {\n// \t// This type is not precise. It may\n// \t// need to be replaced with StatesWorkspace schema pattern\n// \t// similar to what is commented out.\n// \t[key: string]: InternalTypes.ValueDirectoryOrState<unknown>;\n// \t// [key: string]: StateDatastoreSchemaNode;\n// }\n\n/**\n * Miscellaneous options for local state updates\n */\nexport interface LocalStateUpdateOptions {\n\t/**\n\t * When defined, this is the maximum time in milliseconds that this\n\t * update is allowed to be delayed before it must be sent to service.\n\t * When `undefined`, the callee may determine maximum delay.\n\t */\n\tallowableUpdateLatencyMs: number | undefined;\n\n\t/**\n\t * Special option allowed for unicast notifications.\n\t */\n\ttargetClientId?: ClientConnectionId;\n}\n\n/**\n * Contract for States Workspace to support State Manager access to\n * datastore and general internal presence knowledge.\n */\nexport interface StateDatastore<\n\tTKey extends string,\n\tTLocalUpdateValue extends InternalTypes.ValueDirectoryOrState<unknown>,\n\tTStoredValue extends\n\t\tValidatableValueDirectoryOrState<unknown> = ValidatableValueStructure<TLocalUpdateValue>,\n> {\n\treadonly presence: Presence;\n\tlocalUpdate(\n\t\tkey: TKey,\n\t\tvalue: TLocalUpdateValue & {\n\t\t\tignoreUnmonitored?: true;\n\t\t},\n\t\toptions: LocalStateUpdateOptions,\n\t): void;\n\tupdate(key: TKey, attendeeId: AttendeeId, value: TStoredValue): void;\n\tknownValues(key: TKey): {\n\t\tself: AttendeeId | undefined;\n\t\tstates: ClientRecord<TStoredValue>;\n\t};\n}\n\n/**\n * Helper to get a handle from a datastore.\n */\nexport function handleFromDatastore<\n\t// Constraining TSchema would be great, but it seems nested types (at least with undefined) cause trouble.\n\t// TSchema as `unknown` still provides some type safety.\n\t// TSchema extends StateDatastoreSchema,\n\tTKey extends string /* & keyof TSchema */,\n\tTValue extends InternalTypes.ValueDirectoryOrState<unknown>,\n>(\n\tdatastore: StateDatastore<TKey, TValue>,\n): InternalTypes.StateDatastoreHandle<TKey, Exclude<TValue, undefined>> {\n\treturn datastore as unknown as InternalTypes.StateDatastoreHandle<\n\t\tTKey,\n\t\tExclude<TValue, undefined>\n\t>;\n}\n\n/**\n * Helper to get the datastore back from its handle.\n */\nexport function datastoreFromHandle<\n\tTKey extends string,\n\tTValue extends InternalTypes.ValueDirectoryOrState<any>,\n>(handle: InternalTypes.StateDatastoreHandle<TKey, TValue>): StateDatastore<TKey, TValue> {\n\treturn handle as unknown as StateDatastore<TKey, TValue>;\n}\n"]}
|
|
@@ -34,8 +34,9 @@ export interface SystemWorkspace extends Exclude<Presence["attendees"], never> {
|
|
|
34
34
|
* Must be called when the current client acquires a new connection.
|
|
35
35
|
*
|
|
36
36
|
* @param clientConnectionId - The new client connection ID.
|
|
37
|
+
* @param audienceOutOfDate - When true, audience cannot be used as authoritative.
|
|
37
38
|
*/
|
|
38
|
-
onConnectionAdded(clientConnectionId: ClientConnectionId): void;
|
|
39
|
+
onConnectionAdded(clientConnectionId: ClientConnectionId, audienceOutOfDate: boolean): void;
|
|
39
40
|
/**
|
|
40
41
|
* Removes the client connection ID from the system workspace.
|
|
41
42
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"systemWorkspace.d.ts","sourceRoot":"","sources":["../src/systemWorkspace.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uCAAuC,CAAC;AACvE,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AAGrF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAG/D,OAAO,KAAK,EAAY,eAAe,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAErF,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAElE,OAAO,KAAK,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAEtE;;;;;GAKG;AACH,UAAU,oBAAqB,SAAQ,aAAa,CAAC,kBAAkB;IACtE,KAAK,EAAE,UAAU,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACxC,iBAAiB,EAAE;QAClB,CAAC,YAAY,EAAE,kBAAkB,GAAG,oBAAoB,CAAC;KACzD,CAAC;CACF;
|
|
1
|
+
{"version":3,"file":"systemWorkspace.d.ts","sourceRoot":"","sources":["../src/systemWorkspace.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uCAAuC,CAAC;AACvE,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AAGrF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,KAAK,E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