@hocuspocus/provider 1.0.0-alpha.17 → 1.0.0-alpha.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/hocuspocus-provider.cjs +30 -17
- package/dist/hocuspocus-provider.cjs.map +1 -1
- package/dist/hocuspocus-provider.esm.js +30 -17
- package/dist/hocuspocus-provider.esm.js.map +1 -1
- package/dist/packages/provider/src/HocuspocusProvider.d.ts +1 -1
- package/package.json +2 -2
- package/src/HocuspocusProvider.ts +31 -18
|
@@ -1862,27 +1862,36 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
1862
1862
|
setOptions(options = {}) {
|
|
1863
1863
|
this.options = { ...this.options, ...options };
|
|
1864
1864
|
}
|
|
1865
|
-
connect() {
|
|
1865
|
+
async connect() {
|
|
1866
1866
|
if (this.status === WebSocketStatus.Connected) {
|
|
1867
1867
|
return;
|
|
1868
1868
|
}
|
|
1869
1869
|
this.shouldConnect = true;
|
|
1870
1870
|
this.subscribeToBroadcastChannel();
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1871
|
+
try {
|
|
1872
|
+
await retry(this.createWebSocketConnection.bind(this), {
|
|
1873
|
+
delay: this.options.delay,
|
|
1874
|
+
initialDelay: this.options.initialDelay,
|
|
1875
|
+
factor: this.options.factor,
|
|
1876
|
+
maxAttempts: this.options.maxAttempts,
|
|
1877
|
+
minDelay: this.options.minDelay,
|
|
1878
|
+
maxDelay: this.options.maxDelay,
|
|
1879
|
+
jitter: this.options.jitter,
|
|
1880
|
+
timeout: this.options.timeout,
|
|
1881
|
+
beforeAttempt: context => {
|
|
1882
|
+
if (!this.shouldConnect) {
|
|
1883
|
+
context.abort();
|
|
1884
|
+
}
|
|
1885
|
+
},
|
|
1886
|
+
});
|
|
1887
|
+
}
|
|
1888
|
+
catch (err) {
|
|
1889
|
+
// If we aborted the connection attempt then don't throw an error
|
|
1890
|
+
// ref: https://github.com/lifeomic/attempt/blob/master/src/index.ts#L136
|
|
1891
|
+
if (err.code !== 'ATTEMPT_ABORTED') {
|
|
1892
|
+
throw err;
|
|
1893
|
+
}
|
|
1894
|
+
}
|
|
1886
1895
|
}
|
|
1887
1896
|
createWebSocketConnection() {
|
|
1888
1897
|
return new Promise((resolve, reject) => {
|
|
@@ -2104,8 +2113,12 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
2104
2113
|
clearInterval(this.intervals.forceSync);
|
|
2105
2114
|
}
|
|
2106
2115
|
clearInterval(this.intervals.connectionChecker);
|
|
2107
|
-
this.disconnect();
|
|
2108
2116
|
removeAwarenessStates(this.awareness, [this.document.clientID], 'provider destroy');
|
|
2117
|
+
// If there is still a connection attempt outstanding then we should resolve
|
|
2118
|
+
// it before calling disconnect, otherwise it will be rejected in the onClose
|
|
2119
|
+
// handler and trigger a retry
|
|
2120
|
+
this.resolveConnectionAttempt();
|
|
2121
|
+
this.disconnect();
|
|
2109
2122
|
this.awareness.off('update', this.awarenessUpdateHandler);
|
|
2110
2123
|
this.document.off('update', this.documentUpdateHandler);
|
|
2111
2124
|
this.removeAllListeners();
|