@fluidframework/presence 2.10.0 → 2.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/README.md +37 -2
  2. package/dist/alpha.d.ts +1 -1
  3. package/dist/exposedUtilityTypes.d.ts +5 -5
  4. package/dist/exposedUtilityTypes.d.ts.map +1 -1
  5. package/dist/exposedUtilityTypes.js.map +1 -1
  6. package/dist/index.d.ts +1 -1
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js.map +1 -1
  9. package/dist/latestMapValueManager.d.ts +2 -2
  10. package/dist/latestMapValueManager.d.ts.map +1 -1
  11. package/dist/latestMapValueManager.js +2 -2
  12. package/dist/latestMapValueManager.js.map +1 -1
  13. package/dist/latestValueManager.d.ts +2 -2
  14. package/dist/latestValueManager.d.ts.map +1 -1
  15. package/dist/latestValueManager.js +2 -2
  16. package/dist/latestValueManager.js.map +1 -1
  17. package/dist/notificationsManager.d.ts +28 -15
  18. package/dist/notificationsManager.d.ts.map +1 -1
  19. package/dist/notificationsManager.js +3 -5
  20. package/dist/notificationsManager.js.map +1 -1
  21. package/dist/package.json +0 -1
  22. package/dist/presence.d.ts +2 -2
  23. package/dist/presence.d.ts.map +1 -1
  24. package/dist/presence.js.map +1 -1
  25. package/dist/presenceDatastoreManager.d.ts +14 -1
  26. package/dist/presenceDatastoreManager.d.ts.map +1 -1
  27. package/dist/presenceDatastoreManager.js +96 -18
  28. package/dist/presenceDatastoreManager.js.map +1 -1
  29. package/dist/presenceManager.d.ts.map +1 -1
  30. package/dist/presenceManager.js +2 -2
  31. package/dist/presenceManager.js.map +1 -1
  32. package/dist/presenceStates.d.ts +6 -0
  33. package/dist/presenceStates.d.ts.map +1 -1
  34. package/dist/presenceStates.js +7 -1
  35. package/dist/presenceStates.js.map +1 -1
  36. package/dist/systemWorkspace.d.ts +1 -1
  37. package/dist/systemWorkspace.d.ts.map +1 -1
  38. package/dist/systemWorkspace.js.map +1 -1
  39. package/dist/timerManager.d.ts +37 -0
  40. package/dist/timerManager.d.ts.map +1 -0
  41. package/dist/timerManager.js +65 -0
  42. package/dist/timerManager.js.map +1 -0
  43. package/lib/alpha.d.ts +1 -1
  44. package/lib/exposedUtilityTypes.d.ts +5 -5
  45. package/lib/exposedUtilityTypes.d.ts.map +1 -1
  46. package/lib/exposedUtilityTypes.js.map +1 -1
  47. package/lib/index.d.ts +1 -1
  48. package/lib/index.d.ts.map +1 -1
  49. package/lib/index.js.map +1 -1
  50. package/lib/latestMapValueManager.d.ts +2 -2
  51. package/lib/latestMapValueManager.d.ts.map +1 -1
  52. package/lib/latestMapValueManager.js +1 -1
  53. package/lib/latestMapValueManager.js.map +1 -1
  54. package/lib/latestValueManager.d.ts +2 -2
  55. package/lib/latestValueManager.d.ts.map +1 -1
  56. package/lib/latestValueManager.js +1 -1
  57. package/lib/latestValueManager.js.map +1 -1
  58. package/lib/notificationsManager.d.ts +28 -15
  59. package/lib/notificationsManager.d.ts.map +1 -1
  60. package/lib/notificationsManager.js +2 -4
  61. package/lib/notificationsManager.js.map +1 -1
  62. package/lib/presence.d.ts +2 -2
  63. package/lib/presence.d.ts.map +1 -1
  64. package/lib/presence.js.map +1 -1
  65. package/lib/presenceDatastoreManager.d.ts +14 -1
  66. package/lib/presenceDatastoreManager.d.ts.map +1 -1
  67. package/lib/presenceDatastoreManager.js +97 -19
  68. package/lib/presenceDatastoreManager.js.map +1 -1
  69. package/lib/presenceManager.d.ts.map +1 -1
  70. package/lib/presenceManager.js +1 -1
  71. package/lib/presenceManager.js.map +1 -1
  72. package/lib/presenceStates.d.ts +6 -0
  73. package/lib/presenceStates.d.ts.map +1 -1
  74. package/lib/presenceStates.js +6 -1
  75. package/lib/presenceStates.js.map +1 -1
  76. package/lib/systemWorkspace.d.ts +1 -1
  77. package/lib/systemWorkspace.d.ts.map +1 -1
  78. package/lib/systemWorkspace.js.map +1 -1
  79. package/lib/timerManager.d.ts +37 -0
  80. package/lib/timerManager.d.ts.map +1 -0
  81. package/lib/timerManager.js +61 -0
  82. package/lib/timerManager.js.map +1 -0
  83. package/package.json +21 -25
  84. package/dist/events/events.d.ts +0 -198
  85. package/dist/events/events.d.ts.map +0 -1
  86. package/dist/events/events.js +0 -157
  87. package/dist/events/events.js.map +0 -1
  88. package/lib/events/events.d.ts +0 -198
  89. package/lib/events/events.d.ts.map +0 -1
  90. package/lib/events/events.js +0 -152
  91. package/lib/events/events.js.map +0 -1
@@ -2,11 +2,11 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
+ import type { Listenable } from "@fluidframework/core-interfaces";
5
6
  import type { BroadcastControls, BroadcastControlSettings } from "./broadcastControls.js";
6
7
  import type { LatestValueClientData, LatestValueData } from "./latestValueTypes.js";
7
8
  import type { ISessionClient } from "./presence.js";
8
9
  import type { JsonDeserialized, JsonSerializable } from "@fluidframework/presence/internal/core-interfaces";
9
- import type { ISubscribable } from "@fluidframework/presence/internal/events";
10
10
  import type { InternalTypes } from "@fluidframework/presence/internal/exposedInternalTypes";
11
11
  import type { InternalUtilityTypes } from "@fluidframework/presence/internal/exposedUtilityTypes";
12
12
  /**
@@ -34,7 +34,7 @@ export interface LatestValueManager<T> {
34
34
  /**
35
35
  * Events for Latest value manager.
36
36
  */
37
- readonly events: ISubscribable<LatestValueManagerEvents<T>>;
37
+ readonly events: Listenable<LatestValueManagerEvents<T>>;
38
38
  /**
39
39
  * Controls for management of sending updates.
40
40
  */
@@ -1 +1 @@
1
- {"version":3,"file":"latestValueManager.d.ts","sourceRoot":"","sources":["../src/latestValueManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAI1F,OAAO,KAAK,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACpF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,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AAC,CAAC,GAAG,gBAAgB,CAAC,CAAC,CAAC,EAAE;IAE5D;;OAEG;IACH,YAAY,IAAI,gBAAgB,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC,CAAC;IAC3D;;OAEG;IACH,OAAO,IAAI,cAAc,EAAE,CAAC;IAC5B;;OAEG;IACH,WAAW,CAAC,MAAM,EAAE,cAAc,GAAG,eAAe,CAAC,CAAC,CAAC,CAAC;CACxD;AAoFD;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,CAAC,SAAS,MAAM,EAAE,GAAG,SAAS,MAAM,GAAG,MAAM,EACnE,YAAY,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAAG,gBAAgB,CAAC,CAAC,CAAC,GAAG,MAAM,EAChE,QAAQ,CAAC,EAAE,wBAAwB,GACjC,aAAa,CAAC,cAAc,CAC9B,GAAG,EACH,aAAa,CAAC,kBAAkB,CAAC,CAAC,CAAC,EACnC,kBAAkB,CAAC,CAAC,CAAC,CACrB,CAwBA"}
@@ -2,11 +2,11 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
+ import { createEmitter } from "@fluid-internal/client-utils";
5
6
  import { OptionalBroadcastControl } from "./broadcastControls.js";
6
7
  import { brandedObjectEntries } from "./internalTypes.js";
7
8
  import { datastoreFromHandle } from "./stateDatastore.js";
8
9
  import { brandIVM } from "./valueManager.js";
9
- import { createEmitter } from "@fluidframework/presence/internal/events";
10
10
  class LatestValueManagerImpl {
11
11
  constructor(key, datastore, value, controlSettings) {
12
12
  this.key = key;
@@ -1 +1 @@
1
- {"version":3,"file":"latestValueManager.js","sourceRoot":"","sources":["../src/latestValueManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAElE,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAG1D,OAAO,EAAE,mBAAmB,EAAuB,MA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n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { BroadcastControls, BroadcastControlSettings } from \"./broadcastControls.js\";\nimport { OptionalBroadcastControl } from \"./broadcastControls.js\";\nimport type { ValueManager } from \"./internalTypes.js\";\nimport { brandedObjectEntries } from \"./internalTypes.js\";\nimport type { LatestValueClientData, LatestValueData } from \"./latestValueTypes.js\";\nimport type { ISessionClient } from \"./presence.js\";\nimport { datastoreFromHandle, type StateDatastore } from \"./stateDatastore.js\";\nimport { brandIVM } from \"./valueManager.js\";\n\nimport type {\n\tJsonDeserialized,\n\tJsonSerializable,\n} from \"@fluidframework/presence/internal/core-interfaces\";\nimport type { ISubscribable } from \"@fluidframework/presence/internal/events\";\nimport { createEmitter } from \"@fluidframework/presence/internal/events\";\nimport type { InternalTypes } from \"@fluidframework/presence/internal/exposedInternalTypes\";\nimport type { InternalUtilityTypes } from \"@fluidframework/presence/internal/exposedUtilityTypes\";\n\n/**\n * @sealed\n * @alpha\n */\nexport interface LatestValueManagerEvents<T> {\n\t/**\n\t * Raised when remote client's value is updated, which may be the same value.\n\t *\n\t * @eventProperty\n\t */\n\tupdated: (update: LatestValueClientData<T>) => void;\n}\n\n/**\n * Value manager that provides the latest known value from this client to others and read access to their values.\n * All participant clients must provide a value.\n *\n * @remarks Create using {@link Latest} registered to {@link PresenceStates}.\n *\n * @sealed\n * @alpha\n */\nexport interface LatestValueManager<T> {\n\t/**\n\t * Events for Latest value manager.\n\t */\n\treadonly events: ISubscribable<LatestValueManagerEvents<T>>;\n\n\t/**\n\t * Controls for management of sending updates.\n\t */\n\treadonly controls: BroadcastControls;\n\n\t/**\n\t * Current state for this client.\n\t * State for this client that will be transmitted to all other connected clients.\n\t * @remarks Manager assumes ownership of the value and its references. Make a deep clone before\n\t * setting, if needed. No comparison is done to detect changes; all sets are transmitted.\n\t */\n\tget local(): InternalUtilityTypes.FullyReadonly<JsonDeserialized<T>>;\n\tset local(value: JsonSerializable<T> & JsonDeserialized<T>);\n\n\t/**\n\t * Iterable access to remote clients' values.\n\t */\n\tclientValues(): IterableIterator<LatestValueClientData<T>>;\n\t/**\n\t * Array of known clients.\n\t */\n\tclients(): ISessionClient[];\n\t/**\n\t * Access to a specific client's value.\n\t */\n\tclientValue(client: ISessionClient): LatestValueData<T>;\n}\n\nclass LatestValueManagerImpl<T, Key extends string>\n\timplements\n\t\tLatestValueManager<T>,\n\t\tRequired<ValueManager<T, InternalTypes.ValueRequiredState<T>>>\n{\n\tpublic readonly events = createEmitter<LatestValueManagerEvents<T>>();\n\tpublic readonly controls: OptionalBroadcastControl;\n\n\tpublic constructor(\n\t\tprivate readonly key: Key,\n\t\tprivate readonly datastore: StateDatastore<Key, InternalTypes.ValueRequiredState<T>>,\n\t\tpublic readonly value: InternalTypes.ValueRequiredState<T>,\n\t\tcontrolSettings: BroadcastControlSettings | undefined,\n\t) {\n\t\tthis.controls = new OptionalBroadcastControl(controlSettings);\n\t}\n\n\tpublic get local(): InternalUtilityTypes.FullyReadonly<JsonDeserialized<T>> {\n\t\treturn this.value.value;\n\t}\n\n\tpublic set local(value: JsonSerializable<T> & JsonDeserialized<T>) {\n\t\tthis.value.rev += 1;\n\t\tthis.value.timestamp = Date.now();\n\t\tthis.value.value = value;\n\t\tthis.datastore.localUpdate(this.key, this.value, {\n\t\t\tallowableUpdateLatencyMs: this.controls.allowableUpdateLatencyMs,\n\t\t});\n\t}\n\n\tpublic *clientValues(): IterableIterator<LatestValueClientData<T>> {\n\t\tconst allKnownStates = this.datastore.knownValues(this.key);\n\t\tfor (const [clientSessionId, value] of brandedObjectEntries(allKnownStates.states)) {\n\t\t\tif (clientSessionId !== allKnownStates.self) {\n\t\t\t\tyield {\n\t\t\t\t\tclient: this.datastore.lookupClient(clientSessionId),\n\t\t\t\t\tvalue: value.value,\n\t\t\t\t\tmetadata: { revision: value.rev, timestamp: value.timestamp },\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic clients(): ISessionClient[] {\n\t\tconst allKnownStates = this.datastore.knownValues(this.key);\n\t\treturn Object.keys(allKnownStates.states)\n\t\t\t.filter((clientSessionId) => clientSessionId !== allKnownStates.self)\n\t\t\t.map((clientSessionId) => this.datastore.lookupClient(clientSessionId));\n\t}\n\n\tpublic clientValue(client: ISessionClient): LatestValueData<T> {\n\t\tconst allKnownStates = this.datastore.knownValues(this.key);\n\t\tconst clientSessionId = client.sessionId;\n\t\tif (clientSessionId in allKnownStates.states) {\n\t\t\tconst { value, rev: revision } = allKnownStates.states[clientSessionId];\n\t\t\treturn { value, metadata: { revision, timestamp: Date.now() } };\n\t\t}\n\t\tthrow new Error(\"No entry for clientId\");\n\t}\n\n\tpublic update(\n\t\tclient: ISessionClient,\n\t\t_received: number,\n\t\tvalue: InternalTypes.ValueRequiredState<T>,\n\t): void {\n\t\tconst allKnownStates = this.datastore.knownValues(this.key);\n\t\tconst clientSessionId = client.sessionId;\n\t\tif (clientSessionId in allKnownStates.states) {\n\t\t\tconst currentState = allKnownStates.states[clientSessionId];\n\t\t\tif (currentState.rev >= value.rev) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tthis.datastore.update(this.key, clientSessionId, value);\n\t\tthis.events.emit(\"updated\", {\n\t\t\tclient,\n\t\t\tvalue: value.value,\n\t\t\tmetadata: { revision: value.rev, timestamp: value.timestamp },\n\t\t});\n\t}\n}\n\n/**\n * Factory for creating a {@link LatestValueManager}.\n *\n * @alpha\n */\nexport function Latest<T extends object, Key extends string = string>(\n\tinitialValue: JsonSerializable<T> & JsonDeserialized<T> & object,\n\tcontrols?: BroadcastControlSettings,\n): InternalTypes.ManagerFactory<\n\tKey,\n\tInternalTypes.ValueRequiredState<T>,\n\tLatestValueManager<T>\n> {\n\t// LatestValueManager takes ownership of initialValue but makes a shallow\n\t// copy for basic protection.\n\tconst value: InternalTypes.ValueRequiredState<T> = {\n\t\trev: 0,\n\t\ttimestamp: Date.now(),\n\t\tvalue: { ...initialValue },\n\t};\n\tconst factory = (\n\t\tkey: Key,\n\t\tdatastoreHandle: InternalTypes.StateDatastoreHandle<\n\t\t\tKey,\n\t\t\tInternalTypes.ValueRequiredState<T>\n\t\t>,\n\t): {\n\t\tinitialData: { value: typeof value; allowableUpdateLatencyMs: number | undefined };\n\t\tmanager: InternalTypes.StateValue<LatestValueManager<T>>;\n\t} => ({\n\t\tinitialData: { value, allowableUpdateLatencyMs: controls?.allowableUpdateLatencyMs },\n\t\tmanager: brandIVM<LatestValueManagerImpl<T, Key>, T, InternalTypes.ValueRequiredState<T>>(\n\t\t\tnew LatestValueManagerImpl(key, datastoreFromHandle(datastoreHandle), value, controls),\n\t\t),\n\t});\n\treturn Object.assign(factory, { instanceBase: LatestValueManagerImpl });\n}\n"]}
1
+ {"version":3,"file":"latestValueManager.js","sourceRoot":"","sources":["../src/latestValueManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAI7D,OAAO,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAElE,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAG1D,OAAO,EAAE,mBAAmB,EAAuB,MAAM,qBAAqB,CAAC;AAC/E,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAiE7C,MAAM,sBAAsB;IAQ3B,YACkB,GAAQ,EACR,SAAmE,EACpE,KAA0C,EAC1D,eAAqD;QAHpC,QAAG,GAAH,GAAG,CAAK;QACR,cAAS,GAAT,SAAS,CAA0D;QACpE,UAAK,GAAL,KAAK,CAAqC;QAN3C,WAAM,GAAG,aAAa,EAA+B,CAAC;QASrE,IAAI,CAAC,QAAQ,GAAG,IAAI,wBAAwB,CAAC,eAAe,CAAC,CAAC;IAC/D,CAAC;IAED,IAAW,KAAK;QACf,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC;IACzB,CAAC;IAED,IAAW,KAAK,CAAC,KAAgD;QAChE,IAAI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S,EAAE;SAC7D,CAAC,CAAC;IACJ,CAAC;CACD;AAED;;;;GAIG;AACH,MAAM,UAAU,MAAM,CACrB,YAAgE,EAChE,QAAmC;IAMnC,yEAAyE;IACzE,6BAA6B;IAC7B,MAAM,KAAK,GAAwC;QAClD,GAAG,EAAE,CAAC;QACN,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;QACrB,KAAK,EAAE,EAAE,GAAG,YAAY,EAAE;KAC1B,CAAC;IACF,MAAM,OAAO,GAAG,CACf,GAAQ,EACR,eAGC,EAIA,EAAE,CAAC,CAAC;QACL,WAAW,EAAE,EAAE,KAAK,EAAE,wBAAwB,EAAE,QAAQ,EAAE,wBAAwB,EAAE;QACpF,OAAO,EAAE,QAAQ,CAChB,IAAI,sBAAsB,CAAC,GAAG,EAAE,mBAAmB,CAAC,eAAe,CAAC,EAAE,KAAK,EAAE,QAAQ,CAAC,CACtF;KACD,CAAC,CAAC;IACH,OAAO,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,YAAY,EAAE,sBAAsB,EAAE,CAAC,CAAC;AACzE,CAAC","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 { Listenable } from \"@fluidframework/core-interfaces\";\n\nimport type { BroadcastControls, BroadcastControlSettings } from \"./broadcastControls.js\";\nimport { OptionalBroadcastControl } from \"./broadcastControls.js\";\nimport type { ValueManager } from \"./internalTypes.js\";\nimport { brandedObjectEntries } from \"./internalTypes.js\";\nimport type { LatestValueClientData, LatestValueData } from \"./latestValueTypes.js\";\nimport type { ISessionClient } from \"./presence.js\";\nimport { datastoreFromHandle, type StateDatastore } from \"./stateDatastore.js\";\nimport { brandIVM } from \"./valueManager.js\";\n\nimport type {\n\tJsonDeserialized,\n\tJsonSerializable,\n} from \"@fluidframework/presence/internal/core-interfaces\";\nimport type { InternalTypes } from \"@fluidframework/presence/internal/exposedInternalTypes\";\nimport type { InternalUtilityTypes } from \"@fluidframework/presence/internal/exposedUtilityTypes\";\n\n/**\n * @sealed\n * @alpha\n */\nexport interface LatestValueManagerEvents<T> {\n\t/**\n\t * Raised when remote client's value is updated, which may be the same value.\n\t *\n\t * @eventProperty\n\t */\n\tupdated: (update: LatestValueClientData<T>) => void;\n}\n\n/**\n * Value manager that provides the latest known value from this client to others and read access to their values.\n * All participant clients must provide a value.\n *\n * @remarks Create using {@link Latest} registered to {@link PresenceStates}.\n *\n * @sealed\n * @alpha\n */\nexport interface LatestValueManager<T> {\n\t/**\n\t * Events for Latest value manager.\n\t */\n\treadonly events: Listenable<LatestValueManagerEvents<T>>;\n\n\t/**\n\t * Controls for management of sending updates.\n\t */\n\treadonly controls: BroadcastControls;\n\n\t/**\n\t * Current state for this client.\n\t * State for this client that will be transmitted to all other connected clients.\n\t * @remarks Manager assumes ownership of the value and its references. Make a deep clone before\n\t * setting, if needed. No comparison is done to detect changes; all sets are transmitted.\n\t */\n\tget local(): InternalUtilityTypes.FullyReadonly<JsonDeserialized<T>>;\n\tset local(value: JsonSerializable<T> & JsonDeserialized<T>);\n\n\t/**\n\t * Iterable access to remote clients' values.\n\t */\n\tclientValues(): IterableIterator<LatestValueClientData<T>>;\n\t/**\n\t * Array of known clients.\n\t */\n\tclients(): ISessionClient[];\n\t/**\n\t * Access to a specific client's value.\n\t */\n\tclientValue(client: ISessionClient): LatestValueData<T>;\n}\n\nclass LatestValueManagerImpl<T, Key extends string>\n\timplements\n\t\tLatestValueManager<T>,\n\t\tRequired<ValueManager<T, InternalTypes.ValueRequiredState<T>>>\n{\n\tpublic readonly events = createEmitter<LatestValueManagerEvents<T>>();\n\tpublic readonly controls: OptionalBroadcastControl;\n\n\tpublic constructor(\n\t\tprivate readonly key: Key,\n\t\tprivate readonly datastore: StateDatastore<Key, InternalTypes.ValueRequiredState<T>>,\n\t\tpublic readonly value: InternalTypes.ValueRequiredState<T>,\n\t\tcontrolSettings: BroadcastControlSettings | undefined,\n\t) {\n\t\tthis.controls = new OptionalBroadcastControl(controlSettings);\n\t}\n\n\tpublic get local(): InternalUtilityTypes.FullyReadonly<JsonDeserialized<T>> {\n\t\treturn this.value.value;\n\t}\n\n\tpublic set local(value: JsonSerializable<T> & JsonDeserialized<T>) {\n\t\tthis.value.rev += 1;\n\t\tthis.value.timestamp = Date.now();\n\t\tthis.value.value = value;\n\t\tthis.datastore.localUpdate(this.key, this.value, {\n\t\t\tallowableUpdateLatencyMs: this.controls.allowableUpdateLatencyMs,\n\t\t});\n\t}\n\n\tpublic *clientValues(): IterableIterator<LatestValueClientData<T>> {\n\t\tconst allKnownStates = this.datastore.knownValues(this.key);\n\t\tfor (const [clientSessionId, value] of brandedObjectEntries(allKnownStates.states)) {\n\t\t\tif (clientSessionId !== allKnownStates.self) {\n\t\t\t\tyield {\n\t\t\t\t\tclient: this.datastore.lookupClient(clientSessionId),\n\t\t\t\t\tvalue: value.value,\n\t\t\t\t\tmetadata: { revision: value.rev, timestamp: value.timestamp },\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic clients(): ISessionClient[] {\n\t\tconst allKnownStates = this.datastore.knownValues(this.key);\n\t\treturn Object.keys(allKnownStates.states)\n\t\t\t.filter((clientSessionId) => clientSessionId !== allKnownStates.self)\n\t\t\t.map((clientSessionId) => this.datastore.lookupClient(clientSessionId));\n\t}\n\n\tpublic clientValue(client: ISessionClient): LatestValueData<T> {\n\t\tconst allKnownStates = this.datastore.knownValues(this.key);\n\t\tconst clientSessionId = client.sessionId;\n\t\tif (clientSessionId in allKnownStates.states) {\n\t\t\tconst { value, rev: revision } = allKnownStates.states[clientSessionId];\n\t\t\treturn { value, metadata: { revision, timestamp: Date.now() } };\n\t\t}\n\t\tthrow new Error(\"No entry for clientId\");\n\t}\n\n\tpublic update(\n\t\tclient: ISessionClient,\n\t\t_received: number,\n\t\tvalue: InternalTypes.ValueRequiredState<T>,\n\t): void {\n\t\tconst allKnownStates = this.datastore.knownValues(this.key);\n\t\tconst clientSessionId = client.sessionId;\n\t\tif (clientSessionId in allKnownStates.states) {\n\t\t\tconst currentState = allKnownStates.states[clientSessionId];\n\t\t\tif (currentState.rev >= value.rev) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tthis.datastore.update(this.key, clientSessionId, value);\n\t\tthis.events.emit(\"updated\", {\n\t\t\tclient,\n\t\t\tvalue: value.value,\n\t\t\tmetadata: { revision: value.rev, timestamp: value.timestamp },\n\t\t});\n\t}\n}\n\n/**\n * Factory for creating a {@link LatestValueManager}.\n *\n * @alpha\n */\nexport function Latest<T extends object, Key extends string = string>(\n\tinitialValue: JsonSerializable<T> & JsonDeserialized<T> & object,\n\tcontrols?: BroadcastControlSettings,\n): InternalTypes.ManagerFactory<\n\tKey,\n\tInternalTypes.ValueRequiredState<T>,\n\tLatestValueManager<T>\n> {\n\t// LatestValueManager takes ownership of initialValue but makes a shallow\n\t// copy for basic protection.\n\tconst value: InternalTypes.ValueRequiredState<T> = {\n\t\trev: 0,\n\t\ttimestamp: Date.now(),\n\t\tvalue: { ...initialValue },\n\t};\n\tconst factory = (\n\t\tkey: Key,\n\t\tdatastoreHandle: InternalTypes.StateDatastoreHandle<\n\t\t\tKey,\n\t\t\tInternalTypes.ValueRequiredState<T>\n\t\t>,\n\t): {\n\t\tinitialData: { value: typeof value; allowableUpdateLatencyMs: number | undefined };\n\t\tmanager: InternalTypes.StateValue<LatestValueManager<T>>;\n\t} => ({\n\t\tinitialData: { value, allowableUpdateLatencyMs: controls?.allowableUpdateLatencyMs },\n\t\tmanager: brandIVM<LatestValueManagerImpl<T, Key>, T, InternalTypes.ValueRequiredState<T>>(\n\t\t\tnew LatestValueManagerImpl(key, datastoreFromHandle(datastoreHandle), value, controls),\n\t\t),\n\t});\n\treturn Object.assign(factory, { instanceBase: LatestValueManagerImpl });\n}\n"]}
@@ -2,8 +2,8 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
+ import type { Listenable, Off } from "@fluidframework/core-interfaces";
5
6
  import type { ISessionClient } from "./presence.js";
6
- import type { ISubscribable } from "@fluidframework/presence/internal/events";
7
7
  import type { InternalTypes } from "@fluidframework/presence/internal/exposedInternalTypes";
8
8
  import type { InternalUtilityTypes } from "@fluidframework/presence/internal/exposedUtilityTypes";
9
9
  /**
@@ -25,15 +25,28 @@ export interface NotificationsManagerEvents {
25
25
  * @sealed
26
26
  * @alpha
27
27
  */
28
- export interface NotificationSubscribable<E extends InternalUtilityTypes.NotificationEvents<E>> {
28
+ export interface NotificationListenable<TListeners extends InternalUtilityTypes.NotificationListeners<TListeners>> {
29
29
  /**
30
30
  * Register a notification listener.
31
31
  * @param notificationName - the name of the notification
32
- * @param listener - the handler to run when the notification is received from other client
33
- * @returns a function which will deregister the listener when run. This function
34
- * has undefined behavior if called more than once.
32
+ * @param listener - The listener function to run when the notification is fired.
33
+ * @returns A {@link @fluidframework/core-interfaces#Off | function} which will deregister the listener when called.
34
+ * Calling the deregistration function more than once will have no effect.
35
+ *
36
+ * Listeners may also be deregistered by passing the listener to {@link NotificationListenable.off | off()}.
37
+ * @remarks Registering the exact same `listener` object for the same notification more than once will throw an error.
38
+ * If registering the same listener for the same notification multiple times is desired, consider using a wrapper function for the second subscription.
39
+ */
40
+ on<K extends keyof InternalUtilityTypes.NotificationListeners<TListeners>>(notificationName: K, listener: (sender: ISessionClient, ...args: InternalUtilityTypes.JsonDeserializedParameters<TListeners[K]>) => void): Off;
41
+ /**
42
+ * Deregister notification listener.
43
+ * @param notificationName - The name of the notification.
44
+ * @param listener - The listener function to remove from the current set of notification listeners.
45
+ * @remarks If `listener` is not currently registered, this method will have no effect.
46
+ *
47
+ * Listeners may also be deregistered by calling the {@link @fluidframework/core-interfaces#Off | deregistration function} returned when they are {@link NotificationListenable.on | registered}.
35
48
  */
36
- on<K extends keyof InternalUtilityTypes.NotificationEvents<E>>(notificationName: K, listener: (sender: ISessionClient, ...args: InternalUtilityTypes.JsonDeserializedParameters<E[K]>) => void): () => void;
49
+ off<K extends keyof InternalUtilityTypes.NotificationListeners<TListeners>>(notificationName: K, listener: (sender: ISessionClient, ...args: InternalUtilityTypes.JsonDeserializedParameters<TListeners[K]>) => void): void;
37
50
  }
38
51
  /**
39
52
  * Record of notification subscriptions.
@@ -41,8 +54,8 @@ export interface NotificationSubscribable<E extends InternalUtilityTypes.Notific
41
54
  * @sealed
42
55
  * @alpha
43
56
  */
44
- export type NotificationSubscriptions<E extends InternalUtilityTypes.NotificationEvents<E>> = {
45
- [K in string & keyof InternalUtilityTypes.NotificationEvents<E>]: (sender: ISessionClient, ...args: InternalUtilityTypes.JsonDeserializedParameters<E[K]>) => void;
57
+ export type NotificationSubscriptions<E extends InternalUtilityTypes.NotificationListeners<E>> = {
58
+ [K in string & keyof InternalUtilityTypes.NotificationListeners<E>]: (sender: ISessionClient, ...args: InternalUtilityTypes.JsonDeserializedParameters<E[K]>) => void;
46
59
  };
47
60
  /**
48
61
  * Interface for a notification emitter that can send typed notification to other clients.
@@ -50,20 +63,20 @@ export type NotificationSubscriptions<E extends InternalUtilityTypes.Notificatio
50
63
  * @sealed
51
64
  * @alpha
52
65
  */
53
- export interface NotificationEmitter<E extends InternalUtilityTypes.NotificationEvents<E>> {
66
+ export interface NotificationEmitter<E extends InternalUtilityTypes.NotificationListeners<E>> {
54
67
  /**
55
68
  * Emits a notification with the specified name and arguments, notifying all clients.
56
69
  * @param notificationName - the name of the notification to fire
57
70
  * @param args - the arguments sent with the notification
58
71
  */
59
- broadcast<K extends string & keyof InternalUtilityTypes.NotificationEvents<E>>(notificationName: K, ...args: Parameters<E[K]>): void;
72
+ broadcast<K extends string & keyof InternalUtilityTypes.NotificationListeners<E>>(notificationName: K, ...args: Parameters<E[K]>): void;
60
73
  /**
61
74
  * Emits a notification with the specified name and arguments, notifying a single client.
62
75
  * @param notificationName - the name of the notification to fire
63
76
  * @param targetClient - the single client to notify
64
77
  * @param args - the arguments sent with the notification
65
78
  */
66
- unicast<K extends string & keyof InternalUtilityTypes.NotificationEvents<E>>(notificationName: K, targetClient: ISessionClient, ...args: Parameters<E[K]>): void;
79
+ unicast<K extends string & keyof InternalUtilityTypes.NotificationListeners<E>>(notificationName: K, targetClient: ISessionClient, ...args: Parameters<E[K]>): void;
67
80
  }
68
81
  /**
69
82
  * Value manager that provides notifications from this client to others and subscription
@@ -74,11 +87,11 @@ export interface NotificationEmitter<E extends InternalUtilityTypes.Notification
74
87
  * @sealed
75
88
  * @alpha
76
89
  */
77
- export interface NotificationsManager<T extends InternalUtilityTypes.NotificationEvents<T>> {
90
+ export interface NotificationsManager<T extends InternalUtilityTypes.NotificationListeners<T>> {
78
91
  /**
79
92
  * Events for Notifications manager.
80
93
  */
81
- readonly events: ISubscribable<NotificationsManagerEvents>;
94
+ readonly events: Listenable<NotificationsManagerEvents>;
82
95
  /**
83
96
  * Send notifications to other clients.
84
97
  */
@@ -86,7 +99,7 @@ export interface NotificationsManager<T extends InternalUtilityTypes.Notificatio
86
99
  /**
87
100
  * Provides subscription to notifications from other clients.
88
101
  */
89
- readonly notifications: NotificationSubscribable<T>;
102
+ readonly notifications: NotificationListenable<T>;
90
103
  }
91
104
  /**
92
105
  * Factory for creating a {@link NotificationsManager}.
@@ -97,5 +110,5 @@ export interface NotificationsManager<T extends InternalUtilityTypes.Notificatio
97
110
  *
98
111
  * @alpha
99
112
  */
100
- export declare function Notifications<T extends InternalUtilityTypes.NotificationEvents<T>, Key extends string = string>(initialSubscriptions: Partial<NotificationSubscriptions<T>>): InternalTypes.ManagerFactory<Key, InternalTypes.ValueRequiredState<InternalTypes.NotificationType>, NotificationsManager<T>>;
113
+ export declare function Notifications<T extends InternalUtilityTypes.NotificationListeners<T>, Key extends string = string>(initialSubscriptions: Partial<NotificationSubscriptions<T>>): InternalTypes.ManagerFactory<Key, InternalTypes.ValueRequiredState<InternalTypes.NotificationType>, NotificationsManager<T>>;
101
114
  //# sourceMappingURL=notificationsManager.d.ts.map
@@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AS,oBAAoB,CAAC,qBAAqB,CAAC,CAAC,CAAC,EACvD,GAAG,SAAS,MAAM,GAAG,MAAM,EAE3B,oBAAoB,EAAE,OAAO,CAAC,yBAAyB,CAAC,CAAC,CAAC,CAAC,GACzD,aAAa,CAAC,cAAc,CAC9B,GAAG,EACH,aAAa,CAAC,kBAAkB,CAAC,aAAa,CAAC,gBAAgB,CAAC,EAChE,oBAAoB,CAAC,CAAC,CAAC,CACvB,CAuBA"}
@@ -2,9 +2,9 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
+ import { createEmitter } from "@fluid-internal/client-utils";
5
6
  import { datastoreFromHandle } from "./stateDatastore.js";
6
7
  import { brandIVM } from "./valueManager.js";
7
- import { createEmitter } from "@fluidframework/presence/internal/events";
8
8
  /**
9
9
  * Object.keys retyped to support specific records keys and
10
10
  * branded string-based keys.
@@ -38,9 +38,7 @@ class NotificationsManagerImpl {
38
38
  },
39
39
  };
40
40
  // Workaround for types
41
- this.notificationsInternal =
42
- // @ts-expect-error TODO
43
- createEmitter();
41
+ this.notificationsInternal = createEmitter();
44
42
  // @ts-expect-error TODO
45
43
  this.notifications = this.notificationsInternal;
46
44
  // Add event listeners provided at instantiation
@@ -1 +1 @@
1
- {"version":3,"file":"notificationsManager.js","sourceRoot":"","sources":["../src/notificationsManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,mBAAmB,EAAuB,MAAM,qBAAqB,CAAC;AAC/E,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAI7C,OAAO,EAAE,aAAa,EAAE,MAAM,0CAA0C,CAAC;AAoHzE;;;GAGG;AACH,MAAM,UAAU,GAAG,MAAM,CAAC,IAAiE,CAAC;AAE5F,MAAM,wBAAwB;IAiD7B,YACkB,GAAQ,EACR,SAGhB,EACD,oBAA2D;QAL1C,QAAG,GAAH,GAAG,CAAK;QACR,cAAS,GAAT,SAAS,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;YAC9E,yEAAyE;YACzE,8CAA8C;YAC9C,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;gBACzB,IAAI,CAAC,qBAAqB,CAAC,EAAE,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;YAC5C,CAAC;QACF,CAAC;IACF,CAAC;IAEM,MAAM,CACZ,MAAsB,EACtB,SAAiB,EACjB,KAAuE;QAEvE,MAAM,SAAS,GAAG,KAAK,CAAC,KAAK,CAAC,IAAkD,CAAC;QACjF,IAAI,IAAI,CAAC,qBAAqB,CAAC,YAAY,CAAC,SAAS,CAAC,EAAE,CAAC;YACxD,+EAA+E;YAC/E,oGAAoG;YACpG,MAAM,IAAI,GAAG,CAAC,MAAM,EAAE,GAAG,KAAK,CAAC,KAAK,CAAC,IAAI,CAExC,CAAC;YACF,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,SAAS,EAAE,GAAG,IAAI,CAAC,CAAC;QACrD,CAAC;aAAM,CAAC;YACP,IAAI,CAAC,MAAM,CAAC,IAAI,CACf,wBAAwB,EACxB,KAAK,CAAC,KAAK,CAAC,IAAI,EAChB,MAAM,EACN,GAAG,KAAK,CAAC,KAAK,CAAC,IAAI,CACnB,CAAC;QACH,CAAC;IACF,CAAC;CACD;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,aAAa,CAI5B,oBAA2D;IAM3D,MAAM,OAAO,GAAG,CACf,GAAQ,EACR,eAGC,EAGA,EAAE,CAAC,CAAC;QACL,OAAO,EAAE,QAAQ,CAKhB,IAAI,wBAAwB,CAC3B,GAAG,EACH,mBAAmB,CAAC,eAAe,CAAC,EACpC,oBAAoB,CACpB,CACD;KACD,CAAC,CAAC;IACH,OAAO,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,YAAY,EAAE,wBAAwB,EAAE,CAAC,CAAC;AAC3E,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { ValueManager } from \"./internalTypes.js\";\nimport type { ISessionClient } from \"./presence.js\";\nimport { datastoreFromHandle, type StateDatastore } from \"./stateDatastore.js\";\nimport { brandIVM } from \"./valueManager.js\";\n\nimport type { JsonTypeWith } from \"@fluidframework/presence/internal/core-interfaces\";\nimport type { Events, ISubscribable } from \"@fluidframework/presence/internal/events\";\nimport { createEmitter } from \"@fluidframework/presence/internal/events\";\nimport type { InternalTypes } from \"@fluidframework/presence/internal/exposedInternalTypes\";\nimport type { InternalUtilityTypes } from \"@fluidframework/presence/internal/exposedUtilityTypes\";\n\n/**\n * @sealed\n * @alpha\n */\nexport interface NotificationsManagerEvents {\n\t/**\n\t * Raised when notification is received, but no subscribers were found.\n\t *\n\t * @eventProperty\n\t */\n\tunattendedNotification: (\n\t\tname: string,\n\t\tsender: ISessionClient,\n\t\t...content: unknown[]\n\t) => void;\n}\n\n/**\n * An object which allows the registration of listeners so that subscribers can be\n * notified when a notification happens.\n *\n * @sealed\n * @alpha\n */\nexport interface NotificationSubscribable<\n\tE extends InternalUtilityTypes.NotificationEvents<E>,\n> {\n\t/**\n\t * Register a notification listener.\n\t * @param notificationName - the name of the notification\n\t * @param listener - the handler to run when the notification is received from other client\n\t * @returns a function which will deregister the listener when run. This function\n\t * has undefined behavior if called more than once.\n\t */\n\ton<K extends keyof InternalUtilityTypes.NotificationEvents<E>>(\n\t\tnotificationName: K,\n\t\tlistener: (\n\t\t\tsender: ISessionClient,\n\t\t\t...args: InternalUtilityTypes.JsonDeserializedParameters<E[K]>\n\t\t) => void,\n\t): () => void;\n}\n\n/**\n * Record of notification subscriptions.\n *\n * @sealed\n * @alpha\n */\nexport type NotificationSubscriptions<E extends InternalUtilityTypes.NotificationEvents<E>> = {\n\t[K in string & keyof InternalUtilityTypes.NotificationEvents<E>]: (\n\t\tsender: ISessionClient,\n\t\t...args: InternalUtilityTypes.JsonDeserializedParameters<E[K]>\n\t) => void;\n};\n\n/**\n * Interface for a notification emitter that can send typed notification to other clients.\n *\n * @sealed\n * @alpha\n */\nexport interface NotificationEmitter<E extends InternalUtilityTypes.NotificationEvents<E>> {\n\t/**\n\t * Emits a notification with the specified name and arguments, notifying all clients.\n\t * @param notificationName - the name of the notification to fire\n\t * @param args - the arguments sent with the notification\n\t */\n\tbroadcast<K extends string & keyof InternalUtilityTypes.NotificationEvents<E>>(\n\t\tnotificationName: K,\n\t\t...args: Parameters<E[K]>\n\t): void;\n\n\t/**\n\t * Emits a notification with the specified name and arguments, notifying a single client.\n\t * @param notificationName - the name of the notification to fire\n\t * @param targetClient - the single client to notify\n\t * @param args - the arguments sent with the notification\n\t */\n\tunicast<K extends string & keyof InternalUtilityTypes.NotificationEvents<E>>(\n\t\tnotificationName: K,\n\t\ttargetClient: ISessionClient,\n\t\t...args: Parameters<E[K]>\n\t): void;\n}\n\n/**\n * Value manager that provides notifications from this client to others and subscription\n * to their notifications.\n *\n * @remarks Create using {@link Notifications} registered to {@link PresenceStates}.\n *\n * @sealed\n * @alpha\n */\nexport interface NotificationsManager<T extends InternalUtilityTypes.NotificationEvents<T>> {\n\t/**\n\t * Events for Notifications manager.\n\t */\n\treadonly events: ISubscribable<NotificationsManagerEvents>;\n\n\t/**\n\t * Send notifications to other clients.\n\t */\n\treadonly emit: NotificationEmitter<T>;\n\n\t/**\n\t * Provides subscription to notifications from other clients.\n\t */\n\treadonly notifications: NotificationSubscribable<T>;\n}\n\n/**\n * Object.keys retyped to support specific records keys and\n * branded string-based keys.\n */\nconst recordKeys = Object.keys as <K extends string>(o: Partial<Record<K, unknown>>) => K[];\n\nclass NotificationsManagerImpl<\n\tT extends InternalUtilityTypes.NotificationEvents<T>,\n\tKey extends string,\n> implements\n\t\tNotificationsManager<T>,\n\t\tValueManager<\n\t\t\tInternalTypes.NotificationType,\n\t\t\tInternalTypes.ValueRequiredState<InternalTypes.NotificationType>\n\t\t>\n{\n\tpublic readonly events = createEmitter<NotificationsManagerEvents>();\n\n\tpublic readonly emit: NotificationEmitter<T> = {\n\t\tbroadcast: (name, ...args) => {\n\t\t\tthis.datastore.localUpdate(\n\t\t\t\tthis.key,\n\t\t\t\t{\n\t\t\t\t\trev: 0,\n\t\t\t\t\ttimestamp: 0,\n\t\t\t\t\tvalue: { name, args: [...(args as JsonTypeWith<never>[])] },\n\t\t\t\t\tignoreUnmonitored: true,\n\t\t\t\t},\n\t\t\t\t// This is a notification, so we want to send it immediately.\n\t\t\t\t{ allowableUpdateLatencyMs: 0 },\n\t\t\t);\n\t\t},\n\t\tunicast: (name, targetClient, ...args) => {\n\t\t\tthis.datastore.localUpdate(\n\t\t\t\tthis.key,\n\t\t\t\t{\n\t\t\t\t\trev: 0,\n\t\t\t\t\ttimestamp: 0,\n\t\t\t\t\tvalue: { name, args: [...(args as JsonTypeWith<never>[])] },\n\t\t\t\t\tignoreUnmonitored: true,\n\t\t\t\t},\n\t\t\t\t// This is a notification, so we want to send it immediately.\n\t\t\t\t{ allowableUpdateLatencyMs: 0, targetClientId: targetClient.getConnectionId() },\n\t\t\t);\n\t\t},\n\t};\n\n\t// Workaround for types\n\tprivate readonly notificationsInternal =\n\t\t// @ts-expect-error TODO\n\t\tcreateEmitter<NotificationSubscriptions<T>>();\n\n\t// @ts-expect-error TODO\n\tpublic readonly notifications: NotificationSubscribable<T> = this.notificationsInternal;\n\n\tpublic constructor(\n\t\tprivate readonly key: Key,\n\t\tprivate readonly datastore: StateDatastore<\n\t\t\tKey,\n\t\t\tInternalTypes.ValueRequiredState<InternalTypes.NotificationType>\n\t\t>,\n\t\tinitialSubscriptions: Partial<NotificationSubscriptions<T>>,\n\t) {\n\t\t// Add event listeners provided at instantiation\n\t\tfor (const subscriptionName of recordKeys(initialSubscriptions)) {\n\t\t\t// Lingering Event typing issues with Notifications specialization requires\n\t\t\t// this cast. The only thing that really matters is that name is a string.\n\t\t\tconst name = subscriptionName as keyof Events<NotificationSubscriptions<T>>;\n\t\t\tconst value = initialSubscriptions[subscriptionName];\n\t\t\t// This check should not be needed while using exactOptionalPropertyTypes, but\n\t\t\t// typescript appears to ignore that with Partial<>. Good to be defensive\n\t\t\t// against callers sending `undefined` anyway.\n\t\t\tif (value !== undefined) {\n\t\t\t\tthis.notificationsInternal.on(name, value);\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic update(\n\t\tclient: ISessionClient,\n\t\t_received: number,\n\t\tvalue: InternalTypes.ValueRequiredState<InternalTypes.NotificationType>,\n\t): void {\n\t\tconst eventName = value.value.name as keyof Events<NotificationSubscriptions<T>>;\n\t\tif (this.notificationsInternal.hasListeners(eventName)) {\n\t\t\t// Without schema validation, we don't know that the args are the correct type.\n\t\t\t// For now we assume the user is sending the correct types and there is no corruption along the way.\n\t\t\tconst args = [client, ...value.value.args] as Parameters<\n\t\t\t\tNotificationSubscriptions<T>[typeof eventName]\n\t\t\t>;\n\t\t\tthis.notificationsInternal.emit(eventName, ...args);\n\t\t} else {\n\t\t\tthis.events.emit(\n\t\t\t\t\"unattendedNotification\",\n\t\t\t\tvalue.value.name,\n\t\t\t\tclient,\n\t\t\t\t...value.value.args,\n\t\t\t);\n\t\t}\n\t}\n}\n\n/**\n * Factory for creating a {@link NotificationsManager}.\n *\n * @remarks\n * Typescript inference for `Notifications` is not working correctly yet.\n * Explicitly specify generics to make result types usable.\n *\n * @alpha\n */\nexport function Notifications<\n\tT extends InternalUtilityTypes.NotificationEvents<T>,\n\tKey extends string = string,\n>(\n\tinitialSubscriptions: Partial<NotificationSubscriptions<T>>,\n): InternalTypes.ManagerFactory<\n\tKey,\n\tInternalTypes.ValueRequiredState<InternalTypes.NotificationType>,\n\tNotificationsManager<T>\n> {\n\tconst factory = (\n\t\tkey: Key,\n\t\tdatastoreHandle: InternalTypes.StateDatastoreHandle<\n\t\t\tKey,\n\t\t\tInternalTypes.ValueRequiredState<InternalTypes.NotificationType>\n\t\t>,\n\t): {\n\t\tmanager: InternalTypes.StateValue<NotificationsManager<T>>;\n\t} => ({\n\t\tmanager: brandIVM<\n\t\t\tNotificationsManagerImpl<T, Key>,\n\t\t\tInternalTypes.NotificationType,\n\t\t\tInternalTypes.ValueRequiredState<InternalTypes.NotificationType>\n\t\t>(\n\t\t\tnew NotificationsManagerImpl(\n\t\t\t\tkey,\n\t\t\t\tdatastoreFromHandle(datastoreHandle),\n\t\t\t\tinitialSubscriptions,\n\t\t\t),\n\t\t),\n\t});\n\treturn Object.assign(factory, { instanceBase: NotificationsManagerImpl });\n}\n"]}
1
+ {"version":3,"file":"notificationsManager.js","sourceRoot":"","sources":["../src/notificationsManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAK7D,OAAO,EAAE,mBAAmB,EAAuB,MAAM,qBAAqB,CAAC;AAC/E,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AA8I7C;;;GAGG;AACH,MAAM,UAAU,GAAG,MAAM,CAAC,IAAiE,CAAC;AAE5F,MAAM,wBAAwB;IA+C7B,YACkB,GAAQ,EACR,SAGhB,EACD,oBAA2D;QAL1C,QAAG,GAAH,GAAG,CAAK;QACR,cAAS,GAAT,SAAS,CAGzB;QA1Cc,WAAM,GAAG,aAAa,EAA8B,CAAC;QAErD,SAAI,GAA2B;YAC9C,SAAS,EAAE,CAAC,IAAI,EAAE,GAAG,IAAI,EAAE,EAAE;gBAC5B,IAAI,CAAC,SAAS,CAAC,WAAW,CACzB,IAAI,CAAC,GAAG,EACR;oBACC,GAAG,EAAE,CAAC;oBACN,SAAS,EAAE,CAAC;oBACZ,KAAK,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,GAAI,IAA8B,CAAC,EAAE;oBAC3D,iBAAiB,EAAE,IAAI;iBACvB;gBACD,6DAA6D;gBAC7D,EAAE,wBAAwB,EAAE,CAAC,EAAE,CAC/B,CAAC;YACH,CAAC;YACD,OAAO,EAAE,CAAC,IAAI,EAAE,YAAY,EAAE,GAAG,IAAI,EAAE,EAAE;gBACxC,IAAI,CAAC,SAAS,CAAC,WAAW,CACzB,IAAI,CAAC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,CAAC;aAAM,CAAC;YACP,IAAI,CAAC,MAAM,CAAC,IAAI,CACf,wBAAwB,EACxB,KAAK,CAAC,KAAK,CAAC,IAAI,EAChB,MAAM,EACN,GAAG,KAAK,CAAC,KAAK,CAAC,IAAI,CACnB,CAAC;QACH,CAAC;IACF,CAAC;CACD;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,aAAa,CAI5B,oBAA2D;IAM3D,MAAM,OAAO,GAAG,CACf,GAAQ,EACR,eAGC,EAGA,EAAE,CAAC,CAAC;QACL,OAAO,EAAE,QAAQ,CAKhB,IAAI,wBAAwB,CAC3B,GAAG,EACH,mBAAmB,CAAC,eAAe,CAAC,EACpC,oBAAoB,CACpB,CACD;KACD,CAAC,CAAC;IACH,OAAO,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,YAAY,EAAE,wBAAwB,EAAE,CAAC,CAAC;AAC3E,CAAC","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 { Listeners, Listenable, Off } from \"@fluidframework/core-interfaces\";\n\nimport type { ValueManager } from \"./internalTypes.js\";\nimport type { ISessionClient } from \"./presence.js\";\nimport { datastoreFromHandle, type StateDatastore } from \"./stateDatastore.js\";\nimport { brandIVM } from \"./valueManager.js\";\n\nimport type { JsonTypeWith } from \"@fluidframework/presence/internal/core-interfaces\";\nimport type { InternalTypes } from \"@fluidframework/presence/internal/exposedInternalTypes\";\nimport type { InternalUtilityTypes } from \"@fluidframework/presence/internal/exposedUtilityTypes\";\n\n/**\n * @sealed\n * @alpha\n */\nexport interface NotificationsManagerEvents {\n\t/**\n\t * Raised when notification is received, but no subscribers were found.\n\t *\n\t * @eventProperty\n\t */\n\tunattendedNotification: (\n\t\tname: string,\n\t\tsender: ISessionClient,\n\t\t...content: unknown[]\n\t) => void;\n}\n\n/**\n * An object which allows the registration of listeners so that subscribers can be\n * notified when a notification happens.\n *\n * @sealed\n * @alpha\n */\nexport interface NotificationListenable<\n\tTListeners extends InternalUtilityTypes.NotificationListeners<TListeners>,\n> {\n\t/**\n\t * Register a notification listener.\n\t * @param notificationName - the name of the notification\n\t * @param listener - The listener function to run when the notification is fired.\n\t * @returns A {@link @fluidframework/core-interfaces#Off | function} which will deregister the listener when called.\n\t * Calling the deregistration function more than once will have no effect.\n\t *\n\t * Listeners may also be deregistered by passing the listener to {@link NotificationListenable.off | off()}.\n\t * @remarks Registering the exact same `listener` object for the same notification more than once will throw an error.\n\t * If registering the same listener for the same notification multiple times is desired, consider using a wrapper function for the second subscription.\n\t */\n\ton<K extends keyof InternalUtilityTypes.NotificationListeners<TListeners>>(\n\t\tnotificationName: K,\n\t\tlistener: (\n\t\t\tsender: ISessionClient,\n\t\t\t...args: InternalUtilityTypes.JsonDeserializedParameters<TListeners[K]>\n\t\t) => void,\n\t): Off;\n\n\t/**\n\t * Deregister notification listener.\n\t * @param notificationName - The name of the notification.\n\t * @param listener - The listener function to remove from the current set of notification listeners.\n\t * @remarks If `listener` is not currently registered, this method will have no effect.\n\t *\n\t * Listeners may also be deregistered by calling the {@link @fluidframework/core-interfaces#Off | deregistration function} returned when they are {@link NotificationListenable.on | registered}.\n\t */\n\toff<K extends keyof InternalUtilityTypes.NotificationListeners<TListeners>>(\n\t\tnotificationName: K,\n\t\tlistener: (\n\t\t\tsender: ISessionClient,\n\t\t\t...args: InternalUtilityTypes.JsonDeserializedParameters<TListeners[K]>\n\t\t) => void,\n\t): void;\n}\n\n/**\n * Record of notification subscriptions.\n *\n * @sealed\n * @alpha\n */\nexport type NotificationSubscriptions<\n\tE extends InternalUtilityTypes.NotificationListeners<E>,\n> = {\n\t[K in string & keyof InternalUtilityTypes.NotificationListeners<E>]: (\n\t\tsender: ISessionClient,\n\t\t...args: InternalUtilityTypes.JsonDeserializedParameters<E[K]>\n\t) => void;\n};\n\n/**\n * Interface for a notification emitter that can send typed notification to other clients.\n *\n * @sealed\n * @alpha\n */\nexport interface NotificationEmitter<E extends InternalUtilityTypes.NotificationListeners<E>> {\n\t/**\n\t * Emits a notification with the specified name and arguments, notifying all clients.\n\t * @param notificationName - the name of the notification to fire\n\t * @param args - the arguments sent with the notification\n\t */\n\tbroadcast<K extends string & keyof InternalUtilityTypes.NotificationListeners<E>>(\n\t\tnotificationName: K,\n\t\t...args: Parameters<E[K]>\n\t): void;\n\n\t/**\n\t * Emits a notification with the specified name and arguments, notifying a single client.\n\t * @param notificationName - the name of the notification to fire\n\t * @param targetClient - the single client to notify\n\t * @param args - the arguments sent with the notification\n\t */\n\tunicast<K extends string & keyof InternalUtilityTypes.NotificationListeners<E>>(\n\t\tnotificationName: K,\n\t\ttargetClient: ISessionClient,\n\t\t...args: Parameters<E[K]>\n\t): void;\n}\n\n/**\n * Value manager that provides notifications from this client to others and subscription\n * to their notifications.\n *\n * @remarks Create using {@link Notifications} registered to {@link PresenceStates}.\n *\n * @sealed\n * @alpha\n */\nexport interface NotificationsManager<\n\tT extends InternalUtilityTypes.NotificationListeners<T>,\n> {\n\t/**\n\t * Events for Notifications manager.\n\t */\n\treadonly events: Listenable<NotificationsManagerEvents>;\n\n\t/**\n\t * Send notifications to other clients.\n\t */\n\treadonly emit: NotificationEmitter<T>;\n\n\t/**\n\t * Provides subscription to notifications from other clients.\n\t */\n\treadonly notifications: NotificationListenable<T>;\n}\n\n/**\n * Object.keys retyped to support specific records keys and\n * branded string-based keys.\n */\nconst recordKeys = Object.keys as <K extends string>(o: Partial<Record<K, unknown>>) => K[];\n\nclass NotificationsManagerImpl<\n\tT extends InternalUtilityTypes.NotificationListeners<T>,\n\tKey extends string,\n> implements\n\t\tNotificationsManager<T>,\n\t\tValueManager<\n\t\t\tInternalTypes.NotificationType,\n\t\t\tInternalTypes.ValueRequiredState<InternalTypes.NotificationType>\n\t\t>\n{\n\tpublic readonly events = createEmitter<NotificationsManagerEvents>();\n\n\tpublic readonly emit: NotificationEmitter<T> = {\n\t\tbroadcast: (name, ...args) => {\n\t\t\tthis.datastore.localUpdate(\n\t\t\t\tthis.key,\n\t\t\t\t{\n\t\t\t\t\trev: 0,\n\t\t\t\t\ttimestamp: 0,\n\t\t\t\t\tvalue: { name, args: [...(args as JsonTypeWith<never>[])] },\n\t\t\t\t\tignoreUnmonitored: true,\n\t\t\t\t},\n\t\t\t\t// This is a notification, so we want to send it immediately.\n\t\t\t\t{ allowableUpdateLatencyMs: 0 },\n\t\t\t);\n\t\t},\n\t\tunicast: (name, targetClient, ...args) => {\n\t\t\tthis.datastore.localUpdate(\n\t\t\t\tthis.key,\n\t\t\t\t{\n\t\t\t\t\trev: 0,\n\t\t\t\t\ttimestamp: 0,\n\t\t\t\t\tvalue: { name, args: [...(args as JsonTypeWith<never>[])] },\n\t\t\t\t\tignoreUnmonitored: true,\n\t\t\t\t},\n\t\t\t\t// This is a notification, so we want to send it immediately.\n\t\t\t\t{ allowableUpdateLatencyMs: 0, targetClientId: targetClient.getConnectionId() },\n\t\t\t);\n\t\t},\n\t};\n\n\t// Workaround for types\n\tprivate readonly notificationsInternal = createEmitter<NotificationSubscriptions<T>>();\n\n\t// @ts-expect-error TODO\n\tpublic readonly notifications: NotificationListenable<T> = this.notificationsInternal;\n\n\tpublic constructor(\n\t\tprivate readonly key: Key,\n\t\tprivate readonly datastore: StateDatastore<\n\t\t\tKey,\n\t\t\tInternalTypes.ValueRequiredState<InternalTypes.NotificationType>\n\t\t>,\n\t\tinitialSubscriptions: Partial<NotificationSubscriptions<T>>,\n\t) {\n\t\t// Add event listeners provided at instantiation\n\t\tfor (const subscriptionName of recordKeys(initialSubscriptions)) {\n\t\t\t// Lingering Event typing issues with Notifications specialization requires\n\t\t\t// this cast. The only thing that really matters is that name is a string.\n\t\t\tconst name = subscriptionName as keyof Listeners<NotificationSubscriptions<T>>;\n\t\t\tconst value = initialSubscriptions[subscriptionName];\n\t\t\t// This check should not be needed while using exactOptionalPropertyTypes, but\n\t\t\t// typescript appears to ignore that with Partial<>. Good to be defensive\n\t\t\t// against callers sending `undefined` anyway.\n\t\t\tif (value !== undefined) {\n\t\t\t\tthis.notificationsInternal.on(name, value);\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic update(\n\t\tclient: ISessionClient,\n\t\t_received: number,\n\t\tvalue: InternalTypes.ValueRequiredState<InternalTypes.NotificationType>,\n\t): void {\n\t\tconst eventName = value.value.name as keyof Listeners<NotificationSubscriptions<T>>;\n\t\tif (this.notificationsInternal.hasListeners(eventName)) {\n\t\t\t// Without schema validation, we don't know that the args are the correct type.\n\t\t\t// For now we assume the user is sending the correct types and there is no corruption along the way.\n\t\t\tconst args = [client, ...value.value.args] as Parameters<\n\t\t\t\tNotificationSubscriptions<T>[typeof eventName]\n\t\t\t>;\n\t\t\tthis.notificationsInternal.emit(eventName, ...args);\n\t\t} else {\n\t\t\tthis.events.emit(\n\t\t\t\t\"unattendedNotification\",\n\t\t\t\tvalue.value.name,\n\t\t\t\tclient,\n\t\t\t\t...value.value.args,\n\t\t\t);\n\t\t}\n\t}\n}\n\n/**\n * Factory for creating a {@link NotificationsManager}.\n *\n * @remarks\n * Typescript inference for `Notifications` is not working correctly yet.\n * Explicitly specify generics to make result types usable.\n *\n * @alpha\n */\nexport function Notifications<\n\tT extends InternalUtilityTypes.NotificationListeners<T>,\n\tKey extends string = string,\n>(\n\tinitialSubscriptions: Partial<NotificationSubscriptions<T>>,\n): InternalTypes.ManagerFactory<\n\tKey,\n\tInternalTypes.ValueRequiredState<InternalTypes.NotificationType>,\n\tNotificationsManager<T>\n> {\n\tconst factory = (\n\t\tkey: Key,\n\t\tdatastoreHandle: InternalTypes.StateDatastoreHandle<\n\t\t\tKey,\n\t\t\tInternalTypes.ValueRequiredState<InternalTypes.NotificationType>\n\t\t>,\n\t): {\n\t\tmanager: InternalTypes.StateValue<NotificationsManager<T>>;\n\t} => ({\n\t\tmanager: brandIVM<\n\t\t\tNotificationsManagerImpl<T, Key>,\n\t\t\tInternalTypes.NotificationType,\n\t\t\tInternalTypes.ValueRequiredState<InternalTypes.NotificationType>\n\t\t>(\n\t\t\tnew NotificationsManagerImpl(\n\t\t\t\tkey,\n\t\t\t\tdatastoreFromHandle(datastoreHandle),\n\t\t\t\tinitialSubscriptions,\n\t\t\t),\n\t\t),\n\t});\n\treturn Object.assign(factory, { instanceBase: NotificationsManagerImpl });\n}\n"]}
package/lib/presence.d.ts CHANGED
@@ -2,11 +2,11 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
+ import type { Listenable } from "@fluidframework/core-interfaces";
5
6
  import type { SessionId } from "@fluidframework/id-compressor";
6
7
  import type { ClientConnectionId } from "./baseTypes.js";
7
8
  import type { BroadcastControlSettings } from "./broadcastControls.js";
8
9
  import type { PresenceNotifications, PresenceNotificationsSchema, PresenceStates, PresenceStatesSchema, PresenceWorkspaceAddress } from "./types.js";
9
- import type { ISubscribable } from "@fluidframework/presence/internal/events";
10
10
  /**
11
11
  * A Fluid client session identifier.
12
12
  *
@@ -140,7 +140,7 @@ export interface IPresence {
140
140
  /**
141
141
  * Events for Notifications manager.
142
142
  */
143
- readonly events: ISubscribable<PresenceEvents>;
143
+ readonly events: Listenable<PresenceEvents>;
144
144
  /**
145
145
  * Get all attendees in the session.
146
146
  *
@@ -1 +1 @@
1
- {"version":3,"file":"presence.d.ts","sourceRoot":"","sources":["../src/presence.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAE/D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AACvE,OAAO,KAAK,EACX,qBAAqB,EACrB,2BAA2B,EAC3B,cAAc,EACd,oBAAoB,EACpB,wBAAwB,EACxB,MAAM,YAAY,CAAC;AAEpB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0CAA0C,CAAC;AAE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E,wBAAwB,GACjC,cAAc,CAAC,YAAY,CAAC,CAAC;IAEhC;;;;;;OAMG;IACH,gBAAgB,CAAC,mBAAmB,SAAS,2BAA2B,EACvE,eAAe,EAAE,wBAAwB,EACzC,gBAAgB,EAAE,mBAAmB,GACnC,qBAAqB,CAAC,mBAAmB,CAAC,CAAC;CAC9C"}
@@ -1 +1 @@
1
- {"version":3,"file":"presence.js","sourceRoot":"","sources":["../src/presence.ts"],"names":[],"mappings":"AAAA;;;GAGG;AA8BH;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG;IAClC;;OAEG;IACH,SAAS,EAAE,WAAW;IAEtB;;OAEG;IACH,YAAY,EAAE,cAAc;CACnB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { SessionId } from \"@fluidframework/id-compressor\";\n\nimport type { ClientConnectionId } from \"./baseTypes.js\";\nimport type { BroadcastControlSettings } from \"./broadcastControls.js\";\nimport type {\n\tPresenceNotifications,\n\tPresenceNotificationsSchema,\n\tPresenceStates,\n\tPresenceStatesSchema,\n\tPresenceWorkspaceAddress,\n} from \"./types.js\";\n\nimport type { ISubscribable } from \"@fluidframework/presence/internal/events\";\n\n/**\n * A Fluid client session identifier.\n *\n * @remarks\n * Each client once connected to a session is given a unique identifier for the\n * duration of the session. If a client disconnects and reconnects, it will\n * retain its identifier. Prefer use of {@link ISessionClient} as a way to\n * identify clients in a session. {@link ISessionClient.sessionId} will provide\n * the session ID.\n *\n * @alpha\n */\nexport type ClientSessionId = SessionId & { readonly ClientSessionId: \"ClientSessionId\" };\n\n/**\n * The connection status of the {@link ISessionClient}.\n *\n * @alpha\n */\nexport const SessionClientStatus = {\n\t/**\n\t * The session client is connected to the Fluid service.\n\t */\n\tConnected: \"Connected\",\n\n\t/**\n\t * The session client is not connected to the Fluid service.\n\t */\n\tDisconnected: \"Disconnected\",\n} as const;\n\n/**\n * Represents the connection status of an {@link ISessionClient}.\n *\n * This type can be either `'Connected'` or `'Disconnected'`, indicating whether\n * the session client is currently connected to the Fluid service.\n *\n * When `'Disconnected'`:\n * - State changes are kept locally and communicated to others upon reconnect.\n * - Notification requests are discarded (silently).\n *\n * @alpha\n */\nexport type SessionClientStatus =\n\t(typeof SessionClientStatus)[keyof typeof SessionClientStatus];\n\n/**\n * A client within a Fluid session (period of container connectivity to service).\n *\n * @remarks\n * Note: This is very preliminary session client representation.\n *\n * `ISessionClient` should be used as key to distinguish between different\n * clients as they join, rejoin, and disconnect from a session. While a\n * client's {@link ClientConnectionId} from {@link ISessionClient.getConnectionStatus}\n * may change over time, `ISessionClient` will be fixed.\n *\n * @privateRemarks\n * As this is evolved, pay attention to how this relates to Audience, Service\n * Audience, and Quorum representations of clients and users.\n *\n * @sealed\n * @alpha\n */\nexport interface ISessionClient<\n\tSpecificSessionClientId extends ClientSessionId = ClientSessionId,\n> {\n\t/**\n\t * The session ID of the client that is stable over all connections.\n\t */\n\treadonly sessionId: SpecificSessionClientId;\n\n\t/**\n\t * Get current client connection ID.\n\t *\n\t * @returns Current client connection ID.\n\t *\n\t * @remarks\n\t * Connection ID will change on reconnect.\n\t *\n\t * If {@link ISessionClient.getConnectionStatus} is {@link (SessionClientStatus:variable).Disconnected}, this will represent the last known connection ID.\n\t */\n\tgetConnectionId(): ClientConnectionId;\n\n\t/**\n\t * Get connection status of session client.\n\t *\n\t * @returns Connection status of session client.\n\t *\n\t */\n\tgetConnectionStatus(): SessionClientStatus;\n}\n\n/**\n * Utility type limiting to a specific session client. (A session client with\n * a specific session ID - not just any session ID.)\n *\n * @internal\n */\nexport type SpecificSessionClient<SpecificSessionClientId extends ClientSessionId> =\n\tstring extends SpecificSessionClientId ? never : ISessionClient<SpecificSessionClientId>;\n\n/**\n * @sealed\n * @alpha\n */\nexport interface PresenceEvents {\n\t/**\n\t * Raised when new client joins session.\n\t *\n\t * @eventProperty\n\t */\n\tattendeeJoined: (attendee: ISessionClient) => void;\n\n\t/**\n\t * Raised when client appears disconnected from session.\n\t *\n\t * @eventProperty\n\t */\n\tattendeeDisconnected: (attendee: ISessionClient) => void;\n\n\t/**\n\t * Raised when a workspace is activated within the session.\n\t *\n\t * \"Activated\" means that a workspace is being used by a client and this\n\t * client is seeing information for the first time.\n\t *\n\t * @remarks\n\t * Local workspaces may be passively acquired/registered when this event\n\t * is raised. For a notifications workspace, that lazy registration must\n\t * be done before the event handler returns to ensure no notifications\n\t * are missed.\n\t */\n\tworkspaceActivated: (\n\t\tworkspaceAddress: PresenceWorkspaceAddress,\n\t\ttype: \"States\" | \"Notifications\" | \"Unknown\",\n\t) => void;\n}\n\n/**\n * Presence represents known clients within a session and their custom states and notifications.\n *\n * @sealed\n * @alpha\n */\nexport interface IPresence {\n\t/**\n\t * Events for Notifications manager.\n\t */\n\treadonly events: ISubscribable<PresenceEvents>;\n\n\t/**\n\t * Get all attendees in the session.\n\t *\n\t * @remarks\n\t * Attendee states are dynamic and will change as clients join and leave\n\t * the session.\n\t */\n\tgetAttendees(): ReadonlySet<ISessionClient>;\n\n\t/**\n\t * Lookup a specific attendee in the session.\n\t *\n\t * @param clientId - Client connection or session ID\n\t */\n\tgetAttendee(clientId: ClientConnectionId | ClientSessionId): ISessionClient;\n\n\t/**\n\t * Get this client's session client.\n\t *\n\t * @returns This client's session client.\n\t */\n\tgetMyself(): ISessionClient;\n\n\t/**\n\t * Acquires a PresenceStates workspace from store or adds new one.\n\t *\n\t * @param workspaceAddress - Address of the requested PresenceStates Workspace\n\t * @param requestedContent - Requested states for the workspace\n\t * @param controls - Optional settings for default broadcast controls\n\t * @returns A PresenceStates workspace\n\t */\n\tgetStates<StatesSchema extends PresenceStatesSchema>(\n\t\tworkspaceAddress: PresenceWorkspaceAddress,\n\t\trequestedContent: StatesSchema,\n\t\tcontrols?: BroadcastControlSettings,\n\t): PresenceStates<StatesSchema>;\n\n\t/**\n\t * Acquires a Notifications workspace from store or adds new one.\n\t *\n\t * @param workspaceAddress - Address of the requested Notifications Workspace\n\t * @param requestedContent - Requested notifications for the workspace\n\t * @returns A Notifications workspace\n\t */\n\tgetNotifications<NotificationsSchema extends PresenceNotificationsSchema>(\n\t\tnotificationsId: PresenceWorkspaceAddress,\n\t\trequestedContent: NotificationsSchema,\n\t): PresenceNotifications<NotificationsSchema>;\n}\n"]}
1
+ {"version":3,"file":"presence.js","sourceRoot":"","sources":["../src/presence.ts"],"names":[],"mappings":"AAAA;;;GAGG;AA6BH;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG;IAClC;;OAEG;IACH,SAAS,EAAE,WAAW;IAEtB;;OAEG;IACH,YAAY,EAAE,cAAc;CACnB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { Listenable } from \"@fluidframework/core-interfaces\";\nimport type { SessionId } from \"@fluidframework/id-compressor\";\n\nimport type { ClientConnectionId } from \"./baseTypes.js\";\nimport type { BroadcastControlSettings } from \"./broadcastControls.js\";\nimport type {\n\tPresenceNotifications,\n\tPresenceNotificationsSchema,\n\tPresenceStates,\n\tPresenceStatesSchema,\n\tPresenceWorkspaceAddress,\n} from \"./types.js\";\n\n/**\n * A Fluid client session identifier.\n *\n * @remarks\n * Each client once connected to a session is given a unique identifier for the\n * duration of the session. If a client disconnects and reconnects, it will\n * retain its identifier. Prefer use of {@link ISessionClient} as a way to\n * identify clients in a session. {@link ISessionClient.sessionId} will provide\n * the session ID.\n *\n * @alpha\n */\nexport type ClientSessionId = SessionId & { readonly ClientSessionId: \"ClientSessionId\" };\n\n/**\n * The connection status of the {@link ISessionClient}.\n *\n * @alpha\n */\nexport const SessionClientStatus = {\n\t/**\n\t * The session client is connected to the Fluid service.\n\t */\n\tConnected: \"Connected\",\n\n\t/**\n\t * The session client is not connected to the Fluid service.\n\t */\n\tDisconnected: \"Disconnected\",\n} as const;\n\n/**\n * Represents the connection status of an {@link ISessionClient}.\n *\n * This type can be either `'Connected'` or `'Disconnected'`, indicating whether\n * the session client is currently connected to the Fluid service.\n *\n * When `'Disconnected'`:\n * - State changes are kept locally and communicated to others upon reconnect.\n * - Notification requests are discarded (silently).\n *\n * @alpha\n */\nexport type SessionClientStatus =\n\t(typeof SessionClientStatus)[keyof typeof SessionClientStatus];\n\n/**\n * A client within a Fluid session (period of container connectivity to service).\n *\n * @remarks\n * Note: This is very preliminary session client representation.\n *\n * `ISessionClient` should be used as key to distinguish between different\n * clients as they join, rejoin, and disconnect from a session. While a\n * client's {@link ClientConnectionId} from {@link ISessionClient.getConnectionStatus}\n * may change over time, `ISessionClient` will be fixed.\n *\n * @privateRemarks\n * As this is evolved, pay attention to how this relates to Audience, Service\n * Audience, and Quorum representations of clients and users.\n *\n * @sealed\n * @alpha\n */\nexport interface ISessionClient<\n\tSpecificSessionClientId extends ClientSessionId = ClientSessionId,\n> {\n\t/**\n\t * The session ID of the client that is stable over all connections.\n\t */\n\treadonly sessionId: SpecificSessionClientId;\n\n\t/**\n\t * Get current client connection ID.\n\t *\n\t * @returns Current client connection ID.\n\t *\n\t * @remarks\n\t * Connection ID will change on reconnect.\n\t *\n\t * If {@link ISessionClient.getConnectionStatus} is {@link (SessionClientStatus:variable).Disconnected}, this will represent the last known connection ID.\n\t */\n\tgetConnectionId(): ClientConnectionId;\n\n\t/**\n\t * Get connection status of session client.\n\t *\n\t * @returns Connection status of session client.\n\t *\n\t */\n\tgetConnectionStatus(): SessionClientStatus;\n}\n\n/**\n * Utility type limiting to a specific session client. (A session client with\n * a specific session ID - not just any session ID.)\n *\n * @internal\n */\nexport type SpecificSessionClient<SpecificSessionClientId extends ClientSessionId> =\n\tstring extends SpecificSessionClientId ? never : ISessionClient<SpecificSessionClientId>;\n\n/**\n * @sealed\n * @alpha\n */\nexport interface PresenceEvents {\n\t/**\n\t * Raised when new client joins session.\n\t *\n\t * @eventProperty\n\t */\n\tattendeeJoined: (attendee: ISessionClient) => void;\n\n\t/**\n\t * Raised when client appears disconnected from session.\n\t *\n\t * @eventProperty\n\t */\n\tattendeeDisconnected: (attendee: ISessionClient) => void;\n\n\t/**\n\t * Raised when a workspace is activated within the session.\n\t *\n\t * \"Activated\" means that a workspace is being used by a client and this\n\t * client is seeing information for the first time.\n\t *\n\t * @remarks\n\t * Local workspaces may be passively acquired/registered when this event\n\t * is raised. For a notifications workspace, that lazy registration must\n\t * be done before the event handler returns to ensure no notifications\n\t * are missed.\n\t */\n\tworkspaceActivated: (\n\t\tworkspaceAddress: PresenceWorkspaceAddress,\n\t\ttype: \"States\" | \"Notifications\" | \"Unknown\",\n\t) => void;\n}\n\n/**\n * Presence represents known clients within a session and their custom states and notifications.\n *\n * @sealed\n * @alpha\n */\nexport interface IPresence {\n\t/**\n\t * Events for Notifications manager.\n\t */\n\treadonly events: Listenable<PresenceEvents>;\n\n\t/**\n\t * Get all attendees in the session.\n\t *\n\t * @remarks\n\t * Attendee states are dynamic and will change as clients join and leave\n\t * the session.\n\t */\n\tgetAttendees(): ReadonlySet<ISessionClient>;\n\n\t/**\n\t * Lookup a specific attendee in the session.\n\t *\n\t * @param clientId - Client connection or session ID\n\t */\n\tgetAttendee(clientId: ClientConnectionId | ClientSessionId): ISessionClient;\n\n\t/**\n\t * Get this client's session client.\n\t *\n\t * @returns This client's session client.\n\t */\n\tgetMyself(): ISessionClient;\n\n\t/**\n\t * Acquires a PresenceStates workspace from store or adds new one.\n\t *\n\t * @param workspaceAddress - Address of the requested PresenceStates Workspace\n\t * @param requestedContent - Requested states for the workspace\n\t * @param controls - Optional settings for default broadcast controls\n\t * @returns A PresenceStates workspace\n\t */\n\tgetStates<StatesSchema extends PresenceStatesSchema>(\n\t\tworkspaceAddress: PresenceWorkspaceAddress,\n\t\trequestedContent: StatesSchema,\n\t\tcontrols?: BroadcastControlSettings,\n\t): PresenceStates<StatesSchema>;\n\n\t/**\n\t * Acquires a Notifications workspace from store or adds new one.\n\t *\n\t * @param workspaceAddress - Address of the requested Notifications Workspace\n\t * @param requestedContent - Requested notifications for the workspace\n\t * @returns A Notifications workspace\n\t */\n\tgetNotifications<NotificationsSchema extends PresenceNotificationsSchema>(\n\t\tnotificationsId: PresenceWorkspaceAddress,\n\t\trequestedContent: NotificationsSchema,\n\t): PresenceNotifications<NotificationsSchema>;\n}\n"]}
@@ -68,11 +68,24 @@ export declare class PresenceDatastoreManagerImpl implements PresenceDatastoreMa
68
68
  private averageLatency;
69
69
  private returnedMessages;
70
70
  private refreshBroadcastRequested;
71
+ private readonly timer;
71
72
  private readonly workspaces;
72
73
  constructor(clientSessionId: ClientSessionId, runtime: IEphemeralRuntime, lookupClient: (clientId: ClientSessionId) => ISessionClient, logger: ITelemetryLoggerExt | undefined, systemWorkspaceDatastore: SystemWorkspaceDatastore, systemWorkspace: PresenceWorkspaceEntry<PresenceStatesSchema>);
73
74
  joinSession(clientId: ClientConnectionId): void;
74
75
  getWorkspace<TSchema extends PresenceStatesSchema>(internalWorkspaceAddress: InternalWorkspaceAddress, requestedContent: TSchema, controls?: BroadcastControlSettings): PresenceStates<TSchema>;
75
- private localUpdate;
76
+ /**
77
+ * The combined contents of all queued updates. Will be undefined when no messages are queued.
78
+ */
79
+ private queuedData;
80
+ /**
81
+ * Enqueues a new message to be sent. The message may be queued or may be sent immediately depending on the state of
82
+ * the send timer, other messages in the queue, the configured allowed latency, etc.
83
+ */
84
+ private enqueueMessage;
85
+ /**
86
+ * Send any queued signal immediately. Does nothing if no message is queued.
87
+ */
88
+ private sendQueuedMessage;
76
89
  private broadcastAllKnownState;
77
90
  processSignal(message: IInboundSignalMessage | DatastoreUpdateMessage | ClientJoinMessage, local: boolean): void;
78
91
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"presenceDatastoreManager.d.ts","sourceRoot":"","sources":["../src/presenceDatastoreManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,8CAA8C,CAAC;AAC1F,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0CAA0C,CAAC;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UvB,aAAa,CAOnB,OAAO,EAAE,qBAAqB,GAAG,sBAAsB,GAAG,iBAAiB,EAC3E,KAAK,EAAE,OAAO,GACZ,IAAI;IAkEP;;;;;;;;;;OAUG;IACH,OAAO,CAAC,mBAAmB;CAgE3B"}
@@ -3,12 +3,38 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
  import { assert } from "@fluidframework/core-utils/internal";
6
- import { createPresenceStates, mergeUntrackedDatastore } from "./presenceStates.js";
6
+ import { brandedObjectEntries } from "./internalTypes.js";
7
+ import { createPresenceStates, mergeUntrackedDatastore, mergeValueDirectory, } from "./presenceStates.js";
8
+ import { TimerManager } from "./timerManager.js";
7
9
  const datastoreUpdateMessageType = "Pres:DatastoreUpdate";
8
10
  const joinMessageType = "Pres:ClientJoin";
9
11
  function isPresenceMessage(message) {
10
12
  return message.type.startsWith("Pres:");
11
13
  }
14
+ function mergeGeneralDatastoreMessageContent(base, newData) {
15
+ // This function-local "datastore" will hold the merged message data.
16
+ const queueDatastore = base ?? {};
17
+ // Merge the current data with the existing data, if any exists.
18
+ // Iterate over the current message data; individual items are workspaces.
19
+ for (const [workspaceName, workspaceData] of Object.entries(newData)) {
20
+ // Initialize the merged data as the queued datastore entry for the workspace.
21
+ // Since the key might not exist, create an empty object in that case. It will
22
+ // be set explicitly after the loop.
23
+ const mergedData = queueDatastore[workspaceName] ?? {};
24
+ // Iterate over each value manager and its data, merging it as needed.
25
+ for (const valueManagerKey of Object.keys(workspaceData)) {
26
+ for (const [clientSessionId, value] of brandedObjectEntries(workspaceData[valueManagerKey])) {
27
+ mergedData[valueManagerKey] ?? (mergedData[valueManagerKey] = {});
28
+ const oldData = mergedData[valueManagerKey][clientSessionId];
29
+ mergedData[valueManagerKey][clientSessionId] = mergeValueDirectory(oldData, value, 0);
30
+ }
31
+ }
32
+ // Store the merged data in the function-local queue workspace. The whole contents of this
33
+ // datastore will be sent as the message data.
34
+ queueDatastore[workspaceName] = mergedData;
35
+ }
36
+ return queueDatastore;
37
+ }
12
38
  /**
13
39
  * Manages singleton datastore for all Presence.
14
40
  */
@@ -21,6 +47,7 @@ export class PresenceDatastoreManagerImpl {
21
47
  this.averageLatency = 0;
22
48
  this.returnedMessages = 0;
23
49
  this.refreshBroadcastRequested = false;
50
+ this.timer = new TimerManager();
24
51
  this.workspaces = new Map();
25
52
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
26
53
  this.datastore = { "system:presence": systemWorkspaceDatastore };
@@ -55,25 +82,13 @@ export class PresenceDatastoreManagerImpl {
55
82
  if (!this.runtime.connected) {
56
83
  return;
57
84
  }
58
- const clientConnectionId = this.runtime.clientId;
59
- assert(clientConnectionId !== undefined, 0xa59 /* Client connected without clientId */);
60
- const currentClientToSessionValueState = this.datastore["system:presence"].clientToSessionId[clientConnectionId];
61
85
  const updates = {};
62
86
  for (const [key, value] of Object.entries(states)) {
63
87
  updates[key] = { [this.clientSessionId]: value };
64
88
  }
65
- this.localUpdate({
66
- // Always send current connection mapping for some resiliency against
67
- // lost signals. This ensures that client session id found in `updates`
68
- // (which is this client's client session id) is always represented in
69
- // system workspace of recipient clients.
70
- "system:presence": {
71
- clientToSessionId: {
72
- [clientConnectionId]: { ...currentClientToSessionValueState },
73
- },
74
- },
89
+ this.enqueueMessage({
75
90
  [internalWorkspaceAddress]: updates,
76
- });
91
+ }, options);
77
92
  };
78
93
  const entry = createPresenceStates({
79
94
  clientSessionId: this.clientSessionId,
@@ -83,14 +98,77 @@ export class PresenceDatastoreManagerImpl {
83
98
  this.workspaces.set(internalWorkspaceAddress, entry);
84
99
  return entry.public;
85
100
  }
86
- localUpdate(data) {
87
- const content = {
101
+ /**
102
+ * Enqueues a new message to be sent. The message may be queued or may be sent immediately depending on the state of
103
+ * the send timer, other messages in the queue, the configured allowed latency, etc.
104
+ */
105
+ enqueueMessage(data, options) {
106
+ // Merging the message with any queued messages effectively queues the message.
107
+ // It is OK to queue all incoming messages as long as when we send, we send the queued data.
108
+ this.queuedData = mergeGeneralDatastoreMessageContent(this.queuedData, data);
109
+ const { allowableUpdateLatencyMs } = options;
110
+ const now = Date.now();
111
+ const thisMessageDeadline = now + allowableUpdateLatencyMs;
112
+ if (
113
+ // If the timer has not expired, we can short-circuit because the timer will fire
114
+ // and cover this update. In other words, queuing this will be fast enough to
115
+ // meet its deadline, because a timer is already scheduled to fire before its deadline.
116
+ !this.timer.hasExpired() &&
117
+ // If the deadline for this message is later than the overall send deadline, then
118
+ // we can exit early since a timer will take care of sending it.
119
+ thisMessageDeadline >= this.timer.expireTime) {
120
+ return;
121
+ }
122
+ // Either we need to send this message immediately, or we need to schedule a timer
123
+ // to fire at the send deadline that will take care of it.
124
+ // Note that timeoutInMs === allowableUpdateLatency, but the calculation is done this way for clarity.
125
+ const timeoutInMs = thisMessageDeadline - now;
126
+ const scheduleForLater = timeoutInMs > 0;
127
+ if (scheduleForLater) {
128
+ // Schedule the queued messages to be sent at the updateDeadline
129
+ this.timer.setTimeout(this.sendQueuedMessage.bind(this), timeoutInMs);
130
+ }
131
+ else {
132
+ this.sendQueuedMessage();
133
+ }
134
+ }
135
+ /**
136
+ * Send any queued signal immediately. Does nothing if no message is queued.
137
+ */
138
+ sendQueuedMessage() {
139
+ this.timer.clearTimeout();
140
+ if (this.queuedData === undefined) {
141
+ return;
142
+ }
143
+ // Check for connectivity before sending updates.
144
+ if (!this.runtime.connected) {
145
+ // Clear the queued data since we're disconnected. We don't want messages
146
+ // to queue infinitely while disconnected.
147
+ this.queuedData = undefined;
148
+ return;
149
+ }
150
+ const clientConnectionId = this.runtime.clientId;
151
+ assert(clientConnectionId !== undefined, 0xa59 /* Client connected without clientId */);
152
+ const currentClientToSessionValueState = this.datastore["system:presence"].clientToSessionId[clientConnectionId];
153
+ const newMessage = {
88
154
  sendTimestamp: Date.now(),
89
155
  avgLatency: this.averageLatency,
90
156
  // isComplete: false,
91
- data,
157
+ data: {
158
+ // Always send current connection mapping for some resiliency against
159
+ // lost signals. This ensures that client session id found in `updates`
160
+ // (which is this client's client session id) is always represented in
161
+ // system workspace of recipient clients.
162
+ "system:presence": {
163
+ clientToSessionId: {
164
+ [clientConnectionId]: { ...currentClientToSessionValueState },
165
+ },
166
+ },
167
+ ...this.queuedData,
168
+ },
92
169
  };
93
- this.runtime.submitSignal(datastoreUpdateMessageType, content);
170
+ this.queuedData = undefined;
171
+ this.runtime.submitSignal(datastoreUpdateMessageType, newMessage);
94
172
  }
95
173
  broadcastAllKnownState() {
96
174
  this.runtime.submitSignal(datastoreUpdateMessageType, {