@fluidframework/container-loader 2.0.0-dev.1.4.6.106135 → 2.0.0-dev.2.3.0.115467

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 (96) hide show
  1. package/.eslintrc.js +21 -8
  2. package/README.md +21 -11
  3. package/dist/audience.d.ts +0 -4
  4. package/dist/audience.d.ts.map +1 -1
  5. package/dist/audience.js +11 -11
  6. package/dist/audience.js.map +1 -1
  7. package/dist/collabWindowTracker.js +5 -4
  8. package/dist/collabWindowTracker.js.map +1 -1
  9. package/dist/connectionManager.d.ts.map +1 -1
  10. package/dist/connectionManager.js +49 -7
  11. package/dist/connectionManager.js.map +1 -1
  12. package/dist/connectionStateHandler.d.ts +20 -11
  13. package/dist/connectionStateHandler.d.ts.map +1 -1
  14. package/dist/connectionStateHandler.js +65 -36
  15. package/dist/connectionStateHandler.js.map +1 -1
  16. package/dist/container.d.ts +8 -2
  17. package/dist/container.d.ts.map +1 -1
  18. package/dist/container.js +32 -36
  19. package/dist/container.js.map +1 -1
  20. package/dist/containerContext.d.ts +1 -1
  21. package/dist/containerContext.d.ts.map +1 -1
  22. package/dist/containerContext.js +7 -3
  23. package/dist/containerContext.js.map +1 -1
  24. package/dist/containerStorageAdapter.js +1 -1
  25. package/dist/containerStorageAdapter.js.map +1 -1
  26. package/dist/contracts.d.ts +8 -0
  27. package/dist/contracts.d.ts.map +1 -1
  28. package/dist/contracts.js.map +1 -1
  29. package/dist/deltaManager.d.ts +1 -3
  30. package/dist/deltaManager.d.ts.map +1 -1
  31. package/dist/deltaManager.js +40 -16
  32. package/dist/deltaManager.js.map +1 -1
  33. package/dist/packageVersion.d.ts +1 -1
  34. package/dist/packageVersion.js +1 -1
  35. package/dist/packageVersion.js.map +1 -1
  36. package/dist/protocol.d.ts +8 -3
  37. package/dist/protocol.d.ts.map +1 -1
  38. package/dist/protocol.js +34 -8
  39. package/dist/protocol.js.map +1 -1
  40. package/dist/retriableDocumentStorageService.d.ts.map +1 -1
  41. package/dist/retriableDocumentStorageService.js +7 -3
  42. package/dist/retriableDocumentStorageService.js.map +1 -1
  43. package/lib/audience.d.ts +0 -4
  44. package/lib/audience.d.ts.map +1 -1
  45. package/lib/audience.js +11 -11
  46. package/lib/audience.js.map +1 -1
  47. package/lib/collabWindowTracker.js +5 -4
  48. package/lib/collabWindowTracker.js.map +1 -1
  49. package/lib/connectionManager.d.ts.map +1 -1
  50. package/lib/connectionManager.js +49 -7
  51. package/lib/connectionManager.js.map +1 -1
  52. package/lib/connectionStateHandler.d.ts +20 -11
  53. package/lib/connectionStateHandler.d.ts.map +1 -1
  54. package/lib/connectionStateHandler.js +65 -36
  55. package/lib/connectionStateHandler.js.map +1 -1
  56. package/lib/container.d.ts +8 -2
  57. package/lib/container.d.ts.map +1 -1
  58. package/lib/container.js +31 -36
  59. package/lib/container.js.map +1 -1
  60. package/lib/containerContext.d.ts +1 -1
  61. package/lib/containerContext.d.ts.map +1 -1
  62. package/lib/containerContext.js +7 -3
  63. package/lib/containerContext.js.map +1 -1
  64. package/lib/containerStorageAdapter.js +1 -1
  65. package/lib/containerStorageAdapter.js.map +1 -1
  66. package/lib/contracts.d.ts +8 -0
  67. package/lib/contracts.d.ts.map +1 -1
  68. package/lib/contracts.js.map +1 -1
  69. package/lib/deltaManager.d.ts +1 -3
  70. package/lib/deltaManager.d.ts.map +1 -1
  71. package/lib/deltaManager.js +43 -19
  72. package/lib/deltaManager.js.map +1 -1
  73. package/lib/packageVersion.d.ts +1 -1
  74. package/lib/packageVersion.js +1 -1
  75. package/lib/packageVersion.js.map +1 -1
  76. package/lib/protocol.d.ts +8 -3
  77. package/lib/protocol.d.ts.map +1 -1
  78. package/lib/protocol.js +33 -7
  79. package/lib/protocol.js.map +1 -1
  80. package/lib/retriableDocumentStorageService.d.ts.map +1 -1
  81. package/lib/retriableDocumentStorageService.js +7 -3
  82. package/lib/retriableDocumentStorageService.js.map +1 -1
  83. package/package.json +27 -29
  84. package/prettier.config.cjs +8 -0
  85. package/src/audience.ts +11 -12
  86. package/src/collabWindowTracker.ts +5 -5
  87. package/src/connectionManager.ts +56 -11
  88. package/src/connectionStateHandler.ts +87 -39
  89. package/src/container.ts +36 -38
  90. package/src/containerContext.ts +10 -4
  91. package/src/containerStorageAdapter.ts +1 -1
  92. package/src/contracts.ts +8 -0
  93. package/src/deltaManager.ts +61 -39
  94. package/src/packageVersion.ts +1 -1
  95. package/src/protocol.ts +31 -8
  96. package/src/retriableDocumentStorageService.ts +7 -3
package/.eslintrc.js CHANGED
@@ -4,12 +4,25 @@
4
4
  */
5
5
 
6
6
  module.exports = {
7
- "extends": [
8
- require.resolve("@fluidframework/eslint-config-fluid")
9
- ],
10
- "parserOptions": {
11
- "project": ["./tsconfig.json", "./src/test/tsconfig.json"]
7
+ extends: [require.resolve("@fluidframework/eslint-config-fluid"), "prettier"],
8
+ parserOptions: {
9
+ project: ["./tsconfig.json", "./src/test/tsconfig.json"],
10
+ },
11
+ rules: {
12
+ // This library is used in the browser, so we don't want dependencies on most node libraries.
13
+ "import/no-nodejs-modules": ["error", { allow: ["events", "url"] }],
12
14
  },
13
- "rules": {
14
- }
15
- }
15
+ overrides: [
16
+ {
17
+ // Rules only for test files
18
+ files: ["*.spec.ts", "src/test/**"],
19
+ rules: {
20
+ // Test files are run in node only so additional node libraries can be used.
21
+ "import/no-nodejs-modules": [
22
+ "error",
23
+ { allow: ["assert", "events", "url"] },
24
+ ],
25
+ },
26
+ },
27
+ ],
28
+ };
package/README.md CHANGED
@@ -147,7 +147,7 @@ In normal circumstances, container will attempt to reconnect back to ordering se
147
147
 
148
148
  Container will also not attempt to reconnect on lost connection if `Container.disconnect()` was called prior to loss of connection. This can be useful if the hosting application implements "user away" type of experience to reduce cost on both client and server of maintaining connection while user is away. Calling `Container.connect()` will reenable automatic reconnections, but the host might need to allow extra time for reconnection as it likely involves token fetch and processing of a lot of Ops generated by other clients while it was not connected.
149
149
 
150
- Data stores should almost never listen to these events (see more on [Readonly states](#Readonly-states), and should use consensus DDSes if they need to synchronize activity across clients. DDSes listen for these events to know when to resubmit pending Ops.
150
+ Data stores should almost never listen to these events (see more on [Readonly states](#Readonly-states)), and should use consensus DDSes if they need to synchronize activity across clients. DDSes listen for these events to know when to resubmit pending Ops.
151
151
 
152
152
  Hosting application can use these events in order to indicate to user when user changes are not propagating through the system, and thus can be lost (on browser tab being closed). It's advised to use some delay (like 5 seconds) before showing such UI, as network connectivity might be intermittent. Also if container was offline for very long period of time due to `Container.disconnect()` being called, it might take a while to get connected and current.
153
153
 
@@ -156,33 +156,43 @@ Please note that hosts can implement various strategies on how to handle disconn
156
156
  It's worth pointing out that being connected does not mean all user edits are preserved on container closure. There is latency in the system, and loader layer does not provide any guarantees here. Not every implementation needs a solution here (games likely do not care), and thus solving this problem is pushed to framework level (i.e. having a data store that can expose `'dirtyDocument'` signal from ContainerRuntime and request route that can return such data store).
157
157
 
158
158
  ## Readonly states
159
+
159
160
  User permissions can change over lifetime of Container. They can't change during single connection session (in other words, change in permissions causes disconnect and reconnect). Hosts are advised to recheck this property on every reconnect.
160
161
 
161
162
  DeltaManager will emit a `"readonly"` event when transitioning to a read-only state. Readonly events are accessible by data stores and DDSes (through ContainerRuntime.deltaManager). It's expected that data stores adhere to requirements and expose read-only (or rather 'no edit') experiences.
162
163
 
163
- `Container.readOnlyInfo` (and `DeltaManager.readOnlyInfo`) indicates to host if file is writable or not.
164
+ `Container.readOnlyInfo` (and `DeltaManager.readOnlyInfo`) indicates to the host if the file is writable or not.
165
+ It contains the following properties:
166
+
164
167
  ### `readonly`
165
- one of the following:
166
- - true: Container is readonly. One or more of the additional properties listed below will be true.
167
- - undefined: Runtime does not know yet if file is writable or not. Currently we get a signal here only when websocket connection is made to the server.
168
- - false: Container.forceReadonly() was never called or last call was with false, plus it's known that user has write permissions to a file.
168
+
169
+ One of the following:
170
+
171
+ - `true`: Container is read-only. One or more of the additional properties listed below will be `true`.
172
+ - `undefined`: Runtime does not know yet if file is writable or not. Currently we get a signal here only when websocket connection is made to the server.
173
+ - `false`: Container.forceReadonly() was never called or last call was with false, plus it's known that user has write permissions to a file.
169
174
 
170
175
  ### `permissions`
171
- There are two cases when it's true:
172
176
 
173
- 1. User has no write permissions to to modify this container (which usually maps to file in storage, and lack of write permissions by a given user)
177
+ There are two cases when it's `true`:
178
+
179
+ 1. User has no write permissions to modify this container (which usually maps to file in storage, and lack of write permissions by a given user)
174
180
  2. Container was closed, either due to critical error, or due to host closing container. See [Container Lifetime](#Container-lifetime) and [Error Handling](#Error-handling) for more details.
175
181
 
176
182
  ### `forced`
177
- Hosts can also force readonly-mode for a container via calling `Container.forceReadonly(true)`. This can be useful in scenarios like:
178
183
 
179
- - Loss of connectivity, in scenarios where host chooses method of preventing user edits over (or in addition to) showing disconnected UX and warning user of potential data loss on closure of container
184
+ `true` if the Container is in read-only mode due to the host calling `Container.forceReadonly(true)`.
185
+ This can be useful in scenarios like:
186
+
187
+ - Loss of connectivity, in scenarios where host chooses method of preventing user edits over (or in addition to) showing disconnected UX and warning user of potential data loss on closure of container.
180
188
  - Special view-only mode in host. For example can be used by hosts for previewing container content in-place with other host content, and leveraging full-screen / separate window experience for editing.
181
189
 
182
190
  ### `storageOnly`
183
- Storage-only mode is a readonly mode in which the container does not connect to the delta stream and is unable to submit or recieve ops. This is useful for viewing a specific version of a document.
191
+
192
+ Storage-only mode is a read-only mode in which the container does not connect to the delta stream and is unable to submit or receive ops. This is useful for viewing a specific version of a document.
184
193
 
185
194
  ## Dirty events
195
+
186
196
  The Container runtime can communicate with the container to get the container's current state. In response, the container will raise two events - `"dirty"` and `"saved"` events. Transitions between these two events signify presence (or lack of) user changes that were not saved to storage. In other words, if container is dirty, closing it at that moment will result in data loss from user perspective, because not all user changes made it to storage.
187
197
  This information can be used by a host to build appropriate UX that allows user to be confident in the platform. For example, a host may chose to show a dialog asking the user if they want to save their changes before closing. Instead of, or in addition to this, the host may choose to show "Saving..." and "Saved" text somewhere in UX. Coupled with lack of connectivity to ordering service (and appropriate notification to the user) that may create enough continuous notification to user not to require a blocking dialog on closing.
188
198
  Note that when an active connection is in place, it's just a matter of time before changes will be flushed to storage unless there is some source of continuous local changes being generated that prevents container from ever being fully saved. But if there is no active connection, because the user is offline, for example, then a document may stay in a dirty state for very long time.
@@ -29,9 +29,5 @@ export declare class Audience extends EventEmitter implements IAudienceOwner {
29
29
  * Retrieves a specific member of the audience
30
30
  */
31
31
  getMember(clientId: string): IClient | undefined;
32
- /**
33
- * Clears the audience
34
- */
35
- clear(): void;
36
32
  }
37
33
  //# sourceMappingURL=audience.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"audience.d.ts","sourceRoot":"","sources":["../src/audience.ts"],"names":[],"mappings":";AAAA;;;GAGG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,uCAAuC,CAAC;AACvE,OAAO,EAAE,OAAO,EAAE,MAAM,sCAAsC,CAAC;AAE/D;;GAEG;AACH,qBAAa,QAAS,SAAQ,YAAa,YAAW,cAAc;IAChE,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA8B;IAE/C,EAAE,CAAC,KAAK,EAAE,WAAW,GAAG,cAAc,EAAE,QAAQ,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,KAAK,IAAI,GAAG,IAAI;IAK3G;;OAEG;IACI,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO;IAKnD;;;OAGG;IACI,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAW9C;;OAEG;IACI,UAAU,IAAI,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC;IAIzC;;OAEG;IACI,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS;IAIvD;;OAEG;IACI,KAAK,IAAI,IAAI;CAMvB"}
1
+ {"version":3,"file":"audience.d.ts","sourceRoot":"","sources":["../src/audience.ts"],"names":[],"mappings":";AAAA;;;GAGG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEtC,OAAO,EAAE,cAAc,EAAE,MAAM,uCAAuC,CAAC;AACvE,OAAO,EAAE,OAAO,EAAE,MAAM,sCAAsC,CAAC;AAE/D;;GAEG;AACH,qBAAa,QAAS,SAAQ,YAAa,YAAW,cAAc;IAChE,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA8B;IAE/C,EAAE,CAAC,KAAK,EAAE,WAAW,GAAG,cAAc,EAAE,QAAQ,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,KAAK,IAAI,GAAG,IAAI;IAK3G;;OAEG;IACI,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO;IAanD;;;OAGG;IACI,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAW9C;;OAEG;IACI,UAAU,IAAI,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC;IAIzC;;OAEG;IACI,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS;CAG1D"}
package/dist/audience.js CHANGED
@@ -6,6 +6,7 @@ exports.Audience = void 0;
6
6
  * Licensed under the MIT License.
7
7
  */
8
8
  const events_1 = require("events");
9
+ const common_utils_1 = require("@fluidframework/common-utils");
9
10
  /**
10
11
  * Audience represents all clients connected to the op stream.
11
12
  */
@@ -21,8 +22,16 @@ class Audience extends events_1.EventEmitter {
21
22
  * Adds a new client to the audience
22
23
  */
23
24
  addMember(clientId, details) {
24
- this.members.set(clientId, details);
25
- this.emit("addMember", clientId, details);
25
+ // Given that signal delivery is unreliable process, we might observe same client being added twice
26
+ // In such case we should see exactly same payload (IClient), and should not raise event twice!
27
+ if (this.members.has(clientId)) {
28
+ const client = this.members.get(clientId);
29
+ (0, common_utils_1.assert)(JSON.stringify(client) === JSON.stringify(details), 0x4b2 /* new client has different payload from existing one */);
30
+ }
31
+ else {
32
+ this.members.set(clientId, details);
33
+ this.emit("addMember", clientId, details);
34
+ }
26
35
  }
27
36
  /**
28
37
  * Removes a client from the audience. Only emits an event if a client is actually removed
@@ -51,15 +60,6 @@ class Audience extends events_1.EventEmitter {
51
60
  getMember(clientId) {
52
61
  return this.members.get(clientId);
53
62
  }
54
- /**
55
- * Clears the audience
56
- */
57
- clear() {
58
- const clientIds = this.members.keys();
59
- for (const clientId of clientIds) {
60
- this.removeMember(clientId);
61
- }
62
- }
63
63
  }
64
64
  exports.Audience = Audience;
65
65
  //# sourceMappingURL=audience.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"audience.js","sourceRoot":"","sources":["../src/audience.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,mCAAsC;AAItC;;GAEG;AACH,MAAa,QAAS,SAAQ,qBAAY;IAA1C;;QACqB,YAAO,GAAG,IAAI,GAAG,EAAmB,CAAC;IAqD1D,CAAC;IAlDU,EAAE,CAAC,KAAa,EAAE,QAAkC;QACvD,OAAO,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IACrC,CAAC;IAED;;OAEG;IACI,SAAS,CAAC,QAAgB,EAAE,OAAgB;QAC/C,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QACpC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC9C,CAAC;IAED;;;OAGG;IACI,YAAY,CAAC,QAAgB;QAChC,MAAM,aAAa,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QACjD,IAAI,aAAa,KAAK,SAAS,EAAE;YAC7B,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;YAC9B,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,QAAQ,EAAE,aAAa,CAAC,CAAC;YACnD,OAAO,IAAI,CAAC;SACf;aAAM;YACH,OAAO,KAAK,CAAC;SAChB;IACL,CAAC;IAED;;OAEG;IACI,UAAU;QACb,OAAO,IAAI,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACjC,CAAC;IAED;;OAEG;IACI,SAAS,CAAC,QAAgB;QAC7B,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACtC,CAAC;IAED;;OAEG;IACI,KAAK;QACR,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;QACtC,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE;YAC9B,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;SAC/B;IACL,CAAC;CACJ;AAtDD,4BAsDC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\nimport { EventEmitter } from \"events\";\nimport { IAudienceOwner } from \"@fluidframework/container-definitions\";\nimport { IClient } from \"@fluidframework/protocol-definitions\";\n\n/**\n * Audience represents all clients connected to the op stream.\n */\nexport class Audience extends EventEmitter implements IAudienceOwner {\n private readonly members = new Map<string, IClient>();\n\n public on(event: \"addMember\" | \"removeMember\", listener: (clientId: string, client: IClient) => void): this;\n public on(event: string, listener: (...args: any[]) => void): this {\n return super.on(event, listener);\n }\n\n /**\n * Adds a new client to the audience\n */\n public addMember(clientId: string, details: IClient) {\n this.members.set(clientId, details);\n this.emit(\"addMember\", clientId, details);\n }\n\n /**\n * Removes a client from the audience. Only emits an event if a client is actually removed\n * @returns if a client was removed from the audience\n */\n public removeMember(clientId: string): boolean {\n const removedClient = this.members.get(clientId);\n if (removedClient !== undefined) {\n this.members.delete(clientId);\n this.emit(\"removeMember\", clientId, removedClient);\n return true;\n } else {\n return false;\n }\n }\n\n /**\n * Retrieves all the members in the audience\n */\n public getMembers(): Map<string, IClient> {\n return new Map(this.members);\n }\n\n /**\n * Retrieves a specific member of the audience\n */\n public getMember(clientId: string): IClient | undefined {\n return this.members.get(clientId);\n }\n\n /**\n * Clears the audience\n */\n public clear(): void {\n const clientIds = this.members.keys();\n for (const clientId of clientIds) {\n this.removeMember(clientId);\n }\n }\n}\n"]}
1
+ {"version":3,"file":"audience.js","sourceRoot":"","sources":["../src/audience.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,mCAAsC;AACtC,+DAAsD;AAItD;;GAEG;AACH,MAAa,QAAS,SAAQ,qBAAY;IAA1C;;QACqB,YAAO,GAAG,IAAI,GAAG,EAAmB,CAAC;IAmD1D,CAAC;IAhDU,EAAE,CAAC,KAAa,EAAE,QAAkC;QACvD,OAAO,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IACrC,CAAC;IAED;;OAEG;IACI,SAAS,CAAC,QAAgB,EAAE,OAAgB;QAC/C,mGAAmG;QACnG,+FAA+F;QAC/F,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE;YAC5B,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;YAC1C,IAAA,qBAAM,EAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,KAAK,CAAC,wDAAwD,CAAC,CAAC;SAC9H;aACI;YACD,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;YACpC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;SAC7C;IACL,CAAC;IAED;;;OAGG;IACI,YAAY,CAAC,QAAgB;QAChC,MAAM,aAAa,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QACjD,IAAI,aAAa,KAAK,SAAS,EAAE;YAC7B,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;YAC9B,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,QAAQ,EAAE,aAAa,CAAC,CAAC;YACnD,OAAO,IAAI,CAAC;SACf;aAAM;YACH,OAAO,KAAK,CAAC;SAChB;IACL,CAAC;IAED;;OAEG;IACI,UAAU;QACb,OAAO,IAAI,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACjC,CAAC;IAED;;OAEG;IACI,SAAS,CAAC,QAAgB;QAC7B,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACtC,CAAC;CACJ;AApDD,4BAoDC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\nimport { EventEmitter } from \"events\";\nimport { assert } from \"@fluidframework/common-utils\";\nimport { IAudienceOwner } from \"@fluidframework/container-definitions\";\nimport { IClient } from \"@fluidframework/protocol-definitions\";\n\n/**\n * Audience represents all clients connected to the op stream.\n */\nexport class Audience extends EventEmitter implements IAudienceOwner {\n private readonly members = new Map<string, IClient>();\n\n public on(event: \"addMember\" | \"removeMember\", listener: (clientId: string, client: IClient) => void): this;\n public on(event: string, listener: (...args: any[]) => void): this {\n return super.on(event, listener);\n }\n\n /**\n * Adds a new client to the audience\n */\n public addMember(clientId: string, details: IClient) {\n // Given that signal delivery is unreliable process, we might observe same client being added twice\n // In such case we should see exactly same payload (IClient), and should not raise event twice!\n if (this.members.has(clientId)) {\n const client = this.members.get(clientId);\n assert(JSON.stringify(client) === JSON.stringify(details), 0x4b2 /* new client has different payload from existing one */);\n }\n else {\n this.members.set(clientId, details);\n this.emit(\"addMember\", clientId, details);\n }\n }\n\n /**\n * Removes a client from the audience. Only emits an event if a client is actually removed\n * @returns if a client was removed from the audience\n */\n public removeMember(clientId: string): boolean {\n const removedClient = this.members.get(clientId);\n if (removedClient !== undefined) {\n this.members.delete(clientId);\n this.emit(\"removeMember\", clientId, removedClient);\n return true;\n } else {\n return false;\n }\n }\n\n /**\n * Retrieves all the members in the audience\n */\n public getMembers(): Map<string, IClient> {\n return new Map(this.members);\n }\n\n /**\n * Retrieves a specific member of the audience\n */\n public getMember(clientId: string): IClient | undefined {\n return this.members.get(clientId);\n }\n}\n"]}
@@ -66,10 +66,11 @@ class CollabWindowTracker {
66
66
  // Ensure we only send noop after a batch of many ops is processed
67
67
  // eslint-disable-next-line @typescript-eslint/no-floating-promises
68
68
  Promise.resolve().then(() => {
69
- (0, common_utils_1.assert)(this.opsCountSinceNoop >= this.NoopCountFrequency, 0x3ae /* not enough ops were sent to reach the noop frequency */);
70
- this.submitNoop(false /* immediate */);
71
- // reset count now that all ops are processed
72
- this.opsCountSinceNoop = 0;
69
+ if (this.opsCountSinceNoop >= this.NoopCountFrequency) {
70
+ this.submitNoop(false /* immediate */);
71
+ // reset count now that all ops are processed
72
+ this.opsCountSinceNoop = 0;
73
+ }
73
74
  return;
74
75
  });
75
76
  }
@@ -1 +1 @@
1
- {"version":3,"file":"collabWindowTracker.js","sourceRoot":"","sources":["../src/collabWindowTracker.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAA6D;AAC7D,+EAA8F;AAC9F,+DAA8E;AAE9E,MAAM,wBAAwB,GAAG,IAAI,CAAC;AACtC,MAAM,yBAAyB,GAAG,EAAE,CAAC;AAErC,6FAA6F;AAC7F,4GAA4G;AAC5G,yGAAyG;AACzG,2CAA2C;AAC3C,oHAAoH;AACpH,2FAA2F;AAC3F,kHAAkH;AAClH,+CAA+C;AAC/C,gHAAgH;AAChH,yFAAyF;AACzF,qHAAqH;AACrH,oDAAoD;AACpD,EAAE;AACF,kDAAkD;AAClD,oGAAoG;AACpG,iHAAiH;AACjH,sEAAsE;AACtE,4GAA4G;AAC5G,qGAAqG;AACrG,MAAa,mBAAmB;IAI5B,YACqB,MAAmC,EACpD,oBAA4B,wBAAwB,EACnC,qBAA6B,yBAAyB;QAFtD,WAAM,GAAN,MAAM,CAA6B;QAEnC,uBAAkB,GAAlB,kBAA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EAAE;gBAC9B,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;aACxB;YAED,IAAA,qBAAM,EAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,iBAAiB,CAAC,CAAC;SACxD;IACL,CAAC;IAEO,UAAU,CAAC,SAAkB;QACjC,6CAA6C;QAC7C,8EAA8E;QAC9E,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAE,2BAAY,CAAC,MAAiC,CAAC,CAAC,CAAC,kCAAW,CAAC,IAAI,CAAC,CAAC;QAC5F,IAAA,qBAAM,EAAC,IAAI,CAAC,iBAAiB,KAAK,CAAC,EAC/B,KAAK,CAAC,8EAA8E,CAAC,CAAC;IAC9F,CAAC;IAEM,wBAAwB;QAC3B,IAAI,CAAC,iBAAiB,GAAG,CAAC,CAAC;QAC3B,kGAAkG;QAClG,wGAAwG;QACxG,oDAAoD;QACpD,qGAAqG;QACrG,yFAAyF;QACzF,sBAAsB;IAC1B,CAAC;CACJ;AA/ED,kDA+EC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, Timer } from \"@fluidframework/common-utils\";\nimport { ISequencedDocumentMessage, MessageType } from \"@fluidframework/protocol-definitions\";\nimport { isRuntimeMessage, MessageType2 } from \"@fluidframework/driver-utils\";\n\nconst defaultNoopTimeFrequency = 2000;\nconst defaultNoopCountFrequency = 50;\n\n// Here are key considerations when deciding conditions for when to send non-immediate noops:\n// 1. Sending them too often results in increase in file size and bandwidth, as well as catch up performance\n// 2. Sending too infrequently ensures that collab window is large, and as result Sequence DDS would have\n// large catchUp blobs - see Issue #6364\n// 3. Similarly, processes that rely on \"core\" snapshot (and can't parse trailing ops, including above), like search\n// parser in SPO, will result in non-accurate results due to presence of catch up blobs.\n// 4. Ordering service used 250ms timeout to coalesce non-immediate noops. It was changed to 2000 ms to allow more\n// aggressive noop sending from client side.\n// 5. Number of ops sent by all clients is proportional to number of \"write\" clients (every client sends noops),\n// but number of sequenced noops is a function of time (one op per 2 seconds at most).\n// We should consider impact to both outbound traffic (might be huge, depends on number of clients) and file size.\n// Please also see Issue #5629 for more discussions.\n//\n// With that, the current algorithm is as follows:\n// 1. Sent noop 2000 ms of receiving an op if no ops were sent by this client within this timeframe.\n// This will ensure that MSN moves forward with reasonable speed. If that results in too many sequenced noops,\n// server timeout of 2000ms should be reconsidered to be increased.\n// 2. If there are more than 50 ops received without sending any ops, send noop to keep collab window small.\n// Note that system ops (including noops themselves) are excluded, so it's 1 noop per 50 real ops.\nexport class CollabWindowTracker {\n private opsCountSinceNoop = 0;\n private readonly timer: Timer | undefined;\n\n constructor(\n private readonly submit: (type: MessageType) => void,\n NoopTimeFrequency: number = defaultNoopTimeFrequency,\n private readonly NoopCountFrequency: number = defaultNoopCountFrequency,\n ) {\n if (NoopTimeFrequency !== Infinity) {\n this.timer = new Timer(NoopTimeFrequency, () => {\n // Can get here due to this.stopSequenceNumberUpdate() not resetting timer.\n // Also timer callback can fire even after timer cancellation if it was queued before cancellation.\n if (this.opsCountSinceNoop !== 0) {\n this.submitNoop(false /* immediate */);\n }\n });\n }\n }\n\n /**\n * Schedules as ack to the server to update the reference sequence number\n */\n public scheduleSequenceNumberUpdate(message: ISequencedDocumentMessage, immediateNoOp: boolean): void {\n // While processing a message, an immediate no-op can be requested.\n // i.e. to expedite approve or commit phase of quorum.\n if (immediateNoOp) {\n this.submitNoop(true /* immediate */);\n return;\n }\n\n // We don't acknowledge no-ops to avoid acknowledgement cycles (i.e. ack the MSN\n // update, which updates the MSN, then ack the update, etc...).\n // Intent here is for runtime (and DDSes) not to keep too much tracking state / memory\n // due to runtime ops from other clients.\n if (!isRuntimeMessage(message)) {\n return;\n }\n\n this.opsCountSinceNoop++;\n if (this.opsCountSinceNoop === this.NoopCountFrequency) {\n // Ensure we only send noop after a batch of many ops is processed\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n Promise.resolve().then(() => {\n assert(this.opsCountSinceNoop >= this.NoopCountFrequency,\n 0x3ae /* not enough ops were sent to reach the noop frequency */);\n this.submitNoop(false /* immediate */);\n // reset count now that all ops are processed\n this.opsCountSinceNoop = 0;\n return;\n });\n }\n\n if (this.timer !== undefined) {\n if (this.opsCountSinceNoop === 1) {\n this.timer.restart();\n }\n\n assert(this.timer.hasTimer, 0x242 /* \"has timer\" */);\n }\n }\n\n private submitNoop(immediate: boolean) {\n // Anything other than null is immediate noop\n // ADO:1385: Remove cast and use MessageType once definition changes propagate\n this.submit(immediate ? (MessageType2.Accept as unknown as MessageType) : MessageType.NoOp);\n assert(this.opsCountSinceNoop === 0,\n 0x243 /* \"stopSequenceNumberUpdate should be called as result of sending any op!\" */);\n }\n\n public stopSequenceNumberUpdate(): void {\n this.opsCountSinceNoop = 0;\n // Ideally, we cancel timer here. But that will result in too often set/reset cycle if this client\n // keeps sending ops. In most cases it's actually better to let it expire (at most - 4 times per second)\n // for nothing, then have a ton of set/reset cycles.\n // Note that Timer.restart() is smart and will not change timer expiration if we keep extending timer\n // expiration - it will restart the timer instead when it fires with adjusted expiration.\n // this.timer.clear();\n }\n}\n"]}
1
+ {"version":3,"file":"collabWindowTracker.js","sourceRoot":"","sources":["../src/collabWindowTracker.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAA6D;AAC7D,+EAA8F;AAC9F,+DAA8E;AAE9E,MAAM,wBAAwB,GAAG,IAAI,CAAC;AACtC,MAAM,yBAAyB,GAAG,EAAE,CAAC;AAErC,6FAA6F;AAC7F,4GAA4G;AAC5G,yGAAyG;AACzG,2CAA2C;AAC3C,oHAAoH;AACpH,2FAA2F;AAC3F,kHAAkH;AAClH,+CAA+C;AAC/C,gHAAgH;AAChH,yFAAyF;AACzF,qHAAqH;AACrH,oDAAoD;AACpD,EAAE;AACF,kDAAkD;AAClD,oGAAoG;AACpG,iHAAiH;AACjH,sEAAsE;AACtE,4GAA4G;AAC5G,qGAAqG;AACrG,MAAa,mBAAmB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IAAI,IAAI,CAAC,KAAK,KAAK,SAAS,EAAE;YAC1B,IAAI,IAAI,CAAC,iBAAiB,KAAK,CAAC,EAAE;gBAC9B,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;aACxB;YAED,IAAA,qBAAM,EAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,iBAAiB,CAAC,CAAC;SACxD;IACL,CAAC;IAEO,UAAU,CAAC,SAAkB;QACjC,6CAA6C;QAC7C,8EAA8E;QAC9E,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAE,2BAAY,CAAC,MAAiC,CAAC,CAAC,CAAC,kCAAW,CAAC,IAAI,CAAC,CAAC;QAC5F,IAAA,qBAAM,EAAC,IAAI,CAAC,iBAAiB,KAAK,CAAC,EAC/B,KAAK,CAAC,8EAA8E,CAAC,CAAC;IAC9F,CAAC;IAEM,wBAAwB;QAC3B,IAAI,CAAC,iBAAiB,GAAG,CAAC,CAAC;QAC3B,kGAAkG;QAClG,wGAAwG;QACxG,oDAAoD;QACpD,qGAAqG;QACrG,yFAAyF;QACzF,sBAAsB;IAC1B,CAAC;CACJ;AA/ED,kDA+EC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, Timer } from \"@fluidframework/common-utils\";\nimport { ISequencedDocumentMessage, MessageType } from \"@fluidframework/protocol-definitions\";\nimport { isRuntimeMessage, MessageType2 } from \"@fluidframework/driver-utils\";\n\nconst defaultNoopTimeFrequency = 2000;\nconst defaultNoopCountFrequency = 50;\n\n// Here are key considerations when deciding conditions for when to send non-immediate noops:\n// 1. Sending them too often results in increase in file size and bandwidth, as well as catch up performance\n// 2. Sending too infrequently ensures that collab window is large, and as result Sequence DDS would have\n// large catchUp blobs - see Issue #6364\n// 3. Similarly, processes that rely on \"core\" snapshot (and can't parse trailing ops, including above), like search\n// parser in SPO, will result in non-accurate results due to presence of catch up blobs.\n// 4. Ordering service used 250ms timeout to coalesce non-immediate noops. It was changed to 2000 ms to allow more\n// aggressive noop sending from client side.\n// 5. Number of ops sent by all clients is proportional to number of \"write\" clients (every client sends noops),\n// but number of sequenced noops is a function of time (one op per 2 seconds at most).\n// We should consider impact to both outbound traffic (might be huge, depends on number of clients) and file size.\n// Please also see Issue #5629 for more discussions.\n//\n// With that, the current algorithm is as follows:\n// 1. Sent noop 2000 ms of receiving an op if no ops were sent by this client within this timeframe.\n// This will ensure that MSN moves forward with reasonable speed. If that results in too many sequenced noops,\n// server timeout of 2000ms should be reconsidered to be increased.\n// 2. If there are more than 50 ops received without sending any ops, send noop to keep collab window small.\n// Note that system ops (including noops themselves) are excluded, so it's 1 noop per 50 real ops.\nexport class CollabWindowTracker {\n private opsCountSinceNoop = 0;\n private readonly timer: Timer | undefined;\n\n constructor(\n private readonly submit: (type: MessageType) => void,\n NoopTimeFrequency: number = defaultNoopTimeFrequency,\n private readonly NoopCountFrequency: number = defaultNoopCountFrequency,\n ) {\n if (NoopTimeFrequency !== Infinity) {\n this.timer = new Timer(NoopTimeFrequency, () => {\n // Can get here due to this.stopSequenceNumberUpdate() not resetting timer.\n // Also timer callback can fire even after timer cancellation if it was queued before cancellation.\n if (this.opsCountSinceNoop !== 0) {\n this.submitNoop(false /* immediate */);\n }\n });\n }\n }\n\n /**\n * Schedules as ack to the server to update the reference sequence number\n */\n public scheduleSequenceNumberUpdate(message: ISequencedDocumentMessage, immediateNoOp: boolean): void {\n // While processing a message, an immediate no-op can be requested.\n // i.e. to expedite approve or commit phase of quorum.\n if (immediateNoOp) {\n this.submitNoop(true /* immediate */);\n return;\n }\n\n // We don't acknowledge no-ops to avoid acknowledgement cycles (i.e. ack the MSN\n // update, which updates the MSN, then ack the update, etc...).\n // Intent here is for runtime (and DDSes) not to keep too much tracking state / memory\n // due to runtime ops from other clients.\n if (!isRuntimeMessage(message)) {\n return;\n }\n\n this.opsCountSinceNoop++;\n if (this.opsCountSinceNoop === this.NoopCountFrequency) {\n // Ensure we only send noop after a batch of many ops is processed\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n Promise.resolve().then(() => {\n if (this.opsCountSinceNoop >= this.NoopCountFrequency) {\n this.submitNoop(false /* immediate */);\n // reset count now that all ops are processed\n this.opsCountSinceNoop = 0;\n }\n return;\n });\n }\n\n if (this.timer !== undefined) {\n if (this.opsCountSinceNoop === 1) {\n this.timer.restart();\n }\n\n assert(this.timer.hasTimer, 0x242 /* \"has timer\" */);\n }\n }\n\n private submitNoop(immediate: boolean) {\n // Anything other than null is immediate noop\n // ADO:1385: Remove cast and use MessageType once definition changes propagate\n this.submit(immediate ? (MessageType2.Accept as unknown as MessageType) : MessageType.NoOp);\n assert(this.opsCountSinceNoop === 0,\n 0x243 /* \"stopSequenceNumberUpdate should be called as result of sending any op!\" */);\n }\n\n public stopSequenceNumberUpdate(): void {\n this.opsCountSinceNoop = 0;\n // Ideally, we cancel timer here. But that will result in too often set/reset cycle if this client\n // keeps sending ops. In most cases it's actually better to let it expire (at most - 4 times per second)\n // for nothing, then have a ton of set/reset cycles.\n // Note that Timer.restart() is smart and will not change timer expiration if we keep extending timer\n // expiration - it will restart the timer instead when it fires with adjusted expiration.\n // this.timer.clear();\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"connectionManager.d.ts","sourceRoot":"","sources":["../src/connectionManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAEH,gBAAgB,EAChB,oBAAoB,EACvB,MAAM,oCAAoC,CAAC;AAE5C,OAAO,EACH,WAAW,EACX,YAAY,EAEZ,uBAAuB,EAC1B,MAAM,uCAAuC,CAAC;AAE/C,OAAO,EACH,gBAAgB,EAGnB,MAAM,oCAAoC,CAAC;AAY5C,OAAO,EACH,cAAc,EACd,OAAO,EACP,oBAAoB,EACpB,cAAc,EACd,gBAAgB,EAGhB,yBAAyB,EAO5B,MAAM,sCAAsC,CAAC;AAK9C,OAAO,EACH,aAAa,EACb,kBAAkB,EACl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IAYlD;;;;;;;;;;;;;;;;OAgBG;IACI,aAAa,CAAC,QAAQ,EAAE,OAAO;IAoCtC,OAAO,CAAC,uBAAuB;IAQxB,OAAO,CAAC,cAAc,CAAC,EAAE,cAAc;YAOhC,WAAW;IAyIzB;;;;OAIG;IACH,OAAO,CAAC,cAAc;IActB;;;;OAIG;IACH,OAAO,CAAC,yBAAyB;IAqCjC;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAQxB;;;;OAIG;IACH,OAAO,CAAC,4BAA4B;IAwHpC;;;;;;OAMG;IACH,OAAO,CAAC,gBAAgB;IAWxB;;;;;;OAMG;YACW,SAAS;IA2ChB,oBAAoB,CAAC,OAAO,EAAE,IAAI,CAAC,gBAAgB,EAAE,sBAAsB,CAAC,GAAG,gBAAgB,GAAG,SAAS;IAmC3G,YAAY,CAAC,OAAO,EAAE,GAAG;IAQzB,YAAY,CAAC,QAAQ,EAAE,gBAAgB,EAAE;IA4BzC,0BAA0B,CAAC,OAAO,EAAE,yBAAyB;IAuCpE,OAAO,CAAC,QAAQ,CAAC,SAAS,CAGxB;IAGF,OAAO,CAAC,QAAQ,CAAC,WAAW,CAmB1B;IAGF,OAAO,CAAC,QAAQ,CAAC,yBAAyB,CAOxC;IAEF,OAAO,CAAC,QAAQ,CAAC,YAAY,CAK3B;CACL"}
@@ -16,6 +16,7 @@ const protocol_definitions_1 = require("@fluidframework/protocol-definitions");
16
16
  const telemetry_utils_1 = require("@fluidframework/telemetry-utils");
17
17
  const contracts_1 = require("./contracts");
18
18
  const deltaQueue_1 = require("./deltaQueue");
19
+ const protocol_1 = require("./protocol");
19
20
  const MaxReconnectDelayInMs = 8000;
20
21
  const InitialReconnectDelayInMs = 1000;
21
22
  const DefaultChunkSize = 16 * 1024;
@@ -30,10 +31,18 @@ function getNackReconnectInfo(nackContent) {
30
31
  * Implementation of IDocumentDeltaConnection that does not support submitting
31
32
  * or receiving ops. Used in storage-only mode.
32
33
  */
34
+ const clientNoDeltaStream = {
35
+ mode: "read",
36
+ details: { capabilities: { interactive: true } },
37
+ permission: [],
38
+ user: { id: "storage-only client" },
39
+ scopes: [],
40
+ };
41
+ const clientIdNoDeltaStream = "storage-only client";
33
42
  class NoDeltaStream extends common_utils_1.TypedEventEmitter {
34
43
  constructor() {
35
44
  super(...arguments);
36
- this.clientId = "storage-only client";
45
+ this.clientId = clientIdNoDeltaStream;
37
46
  this.claims = {
38
47
  scopes: [protocol_definitions_1.ScopeType.DocRead],
39
48
  };
@@ -43,7 +52,7 @@ class NoDeltaStream extends common_utils_1.TypedEventEmitter {
43
52
  this.version = "";
44
53
  this.initialMessages = [];
45
54
  this.initialSignals = [];
46
- this.initialClients = [];
55
+ this.initialClients = [{ client: clientNoDeltaStream, clientId: clientIdNoDeltaStream }];
47
56
  this.serviceConfiguration = {
48
57
  maxMessageSize: 0,
49
58
  blockSize: 0,
@@ -437,7 +446,12 @@ class ConnectionManager {
437
446
  * @param args - The connection arguments
438
447
  */
439
448
  triggerConnect(connectionMode) {
440
- (0, common_utils_1.assert)(this.connection === undefined, 0x239 /* "called only in disconnected state" */);
449
+ // reconnect() has async await of waitForConnectedState(), and that causes potential race conditions
450
+ // where we might already have a connection. If it were to happen, it's possible that we will connect
451
+ // with different mode to `connectionMode`. Glancing through the caller chains, it looks like code should be
452
+ // fine (if needed, reconnect flow will get triggered again). Places where new mode matters should encode it
453
+ // directly in connectCore - see this.shouldJoinWrite() test as an example.
454
+ // assert(this.connection === undefined, 0x239 /* "called only in disconnected state" */);
441
455
  if (this.reconnectMode !== contracts_1.ReconnectMode.Enabled) {
442
456
  return;
443
457
  }
@@ -491,6 +505,7 @@ class ConnectionManager {
491
505
  * @param connection - The newly established connection
492
506
  */
493
507
  setupNewSuccessfulConnection(connection, requestedMode) {
508
+ var _a;
494
509
  // Old connection should have been cleaned up before establishing a new one
495
510
  (0, common_utils_1.assert)(this.connection === undefined, 0x0e6 /* "old connection exists on new connection setup" */);
496
511
  (0, common_utils_1.assert)(!connection.disposed, 0x28a /* "can't be disposed - Callers need to ensure that!" */);
@@ -500,6 +515,9 @@ class ConnectionManager {
500
515
  // If we asked for "write" and got "read", then file is read-only
501
516
  // But if we ask read, server can still give us write.
502
517
  const readonly = !connection.claims.scopes.includes(protocol_definitions_1.ScopeType.DocWrite);
518
+ if (connection.mode !== requestedMode) {
519
+ this.logger.sendTelemetryEvent({ eventName: "ConnectionModeMismatch", requestedMode, mode: connection.mode });
520
+ }
503
521
  // This connection mode validation logic is moving to the driver layer in 0.44. These two asserts can be
504
522
  // removed after those packages have released and become ubiquitous.
505
523
  (0, common_utils_1.assert)(requestedMode === "read" || readonly === (this.connectionMode === "read"), 0x0e7 /* "claims/connectionMode mismatch" */);
@@ -549,15 +567,39 @@ class ConnectionManager {
549
567
  }
550
568
  }
551
569
  this.props.incomingOpHandler(initialMessages, this.connectFirstConnection ? "InitialOps" : "ReconnectOps");
570
+ const details = ConnectionManager.detailsFromConnection(connection);
571
+ details.checkpointSequenceNumber = checkpointSequenceNumber;
572
+ this.props.connectHandler(details);
573
+ this.connectFirstConnection = false;
574
+ // Synthesize clear & join signals out of initialClients state.
575
+ // This allows us to have single way to process signals, and makes it simpler to initialize
576
+ // protocol in Container.
577
+ const clearSignal = {
578
+ clientId: null,
579
+ content: JSON.stringify({
580
+ type: protocol_1.SignalType.Clear,
581
+ }),
582
+ };
583
+ this.props.signalHandler(clearSignal);
584
+ for (const priorClient of (_a = connection.initialClients) !== null && _a !== void 0 ? _a : []) {
585
+ const joinSignal = {
586
+ clientId: null,
587
+ content: JSON.stringify({
588
+ type: protocol_1.SignalType.ClientJoin,
589
+ content: priorClient, // ISignalClient
590
+ }),
591
+ };
592
+ this.props.signalHandler(joinSignal);
593
+ }
594
+ // Unfortunately, there is no defined order between initialSignals (including join & leave signals)
595
+ // and connection.initialClients. In practice, connection.initialSignals quite often contains join signal
596
+ // for "self" and connection.initialClients does not contain "self", so we have to process them after
597
+ // "clear" signal above.
552
598
  if (connection.initialSignals !== undefined) {
553
599
  for (const signal of connection.initialSignals) {
554
600
  this.props.signalHandler(signal);
555
601
  }
556
602
  }
557
- const details = ConnectionManager.detailsFromConnection(connection);
558
- details.checkpointSequenceNumber = checkpointSequenceNumber;
559
- this.props.connectHandler(details);
560
- this.connectFirstConnection = false;
561
603
  }
562
604
  /**
563
605
  * Disconnect the current connection and reconnect. Closes the container if it fails.