@fluidframework/presence 2.41.0 → 2.43.0-343119
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/broadcastControls.d.ts +2 -3
- package/dist/broadcastControls.d.ts.map +1 -1
- package/dist/broadcastControls.js +2 -3
- package/dist/broadcastControls.js.map +1 -1
- package/dist/datastorePresenceManagerFactory.d.ts.map +1 -1
- package/dist/datastorePresenceManagerFactory.js +1 -0
- package/dist/datastorePresenceManagerFactory.js.map +1 -1
- package/dist/datastoreSupport.d.ts +7 -2
- package/dist/datastoreSupport.d.ts.map +1 -1
- package/dist/datastoreSupport.js +6 -4
- package/dist/datastoreSupport.js.map +1 -1
- package/dist/exposedInternalTypes.d.ts +22 -4
- package/dist/exposedInternalTypes.d.ts.map +1 -1
- package/dist/exposedInternalTypes.js.map +1 -1
- package/dist/exposedUtilityTypes.d.ts +6 -5
- package/dist/exposedUtilityTypes.d.ts.map +1 -1
- package/dist/exposedUtilityTypes.js.map +1 -1
- package/dist/internalTypes.d.ts +11 -9
- package/dist/internalTypes.d.ts.map +1 -1
- package/dist/internalTypes.js.map +1 -1
- package/dist/internalUtils.d.ts +26 -8
- package/dist/internalUtils.d.ts.map +1 -1
- package/dist/internalUtils.js +35 -8
- package/dist/internalUtils.js.map +1 -1
- package/dist/latestMapValueManager.d.ts +28 -7
- package/dist/latestMapValueManager.d.ts.map +1 -1
- package/dist/latestMapValueManager.js +10 -9
- package/dist/latestMapValueManager.js.map +1 -1
- package/dist/latestValueManager.d.ts +17 -3
- package/dist/latestValueManager.d.ts.map +1 -1
- package/dist/latestValueManager.js +20 -9
- package/dist/latestValueManager.js.map +1 -1
- package/dist/latestValueTypes.d.ts +11 -1
- package/dist/latestValueTypes.d.ts.map +1 -1
- package/dist/latestValueTypes.js.map +1 -1
- package/dist/notificationsManager.d.ts +2 -2
- package/dist/notificationsManager.d.ts.map +1 -1
- package/dist/notificationsManager.js +14 -7
- package/dist/notificationsManager.js.map +1 -1
- package/dist/presence.d.ts +7 -5
- package/dist/presence.d.ts.map +1 -1
- package/dist/presence.js.map +1 -1
- package/dist/presenceDatastoreManager.d.ts +5 -6
- package/dist/presenceDatastoreManager.d.ts.map +1 -1
- package/dist/presenceDatastoreManager.js +19 -7
- package/dist/presenceDatastoreManager.js.map +1 -1
- package/dist/presenceManager.d.ts +0 -4
- package/dist/presenceManager.d.ts.map +1 -1
- package/dist/presenceManager.js +1 -3
- package/dist/presenceManager.js.map +1 -1
- package/dist/presenceStates.d.ts +9 -14
- package/dist/presenceStates.d.ts.map +1 -1
- package/dist/presenceStates.js +1 -8
- package/dist/presenceStates.js.map +1 -1
- package/dist/protocol.d.ts +37 -12
- package/dist/protocol.d.ts.map +1 -1
- package/dist/protocol.js +7 -3
- package/dist/protocol.js.map +1 -1
- package/dist/stateDatastore.d.ts +9 -8
- package/dist/stateDatastore.d.ts.map +1 -1
- package/dist/stateDatastore.js +0 -4
- package/dist/stateDatastore.js.map +1 -1
- package/dist/systemWorkspace.d.ts +12 -6
- package/dist/systemWorkspace.d.ts.map +1 -1
- package/dist/systemWorkspace.js +14 -4
- package/dist/systemWorkspace.js.map +1 -1
- package/dist/types.d.ts +3 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/valueManager.d.ts +0 -4
- package/dist/valueManager.d.ts.map +1 -1
- package/dist/valueManager.js +0 -4
- package/dist/valueManager.js.map +1 -1
- package/lib/broadcastControls.d.ts +2 -3
- package/lib/broadcastControls.d.ts.map +1 -1
- package/lib/broadcastControls.js +2 -3
- package/lib/broadcastControls.js.map +1 -1
- package/lib/datastorePresenceManagerFactory.d.ts.map +1 -1
- package/lib/datastorePresenceManagerFactory.js +1 -0
- package/lib/datastorePresenceManagerFactory.js.map +1 -1
- package/lib/datastoreSupport.d.ts +7 -2
- package/lib/datastoreSupport.d.ts.map +1 -1
- package/lib/datastoreSupport.js +6 -4
- package/lib/datastoreSupport.js.map +1 -1
- package/lib/exposedInternalTypes.d.ts +22 -4
- package/lib/exposedInternalTypes.d.ts.map +1 -1
- package/lib/exposedInternalTypes.js.map +1 -1
- package/lib/exposedUtilityTypes.d.ts +6 -5
- package/lib/exposedUtilityTypes.d.ts.map +1 -1
- package/lib/exposedUtilityTypes.js.map +1 -1
- package/lib/internalTypes.d.ts +11 -9
- package/lib/internalTypes.d.ts.map +1 -1
- package/lib/internalTypes.js.map +1 -1
- package/lib/internalUtils.d.ts +26 -8
- package/lib/internalUtils.d.ts.map +1 -1
- package/lib/internalUtils.js +31 -7
- package/lib/internalUtils.js.map +1 -1
- package/lib/latestMapValueManager.d.ts +28 -7
- package/lib/latestMapValueManager.d.ts.map +1 -1
- package/lib/latestMapValueManager.js +11 -10
- package/lib/latestMapValueManager.js.map +1 -1
- package/lib/latestValueManager.d.ts +17 -3
- package/lib/latestValueManager.d.ts.map +1 -1
- package/lib/latestValueManager.js +19 -9
- package/lib/latestValueManager.js.map +1 -1
- package/lib/latestValueTypes.d.ts +11 -1
- package/lib/latestValueTypes.d.ts.map +1 -1
- package/lib/latestValueTypes.js.map +1 -1
- package/lib/notificationsManager.d.ts +2 -2
- package/lib/notificationsManager.d.ts.map +1 -1
- package/lib/notificationsManager.js +14 -7
- package/lib/notificationsManager.js.map +1 -1
- package/lib/presence.d.ts +7 -5
- package/lib/presence.d.ts.map +1 -1
- package/lib/presence.js.map +1 -1
- package/lib/presenceDatastoreManager.d.ts +5 -6
- package/lib/presenceDatastoreManager.d.ts.map +1 -1
- package/lib/presenceDatastoreManager.js +20 -8
- package/lib/presenceDatastoreManager.js.map +1 -1
- package/lib/presenceManager.d.ts +0 -4
- package/lib/presenceManager.d.ts.map +1 -1
- package/lib/presenceManager.js +1 -3
- package/lib/presenceManager.js.map +1 -1
- package/lib/presenceStates.d.ts +9 -14
- package/lib/presenceStates.d.ts.map +1 -1
- package/lib/presenceStates.js +1 -8
- package/lib/presenceStates.js.map +1 -1
- package/lib/protocol.d.ts +37 -12
- package/lib/protocol.d.ts.map +1 -1
- package/lib/protocol.js +6 -2
- package/lib/protocol.js.map +1 -1
- package/lib/stateDatastore.d.ts +9 -8
- package/lib/stateDatastore.d.ts.map +1 -1
- package/lib/stateDatastore.js +0 -4
- package/lib/stateDatastore.js.map +1 -1
- package/lib/systemWorkspace.d.ts +12 -6
- package/lib/systemWorkspace.d.ts.map +1 -1
- package/lib/systemWorkspace.js +14 -4
- package/lib/systemWorkspace.js.map +1 -1
- package/lib/types.d.ts +3 -2
- package/lib/types.d.ts.map +1 -1
- package/lib/types.js.map +1 -1
- package/lib/valueManager.d.ts +0 -4
- package/lib/valueManager.d.ts.map +1 -1
- package/lib/valueManager.js +0 -4
- package/lib/valueManager.js.map +1 -1
- package/package.json +17 -17
package/lib/presenceStates.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import type { ClientConnectionId } from "./baseTypes.js";
|
|
|
6
6
|
import type { BroadcastControlSettings } from "./broadcastControls.js";
|
|
7
7
|
import type { InternalTypes } from "./exposedInternalTypes.js";
|
|
8
8
|
import type { ClientRecord, PostUpdateAction } from "./internalTypes.js";
|
|
9
|
-
import type { AttendeeId,
|
|
9
|
+
import type { AttendeeId, PresenceWithNotifications as Presence } from "./presence.js";
|
|
10
10
|
import type { AnyWorkspace, StatesWorkspaceSchema } from "./types.js";
|
|
11
11
|
/**
|
|
12
12
|
* Extracts `Part` from {@link InternalTypes.ManagerFactory} return type
|
|
@@ -16,14 +16,16 @@ import type { AnyWorkspace, StatesWorkspaceSchema } from "./types.js";
|
|
|
16
16
|
* If the `Part` is an optional property, undefined will be included in the
|
|
17
17
|
* result. Applying `Required` to the return type prior to extracting `Part`
|
|
18
18
|
* does not work as expected. Use Exclude\<, undefined\> can be used as needed.
|
|
19
|
-
*
|
|
20
|
-
* @internal
|
|
21
19
|
*/
|
|
22
20
|
export type MapSchemaElement<TSchema extends StatesWorkspaceSchema, Part extends keyof ReturnType<TSchema[keyof TSchema]>, Keys extends keyof TSchema = keyof TSchema> = ReturnType<TSchema[Keys]>[Part];
|
|
23
21
|
/**
|
|
24
|
-
*
|
|
22
|
+
* Miscellaneous options for local state updates
|
|
25
23
|
*/
|
|
26
24
|
export interface RuntimeLocalUpdateOptions {
|
|
25
|
+
/**
|
|
26
|
+
* The maximum time in milliseconds that this update is allowed to be
|
|
27
|
+
* delayed before it must be sent to the service.
|
|
28
|
+
*/
|
|
27
29
|
allowableUpdateLatencyMs: number;
|
|
28
30
|
/**
|
|
29
31
|
* Special option allowed for unicast notifications.
|
|
@@ -31,12 +33,11 @@ export interface RuntimeLocalUpdateOptions {
|
|
|
31
33
|
targetClientId?: ClientConnectionId;
|
|
32
34
|
}
|
|
33
35
|
/**
|
|
34
|
-
* @
|
|
36
|
+
* Contract for `PresenceDatastoreManager` as required by States Workspaces ({@link PresenceStatesImpl}).
|
|
35
37
|
*/
|
|
36
38
|
export interface PresenceRuntime {
|
|
37
39
|
readonly presence: Presence;
|
|
38
40
|
readonly attendeeId: AttendeeId;
|
|
39
|
-
lookupClient(clientId: ClientConnectionId): Attendee;
|
|
40
41
|
localUpdate(states: {
|
|
41
42
|
[key: string]: ClientUpdateEntry;
|
|
42
43
|
}, options: RuntimeLocalUpdateOptions): void;
|
|
@@ -49,14 +50,12 @@ export interface PresenceRuntime {
|
|
|
49
50
|
*
|
|
50
51
|
* This generic aspect makes some typing difficult. The loose typing is not broadcast to the
|
|
51
52
|
* consumers that are expected to maintain their schema over multiple versions of clients.
|
|
52
|
-
*
|
|
53
|
-
* @internal
|
|
54
53
|
*/
|
|
55
54
|
export interface ValueElementMap<_TSchema extends StatesWorkspaceSchema> {
|
|
56
55
|
[key: string]: ClientRecord<InternalTypes.ValueDirectoryOrState<unknown>>;
|
|
57
56
|
}
|
|
58
57
|
/**
|
|
59
|
-
*
|
|
58
|
+
* Data content of a datastore entry in update messages
|
|
60
59
|
*/
|
|
61
60
|
export type ClientUpdateEntry = InternalTypes.ValueDirectoryOrState<unknown> & {
|
|
62
61
|
ignoreUnmonitored?: true;
|
|
@@ -66,7 +65,7 @@ interface ValueUpdateRecord {
|
|
|
66
65
|
[valueKey: string]: ClientUpdateRecord;
|
|
67
66
|
}
|
|
68
67
|
/**
|
|
69
|
-
*
|
|
68
|
+
* Contract for Workspaces as required by `PresenceDatastoreManager`
|
|
70
69
|
*/
|
|
71
70
|
export interface PresenceStatesInternal {
|
|
72
71
|
ensureContent<TSchemaAdditional extends StatesWorkspaceSchema>(content: TSchemaAdditional, controls: BroadcastControlSettings | undefined): AnyWorkspace<TSchemaAdditional>;
|
|
@@ -74,8 +73,6 @@ export interface PresenceStatesInternal {
|
|
|
74
73
|
}
|
|
75
74
|
/**
|
|
76
75
|
* Merge a value directory.
|
|
77
|
-
*
|
|
78
|
-
* @internal
|
|
79
76
|
*/
|
|
80
77
|
export declare function mergeValueDirectory<T, TValueState extends InternalTypes.ValueRequiredState<T> | InternalTypes.ValueOptionalState<T>>(base: TValueState | InternalTypes.ValueDirectory<T> | undefined, update: TValueState | InternalTypes.ValueDirectory<T>, timeDelta: number): TValueState | InternalTypes.ValueDirectory<T>;
|
|
81
78
|
/**
|
|
@@ -88,8 +85,6 @@ export declare function mergeValueDirectory<T, TValueState extends InternalTypes
|
|
|
88
85
|
* @remarks
|
|
89
86
|
* In the case of ignored unmonitored data, the client entries are not stored,
|
|
90
87
|
* though the value keys will be populated and often remain empty.
|
|
91
|
-
*
|
|
92
|
-
* @internal
|
|
93
88
|
*/
|
|
94
89
|
export declare function mergeUntrackedDatastore(key: string, remoteAllKnownState: ClientUpdateRecord, datastore: ValueElementMap<StatesWorkspaceSchema>, timeModifier: number): void;
|
|
95
90
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"presenceStates.d.ts","sourceRoot":"","sources":["../src/presenceStates.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAA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AAc,CAAC,CAAC,CAAC,CA8B/C;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,uBAAuB,CACtC,GAAG,EAAE,MAAM,EACX,mBAAmB,EAAE,kBAAkB,EACvC,SAAS,EAAE,eAAe,CAAC,qBAAqB,CAAC,EACjD,YAAY,EAAE,MAAM,GAClB,IAAI,CAeN;AA8MD;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,SAAS,qBAAqB,EACzE,OAAO,EAAE,eAAe,EACxB,SAAS,EAAE,eAAe,CAAC,qBAAqB,CAAC,EACjD,cAAc,EAAE,OAAO,EACvB,QAAQ,EAAE,wBAAwB,GAAG,SAAS,GAC5C;IAAE,MAAM,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC;IAAC,QAAQ,EAAE,sBAAsB,CAAA;CAAE,CAOrE"}
|
package/lib/presenceStates.js
CHANGED
|
@@ -12,8 +12,6 @@ function isValueDirectory(value) {
|
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
14
|
* Merge a value directory.
|
|
15
|
-
*
|
|
16
|
-
* @internal
|
|
17
15
|
*/
|
|
18
16
|
export function mergeValueDirectory(base, update, timeDelta) {
|
|
19
17
|
if (!isValueDirectory(update)) {
|
|
@@ -57,8 +55,6 @@ export function mergeValueDirectory(base, update, timeDelta) {
|
|
|
57
55
|
* @remarks
|
|
58
56
|
* In the case of ignored unmonitored data, the client entries are not stored,
|
|
59
57
|
* though the value keys will be populated and often remain empty.
|
|
60
|
-
*
|
|
61
|
-
* @internal
|
|
62
58
|
*/
|
|
63
59
|
export function mergeUntrackedDatastore(key, remoteAllKnownState, datastore, timeModifier) {
|
|
64
60
|
const localAllKnownState = getOrCreateRecord(datastore, key, () => ({}));
|
|
@@ -144,9 +140,6 @@ class PresenceStatesImpl {
|
|
|
144
140
|
const allKnownState = this.datastore[key];
|
|
145
141
|
allKnownState[clientId] = mergeValueDirectory(allKnownState[clientId], value, 0);
|
|
146
142
|
}
|
|
147
|
-
lookupClient(clientId) {
|
|
148
|
-
return this.runtime.lookupClient(clientId);
|
|
149
|
-
}
|
|
150
143
|
add(key, nodeFactory) {
|
|
151
144
|
assert(!(key in this.nodes), 0xa3c /* Already have entry for key in map */);
|
|
152
145
|
const nodeData = nodeFactory(key, handleFromDatastore(this));
|
|
@@ -196,7 +189,7 @@ class PresenceStatesImpl {
|
|
|
196
189
|
else {
|
|
197
190
|
const node = unbrandIVM(brandedIVM);
|
|
198
191
|
for (const [attendeeId, value] of objectEntries(remoteAllKnownState)) {
|
|
199
|
-
const client = this.runtime.
|
|
192
|
+
const client = this.runtime.presence.attendees.getAttendee(attendeeId);
|
|
200
193
|
postUpdateActions.push(...node.update(client, received, value));
|
|
201
194
|
}
|
|
202
195
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"presenceStates.js","sourceRoot":"","sources":["../src/presenceStates.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAI7D,OAAO,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAIlE,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAOtE,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAE1D,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAyH/C,SAAS,gBAAgB,CAMxB,KAAoD;IAEpD,OAAO,OAAO,IAAI,KAAK,CAAC;AACzB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAMlC,IAA+D,EAC/D,MAAqD,EACrD,SAAiB;IAEjB,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,EAAE,CAAC;QAC/B,IAAI,IAAI,KAAK,SAAS,IAAI,MAAM,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;YACjD,OAAO,EAAE,GAAG,MAAM,EAAE,SAAS,EAAE,MAAM,CAAC,SAAS,GAA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uB,EAAE,CAAC;QACjD,KAAK,MAAM,CAAC,GAAG,EAAE,mBAAmB,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,EAAE,CAAC;YAC1E,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YACnC,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;gBAC9B,mFAAmF;gBACnF,uBAAuB,CAAC,GAAG,EAAE,mBAAmB,EAAE,IAAI,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC;YACjF,CAAC;iBAAM,CAAC;gBACP,MAAM,IAAI,GAAG,UAAU,CAAC,UAAU,CAAC,CAAC;gBACpC,KAAK,MAAM,CAAC,UAAU,EAAE,KAAK,CAAC,IAAI,aAAa,CAAC,mBAAmB,CAAC,EAAE,CAAC;oBACtE,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC;oBACrD,iBAAiB,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC;gBACjE,CAAC;YACF,CAAC;QACF,CAAC;QACD,OAAO,iBAAiB,CAAC;IAC1B,CAAC;CACD;AAED;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CACnC,OAAwB,EACxB,SAAiD,EACjD,cAAuB,EACvB,QAA8C;IAE9C,MAAM,IAAI,GAAG,IAAI,kBAAkB,CAAU,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,QAAQ,CAAC,CAAC;IAE3F,OAAO;QACN,MAAM,EAAE,IAAI;QACZ,QAAQ,EAAE,IAAI;KACd,CAAC;AACH,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\n\nimport type { ClientConnectionId } from \"./baseTypes.js\";\nimport type { BroadcastControlSettings } from \"./broadcastControls.js\";\nimport { RequiredBroadcastControl } from \"./broadcastControls.js\";\nimport type { InternalTypes } from \"./exposedInternalTypes.js\";\nimport type { ClientRecord, PostUpdateAction } from \"./internalTypes.js\";\nimport type { RecordEntryTypes } from \"./internalUtils.js\";\nimport { getOrCreateRecord, objectEntries } from \"./internalUtils.js\";\nimport type {\n\tAttendeeId,\n\tAttendee,\n\tPresenceWithNotifications as Presence,\n} from \"./presence.js\";\nimport type { LocalStateUpdateOptions, StateDatastore } from \"./stateDatastore.js\";\nimport { handleFromDatastore } from \"./stateDatastore.js\";\nimport type { AnyWorkspace, StatesWorkspace, StatesWorkspaceSchema } from \"./types.js\";\nimport { unbrandIVM } from \"./valueManager.js\";\n\n/**\n * Extracts `Part` from {@link InternalTypes.ManagerFactory} return type\n * matching the {@link StatesWorkspaceSchema} `Keys` given.\n *\n * @remarks\n * If the `Part` is an optional property, undefined will be included in the\n * result. Applying `Required` to the return type prior to extracting `Part`\n * does not work as expected. Use Exclude\\<, undefined\\> can be used as needed.\n *\n * @internal\n */\nexport type MapSchemaElement<\n\tTSchema extends StatesWorkspaceSchema,\n\tPart extends keyof ReturnType<TSchema[keyof TSchema]>,\n\tKeys extends keyof TSchema = keyof TSchema,\n> = ReturnType<TSchema[Keys]>[Part];\n\n/**\n * @internal\n */\nexport interface RuntimeLocalUpdateOptions {\n\tallowableUpdateLatencyMs: number;\n\n\t/**\n\t * Special option allowed for unicast notifications.\n\t */\n\ttargetClientId?: ClientConnectionId;\n}\n\n/**\n * @internal\n */\nexport interface PresenceRuntime {\n\treadonly presence: Presence;\n\treadonly attendeeId: AttendeeId;\n\tlookupClient(clientId: ClientConnectionId): Attendee;\n\tlocalUpdate(\n\t\tstates: { [key: string]: ClientUpdateEntry },\n\t\toptions: RuntimeLocalUpdateOptions,\n\t): void;\n}\n\ntype PresenceSubSchemaFromWorkspaceSchema<\n\tTSchema extends StatesWorkspaceSchema,\n\tPart extends keyof ReturnType<TSchema[keyof TSchema]>,\n> = {\n\t[Key in keyof TSchema]: MapSchemaElement<TSchema, Part, Key>;\n};\n\ntype MapEntries<TSchema extends StatesWorkspaceSchema> = PresenceSubSchemaFromWorkspaceSchema<\n\tTSchema,\n\t\"manager\"\n>;\n\n/**\n * ValueElementMap is a map of key to a map of clientId to ValueState.\n * It is not restricted to the schema of the map as it may receive updates from other clients\n * with managers that have not been registered locally. Each map node is responsible for keeping\n * all session's state to be able to pick arbitrary client to rebroadcast to others.\n *\n * This generic aspect makes some typing difficult. The loose typing is not broadcast to the\n * consumers that are expected to maintain their schema over multiple versions of clients.\n *\n * @internal\n */\nexport interface ValueElementMap<_TSchema extends StatesWorkspaceSchema> {\n\t[key: string]: ClientRecord<InternalTypes.ValueDirectoryOrState<unknown>>;\n}\n\n// An attempt to make the type more precise, but it is not working.\n// If the casting in support code is too much we could keep two references to the same\n// complete datastore, but with the respective types desired.\n// type ValueElementMap<TSchema extends PresenceStatesNodeSchema> =\n// \t| {\n// \t\t\t[Key in keyof TSchema & string]?: {\n// \t\t\t\t[AttendeeId: AttendeeId]: InternalTypes.ValueDirectoryOrState<MapSchemaElement<TSchema,\"value\",Key>>;\n// \t\t\t};\n// \t }\n// \t| {\n// \t\t\t[key: string]: ClientRecord<InternalTypes.ValueDirectoryOrState<unknown>>;\n// \t };\n// interface ValueElementMap<TValue> {\n// \t[Id: string]: ClientRecord<InternalTypes.ValueDirectoryOrState<TValue>>;\n// \t// Version with local packed in is convenient for map, but not for join broadcast to serialize simply.\n// \t// [Id: string]: {\n// \t// \tlocal: InternalTypes.ValueDirectoryOrState<TValue>;\n// \t// \tall: ClientRecord<InternalTypes.ValueDirectoryOrState<TValue>>;\n// \t// };\n// }\n\n/**\n * @internal\n */\nexport type ClientUpdateEntry = InternalTypes.ValueDirectoryOrState<unknown> & {\n\tignoreUnmonitored?: true;\n};\n\ntype ClientUpdateRecord = ClientRecord<ClientUpdateEntry>;\n\ninterface ValueUpdateRecord {\n\t[valueKey: string]: ClientUpdateRecord;\n}\n\n/**\n * @internal\n */\nexport interface PresenceStatesInternal {\n\tensureContent<TSchemaAdditional extends StatesWorkspaceSchema>(\n\t\tcontent: TSchemaAdditional,\n\t\tcontrols: BroadcastControlSettings | undefined,\n\t): AnyWorkspace<TSchemaAdditional>;\n\tprocessUpdate(\n\t\treceived: number,\n\t\ttimeModifier: number,\n\t\tremoteDatastore: ValueUpdateRecord,\n\t\tsenderConnectionId: ClientConnectionId,\n\t): PostUpdateAction[];\n}\n\nfunction isValueDirectory<\n\tT,\n\tTValueState extends\n\t\t| InternalTypes.ValueRequiredState<T>\n\t\t| InternalTypes.ValueOptionalState<T>,\n>(\n\tvalue: InternalTypes.ValueDirectory<T> | TValueState,\n): value is InternalTypes.ValueDirectory<T> {\n\treturn \"items\" in value;\n}\n\n/**\n * Merge a value directory.\n *\n * @internal\n */\nexport function mergeValueDirectory<\n\tT,\n\tTValueState extends\n\t\t| InternalTypes.ValueRequiredState<T>\n\t\t| InternalTypes.ValueOptionalState<T>,\n>(\n\tbase: TValueState | InternalTypes.ValueDirectory<T> | undefined,\n\tupdate: TValueState | InternalTypes.ValueDirectory<T>,\n\ttimeDelta: number,\n): TValueState | InternalTypes.ValueDirectory<T> {\n\tif (!isValueDirectory(update)) {\n\t\tif (base === undefined || update.rev > base.rev) {\n\t\t\treturn { ...update, timestamp: update.timestamp + timeDelta };\n\t\t}\n\t\treturn base;\n\t}\n\n\tlet mergeBase: InternalTypes.ValueDirectory<T>;\n\tif (base === undefined) {\n\t\tmergeBase = { rev: update.rev, items: {} };\n\t} else {\n\t\tconst baseIsDirectory = isValueDirectory(base);\n\t\tif (base.rev >= update.rev) {\n\t\t\tif (!baseIsDirectory) {\n\t\t\t\t// base is leaf value that is more recent - nothing to do\n\t\t\t\treturn base;\n\t\t\t}\n\t\t\t// While base has more advanced revision, assume mis-ordering or\n\t\t\t// missed and catchup update needs merged in.\n\t\t\tmergeBase = base;\n\t\t} else {\n\t\t\tmergeBase = { rev: update.rev, items: baseIsDirectory ? base.items : {} };\n\t\t}\n\t}\n\tfor (const [key, value] of Object.entries(update.items)) {\n\t\tconst baseElement = mergeBase.items[key];\n\t\tmergeBase.items[key] = mergeValueDirectory(baseElement, value, timeDelta);\n\t}\n\treturn mergeBase;\n}\n\n/**\n * Updates remote state into the local [untracked] datastore.\n *\n * @param key - The key of the datastore to merge the untracked data into.\n * @param remoteAllKnownState - The remote state to merge into the datastore.\n * @param datastore - The datastore to merge the untracked data into.\n *\n * @remarks\n * In the case of ignored unmonitored data, the client entries are not stored,\n * though the value keys will be populated and often remain empty.\n *\n * @internal\n */\nexport function mergeUntrackedDatastore(\n\tkey: string,\n\tremoteAllKnownState: ClientUpdateRecord,\n\tdatastore: ValueElementMap<StatesWorkspaceSchema>,\n\ttimeModifier: number,\n): void {\n\tconst localAllKnownState = getOrCreateRecord(\n\t\tdatastore,\n\t\tkey,\n\t\t(): RecordEntryTypes<typeof datastore> => ({}),\n\t);\n\tfor (const [attendeeId, value] of objectEntries(remoteAllKnownState)) {\n\t\tif (!(\"ignoreUnmonitored\" in value)) {\n\t\t\tlocalAllKnownState[attendeeId] = mergeValueDirectory(\n\t\t\t\tlocalAllKnownState[attendeeId],\n\t\t\t\tvalue,\n\t\t\t\ttimeModifier,\n\t\t\t);\n\t\t}\n\t}\n}\n\n/**\n * The default allowable update latency for StatesWorkspace in milliseconds.\n */\nconst defaultAllowableUpdateLatencyMs = 60;\n\n/**\n * Produces the value type of a schema element or set of elements.\n */\ntype SchemaElementValueType<\n\tTSchema extends StatesWorkspaceSchema,\n\tKeys extends keyof TSchema & string,\n> = Exclude<MapSchemaElement<TSchema, \"initialData\", Keys>, undefined>[\"value\"];\n\nclass PresenceStatesImpl<TSchema extends StatesWorkspaceSchema>\n\timplements\n\t\tPresenceStatesInternal,\n\t\tAnyWorkspace<TSchema>,\n\t\tStateDatastore<\n\t\t\tkeyof TSchema & string,\n\t\t\tSchemaElementValueType<TSchema, keyof TSchema & string>\n\t\t>\n{\n\tprivate readonly nodes: MapEntries<TSchema>;\n\tpublic readonly states: StatesWorkspace<TSchema>[\"states\"];\n\tpublic readonly notifications: AnyWorkspace<TSchema>[\"notifications\"];\n\n\tpublic readonly controls: RequiredBroadcastControl;\n\n\tpublic constructor(\n\t\tprivate readonly runtime: PresenceRuntime,\n\t\tprivate readonly datastore: ValueElementMap<TSchema>,\n\t\tinitialContent: TSchema,\n\t\tcontrolsSettings: BroadcastControlSettings | undefined,\n\t) {\n\t\tthis.controls = new RequiredBroadcastControl(defaultAllowableUpdateLatencyMs);\n\t\tif (controlsSettings?.allowableUpdateLatencyMs !== undefined) {\n\t\t\tthis.controls.allowableUpdateLatencyMs = controlsSettings.allowableUpdateLatencyMs;\n\t\t}\n\n\t\t// Prepare initial map content from initial state\n\t\t{\n\t\t\tconst attendeeId = this.runtime.attendeeId;\n\t\t\t// Empty record does not satisfy the type, but nodes will post loop.\n\t\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\t\tconst nodes = {} as MapEntries<TSchema>;\n\t\t\tlet anyInitialValues = false;\n\t\t\tconst newValues: { [key: string]: InternalTypes.ValueDirectoryOrState<unknown> } = {};\n\t\t\tlet cumulativeAllowableUpdateLatencyMs: number | undefined;\n\t\t\tfor (const [key, nodeFactory] of Object.entries(initialContent)) {\n\t\t\t\tconst newNodeData = nodeFactory(key, handleFromDatastore(this));\n\t\t\t\tnodes[key as keyof TSchema] = newNodeData.manager;\n\t\t\t\tif (\"initialData\" in newNodeData) {\n\t\t\t\t\tconst { value, allowableUpdateLatencyMs } = newNodeData.initialData;\n\t\t\t\t\t(datastore[key] ??= {})[attendeeId] = value;\n\t\t\t\t\tnewValues[key] = value;\n\t\t\t\t\tif (allowableUpdateLatencyMs !== undefined) {\n\t\t\t\t\t\tcumulativeAllowableUpdateLatencyMs =\n\t\t\t\t\t\t\tcumulativeAllowableUpdateLatencyMs === undefined\n\t\t\t\t\t\t\t\t? allowableUpdateLatencyMs\n\t\t\t\t\t\t\t\t: Math.min(cumulativeAllowableUpdateLatencyMs, allowableUpdateLatencyMs);\n\t\t\t\t\t}\n\t\t\t\t\tanyInitialValues = true;\n\t\t\t\t}\n\t\t\t}\n\t\t\tthis.nodes = nodes;\n\t\t\t// states and notifications are the public view of nodes that limits the entries\n\t\t\t// types to the public interface of State objects with an additional type\n\t\t\t// filter that beguiles the type system. So just reinterpret cast.\n\t\t\tconst properties = nodes as unknown as AnyWorkspace<TSchema>[\"states\"];\n\t\t\t// `AnyWorkspace` support comes from defining both `states` for\n\t\t\t// `StatesWorkspace` and `notifications` for `NotificationsWorkspace`.\n\t\t\t// `notifications` is always a subset of what `states` can be; so the same.\n\t\t\tthis.notifications = this.states = properties;\n\n\t\t\tif (anyInitialValues) {\n\t\t\t\tthis.runtime.localUpdate(newValues, {\n\t\t\t\t\tallowableUpdateLatencyMs:\n\t\t\t\t\t\tcumulativeAllowableUpdateLatencyMs ?? this.controls.allowableUpdateLatencyMs,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic get presence(): Presence {\n\t\treturn this.runtime.presence;\n\t}\n\n\tpublic knownValues<Key extends keyof TSchema & string>(\n\t\tkey: Key,\n\t): {\n\t\tself: AttendeeId | undefined;\n\t\tstates: ClientRecord<SchemaElementValueType<TSchema, Key>>;\n\t} {\n\t\treturn {\n\t\t\tself: this.runtime.attendeeId,\n\t\t\t// Caller must only use `key`s that are part of `this.datastore`.\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tstates: this.datastore[key]!,\n\t\t};\n\t}\n\n\tpublic localUpdate<Key extends keyof TSchema & string>(\n\t\tkey: Key,\n\t\tvalue: SchemaElementValueType<TSchema, Key> & ClientUpdateEntry,\n\t\toptions: LocalStateUpdateOptions,\n\t): void {\n\t\tthis.runtime.localUpdate(\n\t\t\t{ [key]: value },\n\t\t\t{\n\t\t\t\t...options,\n\t\t\t\tallowableUpdateLatencyMs:\n\t\t\t\t\toptions.allowableUpdateLatencyMs ?? this.controls.allowableUpdateLatencyMs,\n\t\t\t},\n\t\t);\n\t}\n\n\tpublic update<Key extends keyof TSchema & string>(\n\t\tkey: Key,\n\t\tclientId: AttendeeId,\n\t\tvalue: Exclude<MapSchemaElement<TSchema, \"initialData\", Key>, undefined>[\"value\"],\n\t): void {\n\t\t// Callers my only use `key`s that are part of `this.datastore`.\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\tconst allKnownState = this.datastore[key]!;\n\t\tallKnownState[clientId] = mergeValueDirectory(allKnownState[clientId], value, 0);\n\t}\n\n\tpublic lookupClient(clientId: ClientConnectionId): Attendee {\n\t\treturn this.runtime.lookupClient(clientId);\n\t}\n\n\tpublic add<\n\t\tTKey extends string,\n\t\tTValue extends InternalTypes.ValueDirectoryOrState<unknown>,\n\t\tTValueManager,\n\t>(\n\t\tkey: TKey,\n\t\tnodeFactory: InternalTypes.ManagerFactory<TKey, TValue, TValueManager>,\n\t): asserts this is StatesWorkspace<\n\t\tTSchema & Record<TKey, InternalTypes.ManagerFactory<TKey, TValue, TValueManager>>\n\t> {\n\t\tassert(!(key in this.nodes), 0xa3c /* Already have entry for key in map */);\n\t\tconst nodeData = nodeFactory(key, handleFromDatastore(this));\n\t\tthis.nodes[key] = nodeData.manager;\n\t\tif (\"initialData\" in nodeData) {\n\t\t\tconst { value, allowableUpdateLatencyMs } = nodeData.initialData;\n\t\t\tlet datastoreValue = this.datastore[key];\n\t\t\tif (datastoreValue === undefined) {\n\t\t\t\tdatastoreValue = this.datastore[key] = {};\n\t\t\t} else {\n\t\t\t\t// Already have received state from other clients. Kept in `all`.\n\t\t\t\t// TODO: Send current `all` state to state manager.\n\t\t\t}\n\t\t\tdatastoreValue[this.runtime.attendeeId] = value;\n\t\t\tthis.runtime.localUpdate(\n\t\t\t\t{ [key]: value },\n\t\t\t\t{\n\t\t\t\t\tallowableUpdateLatencyMs:\n\t\t\t\t\t\tallowableUpdateLatencyMs ?? this.controls.allowableUpdateLatencyMs,\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\t}\n\n\tpublic ensureContent<TSchemaAdditional extends StatesWorkspaceSchema>(\n\t\tcontent: TSchemaAdditional,\n\t\tcontrols: BroadcastControlSettings | undefined,\n\t): AnyWorkspace<TSchema & TSchemaAdditional> {\n\t\tif (controls?.allowableUpdateLatencyMs !== undefined) {\n\t\t\tthis.controls.allowableUpdateLatencyMs = controls.allowableUpdateLatencyMs;\n\t\t}\n\t\tfor (const [key, nodeFactory] of Object.entries(content)) {\n\t\t\tconst brandedIVM = this.nodes[key];\n\t\t\tif (brandedIVM === undefined) {\n\t\t\t\tthis.add(key, nodeFactory);\n\t\t\t} else {\n\t\t\t\tconst node = unbrandIVM(brandedIVM);\n\t\t\t\tif (!(node instanceof nodeFactory.instanceBase)) {\n\t\t\t\t\tthrow new TypeError(`State \"${key}\" previously created by different State object.`);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn this as AnyWorkspace<TSchema & TSchemaAdditional>;\n\t}\n\n\tpublic processUpdate(\n\t\treceived: number,\n\t\ttimeModifier: number,\n\t\tremoteDatastore: ValueUpdateRecord,\n\t): PostUpdateAction[] {\n\t\tconst postUpdateActions: PostUpdateAction[] = [];\n\t\tfor (const [key, remoteAllKnownState] of Object.entries(remoteDatastore)) {\n\t\t\tconst brandedIVM = this.nodes[key];\n\t\t\tif (brandedIVM === undefined) {\n\t\t\t\t// Assume all broadcast state is meant to be kept even if not currently registered.\n\t\t\t\tmergeUntrackedDatastore(key, remoteAllKnownState, this.datastore, timeModifier);\n\t\t\t} else {\n\t\t\t\tconst node = unbrandIVM(brandedIVM);\n\t\t\t\tfor (const [attendeeId, value] of objectEntries(remoteAllKnownState)) {\n\t\t\t\t\tconst client = this.runtime.lookupClient(attendeeId);\n\t\t\t\t\tpostUpdateActions.push(...node.update(client, received, value));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn postUpdateActions;\n\t}\n}\n\n/**\n * Create a new Workspace using the DataStoreRuntime provided.\n * @param initialContent - The initial State objects to register.\n */\nexport function createPresenceStates<TSchema extends StatesWorkspaceSchema>(\n\truntime: PresenceRuntime,\n\tdatastore: ValueElementMap<StatesWorkspaceSchema>,\n\tinitialContent: TSchema,\n\tcontrols: BroadcastControlSettings | undefined,\n): { public: AnyWorkspace<TSchema>; internal: PresenceStatesInternal } {\n\tconst impl = new PresenceStatesImpl<TSchema>(runtime, datastore, initialContent, controls);\n\n\treturn {\n\t\tpublic: impl,\n\t\tinternal: impl,\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"presenceStates.js","sourceRoot":"","sources":["../src/presenceStates.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAI7D,OAAO,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAIlE,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGtE,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAE1D,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAwH/C,SAAS,gBAAgB,CAMxB,KAAoD;IAEpD,OAAO,OAAO,IAAI,KAAK,CAAC;AACzB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAMlC,IAA+D,EAC/D,MAAqD,EACrD,SAAiB;IAEjB,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,EAAE,CAAC;QAC/B,IAAI,IAAI,KAAK,SAAS,IAAI,MAAM,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;YACjD,OAAO,EAAE,GAAG,MAAM,EAAE,SAAS,EAAE,MAAM,CAAC,SAAS,GAAG,SAAS,EAAE,CAAC;QAC/D,CAAC;QACD,OAAO,IAAI,CAAC;IACb,CAAC;IAED,IAAI,SAA0C,CAAC;IAC/C,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACxB,SAAS,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,GAAG,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I,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC;YACjF,CAAC;iBAAM,CAAC;gBACP,MAAM,IAAI,GAAG,UAAU,CAAC,UAAU,CAAC,CAAC;gBACpC,KAAK,MAAM,CAAC,UAAU,EAAE,KAAK,CAAC,IAAI,aAAa,CAAC,mBAAmB,CAAC,EAAE,CAAC;oBACtE,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;oBACvE,iBAAiB,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC;gBACjE,CAAC;YACF,CAAC;QACF,CAAC;QACD,OAAO,iBAAiB,CAAC;IAC1B,CAAC;CACD;AAED;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CACnC,OAAwB,EACxB,SAAiD,EACjD,cAAuB,EACvB,QAA8C;IAE9C,MAAM,IAAI,GAAG,IAAI,kBAAkB,CAAU,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,QAAQ,CAAC,CAAC;IAE3F,OAAO;QACN,MAAM,EAAE,IAAI;QACZ,QAAQ,EAAE,IAAI;KACd,CAAC;AACH,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\n\nimport type { ClientConnectionId } from \"./baseTypes.js\";\nimport type { BroadcastControlSettings } from \"./broadcastControls.js\";\nimport { RequiredBroadcastControl } from \"./broadcastControls.js\";\nimport type { InternalTypes } from \"./exposedInternalTypes.js\";\nimport type { ClientRecord, PostUpdateAction } from \"./internalTypes.js\";\nimport type { RecordEntryTypes } from \"./internalUtils.js\";\nimport { getOrCreateRecord, objectEntries } from \"./internalUtils.js\";\nimport type { AttendeeId, PresenceWithNotifications as Presence } from \"./presence.js\";\nimport type { LocalStateUpdateOptions, StateDatastore } from \"./stateDatastore.js\";\nimport { handleFromDatastore } from \"./stateDatastore.js\";\nimport type { AnyWorkspace, StatesWorkspace, StatesWorkspaceSchema } from \"./types.js\";\nimport { unbrandIVM } from \"./valueManager.js\";\n\n/**\n * Extracts `Part` from {@link InternalTypes.ManagerFactory} return type\n * matching the {@link StatesWorkspaceSchema} `Keys` given.\n *\n * @remarks\n * If the `Part` is an optional property, undefined will be included in the\n * result. Applying `Required` to the return type prior to extracting `Part`\n * does not work as expected. Use Exclude\\<, undefined\\> can be used as needed.\n */\nexport type MapSchemaElement<\n\tTSchema extends StatesWorkspaceSchema,\n\tPart extends keyof ReturnType<TSchema[keyof TSchema]>,\n\tKeys extends keyof TSchema = keyof TSchema,\n> = ReturnType<TSchema[Keys]>[Part];\n\n/**\n * Miscellaneous options for local state updates\n */\nexport interface RuntimeLocalUpdateOptions {\n\t/**\n\t * The maximum time in milliseconds that this update is allowed to be\n\t * delayed before it must be sent to the service.\n\t */\n\tallowableUpdateLatencyMs: number;\n\n\t/**\n\t * Special option allowed for unicast notifications.\n\t */\n\ttargetClientId?: ClientConnectionId;\n}\n\n/**\n * Contract for `PresenceDatastoreManager` as required by States Workspaces ({@link PresenceStatesImpl}).\n */\nexport interface PresenceRuntime {\n\treadonly presence: Presence;\n\treadonly attendeeId: AttendeeId;\n\tlocalUpdate(\n\t\tstates: { [key: string]: ClientUpdateEntry },\n\t\toptions: RuntimeLocalUpdateOptions,\n\t): void;\n}\n\ntype PresenceSubSchemaFromWorkspaceSchema<\n\tTSchema extends StatesWorkspaceSchema,\n\tPart extends keyof ReturnType<TSchema[keyof TSchema]>,\n> = {\n\t[Key in keyof TSchema]: MapSchemaElement<TSchema, Part, Key>;\n};\n\ntype MapEntries<TSchema extends StatesWorkspaceSchema> = PresenceSubSchemaFromWorkspaceSchema<\n\tTSchema,\n\t\"manager\"\n>;\n\n/**\n * ValueElementMap is a map of key to a map of clientId to ValueState.\n * It is not restricted to the schema of the map as it may receive updates from other clients\n * with managers that have not been registered locally. Each map node is responsible for keeping\n * all session's state to be able to pick arbitrary client to rebroadcast to others.\n *\n * This generic aspect makes some typing difficult. The loose typing is not broadcast to the\n * consumers that are expected to maintain their schema over multiple versions of clients.\n */\nexport interface ValueElementMap<_TSchema extends StatesWorkspaceSchema> {\n\t[key: string]: ClientRecord<InternalTypes.ValueDirectoryOrState<unknown>>;\n}\n\n// An attempt to make the type more precise, but it is not working.\n// If the casting in support code is too much we could keep two references to the same\n// complete datastore, but with the respective types desired.\n// type ValueElementMap<TSchema extends PresenceStatesNodeSchema> =\n// \t| {\n// \t\t\t[Key in keyof TSchema & string]?: {\n// \t\t\t\t[AttendeeId: AttendeeId]: InternalTypes.ValueDirectoryOrState<MapSchemaElement<TSchema,\"value\",Key>>;\n// \t\t\t};\n// \t }\n// \t| {\n// \t\t\t[key: string]: ClientRecord<InternalTypes.ValueDirectoryOrState<unknown>>;\n// \t };\n// interface ValueElementMap<TValue> {\n// \t[Id: string]: ClientRecord<InternalTypes.ValueDirectoryOrState<TValue>>;\n// \t// Version with local packed in is convenient for map, but not for join broadcast to serialize simply.\n// \t// [Id: string]: {\n// \t// \tlocal: InternalTypes.ValueDirectoryOrState<TValue>;\n// \t// \tall: ClientRecord<InternalTypes.ValueDirectoryOrState<TValue>>;\n// \t// };\n// }\n\n/**\n * Data content of a datastore entry in update messages\n */\nexport type ClientUpdateEntry = InternalTypes.ValueDirectoryOrState<unknown> & {\n\tignoreUnmonitored?: true;\n};\n\ntype ClientUpdateRecord = ClientRecord<ClientUpdateEntry>;\n\ninterface ValueUpdateRecord {\n\t[valueKey: string]: ClientUpdateRecord;\n}\n\n/**\n * Contract for Workspaces as required by `PresenceDatastoreManager`\n */\nexport interface PresenceStatesInternal {\n\tensureContent<TSchemaAdditional extends StatesWorkspaceSchema>(\n\t\tcontent: TSchemaAdditional,\n\t\tcontrols: BroadcastControlSettings | undefined,\n\t): AnyWorkspace<TSchemaAdditional>;\n\tprocessUpdate(\n\t\treceived: number,\n\t\ttimeModifier: number,\n\t\tremoteDatastore: ValueUpdateRecord,\n\t\tsenderConnectionId: ClientConnectionId,\n\t): PostUpdateAction[];\n}\n\nfunction isValueDirectory<\n\tT,\n\tTValueState extends\n\t\t| InternalTypes.ValueRequiredState<T>\n\t\t| InternalTypes.ValueOptionalState<T>,\n>(\n\tvalue: InternalTypes.ValueDirectory<T> | TValueState,\n): value is InternalTypes.ValueDirectory<T> {\n\treturn \"items\" in value;\n}\n\n/**\n * Merge a value directory.\n */\nexport function mergeValueDirectory<\n\tT,\n\tTValueState extends\n\t\t| InternalTypes.ValueRequiredState<T>\n\t\t| InternalTypes.ValueOptionalState<T>,\n>(\n\tbase: TValueState | InternalTypes.ValueDirectory<T> | undefined,\n\tupdate: TValueState | InternalTypes.ValueDirectory<T>,\n\ttimeDelta: number,\n): TValueState | InternalTypes.ValueDirectory<T> {\n\tif (!isValueDirectory(update)) {\n\t\tif (base === undefined || update.rev > base.rev) {\n\t\t\treturn { ...update, timestamp: update.timestamp + timeDelta };\n\t\t}\n\t\treturn base;\n\t}\n\n\tlet mergeBase: InternalTypes.ValueDirectory<T>;\n\tif (base === undefined) {\n\t\tmergeBase = { rev: update.rev, items: {} };\n\t} else {\n\t\tconst baseIsDirectory = isValueDirectory(base);\n\t\tif (base.rev >= update.rev) {\n\t\t\tif (!baseIsDirectory) {\n\t\t\t\t// base is leaf value that is more recent - nothing to do\n\t\t\t\treturn base;\n\t\t\t}\n\t\t\t// While base has more advanced revision, assume mis-ordering or\n\t\t\t// missed and catchup update needs merged in.\n\t\t\tmergeBase = base;\n\t\t} else {\n\t\t\tmergeBase = { rev: update.rev, items: baseIsDirectory ? base.items : {} };\n\t\t}\n\t}\n\tfor (const [key, value] of Object.entries(update.items)) {\n\t\tconst baseElement = mergeBase.items[key];\n\t\tmergeBase.items[key] = mergeValueDirectory(baseElement, value, timeDelta);\n\t}\n\treturn mergeBase;\n}\n\n/**\n * Updates remote state into the local [untracked] datastore.\n *\n * @param key - The key of the datastore to merge the untracked data into.\n * @param remoteAllKnownState - The remote state to merge into the datastore.\n * @param datastore - The datastore to merge the untracked data into.\n *\n * @remarks\n * In the case of ignored unmonitored data, the client entries are not stored,\n * though the value keys will be populated and often remain empty.\n */\nexport function mergeUntrackedDatastore(\n\tkey: string,\n\tremoteAllKnownState: ClientUpdateRecord,\n\tdatastore: ValueElementMap<StatesWorkspaceSchema>,\n\ttimeModifier: number,\n): void {\n\tconst localAllKnownState = getOrCreateRecord(\n\t\tdatastore,\n\t\tkey,\n\t\t(): RecordEntryTypes<typeof datastore> => ({}),\n\t);\n\tfor (const [attendeeId, value] of objectEntries(remoteAllKnownState)) {\n\t\tif (!(\"ignoreUnmonitored\" in value)) {\n\t\t\tlocalAllKnownState[attendeeId] = mergeValueDirectory(\n\t\t\t\tlocalAllKnownState[attendeeId],\n\t\t\t\tvalue,\n\t\t\t\ttimeModifier,\n\t\t\t);\n\t\t}\n\t}\n}\n\n/**\n * The default allowable update latency for StatesWorkspace in milliseconds.\n */\nconst defaultAllowableUpdateLatencyMs = 60;\n\n/**\n * Produces the value type of a schema element or set of elements.\n */\ntype SchemaElementValueType<\n\tTSchema extends StatesWorkspaceSchema,\n\tKeys extends keyof TSchema & string,\n> = Exclude<MapSchemaElement<TSchema, \"initialData\", Keys>, undefined>[\"value\"];\n\nclass PresenceStatesImpl<TSchema extends StatesWorkspaceSchema>\n\timplements\n\t\tPresenceStatesInternal,\n\t\tAnyWorkspace<TSchema>,\n\t\tStateDatastore<\n\t\t\tkeyof TSchema & string,\n\t\t\tSchemaElementValueType<TSchema, keyof TSchema & string>\n\t\t>\n{\n\tprivate readonly nodes: MapEntries<TSchema>;\n\tpublic readonly states: StatesWorkspace<TSchema>[\"states\"];\n\tpublic readonly notifications: AnyWorkspace<TSchema>[\"notifications\"];\n\n\tpublic readonly controls: RequiredBroadcastControl;\n\n\tpublic constructor(\n\t\tprivate readonly runtime: PresenceRuntime,\n\t\tprivate readonly datastore: ValueElementMap<TSchema>,\n\t\tinitialContent: TSchema,\n\t\tcontrolsSettings: BroadcastControlSettings | undefined,\n\t) {\n\t\tthis.controls = new RequiredBroadcastControl(defaultAllowableUpdateLatencyMs);\n\t\tif (controlsSettings?.allowableUpdateLatencyMs !== undefined) {\n\t\t\tthis.controls.allowableUpdateLatencyMs = controlsSettings.allowableUpdateLatencyMs;\n\t\t}\n\n\t\t// Prepare initial map content from initial state\n\t\t{\n\t\t\tconst attendeeId = this.runtime.attendeeId;\n\t\t\t// Empty record does not satisfy the type, but nodes will post loop.\n\t\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\t\tconst nodes = {} as MapEntries<TSchema>;\n\t\t\tlet anyInitialValues = false;\n\t\t\tconst newValues: { [key: string]: InternalTypes.ValueDirectoryOrState<unknown> } = {};\n\t\t\tlet cumulativeAllowableUpdateLatencyMs: number | undefined;\n\t\t\tfor (const [key, nodeFactory] of Object.entries(initialContent)) {\n\t\t\t\tconst newNodeData = nodeFactory(key, handleFromDatastore(this));\n\t\t\t\tnodes[key as keyof TSchema] = newNodeData.manager;\n\t\t\t\tif (\"initialData\" in newNodeData) {\n\t\t\t\t\tconst { value, allowableUpdateLatencyMs } = newNodeData.initialData;\n\t\t\t\t\t(datastore[key] ??= {})[attendeeId] = value;\n\t\t\t\t\tnewValues[key] = value;\n\t\t\t\t\tif (allowableUpdateLatencyMs !== undefined) {\n\t\t\t\t\t\tcumulativeAllowableUpdateLatencyMs =\n\t\t\t\t\t\t\tcumulativeAllowableUpdateLatencyMs === undefined\n\t\t\t\t\t\t\t\t? allowableUpdateLatencyMs\n\t\t\t\t\t\t\t\t: Math.min(cumulativeAllowableUpdateLatencyMs, allowableUpdateLatencyMs);\n\t\t\t\t\t}\n\t\t\t\t\tanyInitialValues = true;\n\t\t\t\t}\n\t\t\t}\n\t\t\tthis.nodes = nodes;\n\t\t\t// states and notifications are the public view of nodes that limits the entries\n\t\t\t// types to the public interface of State objects with an additional type\n\t\t\t// filter that beguiles the type system. So just reinterpret cast.\n\t\t\tconst properties = nodes as unknown as AnyWorkspace<TSchema>[\"states\"];\n\t\t\t// `AnyWorkspace` support comes from defining both `states` for\n\t\t\t// `StatesWorkspace` and `notifications` for `NotificationsWorkspace`.\n\t\t\t// `notifications` is always a subset of what `states` can be; so the same.\n\t\t\tthis.notifications = this.states = properties;\n\n\t\t\tif (anyInitialValues) {\n\t\t\t\tthis.runtime.localUpdate(newValues, {\n\t\t\t\t\tallowableUpdateLatencyMs:\n\t\t\t\t\t\tcumulativeAllowableUpdateLatencyMs ?? this.controls.allowableUpdateLatencyMs,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic get presence(): Presence {\n\t\treturn this.runtime.presence;\n\t}\n\n\tpublic knownValues<Key extends keyof TSchema & string>(\n\t\tkey: Key,\n\t): {\n\t\tself: AttendeeId | undefined;\n\t\tstates: ClientRecord<SchemaElementValueType<TSchema, Key>>;\n\t} {\n\t\treturn {\n\t\t\tself: this.runtime.attendeeId,\n\t\t\t// Caller must only use `key`s that are part of `this.datastore`.\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tstates: this.datastore[key]!,\n\t\t};\n\t}\n\n\tpublic localUpdate<Key extends keyof TSchema & string>(\n\t\tkey: Key,\n\t\tvalue: SchemaElementValueType<TSchema, Key> & ClientUpdateEntry,\n\t\toptions: LocalStateUpdateOptions,\n\t): void {\n\t\tthis.runtime.localUpdate(\n\t\t\t{ [key]: value },\n\t\t\t{\n\t\t\t\t...options,\n\t\t\t\tallowableUpdateLatencyMs:\n\t\t\t\t\toptions.allowableUpdateLatencyMs ?? this.controls.allowableUpdateLatencyMs,\n\t\t\t},\n\t\t);\n\t}\n\n\tpublic update<Key extends keyof TSchema & string>(\n\t\tkey: Key,\n\t\tclientId: AttendeeId,\n\t\tvalue: Exclude<MapSchemaElement<TSchema, \"initialData\", Key>, undefined>[\"value\"],\n\t): void {\n\t\t// Callers my only use `key`s that are part of `this.datastore`.\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\tconst allKnownState = this.datastore[key]!;\n\t\tallKnownState[clientId] = mergeValueDirectory(allKnownState[clientId], value, 0);\n\t}\n\n\tpublic add<\n\t\tTKey extends string,\n\t\tTValue extends InternalTypes.ValueDirectoryOrState<unknown>,\n\t\tTValueManager,\n\t>(\n\t\tkey: TKey,\n\t\tnodeFactory: InternalTypes.ManagerFactory<TKey, TValue, TValueManager>,\n\t): asserts this is StatesWorkspace<\n\t\tTSchema & Record<TKey, InternalTypes.ManagerFactory<TKey, TValue, TValueManager>>\n\t> {\n\t\tassert(!(key in this.nodes), 0xa3c /* Already have entry for key in map */);\n\t\tconst nodeData = nodeFactory(key, handleFromDatastore(this));\n\t\tthis.nodes[key] = nodeData.manager;\n\t\tif (\"initialData\" in nodeData) {\n\t\t\tconst { value, allowableUpdateLatencyMs } = nodeData.initialData;\n\t\t\tlet datastoreValue = this.datastore[key];\n\t\t\tif (datastoreValue === undefined) {\n\t\t\t\tdatastoreValue = this.datastore[key] = {};\n\t\t\t} else {\n\t\t\t\t// Already have received state from other clients. Kept in `all`.\n\t\t\t\t// TODO: Send current `all` state to state manager.\n\t\t\t}\n\t\t\tdatastoreValue[this.runtime.attendeeId] = value;\n\t\t\tthis.runtime.localUpdate(\n\t\t\t\t{ [key]: value },\n\t\t\t\t{\n\t\t\t\t\tallowableUpdateLatencyMs:\n\t\t\t\t\t\tallowableUpdateLatencyMs ?? this.controls.allowableUpdateLatencyMs,\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\t}\n\n\tpublic ensureContent<TSchemaAdditional extends StatesWorkspaceSchema>(\n\t\tcontent: TSchemaAdditional,\n\t\tcontrols: BroadcastControlSettings | undefined,\n\t): AnyWorkspace<TSchema & TSchemaAdditional> {\n\t\tif (controls?.allowableUpdateLatencyMs !== undefined) {\n\t\t\tthis.controls.allowableUpdateLatencyMs = controls.allowableUpdateLatencyMs;\n\t\t}\n\t\tfor (const [key, nodeFactory] of Object.entries(content)) {\n\t\t\tconst brandedIVM = this.nodes[key];\n\t\t\tif (brandedIVM === undefined) {\n\t\t\t\tthis.add(key, nodeFactory);\n\t\t\t} else {\n\t\t\t\tconst node = unbrandIVM(brandedIVM);\n\t\t\t\tif (!(node instanceof nodeFactory.instanceBase)) {\n\t\t\t\t\tthrow new TypeError(`State \"${key}\" previously created by different State object.`);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn this as AnyWorkspace<TSchema & TSchemaAdditional>;\n\t}\n\n\tpublic processUpdate(\n\t\treceived: number,\n\t\ttimeModifier: number,\n\t\tremoteDatastore: ValueUpdateRecord,\n\t): PostUpdateAction[] {\n\t\tconst postUpdateActions: PostUpdateAction[] = [];\n\t\tfor (const [key, remoteAllKnownState] of Object.entries(remoteDatastore)) {\n\t\t\tconst brandedIVM = this.nodes[key];\n\t\t\tif (brandedIVM === undefined) {\n\t\t\t\t// Assume all broadcast state is meant to be kept even if not currently registered.\n\t\t\t\tmergeUntrackedDatastore(key, remoteAllKnownState, this.datastore, timeModifier);\n\t\t\t} else {\n\t\t\t\tconst node = unbrandIVM(brandedIVM);\n\t\t\t\tfor (const [attendeeId, value] of objectEntries(remoteAllKnownState)) {\n\t\t\t\t\tconst client = this.runtime.presence.attendees.getAttendee(attendeeId);\n\t\t\t\t\tpostUpdateActions.push(...node.update(client, received, value));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn postUpdateActions;\n\t}\n}\n\n/**\n * Create a new Workspace using the DataStoreRuntime provided.\n * @param initialContent - The initial State objects to register.\n */\nexport function createPresenceStates<TSchema extends StatesWorkspaceSchema>(\n\truntime: PresenceRuntime,\n\tdatastore: ValueElementMap<StatesWorkspaceSchema>,\n\tinitialContent: TSchema,\n\tcontrols: BroadcastControlSettings | undefined,\n): { public: AnyWorkspace<TSchema>; internal: PresenceStatesInternal } {\n\tconst impl = new PresenceStatesImpl<TSchema>(runtime, datastore, initialContent, controls);\n\n\treturn {\n\t\tpublic: impl,\n\t\tinternal: impl,\n\t};\n}\n"]}
|
package/lib/protocol.d.ts
CHANGED
|
@@ -7,25 +7,31 @@ import type { ClientConnectionId } from "./baseTypes.js";
|
|
|
7
7
|
import type { AttendeeId } from "./presence.js";
|
|
8
8
|
import type { ClientUpdateEntry } from "./presenceStates.js";
|
|
9
9
|
import type { SystemWorkspaceDatastore } from "./systemWorkspace.js";
|
|
10
|
+
import type { WorkspaceAddress } from "./types.js";
|
|
10
11
|
/**
|
|
11
|
-
*
|
|
12
|
+
* Datastore that contains system workspace data
|
|
12
13
|
*/
|
|
13
14
|
export interface SystemDatastore {
|
|
14
15
|
"system:presence": SystemWorkspaceDatastore;
|
|
15
16
|
}
|
|
16
17
|
/**
|
|
17
|
-
*
|
|
18
|
+
* Expected address format for general workspaces in the presence protocol.
|
|
19
|
+
*/
|
|
20
|
+
export type InternalWorkspaceAddress = `${"s" | "n"}:${WorkspaceAddress}`;
|
|
21
|
+
/**
|
|
22
|
+
* General datastore (and message) structure.
|
|
18
23
|
*/
|
|
19
24
|
export interface GeneralDatastoreMessageContent {
|
|
20
|
-
[WorkspaceAddress:
|
|
25
|
+
[WorkspaceAddress: InternalWorkspaceAddress]: {
|
|
21
26
|
[StateValueManagerKey: string]: {
|
|
22
27
|
[AttendeeId: AttendeeId]: ClientUpdateEntry;
|
|
23
28
|
};
|
|
24
29
|
};
|
|
25
30
|
}
|
|
26
|
-
type DatastoreMessageContent =
|
|
31
|
+
type DatastoreMessageContent = SystemDatastore & GeneralDatastoreMessageContent;
|
|
32
|
+
type AcknowledgmentId = string;
|
|
27
33
|
/**
|
|
28
|
-
*
|
|
34
|
+
* Datastore update message type.
|
|
29
35
|
*/
|
|
30
36
|
export declare const datastoreUpdateMessageType = "Pres:DatastoreUpdate";
|
|
31
37
|
interface DatastoreUpdateMessage {
|
|
@@ -33,20 +39,21 @@ interface DatastoreUpdateMessage {
|
|
|
33
39
|
content: {
|
|
34
40
|
sendTimestamp: number;
|
|
35
41
|
avgLatency: number;
|
|
42
|
+
acknowledgementId?: AcknowledgmentId;
|
|
36
43
|
isComplete?: true;
|
|
37
44
|
data: DatastoreMessageContent;
|
|
38
45
|
};
|
|
39
46
|
}
|
|
40
47
|
/**
|
|
41
|
-
*
|
|
48
|
+
* Outbound datastore update message
|
|
42
49
|
*/
|
|
43
50
|
export type OutboundDatastoreUpdateMessage = OutboundExtensionMessage<DatastoreUpdateMessage>;
|
|
44
51
|
/**
|
|
45
|
-
*
|
|
52
|
+
* Inbound and verified datastore update message
|
|
46
53
|
*/
|
|
47
54
|
export type InboundDatastoreUpdateMessage = VerifiedInboundExtensionMessage<DatastoreUpdateMessage>;
|
|
48
55
|
/**
|
|
49
|
-
*
|
|
56
|
+
* Client join message type.
|
|
50
57
|
*/
|
|
51
58
|
export declare const joinMessageType = "Pres:ClientJoin";
|
|
52
59
|
interface ClientJoinMessage {
|
|
@@ -59,16 +66,34 @@ interface ClientJoinMessage {
|
|
|
59
66
|
};
|
|
60
67
|
}
|
|
61
68
|
/**
|
|
62
|
-
*
|
|
69
|
+
* Acknowledgement message type.
|
|
70
|
+
*/
|
|
71
|
+
export declare const acknowledgementMessageType = "Pres:Ack";
|
|
72
|
+
interface AcknowledgementMessage {
|
|
73
|
+
type: typeof acknowledgementMessageType;
|
|
74
|
+
content: {
|
|
75
|
+
id: AcknowledgmentId;
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Outbound acknowledgement message.
|
|
80
|
+
*/
|
|
81
|
+
export type OutboundAcknowledgementMessage = OutboundExtensionMessage<AcknowledgementMessage>;
|
|
82
|
+
/**
|
|
83
|
+
* Outbound client join message
|
|
63
84
|
*/
|
|
64
85
|
export type OutboundClientJoinMessage = OutboundExtensionMessage<ClientJoinMessage>;
|
|
65
86
|
/**
|
|
66
|
-
*
|
|
87
|
+
* Inbound and verified client join message
|
|
67
88
|
*/
|
|
68
89
|
export type InboundClientJoinMessage = VerifiedInboundExtensionMessage<ClientJoinMessage>;
|
|
69
90
|
/**
|
|
70
|
-
*
|
|
91
|
+
* Outbound presence message.
|
|
92
|
+
*/
|
|
93
|
+
export type OutboundPresenceMessage = OutboundAcknowledgementMessage | OutboundClientJoinMessage | OutboundDatastoreUpdateMessage;
|
|
94
|
+
/**
|
|
95
|
+
* Messages structures that can be sent and received as understood in the presence protocol
|
|
71
96
|
*/
|
|
72
|
-
export type SignalMessages = ClientJoinMessage | DatastoreUpdateMessage;
|
|
97
|
+
export type SignalMessages = AcknowledgementMessage | ClientJoinMessage | DatastoreUpdateMessage;
|
|
73
98
|
export {};
|
|
74
99
|
//# sourceMappingURL=protocol.d.ts.map
|
package/lib/protocol.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACX,wBAAwB,EACxB,+BAA+B,EAC/B,MAAM,wDAAwD,CAAC;AAEhE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACX,wBAAwB,EACxB,+BAA+B,EAC/B,MAAM,wDAAwD,CAAC;AAEhE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,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,uBAAuB,CAAC;KAC9B,CAAC;CACF;AAED;;GAEG;AACH,eAAO,MAAM,0BAA0B,aAAa,CAAC;AAErD,UAAU,sBAAsB;IAC/B,IAAI,EAAE,OAAO,0BAA0B,CAAC;IACxC,OAAO,EAAE;QACR,EAAE,EAAE,gBAAgB,CAAC;KACrB,CAAC;CACF;AAED;;GAEG;AACH,MAAM,MAAM,8BAA8B,GAAG,wBAAwB,CAAC,sBAAsB,CAAC,CAAC;AAE9F;;GAEG;AACH,MAAM,MAAM,yBAAyB,GAAG,wBAAwB,CAAC,iBAAiB,CAAC,CAAC;AAEpF;;GAEG;AACH,MAAM,MAAM,wBAAwB,GAAG,+BAA+B,CAAC,iBAAiB,CAAC,CAAC;AAE1F;;GAEG;AACH,MAAM,MAAM,uBAAuB,GAChC,8BAA8B,GAC9B,yBAAyB,GACzB,8BAA8B,CAAC;AAElC;;GAEG;AACH,MAAM,MAAM,cAAc,GACvB,sBAAsB,GACtB,iBAAiB,GACjB,sBAAsB,CAAC"}
|
package/lib/protocol.js
CHANGED
|
@@ -3,11 +3,15 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* Datastore update message type.
|
|
7
7
|
*/
|
|
8
8
|
export const datastoreUpdateMessageType = "Pres:DatastoreUpdate";
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
10
|
+
* Client join message type.
|
|
11
11
|
*/
|
|
12
12
|
export const joinMessageType = "Pres:ClientJoin";
|
|
13
|
+
/**
|
|
14
|
+
* Acknowledgement message type.
|
|
15
|
+
*/
|
|
16
|
+
export const acknowledgementMessageType = "Pres:Ack";
|
|
13
17
|
//# sourceMappingURL=protocol.js.map
|
package/lib/protocol.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAuCH;;GAEG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,sBAAsB,CAAC;AAuBjE;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,iBAAiB,CAAC;AAWjD;;GAEG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,UAAU,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type {\n\tOutboundExtensionMessage,\n\tVerifiedInboundExtensionMessage,\n} from \"@fluidframework/container-runtime-definitions/internal\";\n\nimport type { ClientConnectionId } from \"./baseTypes.js\";\nimport type { AttendeeId } from \"./presence.js\";\nimport type { ClientUpdateEntry } from \"./presenceStates.js\";\nimport type { SystemWorkspaceDatastore } from \"./systemWorkspace.js\";\nimport type { WorkspaceAddress } from \"./types.js\";\n\n/**\n * Datastore that contains system workspace data\n */\nexport interface SystemDatastore {\n\t\"system:presence\": SystemWorkspaceDatastore;\n}\n\n/**\n * Expected address format for general workspaces in the presence protocol.\n */\nexport type InternalWorkspaceAddress = `${\"s\" | \"n\"}:${WorkspaceAddress}`;\n\n/**\n * General datastore (and message) structure.\n */\nexport interface GeneralDatastoreMessageContent {\n\t[WorkspaceAddress: InternalWorkspaceAddress]: {\n\t\t[StateValueManagerKey: string]: {\n\t\t\t[AttendeeId: AttendeeId]: ClientUpdateEntry;\n\t\t};\n\t};\n}\n\ntype DatastoreMessageContent = SystemDatastore & GeneralDatastoreMessageContent;\ntype AcknowledgmentId = string;\n\n/**\n * Datastore update message type.\n */\nexport const datastoreUpdateMessageType = \"Pres:DatastoreUpdate\";\ninterface DatastoreUpdateMessage {\n\ttype: typeof datastoreUpdateMessageType;\n\tcontent: {\n\t\tsendTimestamp: number;\n\t\tavgLatency: number;\n\t\tacknowledgementId?: AcknowledgmentId;\n\t\tisComplete?: true;\n\t\tdata: DatastoreMessageContent;\n\t};\n}\n\n/**\n * Outbound datastore update message\n */\nexport type OutboundDatastoreUpdateMessage = OutboundExtensionMessage<DatastoreUpdateMessage>;\n\n/**\n * Inbound and verified datastore update message\n */\nexport type InboundDatastoreUpdateMessage =\n\tVerifiedInboundExtensionMessage<DatastoreUpdateMessage>;\n\n/**\n * Client join message type.\n */\nexport const joinMessageType = \"Pres:ClientJoin\";\ninterface ClientJoinMessage {\n\ttype: typeof joinMessageType;\n\tcontent: {\n\t\tupdateProviders: ClientConnectionId[];\n\t\tsendTimestamp: number;\n\t\tavgLatency: number;\n\t\tdata: DatastoreMessageContent;\n\t};\n}\n\n/**\n * Acknowledgement message type.\n */\nexport const acknowledgementMessageType = \"Pres:Ack\";\n\ninterface AcknowledgementMessage {\n\ttype: typeof acknowledgementMessageType;\n\tcontent: {\n\t\tid: AcknowledgmentId;\n\t};\n}\n\n/**\n * Outbound acknowledgement message.\n */\nexport type OutboundAcknowledgementMessage = OutboundExtensionMessage<AcknowledgementMessage>;\n\n/**\n * Outbound client join message\n */\nexport type OutboundClientJoinMessage = OutboundExtensionMessage<ClientJoinMessage>;\n\n/**\n * Inbound and verified client join message\n */\nexport type InboundClientJoinMessage = VerifiedInboundExtensionMessage<ClientJoinMessage>;\n\n/**\n * Outbound presence message.\n */\nexport type OutboundPresenceMessage =\n\t| OutboundAcknowledgementMessage\n\t| OutboundClientJoinMessage\n\t| OutboundDatastoreUpdateMessage;\n\n/**\n * Messages structures that can be sent and received as understood in the presence protocol\n */\nexport type SignalMessages =\n\t| AcknowledgementMessage\n\t| ClientJoinMessage\n\t| DatastoreUpdateMessage;\n"]}
|
package/lib/stateDatastore.d.ts
CHANGED
|
@@ -5,11 +5,16 @@
|
|
|
5
5
|
import type { ClientConnectionId } from "./baseTypes.js";
|
|
6
6
|
import type { InternalTypes } from "./exposedInternalTypes.js";
|
|
7
7
|
import type { ClientRecord } from "./internalTypes.js";
|
|
8
|
-
import type {
|
|
8
|
+
import type { AttendeeId, PresenceWithNotifications as Presence } from "./presence.js";
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
10
|
+
* Miscellaneous options for local state updates
|
|
11
11
|
*/
|
|
12
12
|
export interface LocalStateUpdateOptions {
|
|
13
|
+
/**
|
|
14
|
+
* When defined, this is the maximum time in milliseconds that this
|
|
15
|
+
* update is allowed to be delayed before it must be sent to service.
|
|
16
|
+
* When `undefined`, the callee may determine maximum delay.
|
|
17
|
+
*/
|
|
13
18
|
allowableUpdateLatencyMs: number | undefined;
|
|
14
19
|
/**
|
|
15
20
|
* Special option allowed for unicast notifications.
|
|
@@ -17,7 +22,8 @@ export interface LocalStateUpdateOptions {
|
|
|
17
22
|
targetClientId?: ClientConnectionId;
|
|
18
23
|
}
|
|
19
24
|
/**
|
|
20
|
-
*
|
|
25
|
+
* Contract for States Workspace to support State Manager access to
|
|
26
|
+
* datastore and general internal presence knowledge.
|
|
21
27
|
*/
|
|
22
28
|
export interface StateDatastore<TKey extends string, TValue extends InternalTypes.ValueDirectoryOrState<any>> {
|
|
23
29
|
readonly presence: Presence;
|
|
@@ -29,18 +35,13 @@ export interface StateDatastore<TKey extends string, TValue extends InternalType
|
|
|
29
35
|
self: AttendeeId | undefined;
|
|
30
36
|
states: ClientRecord<TValue>;
|
|
31
37
|
};
|
|
32
|
-
lookupClient(clientId: ClientConnectionId): Attendee;
|
|
33
38
|
}
|
|
34
39
|
/**
|
|
35
40
|
* Helper to get a handle from a datastore.
|
|
36
|
-
*
|
|
37
|
-
* @internal
|
|
38
41
|
*/
|
|
39
42
|
export declare function handleFromDatastore<TKey extends string, TValue extends InternalTypes.ValueDirectoryOrState<unknown>>(datastore: StateDatastore<TKey, TValue>): InternalTypes.StateDatastoreHandle<TKey, Exclude<TValue, undefined>>;
|
|
40
43
|
/**
|
|
41
44
|
* Helper to get the datastore back from its handle.
|
|
42
|
-
*
|
|
43
|
-
* @internal
|
|
44
45
|
*/
|
|
45
46
|
export declare function datastoreFromHandle<TKey extends string, TValue extends InternalTypes.ValueDirectoryOrState<any>>(handle: InternalTypes.StateDatastoreHandle<TKey, TValue>): StateDatastore<TKey, TValue>;
|
|
46
47
|
//# sourceMappingURL=stateDatastore.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stateDatastore.d.ts","sourceRoot":"","sources":["../src/stateDatastore.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"stateDatastore.d.ts","sourceRoot":"","sources":["../src/stateDatastore.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,EAAE,UAAU,EAAE,yBAAyB,IAAI,QAAQ,EAAE,MAAM,eAAe,CAAC;AAcvF;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACvC;;;;OAIG;IACH,wBAAwB,EAAE,MAAM,GAAG,SAAS,CAAC;IAE7C;;OAEG;IACH,cAAc,CAAC,EAAE,kBAAkB,CAAC;CACpC;AAED;;;GAGG;AACH,MAAM,WAAW,cAAc,CAC9B,IAAI,SAAS,MAAM,EACnB,MAAM,SAAS,aAAa,CAAC,qBAAqB,CAAC,GAAG,CAAC;IAEvD,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,WAAW,CACV,GAAG,EAAE,IAAI,EACT,KAAK,EAAE,MAAM,GAAG;QACf,iBAAiB,CAAC,EAAE,IAAI,CAAC;KACzB,EACD,OAAO,EAAE,uBAAuB,GAC9B,IAAI,CAAC;IACR,MAAM,CAAC,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/D,WAAW,CAAC,GAAG,EAAE,IAAI,GAAG;QACvB,IAAI,EAAE,UAAU,GAAG,SAAS,CAAC;QAC7B,MAAM,EAAE,YAAY,CAAC,MAAM,CAAC,CAAC;KAC7B,CAAC;CACF;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAIlC,IAAI,SAAS,MAAM,EACnB,MAAM,SAAS,aAAa,CAAC,qBAAqB,CAAC,OAAO,CAAC,EAE3D,SAAS,EAAE,cAAc,CAAC,IAAI,EAAE,MAAM,CAAC,GACrC,aAAa,CAAC,oBAAoB,CAAC,IAAI,EAAE,OAAO,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAKtE;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAClC,IAAI,SAAS,MAAM,EACnB,MAAM,SAAS,aAAa,CAAC,qBAAqB,CAAC,GAAG,CAAC,EACtD,MAAM,EAAE,aAAa,CAAC,oBAAoB,CAAC,IAAI,EAAE,MAAM,CAAC,GAAG,cAAc,CAAC,IAAI,EAAE,MAAM,CAAC,CAExF"}
|
package/lib/stateDatastore.js
CHANGED
|
@@ -4,16 +4,12 @@
|
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
6
6
|
* Helper to get a handle from a datastore.
|
|
7
|
-
*
|
|
8
|
-
* @internal
|
|
9
7
|
*/
|
|
10
8
|
export function handleFromDatastore(datastore) {
|
|
11
9
|
return datastore;
|
|
12
10
|
}
|
|
13
11
|
/**
|
|
14
12
|
* Helper to get the datastore back from its handle.
|
|
15
|
-
*
|
|
16
|
-
* @internal
|
|
17
13
|
*/
|
|
18
14
|
export function datastoreFromHandle(handle) {
|
|
19
15
|
return handle;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stateDatastore.js","sourceRoot":"","sources":["../src/stateDatastore.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"stateDatastore.js","sourceRoot":"","sources":["../src/stateDatastore.ts"],"names":[],"mappings":"AAAA;;;GAGG;AA2DH;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAOlC,SAAuC;IAEvC,OAAO,SAGN,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAGjC,MAAwD;IACzD,OAAO,MAAiD,CAAC;AAC1D,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { ClientConnectionId } from \"./baseTypes.js\";\nimport type { InternalTypes } from \"./exposedInternalTypes.js\";\nimport type { ClientRecord } from \"./internalTypes.js\";\nimport type { AttendeeId, PresenceWithNotifications as Presence } from \"./presence.js\";\n\n// type StateDatastoreSchemaNode<\n// \tTValue extends InternalTypes.ValueDirectoryOrState<any> = InternalTypes.ValueDirectoryOrState<unknown>,\n// > = TValue extends InternalTypes.ValueDirectoryOrState<infer T> ? InternalTypes.ValueDirectoryOrState<T> : never;\n\n// export interface StateDatastoreSchema {\n// \t// This type is not precise. It may\n// \t// need to be replaced with StatesWorkspace schema pattern\n// \t// similar to what is commented out.\n// \t[key: string]: InternalTypes.ValueDirectoryOrState<unknown>;\n// \t// [key: string]: StateDatastoreSchemaNode;\n// }\n\n/**\n * Miscellaneous options for local state updates\n */\nexport interface LocalStateUpdateOptions {\n\t/**\n\t * When defined, this is the maximum time in milliseconds that this\n\t * update is allowed to be delayed before it must be sent to service.\n\t * When `undefined`, the callee may determine maximum delay.\n\t */\n\tallowableUpdateLatencyMs: number | undefined;\n\n\t/**\n\t * Special option allowed for unicast notifications.\n\t */\n\ttargetClientId?: ClientConnectionId;\n}\n\n/**\n * Contract for States Workspace to support State Manager access to\n * datastore and general internal presence knowledge.\n */\nexport interface StateDatastore<\n\tTKey extends string,\n\tTValue extends InternalTypes.ValueDirectoryOrState<any>,\n> {\n\treadonly presence: Presence;\n\tlocalUpdate(\n\t\tkey: TKey,\n\t\tvalue: TValue & {\n\t\t\tignoreUnmonitored?: true;\n\t\t},\n\t\toptions: LocalStateUpdateOptions,\n\t): void;\n\tupdate(key: TKey, attendeeId: AttendeeId, value: TValue): void;\n\tknownValues(key: TKey): {\n\t\tself: AttendeeId | undefined;\n\t\tstates: ClientRecord<TValue>;\n\t};\n}\n\n/**\n * Helper to get a handle from a datastore.\n */\nexport function handleFromDatastore<\n\t// Constraining TSchema would be great, but it seems nested types (at least with undefined) cause trouble.\n\t// TSchema as `unknown` still provides some type safety.\n\t// TSchema extends StateDatastoreSchema,\n\tTKey extends string /* & keyof TSchema */,\n\tTValue extends InternalTypes.ValueDirectoryOrState<unknown>,\n>(\n\tdatastore: StateDatastore<TKey, TValue>,\n): InternalTypes.StateDatastoreHandle<TKey, Exclude<TValue, undefined>> {\n\treturn datastore as unknown as InternalTypes.StateDatastoreHandle<\n\t\tTKey,\n\t\tExclude<TValue, undefined>\n\t>;\n}\n\n/**\n * Helper to get the datastore back from its handle.\n */\nexport function datastoreFromHandle<\n\tTKey extends string,\n\tTValue extends InternalTypes.ValueDirectoryOrState<any>,\n>(handle: InternalTypes.StateDatastoreHandle<TKey, TValue>): StateDatastore<TKey, TValue> {\n\treturn handle as unknown as StateDatastore<TKey, TValue>;\n}\n"]}
|
package/lib/systemWorkspace.d.ts
CHANGED
|
@@ -10,17 +10,24 @@ import type { AttendeesEvents, AttendeeId, Presence } from "./presence.js";
|
|
|
10
10
|
import type { PresenceStatesInternal } from "./presenceStates.js";
|
|
11
11
|
import type { AnyWorkspace, StatesWorkspaceSchema } from "./types.js";
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
13
|
+
* `ConnectionValueState` is known value state for `clientToSessionId` data.
|
|
14
14
|
*
|
|
15
|
-
* @
|
|
15
|
+
* @remarks
|
|
16
|
+
* It is {@link InternalTypes.ValueRequiredState} with a known value type.
|
|
17
|
+
*/
|
|
18
|
+
interface ConnectionValueState extends InternalTypes.ValueStateMetadata {
|
|
19
|
+
value: AttendeeId;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The system workspace's datastore structure.
|
|
16
23
|
*/
|
|
17
24
|
export interface SystemWorkspaceDatastore {
|
|
18
25
|
clientToSessionId: {
|
|
19
|
-
[ConnectionId: ClientConnectionId]:
|
|
26
|
+
[ConnectionId: ClientConnectionId]: ConnectionValueState;
|
|
20
27
|
};
|
|
21
28
|
}
|
|
22
29
|
/**
|
|
23
|
-
*
|
|
30
|
+
* Internal workspace that manages metadata for session attendees.
|
|
24
31
|
*/
|
|
25
32
|
export interface SystemWorkspace extends Exclude<Presence["attendees"], never> {
|
|
26
33
|
/**
|
|
@@ -38,8 +45,6 @@ export interface SystemWorkspace extends Exclude<Presence["attendees"], never> {
|
|
|
38
45
|
}
|
|
39
46
|
/**
|
|
40
47
|
* Instantiates the system workspace.
|
|
41
|
-
*
|
|
42
|
-
* @internal
|
|
43
48
|
*/
|
|
44
49
|
export declare function createSystemWorkspace(attendeeId: AttendeeId, datastore: SystemWorkspaceDatastore, events: Listenable<AttendeesEvents> & IEmitter<AttendeesEvents>, audience: IAudience): {
|
|
45
50
|
workspace: SystemWorkspace;
|
|
@@ -48,4 +53,5 @@ export declare function createSystemWorkspace(attendeeId: AttendeeId, datastore:
|
|
|
48
53
|
public: AnyWorkspace<StatesWorkspaceSchema>;
|
|
49
54
|
};
|
|
50
55
|
};
|
|
56
|
+
export {};
|
|
51
57
|
//# sourceMappingURL=systemWorkspace.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"systemWorkspace.d.ts","sourceRoot":"","sources":["../src/systemWorkspace.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uCAAuC,CAAC;AACvE,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AAGrF,OAAO,KAAK,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MAAM,EAAE,UAAU,CAAC,eAAe,CAAC,GAAG,QAAQ,CAAC,eAAe,CAAC,EAC/D,QAAQ,EAAE,SAAS,GACjB;IACF,SAAS,EAAE,eAAe,CAAC;IAC3B,WAAW,EAAE;QACZ,QAAQ,EAAE,sBAAsB,CAAC;QACjC,MAAM,EAAE,YAAY,CAAC,qBAAqB,CAAC,CAAC;KAC5C,CAAC;CACF,CASA"}
|
package/lib/systemWorkspace.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
import { assert } from "@fluidframework/core-utils/internal";
|
|
6
|
+
import { revealOpaqueJson } from "./internalUtils.js";
|
|
6
7
|
import { AttendeeStatus } from "./presence.js";
|
|
7
8
|
import { TimerManager } from "./timerManager.js";
|
|
8
9
|
class SessionClient {
|
|
@@ -55,10 +56,21 @@ class SystemWorkspaceImpl {
|
|
|
55
56
|
ensureContent(_content) {
|
|
56
57
|
throw new Error("Method not implemented.");
|
|
57
58
|
}
|
|
58
|
-
processUpdate(_received, _timeModifier,
|
|
59
|
+
processUpdate(_received, _timeModifier,
|
|
60
|
+
/**
|
|
61
|
+
* Remote datastore typed to match {@link PresenceStatesInternal.processUpdate}'s
|
|
62
|
+
* `ValueUpdateRecord` type that uses {@link InternalTypes.ValueRequiredState}
|
|
63
|
+
* and expects an Opaque JSON type. (We get away with a non-`unknown` value type
|
|
64
|
+
* per TypeScript's method parameter bivariance.) Proper type would be
|
|
65
|
+
* {@link ConnectionValueState} directly.
|
|
66
|
+
* {@link ClientConnectionId} use for index is also a deviation, but conveniently
|
|
67
|
+
* the accurate {@link AttendeeId} type is just a branded string, and
|
|
68
|
+
* {@link ClientConnectionId} is just `string`.
|
|
69
|
+
*/
|
|
70
|
+
remoteDatastore, senderConnectionId) {
|
|
59
71
|
const audienceMembers = this.audience.getMembers();
|
|
60
72
|
const postUpdateActions = [];
|
|
61
|
-
for (const [clientConnectionId, value] of Object.entries(remoteDatastore.clientToSessionId)) {
|
|
73
|
+
for (const [clientConnectionId, value] of Object.entries(revealOpaqueJson(remoteDatastore.clientToSessionId))) {
|
|
62
74
|
const attendeeId = value.value;
|
|
63
75
|
const { attendee, isJoining } = this.ensureAttendee(attendeeId, clientConnectionId,
|
|
64
76
|
/* order */ value.rev,
|
|
@@ -183,8 +195,6 @@ class SystemWorkspaceImpl {
|
|
|
183
195
|
}
|
|
184
196
|
/**
|
|
185
197
|
* Instantiates the system workspace.
|
|
186
|
-
*
|
|
187
|
-
* @internal
|
|
188
198
|
*/
|
|
189
199
|
export function createSystemWorkspace(attendeeId, datastore, events, audience) {
|
|
190
200
|
const workspace = new SystemWorkspaceImpl(attendeeId, datastore, events, audience);
|