@fluidframework/presence 2.80.0 → 2.81.0-374083
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/getPresence.js +2 -2
- package/dist/getPresence.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.d.ts.map +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/presenceDatastoreManager.d.ts.map +1 -1
- package/dist/presenceDatastoreManager.js +6 -5
- package/dist/presenceDatastoreManager.js.map +1 -1
- package/dist/presenceManager.js +1 -1
- package/dist/presenceManager.js.map +1 -1
- package/dist/systemWorkspace.js +1 -1
- package/dist/systemWorkspace.js.map +1 -1
- package/lib/getPresence.js +2 -2
- package/lib/getPresence.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.d.ts.map +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/presenceDatastoreManager.d.ts.map +1 -1
- package/lib/presenceDatastoreManager.js +6 -5
- package/lib/presenceDatastoreManager.js.map +1 -1
- package/lib/presenceManager.js +1 -1
- package/lib/presenceManager.js.map +1 -1
- package/lib/systemWorkspace.js +1 -1
- package/lib/systemWorkspace.js.map +1 -1
- package/package.json +21 -21
package/dist/getPresence.js
CHANGED
|
@@ -48,7 +48,7 @@ class ContainerPresenceManager {
|
|
|
48
48
|
assertCompatibilityInvariants(newCompatibilityRequest);
|
|
49
49
|
// There have not yet been any changes that would require action to upgrade.
|
|
50
50
|
// But also mixed runtime versions are not yet expected.
|
|
51
|
-
(0, internal_1.fail)(
|
|
51
|
+
(0, internal_1.fail)(0xcb1 /* Presence is only expected to be accessed with a single version. */);
|
|
52
52
|
}
|
|
53
53
|
onNewUse() {
|
|
54
54
|
// No-op
|
|
@@ -69,7 +69,7 @@ const ContainerPresenceFactory = {
|
|
|
69
69
|
assertCompatibilityInvariants(existingInstantiation.compatibility);
|
|
70
70
|
// There have not yet been any changes that would require action to upgrade.
|
|
71
71
|
// But also mixed runtime versions are not yet expected.
|
|
72
|
-
(0, internal_1.fail)(
|
|
72
|
+
(0, internal_1.fail)(0xcb2 /* Presence is only expected to be accessed with a single version. */);
|
|
73
73
|
},
|
|
74
74
|
instantiateExtension(host) {
|
|
75
75
|
return new ContainerPresenceManager(host);
|
package/dist/getPresence.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getPresence.js","sourceRoot":"","sources":["../src/getPresence.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAUH,kEAAmE;AAEnE,oEAAiF;AAQjF,2DAAiD;AAGjD,6DAA6D;AAG7D,MAAM,qBAAqB,GAAG;IAC7B,UAAU,EAAE,CAAC;IACb,OAAO,EAAE,8BAAU;IACnB,YAAY,EAAE,IAAI,GAAG,CAAC,EAAE,CAAC;CACwB,CAAC;AAEnD;;;;;GAKG;AACH,MAAM,+BAA+B,GAAG,QAAQ,CAAC;AAEjD,SAAS,6BAA6B,CAAC,aAA4C;IAClF,IAAA,iBAAM,EACL,aAAa,CAAC,UAAU,KAAK,qBAAqB,CAAC,UAAU,EAC7D,KAAK,CAAC,iDAAiD,CACvD,CAAC;IACF,IAAA,iBAAM,EACL,aAAa,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,EACtC,KAAK,CAAC,gDAAgD,CACtD,CAAC;IACF,IAAA,iBAAM,EACL,MAAM,CAAC,UAAU,CAAC,aAAa,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAChD,MAAM,CAAC,UAAU,CAAC,qBAAqB,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAC1D,KAAK,CAAC,8DAA8D,CACpE,CAAC;IACF,IAAA,iBAAM,EACL,qBAAqB,CAAC,YAAY,CAAC,IAAI,KAAK,CAAC,EAC7C,KAAK,CAAC,4CAA4C,CAClD,CAAC;AACH,CAAC;AAED;;GAEG;A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microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { ILayerCompatSupportRequirements } from \"@fluid-internal/client-utils\";\nimport type {\n\tContainerExtension,\n\tContainerExtensionFactory,\n\tExtensionInstantiationResult,\n\tExtensionRuntimeProperties as GenericExtensionRuntimeProperties,\n\tInboundExtensionMessage,\n} from \"@fluidframework/container-runtime-definitions/internal\";\nimport { assert, fail } from \"@fluidframework/core-utils/internal\";\nimport type { IFluidContainer } from \"@fluidframework/fluid-static\";\nimport { isInternalFluidContainer } from \"@fluidframework/fluid-static/internal\";\nimport type {\n\tExtensionCompatibilityDetails,\n\tFluidDataStoreContextInternal,\n\tIFluidDataStoreContext,\n} from \"@fluidframework/runtime-definitions/internal\";\n\nimport type { ExtensionHost, ExtensionRuntimeProperties } from \"./internalTypes.js\";\nimport { pkgVersion } from \"./packageVersion.js\";\nimport type { Presence, PresenceWithNotifications } from \"./presence.js\";\nimport type { PresenceExtensionInterface } from \"./presenceManager.js\";\nimport { createPresenceManager } from \"./presenceManager.js\";\nimport type { SignalMessages } from \"./protocol.js\";\n\nconst presenceCompatibility = {\n\tgeneration: 1,\n\tversion: pkgVersion,\n\tcapabilities: new Set([]),\n} as const satisfies ExtensionCompatibilityDetails;\n\n/**\n * Minimal compatible package version.\n * If an existing presence extension is registered with this version or higher,\n * it can be used instead of instantiating new instance from this version of\n * the package (assuming also capabilities are compatible).\n */\nconst minimalCompatiblePackageVersion = \"2.71.0\";\n\nfunction assertCompatibilityInvariants(compatibility: ExtensionCompatibilityDetails): void {\n\tassert(\n\t\tcompatibility.generation === presenceCompatibility.generation,\n\t\t0xc97 /* Presence compatibility generation mismatch. */,\n\t);\n\tassert(\n\t\tcompatibility.version.startsWith(\"2.\"),\n\t\t0xc98 /* Registered version is not major version 2. */,\n\t);\n\tassert(\n\t\tNumber.parseFloat(compatibility.version.slice(2)) <\n\t\t\tNumber.parseFloat(presenceCompatibility.version.slice(2)),\n\t\t0xc99 /* Registered version is not less than the current version. */,\n\t);\n\tassert(\n\t\tpresenceCompatibility.capabilities.size === 0,\n\t\t0xc9a /* Presence capabilities should be empty. */,\n\t);\n}\n\n/**\n * Common Presence manager for a container\n */\nclass ContainerPresenceManager\n\timplements\n\t\tContainerExtension<ExtensionRuntimeProperties>,\n\t\tReturnType<\n\t\t\tContainerExtensionFactory<\n\t\t\t\tPresenceWithNotifications,\n\t\t\t\tExtensionRuntimeProperties\n\t\t\t>[\"instantiateExtension\"]\n\t\t>\n{\n\t// ContainerExtensionFactory return elements\n\tpublic readonly compatibility = presenceCompatibility;\n\tpublic readonly interface: PresenceWithNotifications;\n\tpublic readonly extension = this;\n\n\tprivate readonly manager: PresenceExtensionInterface;\n\n\tpublic constructor(host: ExtensionHost) {\n\t\tthis.interface = this.manager = createPresenceManager({\n\t\t\t...host,\n\t\t\tsubmitSignal: (message) => {\n\t\t\t\thost.submitAddressedSignal([], message);\n\t\t\t},\n\t\t});\n\t}\n\n\tpublic handleVersionOrCapabilitiesMismatch<_TRequestedInterface>(\n\t\tourExistingInstantiation: Readonly<\n\t\t\tExtensionInstantiationResult<PresenceWithNotifications, ExtensionRuntimeProperties, []>\n\t\t>,\n\t\tnewCompatibilityRequest: ExtensionCompatibilityDetails,\n\t): never {\n\t\tassert(\n\t\t\tourExistingInstantiation.compatibility === presenceCompatibility,\n\t\t\t0xc9b /* Presence extension called without own compatibility details */,\n\t\t);\n\t\tassertCompatibilityInvariants(newCompatibilityRequest);\n\t\t// There have not yet been any changes that would require action to upgrade.\n\t\t// But also mixed runtime versions are not yet expected.\n\t\tfail(0xcb1 /* Presence is only expected to be accessed with a single version. */);\n\t}\n\n\tpublic onNewUse(): void {\n\t\t// No-op\n\t}\n\n\tpublic processSignal(\n\t\taddressChain: string[],\n\t\tmessage: InboundExtensionMessage<SignalMessages>,\n\t\tlocal: boolean,\n\t): void {\n\t\tthis.manager.processSignal(addressChain, message, local);\n\t}\n}\n\nconst extensionId = \"dis:bb89f4c0-80fd-4f0c-8469-4f2848ee7f4a\";\n\nconst ContainerPresenceFactory = {\n\thostRequirements: {\n\t\tminSupportedGeneration: 1,\n\t\trequiredFeatures: [],\n\t} as const satisfies ILayerCompatSupportRequirements,\n\n\tinstanceExpectations: { ...presenceCompatibility, version: minimalCompatiblePackageVersion },\n\n\tresolvePriorInstantiation(\n\t\texistingInstantiation: ExtensionInstantiationResult<\n\t\t\tunknown,\n\t\t\tGenericExtensionRuntimeProperties,\n\t\t\tunknown[]\n\t\t>,\n\t): never {\n\t\t// Validate assumptions about existing instance\n\t\tassertCompatibilityInvariants(existingInstantiation.compatibility);\n\t\t// There have not yet been any changes that would require action to upgrade.\n\t\t// But also mixed runtime versions are not yet expected.\n\t\tfail(0xcb2 /* Presence is only expected to be accessed with a single version. */);\n\t},\n\n\tinstantiateExtension(host: ExtensionHost): ContainerPresenceManager {\n\t\treturn new ContainerPresenceManager(host);\n\t},\n\n\t[Symbol.hasInstance]: (instance: unknown): instance is ContainerPresenceManager => {\n\t\treturn instance instanceof ContainerPresenceManager;\n\t},\n} as const satisfies ContainerExtensionFactory<\n\tPresenceWithNotifications,\n\tExtensionRuntimeProperties\n>;\n\n/**\n * Acquire a {@link Presence} from a Fluid Container\n * @param fluidContainer - Fluid Container to acquire the map from\n * @returns the {@link Presence}\n *\n * @beta\n */\nexport const getPresence: (fluidContainer: IFluidContainer) => Presence = getPresenceAlpha;\n\n/**\n * Acquire a {@link PresenceWithNotifications} from a Fluid Container\n * @param fluidContainer - Fluid Container to acquire the map from\n * @returns the {@link PresenceWithNotifications}\n *\n * @alpha\n */\nexport function getPresenceAlpha(fluidContainer: IFluidContainer): PresenceWithNotifications {\n\tassert(\n\t\tisInternalFluidContainer(fluidContainer),\n\t\t0xa2f /* IFluidContainer was not recognized. Only Containers generated by the Fluid Framework are supported. */,\n\t);\n\tconst presence = fluidContainer.acquireExtension(extensionId, ContainerPresenceFactory);\n\treturn presence;\n}\n\nfunction assertContextHasExtensionProvider(\n\tcontext: IFluidDataStoreContext,\n): asserts context is FluidDataStoreContextInternal {\n\tassert(\n\t\t\"getExtension\" in context,\n\t\t0xc9c /* Data store context does not implement ContainerExtensionProvider */,\n\t);\n}\n\n/**\n * Get {@link Presence} from a Fluid Data Store Context\n *\n * @legacy @alpha\n */\nexport function getPresenceFromDataStoreContext(context: IFluidDataStoreContext): Presence {\n\tassertContextHasExtensionProvider(context);\n\treturn context.getExtension(extensionId, ContainerPresenceFactory);\n}\n"]}
|
package/dist/packageVersion.d.ts
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
|
|
6
6
|
*/
|
|
7
7
|
export declare const pkgName = "@fluidframework/presence";
|
|
8
|
-
export declare const pkgVersion = "2.
|
|
8
|
+
export declare const pkgVersion = "2.81.0-374083";
|
|
9
9
|
//# sourceMappingURL=packageVersion.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,6BAA6B,CAAC;AAClD,eAAO,MAAM,UAAU,
|
|
1
|
+
{"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,6BAA6B,CAAC;AAClD,eAAO,MAAM,UAAU,kBAAkB,CAAC"}
|
package/dist/packageVersion.js
CHANGED
|
@@ -8,5 +8,5 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.pkgVersion = exports.pkgName = void 0;
|
|
10
10
|
exports.pkgName = "@fluidframework/presence";
|
|
11
|
-
exports.pkgVersion = "2.
|
|
11
|
+
exports.pkgVersion = "2.81.0-374083";
|
|
12
12
|
//# sourceMappingURL=packageVersion.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,0BAA0B,CAAC;AACrC,QAAA,UAAU,GAAG,
|
|
1
|
+
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,0BAA0B,CAAC;AACrC,QAAA,UAAU,GAAG,eAAe,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/presence\";\nexport const pkgVersion = \"2.81.0-374083\";\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"presenceDatastoreManager.d.ts","sourceRoot":"","sources":["../src/presenceDatastoreManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,wDAAwD,CAAC;AACtG,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0CAA0C,CAAC;AAEzE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0CAA0C,CAAC;AAEpF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAEvE,OAAO,KAAK,EACX,iBAAiB,EAEjB,wBAAwB,EACxB,yBAAyB,EAEzB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,KAAK,EACX,UAAU,EACV,yBAAyB,IAAI,QAAQ,EACrC,cAAc,EACd,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAGX,sBAAsB,EAEtB,MAAM,qBAAqB,CAAC;AAM7B,OAAO,KAAK,EAKX,wBAAwB,EAExB,cAAc,EAEd,MAAM,eA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;;;;;;;;;;OAUG;IACH,OAAO,CAAC,mBAAmB;CAqG3B"}
|
|
@@ -188,7 +188,7 @@ class PresenceDatastoreManagerImpl {
|
|
|
188
188
|
// When self is not represented, audience is an unreliable state,
|
|
189
189
|
// especially during a reconnect. An alternateProvider is expected
|
|
190
190
|
// to have been provided for this call to be useful (efficient).
|
|
191
|
-
(0, internal_1.assert)(alternateProvider !== undefined,
|
|
191
|
+
(0, internal_1.assert)(alternateProvider !== undefined, 0xcba /* Self is not in audience and no alternateProvider given */);
|
|
192
192
|
}
|
|
193
193
|
// Broadcast join message to all clients
|
|
194
194
|
// Select primary update providers
|
|
@@ -236,6 +236,7 @@ class PresenceDatastoreManagerImpl {
|
|
|
236
236
|
return existing.internal.ensureContent(requestedContent, controls);
|
|
237
237
|
}
|
|
238
238
|
let workspaceDatastore = this.datastore[internalWorkspaceAddress];
|
|
239
|
+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- using ??= could change behavior if value is falsy
|
|
239
240
|
if (workspaceDatastore === undefined) {
|
|
240
241
|
workspaceDatastore = this.datastore[internalWorkspaceAddress] = {};
|
|
241
242
|
}
|
|
@@ -323,7 +324,7 @@ class PresenceDatastoreManagerImpl {
|
|
|
323
324
|
const currentClientToSessionValueState =
|
|
324
325
|
// When connected, `clientToSessionId` must always have current connection entry.
|
|
325
326
|
this.datastore["system:presence"].clientToSessionId[clientConnectionId];
|
|
326
|
-
(0, internal_1.assert)(currentClientToSessionValueState !== undefined,
|
|
327
|
+
(0, internal_1.assert)(currentClientToSessionValueState !== undefined, 0xcbb /* Client connection update missing */);
|
|
327
328
|
const newMessage = {
|
|
328
329
|
sendTimestamp: Date.now(),
|
|
329
330
|
avgLatency: this.averageLatency,
|
|
@@ -444,7 +445,7 @@ class PresenceDatastoreManagerImpl {
|
|
|
444
445
|
processSignal(message, local, optional) {
|
|
445
446
|
const received = Date.now();
|
|
446
447
|
if (!isPresenceMessage(message)) {
|
|
447
|
-
(0, internal_1.assert)(optional,
|
|
448
|
+
(0, internal_1.assert)(optional, 0xcbc /* Unrecognized message type in critical message */);
|
|
448
449
|
return;
|
|
449
450
|
}
|
|
450
451
|
if (local) {
|
|
@@ -477,7 +478,7 @@ class PresenceDatastoreManagerImpl {
|
|
|
477
478
|
const joinResponseFor = message.content.joinResponseFor;
|
|
478
479
|
if (joinResponseFor) {
|
|
479
480
|
const selfClientId = this.runtime.getClientId();
|
|
480
|
-
(0, internal_1.assert)(selfClientId !== undefined,
|
|
481
|
+
(0, internal_1.assert)(selfClientId !== undefined, 0xcbd /* Received signal without clientId */);
|
|
481
482
|
let justGainedCompleteSnapshot = false;
|
|
482
483
|
if (joinResponseFor.includes(selfClientId)) {
|
|
483
484
|
if (this.reasonForCompleteSnapshot) {
|
|
@@ -520,7 +521,7 @@ class PresenceDatastoreManagerImpl {
|
|
|
520
521
|
}
|
|
521
522
|
// If the message requests an acknowledgement, we will send a targeted acknowledgement message back to just the requestor.
|
|
522
523
|
if (message.content.acknowledgementId !== undefined) {
|
|
523
|
-
(0, internal_1.assert)(this.targetedSignalSupport,
|
|
524
|
+
(0, internal_1.assert)(this.targetedSignalSupport, 0xcbe /* Acknowledgment message was requested while targeted signal capability is not supported */);
|
|
524
525
|
this.runtime.submitSignal({
|
|
525
526
|
type: protocol_js_1.acknowledgementMessageType,
|
|
526
527
|
content: { id: message.content.acknowledgementId },
|
|
@@ -1 +1 @@
|
|
|
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;CA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AY,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;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
|
+
{"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,OAAgD;IAEhD,OAAO,iBAAiB,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AAC5C,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,gBAAgB,CAC/B,GAA+D;IAE/D,OAAO,OAAO,IAAI,GAAG,CAAC;AACvB,CAAC;AAJD,4CAIC;AA2BD,SAAS,mCAAmC,CAC3C,IAAgD,EAChD,OAAuC;IAEvC,qEAAqE;IACrE,MAAM,cAAc,GAAG,IAAI,IAAI,EAAE,CAAC;IAElC,gEAAgE;IAChE,0EAA0E;IAC1E,KAAK,MAAM,CAAC,aAAa,EAAE,aAAa,CAAC,IAAI,IAAA,gCAAa,EAAC,OAAO,CAAC,EAAE,CAAC;QACrE,8EAA8E;QAC9E,8EAA8E;QAC9E,oCAAoC;QACpC,MAAM,UA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IACF,CAAC;CACD;AAjvBD,oEAivBC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { InboundExtensionMessage } from \"@fluidframework/container-runtime-definitions/internal\";\nimport type { IEmitter } from \"@fluidframework/core-interfaces/internal\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport type { ITelemetryLoggerExt } from \"@fluidframework/telemetry-utils/internal\";\n\nimport type { ClientConnectionId } from \"./baseTypes.js\";\nimport type { BroadcastControlSettings } from \"./broadcastControls.js\";\nimport type { InternalTypes } from \"./exposedInternalTypes.js\";\nimport type {\n\tIEphemeralRuntime,\n\tPostUpdateAction,\n\tValidatableOptionalState,\n\tValidatableValueDirectory,\n\tValidatableValueStructure,\n} from \"./internalTypes.js\";\nimport { objectEntries } from \"./internalUtils.js\";\nimport type {\n\tAttendeeId,\n\tPresenceWithNotifications as Presence,\n\tPresenceEvents,\n} from \"./presence.js\";\nimport type {\n\tClientUpdateEntry,\n\tRuntimeLocalUpdateOptions,\n\tPresenceStatesInternal,\n\tValueElementMap,\n} from \"./presenceStates.js\";\nimport {\n\tcreatePresenceStates,\n\tmergeUntrackedDatastore,\n\tmergeValueDirectory,\n} from \"./presenceStates.js\";\nimport type {\n\tDatastoreMessageContent,\n\tGeneralDatastoreMessageContent,\n\tInboundClientJoinMessage,\n\tInboundDatastoreUpdateMessage,\n\tInternalWorkspaceAddress,\n\tOutboundDatastoreUpdateMessage,\n\tSignalMessages,\n\tSystemDatastore,\n} from \"./protocol.js\";\nimport {\n\tacknowledgementMessageType,\n\tdatastoreUpdateMessageType,\n\tjoinMessageType,\n} from \"./protocol.js\";\nimport type { SystemWorkspaceDatastore } from \"./systemWorkspace.js\";\nimport { TimerManager } from \"./timerManager.js\";\nimport type {\n\tAnyWorkspace,\n\tNotificationsWorkspace,\n\tNotificationsWorkspaceSchema,\n\tStatesWorkspace,\n\tStatesWorkspaceSchema,\n\tWorkspaceAddress,\n} from \"./types.js\";\n\ninterface AnyWorkspaceEntry<TSchema extends StatesWorkspaceSchema> {\n\tpublic: AnyWorkspace<TSchema>;\n\tinternal: PresenceStatesInternal;\n}\n\n/**\n * Datastore structure used for broadcasting to other clients.\n * Validation metadata is stripped before transmission.\n */\ntype PresenceDatastore = SystemDatastore & {\n\t[WorkspaceAddress: InternalWorkspaceAddress]: ValueElementMap<StatesWorkspaceSchema>;\n};\n\nconst internalWorkspaceTypes: Readonly<Record<string, \"States\" | \"Notifications\">> = {\n\ts: \"States\",\n\tn: \"Notifications\",\n} as const;\n\nconst knownMessageTypes = new Set([\n\tjoinMessageType,\n\tdatastoreUpdateMessageType,\n\tacknowledgementMessageType,\n]);\nfunction isPresenceMessage(\n\tmessage: InboundExtensionMessage<SignalMessages>,\n): message is InboundDatastoreUpdateMessage | InboundClientJoinMessage {\n\treturn knownMessageTypes.has(message.type);\n}\n\n/**\n * Type guard to check if a value hierarchy object is a directory (has \"items\"\n * property).\n *\n * @param obj - The object to check\n * @returns True if the object is a {@link ValidatableValueDirectory}\n */\nexport function isValueDirectory<T>(\n\tobj: ValidatableValueDirectory<T> | ValidatableOptionalState<T>,\n): obj is ValidatableValueDirectory<T> {\n\treturn \"items\" in obj;\n}\n\n/**\n * High-level contract for manager of singleton Presence datastore\n */\nexport interface PresenceDatastoreManager {\n\tjoinSession(\n\t\tclientId: ClientConnectionId,\n\t\talternateProvider: ClientConnectionId | undefined,\n\t): void;\n\tonDisconnected(): void;\n\tgetWorkspace<TSchema extends StatesWorkspaceSchema>(\n\t\tinternalWorkspaceAddress: `s:${WorkspaceAddress}`,\n\t\trequestedContent: TSchema,\n\t\tcontrols?: BroadcastControlSettings,\n\t): StatesWorkspace<TSchema>;\n\tgetWorkspace<TSchema extends NotificationsWorkspaceSchema>(\n\t\tinternalWorkspaceAddress: `n:${WorkspaceAddress}`,\n\t\trequestedContent: TSchema,\n\t): NotificationsWorkspace<TSchema>;\n\tprocessSignal(\n\t\tmessage: InboundExtensionMessage<SignalMessages> & { clientId: ClientConnectionId },\n\t\tlocal: boolean,\n\t\toptional: boolean,\n\t): void;\n}\n\nfunction mergeGeneralDatastoreMessageContent(\n\tbase: GeneralDatastoreMessageContent | undefined,\n\tnewData: GeneralDatastoreMessageContent,\n): GeneralDatastoreMessageContent {\n\t// This function-local \"datastore\" will hold the merged message data.\n\tconst queueDatastore = base ?? {};\n\n\t// Merge the current data with the existing data, if any exists.\n\t// Iterate over the current message data; individual items are workspaces.\n\tfor (const [workspaceName, workspaceData] of objectEntries(newData)) {\n\t\t// Initialize the merged data as the queued datastore entry for the workspace.\n\t\t// Since the key might not exist, create an empty object in that case. It will\n\t\t// be set explicitly after the loop.\n\t\tconst mergedData = queueDatastore[workspaceName] ?? {};\n\n\t\t// Iterate over each value manager and its data, merging it as needed.\n\t\tfor (const [valueManagerKey, valueManagerValue] of objectEntries(workspaceData)) {\n\t\t\tfor (const [attendeeId, value] of objectEntries(valueManagerValue)) {\n\t\t\t\tconst mergeObject = (mergedData[valueManagerKey] ??= {});\n\t\t\t\tconst oldData = mergeObject[attendeeId];\n\t\t\t\tmergeObject[attendeeId] = mergeValueDirectory(\n\t\t\t\t\toldData,\n\t\t\t\t\tvalue,\n\t\t\t\t\t0, // local values do not need a time shift\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\t// Store the merged data in the function-local queue workspace. The whole contents of this\n\t\t// datastore will be sent as the message data.\n\t\tqueueDatastore[workspaceName] = mergedData;\n\t}\n\treturn queueDatastore;\n}\n\n/**\n * Delays used for broadcasting join responses to clients.\n *\n * @remarks\n * Exported for test coordination.\n * These could be made customizable in the future to accommodate different\n * session configurations.\n */\nexport const broadcastJoinResponseDelaysMs = {\n\t/**\n\t * The delay in milliseconds before a join response is sent to any client.\n\t * This is used to accumulate other join response requests and reduce\n\t * network traffic.\n\t */\n\tnamedResponder: 200,\n\t/**\n\t * The additional delay in milliseconds a backup responder waits before sending\n\t * a join response to allow others to respond first.\n\t */\n\tbackupResponderIncrement: 40,\n} as const;\n\n/**\n * Manages singleton datastore for all Presence.\n */\nexport class PresenceDatastoreManagerImpl implements PresenceDatastoreManager {\n\tprivate readonly datastore: PresenceDatastore;\n\tprivate averageLatency = 0;\n\tprivate returnedMessages = 0;\n\tprivate readonly sendMessageTimer = new TimerManager();\n\tprivate readonly workspaces = new Map<string, AnyWorkspaceEntry<StatesWorkspaceSchema>>();\n\tprivate readonly targetedSignalSupport: boolean;\n\n\t/**\n\t * Tracks whether this client has complete snapshot level knowledge and\n\t * how that determination was reached.\n\t * - \"alone\": no other audience members detected at join\n\t * - \"join response\": another client has responded to our join request\n\t * - \"full requests\": all others have requested response from us\n\t *\n\t * @remarks\n\t * Only applies when not using targeted join responses.\n\t *\n\t * Without a complete snapshot, we cannot fully onboard any other clients.\n\t * One exception to this is if this client is the only participant in the\n\t * session. In such a case, there is no one to respond to the join request.\n\t * Another exception is multiple clients attempting to join at the same\n\t * time and thus expecting that someone has full knowledge, yet none have\n\t * received a complete update to think they are qualified to respond.\n\t * Generically if the number of outstanding requestors meets or exceeds the\n\t * count of other audience members, then we can consider the snapshot\n\t * complete (as all will have provided their own complete information in\n\t * their join responses).\n\t */\n\tprivate reasonForCompleteSnapshot?: \"alone\" | \"join response\" | \"full requests\";\n\n\t/**\n\t * Map of outstanding broadcast (join response) requests.\n\t */\n\tprivate readonly broadcastRequests = new Map<\n\t\tClientConnectionId,\n\t\t{ deadlineTime: number; responseOrder?: number | undefined }\n\t>();\n\t/**\n\t * Timer for managing broadcast (join response) request timing.\n\t */\n\tprivate readonly broadcastRequestsTimer = new TimerManager();\n\n\tpublic constructor(\n\t\tprivate readonly attendeeId: AttendeeId,\n\t\tprivate readonly runtime: IEphemeralRuntime,\n\t\tprivate readonly logger: ITelemetryLoggerExt | undefined,\n\t\tprivate readonly events: IEmitter<PresenceEvents>,\n\t\tprivate readonly presence: Presence,\n\t\tsystemWorkspaceDatastore: SystemWorkspaceDatastore,\n\t\tsystemWorkspace: AnyWorkspaceEntry<StatesWorkspaceSchema>,\n\t) {\n\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\tthis.datastore = { \"system:presence\": systemWorkspaceDatastore } as PresenceDatastore;\n\t\tthis.workspaces.set(\"system:presence\", systemWorkspace);\n\t\tthis.targetedSignalSupport = this.runtime.supportedFeatures.has(\"submit_signals_v2\");\n\t\t// If audience member is removed, they won't need a broadcast response.\n\t\tthis.runtime.getAudience().on(\"removeMember\", (clientId) => {\n\t\t\tthis.broadcastRequests.delete(clientId);\n\t\t});\n\t}\n\n\tprivate getAudienceInformation(selfClientId: ClientConnectionId): {\n\t\tselfPresent: boolean;\n\t\tinteractiveMembersExcludingSelf: {\n\t\t\tall: Set<ClientConnectionId>;\n\t\t\twriters: Set<ClientConnectionId>;\n\t\t};\n\t} {\n\t\tconst audience = this.runtime.getAudience();\n\t\tconst members = audience.getMembers();\n\t\tconst all = new Set<ClientConnectionId>();\n\t\tconst writers = new Set<ClientConnectionId>();\n\t\tconst selfPresent = members.has(selfClientId);\n\t\tif (selfPresent) {\n\t\t\t// Remove self\n\t\t\tmembers.delete(selfClientId);\n\t\t}\n\t\t// Gather interactive client IDs\n\t\tfor (const [id, client] of members) {\n\t\t\tif (client.details.capabilities.interactive) {\n\t\t\t\tall.add(id);\n\t\t\t\tif (client.mode === \"write\") {\n\t\t\t\t\twriters.add(id);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn {\n\t\t\tselfPresent,\n\t\t\tinteractiveMembersExcludingSelf: {\n\t\t\t\tall,\n\t\t\t\twriters,\n\t\t\t},\n\t\t};\n\t}\n\n\tpublic joinSession(\n\t\tselfClientId: ClientConnectionId,\n\t\talternateProvider: ClientConnectionId | undefined = undefined,\n\t): void {\n\t\t// Before broadcasting the join message, check that there is at least\n\t\t// one audience member present (self or another). This is useful to\n\t\t// optimize join messages while not using targeted join responses.\n\t\t// (We need at least one other to be able to elect them as update\n\t\t// provider.)\n\t\t// Lack of anyone likely means that this client is very freshly joined\n\t\t// and has not received any Join Signals (type=\"join\") from the service\n\t\t// yet.\n\t\tconst { selfPresent, interactiveMembersExcludingSelf } =\n\t\t\tthis.getAudienceInformation(selfClientId);\n\n\t\tif (selfPresent) {\n\t\t\tif (interactiveMembersExcludingSelf.all.size === 0) {\n\t\t\t\t// If there aren't any members connected except self, then this client\n\t\t\t\t// must have complete information.\n\t\t\t\tthis.reasonForCompleteSnapshot = \"alone\";\n\t\t\t\t// It would be possible to return at this time and skip ClientJoin\n\t\t\t\t// signal. Instead continue in case audience information is\n\t\t\t\t// inaccurate. This client might temporarily erroneously believe it\n\t\t\t\t// has complete information, but the other(s) should respond to\n\t\t\t\t// ClientJoin soon rectifying that and covering for bad incomplete\n\t\t\t\t// responses this client sent in the meantime.\n\t\t\t}\n\t\t} else {\n\t\t\t// When self is not represented, audience is an unreliable state,\n\t\t\t// especially during a reconnect. An alternateProvider is expected\n\t\t\t// to have been provided for this call to be useful (efficient).\n\t\t\tassert(\n\t\t\t\talternateProvider !== undefined,\n\t\t\t\t0xcba /* Self is not in audience and no alternateProvider given */,\n\t\t\t);\n\t\t}\n\n\t\t// Broadcast join message to all clients\n\t\t// Select primary update providers\n\t\t// Use write members if any, then fallback to read-only members.\n\t\tconst updateProviders = [\n\t\t\t...(interactiveMembersExcludingSelf.writers.size > 0\n\t\t\t\t? interactiveMembersExcludingSelf.writers\n\t\t\t\t: interactiveMembersExcludingSelf.all),\n\t\t];\n\t\t// Limit to three providers to prevent flooding the network.\n\t\t// If none respond, others present will (should) after a delay.\n\t\tif (updateProviders.length > 3) {\n\t\t\tupdateProviders.length = 3;\n\t\t} else if (updateProviders.length === 0 && alternateProvider !== undefined) {\n\t\t\tupdateProviders.push(alternateProvider);\n\t\t}\n\t\tthis.runtime.submitSignal({\n\t\t\ttype: joinMessageType,\n\t\t\tcontent: {\n\t\t\t\tsendTimestamp: Date.now(),\n\t\t\t\tavgLatency: this.averageLatency,\n\t\t\t\tdata: this.stripValidationMetadata(this.datastore),\n\t\t\t\tupdateProviders,\n\t\t\t},\n\t\t});\n\t\tthis.logger?.sendTelemetryEvent({\n\t\t\teventName: \"JoinRequested\",\n\t\t\tdetails: {\n\t\t\t\tattendeeId: this.attendeeId,\n\t\t\t\tconnectionId: selfClientId,\n\t\t\t\t// Empty updateProviders is indicative of join when alone.\n\t\t\t\tupdateProviders: JSON.stringify(updateProviders),\n\t\t\t\t// If false and providers is single entry, then join was probably forced.\n\t\t\t\tselfPresent,\n\t\t\t},\n\t\t});\n\t}\n\n\tpublic onDisconnected(): void {\n\t\tdelete this.reasonForCompleteSnapshot;\n\t}\n\n\tpublic getWorkspace<TSchema extends StatesWorkspaceSchema>(\n\t\tinternalWorkspaceAddress: InternalWorkspaceAddress,\n\t\trequestedContent: TSchema,\n\t\tcontrols?: BroadcastControlSettings,\n\t): AnyWorkspace<TSchema> {\n\t\tconst existing = this.workspaces.get(internalWorkspaceAddress);\n\t\tif (existing) {\n\t\t\treturn existing.internal.ensureContent(requestedContent, controls);\n\t\t}\n\n\t\tlet workspaceDatastore: ValueElementMap<StatesWorkspaceSchema> | undefined =\n\t\t\tthis.datastore[internalWorkspaceAddress];\n\t\t// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- using ??= could change behavior if value is falsy\n\t\tif (workspaceDatastore === undefined) {\n\t\t\tworkspaceDatastore = this.datastore[internalWorkspaceAddress] = {};\n\t\t}\n\n\t\tconst localUpdate = (\n\t\t\tstates: { [key: string]: ClientUpdateEntry },\n\t\t\toptions: RuntimeLocalUpdateOptions,\n\t\t): void => {\n\t\t\t// Check for connectivity before sending updates.\n\t\t\tif (this.runtime.getJoinedStatus() === \"disconnected\") {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst updates: GeneralDatastoreMessageContent[InternalWorkspaceAddress] = {};\n\t\t\tfor (const [key, value] of Object.entries(states)) {\n\t\t\t\tupdates[key] = { [this.attendeeId]: value };\n\t\t\t}\n\n\t\t\tthis.enqueueMessage(\n\t\t\t\t{\n\t\t\t\t\t[internalWorkspaceAddress]: updates,\n\t\t\t\t},\n\t\t\t\toptions,\n\t\t\t);\n\t\t};\n\n\t\tconst entry = createPresenceStates(\n\t\t\t{\n\t\t\t\tpresence: this.presence,\n\t\t\t\tattendeeId: this.attendeeId,\n\t\t\t\tlocalUpdate,\n\t\t\t},\n\t\t\tworkspaceDatastore,\n\t\t\trequestedContent,\n\t\t\tcontrols,\n\t\t);\n\n\t\tthis.workspaces.set(internalWorkspaceAddress, entry);\n\t\treturn entry.public;\n\t}\n\n\t/**\n\t * The combined contents of all queued updates. Will be `\"sendAll\"` when a\n\t * full broadcast is pending or `undefined` when no messages are queued.\n\t */\n\tprivate queuedData: GeneralDatastoreMessageContent | \"sendAll\" | undefined;\n\n\t/**\n\t * Enqueues a new message to be sent. The message may be queued or may be sent immediately depending on the state of\n\t * the send timer, other messages in the queue, the configured allowed latency, etc.\n\t */\n\tprivate enqueueMessage(\n\t\tdata: GeneralDatastoreMessageContent | \"sendAll\",\n\t\toptions: RuntimeLocalUpdateOptions,\n\t): void {\n\t\tif (this.queuedData !== \"sendAll\") {\n\t\t\tthis.queuedData =\n\t\t\t\tdata === \"sendAll\"\n\t\t\t\t\t? \"sendAll\"\n\t\t\t\t\t: // Merging the message with any queued messages effectively queues the message.\n\t\t\t\t\t\t// It is OK to queue all incoming messages as long as when we send, we send the queued data.\n\t\t\t\t\t\tmergeGeneralDatastoreMessageContent(this.queuedData, data);\n\t\t}\n\n\t\tconst { allowableUpdateLatencyMs } = options;\n\t\tconst now = Date.now();\n\t\tconst thisMessageDeadline = now + allowableUpdateLatencyMs;\n\n\t\tif (\n\t\t\t// If the timer has not expired, we can short-circuit because the timer will fire\n\t\t\t// and cover this update. In other words, queuing this will be fast enough to\n\t\t\t// meet its deadline, because a timer is already scheduled to fire before its deadline.\n\t\t\t!this.sendMessageTimer.hasExpired() &&\n\t\t\t// If the deadline for this message is later than the overall send deadline, then\n\t\t\t// we can exit early since a timer will take care of sending it.\n\t\t\tthisMessageDeadline >= this.sendMessageTimer.expireTime\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Either we need to send this message immediately, or we need to schedule a timer\n\t\t// to fire at the send deadline that will take care of it.\n\n\t\t// Note that timeoutInMs === allowableUpdateLatencyMs, but the calculation is done this way for clarity.\n\t\tconst timeoutInMs = thisMessageDeadline - now;\n\t\tconst scheduleForLater = timeoutInMs > 0;\n\n\t\tif (scheduleForLater) {\n\t\t\t// Schedule the queued messages to be sent at the updateDeadline\n\t\t\tthis.sendMessageTimer.setTimeout(this.sendQueuedMessage.bind(this), timeoutInMs);\n\t\t} else {\n\t\t\tthis.sendQueuedMessage();\n\t\t}\n\t}\n\n\t/**\n\t * Send any queued signal immediately. Does nothing if no message is queued.\n\t */\n\tprivate sendQueuedMessage(): void {\n\t\tthis.sendMessageTimer.clearTimeout();\n\n\t\tif (this.queuedData === undefined) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Check for connectivity before sending updates.\n\t\tif (this.runtime.getJoinedStatus() === \"disconnected\") {\n\t\t\t// Clear the queued data since we're disconnected. We don't want messages\n\t\t\t// to queue infinitely while disconnected.\n\t\t\tthis.queuedData = undefined;\n\t\t\treturn;\n\t\t}\n\n\t\tif (this.queuedData === \"sendAll\") {\n\t\t\tthis.broadcastAllKnownState();\n\t\t\treturn;\n\t\t}\n\n\t\tconst clientConnectionId = this.runtime.getClientId();\n\t\tassert(clientConnectionId !== undefined, 0xa59 /* Client connected without clientId */);\n\t\tconst currentClientToSessionValueState =\n\t\t\t// When connected, `clientToSessionId` must always have current connection entry.\n\t\t\tthis.datastore[\"system:presence\"].clientToSessionId[clientConnectionId];\n\t\tassert(\n\t\t\tcurrentClientToSessionValueState !== undefined,\n\t\t\t0xcbb /* Client connection update missing */,\n\t\t);\n\n\t\tconst newMessage = {\n\t\t\tsendTimestamp: Date.now(),\n\t\t\tavgLatency: this.averageLatency,\n\t\t\t// isComplete: false,\n\t\t\tdata: {\n\t\t\t\t// Always send current connection mapping for some resiliency against\n\t\t\t\t// lost signals. This ensures that client session id found in `updates`\n\t\t\t\t// (which is this client's client session id) is always represented in\n\t\t\t\t// system workspace of recipient clients.\n\t\t\t\t\"system:presence\": {\n\t\t\t\t\tclientToSessionId: {\n\t\t\t\t\t\t[clientConnectionId]: { ...currentClientToSessionValueState },\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t...this.queuedData,\n\t\t\t},\n\t\t} satisfies OutboundDatastoreUpdateMessage[\"content\"];\n\t\tthis.queuedData = undefined;\n\t\tthis.runtime.submitSignal({ type: datastoreUpdateMessageType, content: newMessage });\n\t}\n\n\t/**\n\t * Recursively strips validation metadata (validatedValue) from datastore before broadcasting.\n\t * This ensures that validation metadata doesn't leak into signals sent to other clients.\n\t */\n\tprivate stripValidationMetadata(datastore: PresenceDatastore): DatastoreMessageContent {\n\t\tconst messageContent: DatastoreMessageContent = {\n\t\t\t[\"system:presence\"]: datastore[\"system:presence\"],\n\t\t};\n\n\t\tfor (const [workspaceAddress, workspace] of objectEntries(datastore)) {\n\t\t\t// System workspace has no validation metadata and is already\n\t\t\t// set in messageContent; so, it can be skipped.\n\t\t\tif (workspaceAddress === \"system:presence\") continue;\n\n\t\t\tconst workspaceData: GeneralDatastoreMessageContent[typeof workspaceAddress] = {};\n\n\t\t\tfor (const [stateName, clientRecord] of objectEntries(workspace)) {\n\t\t\t\tconst cleanClientRecord: GeneralDatastoreMessageContent[typeof workspaceAddress][typeof stateName] =\n\t\t\t\t\t{};\n\n\t\t\t\tfor (const [attendeeId, valueData] of objectEntries(clientRecord)) {\n\t\t\t\t\tcleanClientRecord[attendeeId] = this.stripValidationFromValueData(valueData);\n\t\t\t\t}\n\n\t\t\t\tworkspaceData[stateName] = cleanClientRecord;\n\t\t\t}\n\n\t\t\tmessageContent[workspaceAddress] = workspaceData;\n\t\t}\n\n\t\treturn messageContent;\n\t}\n\n\t/**\n\t * Strips validation metadata from individual value data entries.\n\t */\n\tprivate stripValidationFromValueData<\n\t\tT extends\n\t\t\t| InternalTypes.ValueDirectory<unknown>\n\t\t\t| InternalTypes.ValueRequiredState<unknown>\n\t\t\t| InternalTypes.ValueOptionalState<unknown>,\n\t>(valueDataIn: ValidatableValueStructure<T>): T {\n\t\t// Clone the input object since we may mutate it\n\t\tconst valueData = { ...valueDataIn };\n\n\t\t// Handle directory structures (with \"items\" property)\n\t\tif (isValueDirectory(valueData)) {\n\t\t\tfor (const [key, item] of Object.entries(valueData.items)) {\n\t\t\t\tvalueData.items[key] = this.stripValidationFromValueData(item);\n\t\t\t}\n\n\t\t\t// This `satisfies` test is rather weak while ValidatableValueDirectory\n\t\t\t// only has optional properties over InternalTypes.ValueDirectory and\n\t\t\t// thus readily does satisfy. If `validatedValue?: never` is uncommented\n\t\t\t// in Value*State then this will fail.\n\t\t\tvalueData satisfies InternalTypes.ValueDirectory<unknown>;\n\t\t\treturn valueData as T;\n\t\t}\n\n\t\tdelete valueData.validatedValue;\n\t\t// This `satisfies` test is rather weak while Validatable*State\n\t\t// only has optional properties over InternalTypes.Value*State and\n\t\t// thus readily does satisfy. If `validatedValue?: never` is uncommented\n\t\t// in Value*State then this will fail.\n\t\tvalueData satisfies\n\t\t\t| InternalTypes.ValueRequiredState<unknown>\n\t\t\t| InternalTypes.ValueOptionalState<unknown>;\n\t\treturn valueData as T;\n\t}\n\n\tprivate broadcastAllKnownState(): void {\n\t\tconst content: OutboundDatastoreUpdateMessage[\"content\"] = {\n\t\t\tsendTimestamp: Date.now(),\n\t\t\tavgLatency: this.averageLatency,\n\t\t\tisComplete: true,\n\t\t\tdata: this.stripValidationMetadata(this.datastore),\n\t\t};\n\n\t\tconst primaryRequestors: ClientConnectionId[] = [];\n\t\tconst secondaryRequestors: [ClientConnectionId, number][] = [];\n\t\tif (this.broadcastRequests.size > 0) {\n\t\t\tcontent.joinResponseFor = [...this.broadcastRequests.keys()];\n\t\t\tif (this.logger) {\n\t\t\t\t// Build telemetry data\n\t\t\t\tfor (const [requestor, { responseOrder }] of this.broadcastRequests.entries()) {\n\t\t\t\t\tif (responseOrder === undefined) {\n\t\t\t\t\t\tprimaryRequestors.push(requestor);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tsecondaryRequestors.push([requestor, responseOrder]);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tthis.broadcastRequests.clear();\n\t\t}\n\n\t\t// This broadcast will satisfy all requests; clear any remaining timer.\n\t\tthis.broadcastRequestsTimer.clearTimeout();\n\t\tthis.sendMessageTimer.clearTimeout();\n\n\t\tthis.runtime.submitSignal({\n\t\t\ttype: datastoreUpdateMessageType,\n\t\t\tcontent,\n\t\t});\n\t\tif (content.joinResponseFor) {\n\t\t\tthis.logger?.sendTelemetryEvent({\n\t\t\t\teventName: \"JoinResponse\",\n\t\t\t\tdetails: {\n\t\t\t\t\ttype: \"broadcastAll\",\n\t\t\t\t\tattendeeId: this.attendeeId,\n\t\t\t\t\tconnectionId: this.runtime.getClientId(),\n\t\t\t\t\tprimaryResponses: JSON.stringify(primaryRequestors),\n\t\t\t\t\tsecondaryResponses: JSON.stringify(secondaryRequestors),\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\n\t\t// Sending all must account for anything queued before.\n\t\tthis.queuedData = undefined;\n\t}\n\n\tpublic processSignal(\n\t\tmessage: InboundExtensionMessage<SignalMessages> & { clientId: ClientConnectionId },\n\t\tlocal: boolean,\n\t\toptional: boolean,\n\t): void {\n\t\tconst received = Date.now();\n\t\tif (!isPresenceMessage(message)) {\n\t\t\tassert(optional, 0xcbc /* Unrecognized message type in critical message */);\n\t\t\treturn;\n\t\t}\n\n\t\tif (local) {\n\t\t\tconst deliveryDelta = received - message.content.sendTimestamp;\n\t\t\t// Limit returnedMessages count to 256 such that newest message\n\t\t\t// always contributes at least 1/256th to the average. Older\n\t\t\t// messages have more weight, but that diminishes as new messages\n\t\t\t// contribute.\n\t\t\tthis.returnedMessages = Math.min(this.returnedMessages + 1, 256);\n\t\t\tthis.averageLatency =\n\t\t\t\t(this.averageLatency * (this.returnedMessages - 1) + deliveryDelta) /\n\t\t\t\tthis.returnedMessages;\n\t\t\treturn;\n\t\t}\n\n\t\tconst timeModifier =\n\t\t\treceived -\n\t\t\t(this.averageLatency + message.content.avgLatency + message.content.sendTimestamp);\n\n\t\tconst postUpdateActions: PostUpdateAction[] = [];\n\n\t\tif (message.type === joinMessageType) {\n\t\t\t// It is possible for some signals to come in while client is not connected due\n\t\t\t// to how work is scheduled. If we are not connected, we can't respond to the\n\t\t\t// join request. We will make our own Join request once we are connected.\n\t\t\tif (this.runtime.getJoinedStatus() !== \"disconnected\") {\n\t\t\t\tthis.prepareJoinResponse(message.content.updateProviders, message.clientId);\n\t\t\t}\n\t\t\t// It is okay to continue processing the contained updates even if we are not\n\t\t\t// connected.\n\t\t} else {\n\t\t\t// Update join response requests that are now satisfied.\n\t\t\tconst joinResponseFor = message.content.joinResponseFor;\n\t\t\tif (joinResponseFor) {\n\t\t\t\tconst selfClientId = this.runtime.getClientId();\n\t\t\t\tassert(selfClientId !== undefined, 0xcbd /* Received signal without clientId */);\n\n\t\t\t\tlet justGainedCompleteSnapshot = false;\n\t\t\t\tif (joinResponseFor.includes(selfClientId)) {\n\t\t\t\t\tif (this.reasonForCompleteSnapshot) {\n\t\t\t\t\t\tif (this.reasonForCompleteSnapshot === \"alone\") {\n\t\t\t\t\t\t\t// No response was expected. This might happen when\n\t\t\t\t\t\t\t// either cautionary ClientJoin signal is received\n\t\t\t\t\t\t\t// by audience member that was unknown.\n\t\t\t\t\t\t\tthis.logger?.sendTelemetryEvent({\n\t\t\t\t\t\t\t\teventName: \"JoinResponseWhenAlone\",\n\t\t\t\t\t\t\t\tdetails: {\n\t\t\t\t\t\t\t\t\tattendeeId: this.attendeeId,\n\t\t\t\t\t\t\t\t\tconnectionId: this.runtime.getClientId(),\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// If we are the intended recipient of the join response,\n\t\t\t\t\t\t// we can consider our knowledge complete and can respond\n\t\t\t\t\t\t// to others join requests.\n\t\t\t\t\t\tjustGainedCompleteSnapshot = true;\n\t\t\t\t\t}\n\t\t\t\t\tthis.reasonForCompleteSnapshot = \"join response\";\n\t\t\t\t}\n\t\t\t\tif (this.broadcastRequests.size > 0) {\n\t\t\t\t\tfor (const responseFor of joinResponseFor) {\n\t\t\t\t\t\tthis.broadcastRequests.delete(responseFor);\n\t\t\t\t\t}\n\t\t\t\t\tif (this.broadcastRequests.size === 0) {\n\t\t\t\t\t\t// If no more requests are pending, clear any timer.\n\t\t\t\t\t\tthis.broadcastRequestsTimer.clearTimeout();\n\t\t\t\t\t} else if (justGainedCompleteSnapshot) {\n\t\t\t\t\t\t// May or may not be time to respond to remaining requests.\n\t\t\t\t\t\t// Clear the timer and recheck after processing.\n\t\t\t\t\t\tthis.broadcastRequestsTimer.clearTimeout();\n\t\t\t\t\t\tpostUpdateActions.push(this.sendJoinResponseIfStillNeeded);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// If the message requests an acknowledgement, we will send a targeted acknowledgement message back to just the requestor.\n\t\t\tif (message.content.acknowledgementId !== undefined) {\n\t\t\t\tassert(\n\t\t\t\t\tthis.targetedSignalSupport,\n\t\t\t\t\t0xcbe /* Acknowledgment message was requested while targeted signal capability is not supported */,\n\t\t\t\t);\n\t\t\t\tthis.runtime.submitSignal({\n\t\t\t\t\ttype: acknowledgementMessageType,\n\t\t\t\t\tcontent: { id: message.content.acknowledgementId },\n\t\t\t\t\ttargetClientId: message.clientId,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\t// Handle activation of unregistered workspaces before processing updates.\n\t\tfor (const [workspaceAddress] of objectEntries(message.content.data)) {\n\t\t\t// The first part of OR condition checks if workspace is already registered.\n\t\t\t// The second part checks if the workspace has already been seen before.\n\t\t\t// In either case we can skip emitting 'workspaceActivated' event.\n\t\t\tif (this.workspaces.has(workspaceAddress) || this.datastore[workspaceAddress]) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// Separate internal type prefix from public workspace address\n\t\t\tconst match = /^([^:]):([^:]+:.+)$/.exec(workspaceAddress) as\n\t\t\t\t| null\n\t\t\t\t| [string, string, WorkspaceAddress];\n\n\t\t\tif (match === null) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst prefix = match[1];\n\t\t\tconst publicWorkspaceAddress = match[2];\n\n\t\t\tconst internalWorkspaceType = internalWorkspaceTypes[prefix] ?? \"Unknown\";\n\n\t\t\tthis.events.emit(\"workspaceActivated\", publicWorkspaceAddress, internalWorkspaceType);\n\t\t}\n\n\t\t// While the system workspace is processed here too, it is declared as\n\t\t// conforming to the general schema. So drop its override.\n\t\tconst data = message.content.data as Omit<typeof message.content.data, \"system:presence\">;\n\t\tfor (const [workspaceAddress, remoteDatastore] of objectEntries(data)) {\n\t\t\t// Direct to the appropriate Presence Workspace, if present.\n\t\t\tconst workspace = this.workspaces.get(workspaceAddress);\n\t\t\tif (workspace) {\n\t\t\t\tpostUpdateActions.push(\n\t\t\t\t\t...workspace.internal.processUpdate(\n\t\t\t\t\t\treceived,\n\t\t\t\t\t\ttimeModifier,\n\t\t\t\t\t\tremoteDatastore,\n\t\t\t\t\t\tmessage.clientId,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\t// All broadcast state is kept even if not currently registered, unless a value\n\t\t\t\t// notes itself to be ignored.\n\n\t\t\t\t// Ensure there is a datastore at this address and get it.\n\t\t\t\tconst workspaceDatastore = (this.datastore[workspaceAddress] ??= {});\n\t\t\t\tfor (const [key, remoteAllKnownState] of Object.entries(remoteDatastore)) {\n\t\t\t\t\tmergeUntrackedDatastore(key, remoteAllKnownState, workspaceDatastore, timeModifier);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tfor (const action of postUpdateActions) {\n\t\t\taction();\n\t\t}\n\t}\n\n\t/**\n\t * Broadcasts a join response (complete datastore update message)\n\t * if there is an outstanding join response request.\n\t */\n\tprivate readonly sendJoinResponseIfStillNeeded = (): void => {\n\t\t// Make sure we are currently connected and a broadcast is still needed.\n\t\t// If not connected, nothing we can do.\n\t\tif (this.runtime.getJoinedStatus() !== \"disconnected\" && this.broadcastRequests.size > 0) {\n\t\t\t// Confirm that of remaining requests, now is the time to respond.\n\t\t\tconst now = Date.now();\n\t\t\tlet minResponseTime = Number.POSITIVE_INFINITY;\n\t\t\tfor (const { deadlineTime } of this.broadcastRequests.values()) {\n\t\t\t\tminResponseTime = Math.min(minResponseTime, deadlineTime);\n\t\t\t}\n\t\t\tif (minResponseTime <= now) {\n\t\t\t\tif (this.reasonForCompleteSnapshot) {\n\t\t\t\t\tthis.broadcastAllKnownState();\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// No response needed yet - schedule a later attempt\n\t\t\t\tthis.broadcastRequestsTimer.setTimeout(\n\t\t\t\t\tthis.sendJoinResponseIfStillNeeded,\n\t\t\t\t\tminResponseTime - now,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t};\n\n\t/**\n\t * Handles responding to another client joining the session.\n\t *\n\t * @param updateProviders - list of client connection id's that requestor selected\n\t * to provide response\n\t * @param requestor - `requestor` is only used in telemetry. While it is the requestor's\n\t * client connection id, that is not most important. It is important that this is a\n\t * unique shared id across all clients that might respond as we want to monitor the\n\t * response patterns. The convenience of being client connection id will allow\n\t * correlation with other telemetry where it is often called just `clientId`.\n\t */\n\tprivate prepareJoinResponse(\n\t\tupdateProviders: ClientConnectionId[],\n\t\trequestor: ClientConnectionId,\n\t): void {\n\t\t// We must be connected to receive this message, so clientId should be defined.\n\t\t// If it isn't then, not really a problem; just won't be in provider or audience list.\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\tconst selfClientId = this.runtime.getClientId()!;\n\t\tlet joinResponseDelayMs = broadcastJoinResponseDelaysMs.namedResponder;\n\t\tlet relativeResponseOrder: number | undefined;\n\t\tif (!updateProviders.includes(selfClientId)) {\n\t\t\t// Schedule a broadcast to the new client after a delay only to send if\n\t\t\t// another broadcast satisfying the request hasn't been seen in the\n\t\t\t// meantime. The delay is based on the position in the quorum list. It\n\t\t\t// doesn't have to be a stable list across all clients. We need\n\t\t\t// something to provide suggested order to prevent a flood of broadcasts.\n\t\t\tconst quorumMembers = this.runtime.getQuorum().getMembers();\n\t\t\tconst self = quorumMembers.get(selfClientId);\n\t\t\tif (self) {\n\t\t\t\t// Compute order quorum join order (indicated by sequenceNumber)\n\t\t\t\trelativeResponseOrder = 0;\n\t\t\t\tfor (const { client, sequenceNumber } of quorumMembers.values()) {\n\t\t\t\t\tif (\n\t\t\t\t\t\tsequenceNumber < self.sequenceNumber &&\n\t\t\t\t\t\tclient.details.capabilities.interactive\n\t\t\t\t\t) {\n\t\t\t\t\t\trelativeResponseOrder++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// Order past quorum members + arbitrary additional offset up to 10\n\t\t\t\tlet possibleQuorumRespondents = 0;\n\t\t\t\tfor (const { client } of quorumMembers.values()) {\n\t\t\t\t\tif (client.details.capabilities.interactive) {\n\t\t\t\t\t\tpossibleQuorumRespondents++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\trelativeResponseOrder = possibleQuorumRespondents + Math.random() * 10;\n\t\t\t}\n\t\t\t// When not named to provide update, wait an additional amount\n\t\t\t// of time for those named or others to respond.\n\t\t\tjoinResponseDelayMs +=\n\t\t\t\tbroadcastJoinResponseDelaysMs.backupResponderIncrement *\n\t\t\t\t(3 * updateProviders.length + relativeResponseOrder);\n\t\t}\n\n\t\t// Add the requestor to the list of clients that will receive the broadcast.\n\t\tconst deadlineTime = Date.now() + joinResponseDelayMs;\n\t\tthis.broadcastRequests.set(requestor, {\n\t\t\tdeadlineTime,\n\t\t\tresponseOrder: relativeResponseOrder,\n\t\t});\n\n\t\tif (!this.reasonForCompleteSnapshot) {\n\t\t\t// Check if requestor count meets or exceeds count of other audience\n\t\t\t// members indicating that we effectively have a complete snapshot\n\t\t\t// (once the current message being processed is processed).\n\t\t\tconst { selfPresent, interactiveMembersExcludingSelf } =\n\t\t\t\tthis.getAudienceInformation(selfClientId);\n\t\t\tif (\n\t\t\t\t// Self-present check is done to help ensure that audience\n\t\t\t\t// information is accurate. If self is not present, audience\n\t\t\t\t// information might be incomplete.\n\t\t\t\tselfPresent &&\n\t\t\t\tthis.broadcastRequests.size >= interactiveMembersExcludingSelf.all.size\n\t\t\t) {\n\t\t\t\t// Note that no action is taken here specifically.\n\t\t\t\t// We want action to be queued so that it takes place after\n\t\t\t\t// current message is completely processed. All of the actions\n\t\t\t\t// below should be delayed (not immediate).\n\t\t\t\tthis.reasonForCompleteSnapshot = \"full requests\";\n\t\t\t}\n\t\t}\n\n\t\t// Check if capable of full primary response. If requested to provide\n\t\t// primary response, but do not yet have complete snapshot, we need to\n\t\t// delay a full response, until we think we have complete snapshot. In\n\t\t// the meantime we will send partial updates as usual.\n\t\tif (this.reasonForCompleteSnapshot && updateProviders.includes(selfClientId)) {\n\t\t\t// Use regular message queue to handle timing of the broadcast.\n\t\t\t// Any more immediate broadcasts will accelerate the response time.\n\t\t\t// As a primary responder, it is expected that broadcast will happen and\n\t\t\t// using the regular queue allows other updates to avoid merge work.\n\t\t\tthis.enqueueMessage(\"sendAll\", {\n\t\t\t\tallowableUpdateLatencyMs: joinResponseDelayMs,\n\t\t\t});\n\t\t} else {\n\t\t\t// Check if there isn't already a timer scheduled to send a join\n\t\t\t// response with in this request's deadline.\n\t\t\tif (\n\t\t\t\tthis.broadcastRequestsTimer.hasExpired() ||\n\t\t\t\tdeadlineTime < this.broadcastRequestsTimer.expireTime\n\t\t\t) {\n\t\t\t\t// Set or update the timer.\n\t\t\t\tthis.broadcastRequestsTimer.setTimeout(\n\t\t\t\t\tthis.sendJoinResponseIfStillNeeded,\n\t\t\t\t\tjoinResponseDelayMs,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
|
package/dist/presenceManager.js
CHANGED
|
@@ -109,7 +109,7 @@ class PresenceManager {
|
|
|
109
109
|
// rolling.
|
|
110
110
|
if (!local && !this.joined) {
|
|
111
111
|
const selfClientId = this.runtime.getClientId();
|
|
112
|
-
(0, internal_1.assert)(selfClientId !== undefined,
|
|
112
|
+
(0, internal_1.assert)(selfClientId !== undefined, 0xcbf /* Received signal without clientId */);
|
|
113
113
|
this.onJoin(selfClientId, /* alternateUpdateProvider */ message.clientId);
|
|
114
114
|
}
|
|
115
115
|
this.datastoreManager.processSignal(message, local,
|
|
@@ -1 +1 @@
|
|
|
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,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;SAC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AE,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"]}
|
|
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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MAAM,EACN,MAAM,EACN,QAAQ,EACR,wBAAwB,EACxB,qBAAqB,CAAC,WAAW,CACjC,CAAC;IACF,OAAO,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, 0xcbf /* 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/systemWorkspace.js
CHANGED
|
@@ -100,7 +100,7 @@ class SystemWorkspaceImpl {
|
|
|
100
100
|
onConnectionAdded(clientConnectionId, audienceOutOfDate) {
|
|
101
101
|
(0, internal_1.assert)(this.selfAttendee.getConnectionStatus() === presence_js_1.AttendeeStatus.Disconnected, 0xaad /* Local client should be 'Disconnected' before adding new connection. */);
|
|
102
102
|
const selfInAudience = this.audience.getMember(clientConnectionId) !== undefined;
|
|
103
|
-
(0, internal_1.assert)(selfInAudience || audienceOutOfDate,
|
|
103
|
+
(0, internal_1.assert)(selfInAudience || audienceOutOfDate, 0xcc0 /* Local client must be in audience for presence to handle added connection. */);
|
|
104
104
|
if (!(clientConnectionId in this.datastore.clientToSessionId)) {
|
|
105
105
|
this.datastore.clientToSessionId[clientConnectionId] = {
|
|
106
106
|
rev: this.selfAttendee.order++,
|