@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
|
@@ -1886,27 +1886,36 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
1886
1886
|
setOptions(options = {}) {
|
|
1887
1887
|
this.options = { ...this.options, ...options };
|
|
1888
1888
|
}
|
|
1889
|
-
connect() {
|
|
1889
|
+
async connect() {
|
|
1890
1890
|
if (this.status === exports.WebSocketStatus.Connected) {
|
|
1891
1891
|
return;
|
|
1892
1892
|
}
|
|
1893
1893
|
this.shouldConnect = true;
|
|
1894
1894
|
this.subscribeToBroadcastChannel();
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1895
|
+
try {
|
|
1896
|
+
await attempt.retry(this.createWebSocketConnection.bind(this), {
|
|
1897
|
+
delay: this.options.delay,
|
|
1898
|
+
initialDelay: this.options.initialDelay,
|
|
1899
|
+
factor: this.options.factor,
|
|
1900
|
+
maxAttempts: this.options.maxAttempts,
|
|
1901
|
+
minDelay: this.options.minDelay,
|
|
1902
|
+
maxDelay: this.options.maxDelay,
|
|
1903
|
+
jitter: this.options.jitter,
|
|
1904
|
+
timeout: this.options.timeout,
|
|
1905
|
+
beforeAttempt: context => {
|
|
1906
|
+
if (!this.shouldConnect) {
|
|
1907
|
+
context.abort();
|
|
1908
|
+
}
|
|
1909
|
+
},
|
|
1910
|
+
});
|
|
1911
|
+
}
|
|
1912
|
+
catch (err) {
|
|
1913
|
+
// If we aborted the connection attempt then don't throw an error
|
|
1914
|
+
// ref: https://github.com/lifeomic/attempt/blob/master/src/index.ts#L136
|
|
1915
|
+
if (err.code !== 'ATTEMPT_ABORTED') {
|
|
1916
|
+
throw err;
|
|
1917
|
+
}
|
|
1918
|
+
}
|
|
1910
1919
|
}
|
|
1911
1920
|
createWebSocketConnection() {
|
|
1912
1921
|
return new Promise((resolve, reject) => {
|
|
@@ -2128,8 +2137,12 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
2128
2137
|
clearInterval(this.intervals.forceSync);
|
|
2129
2138
|
}
|
|
2130
2139
|
clearInterval(this.intervals.connectionChecker);
|
|
2131
|
-
this.disconnect();
|
|
2132
2140
|
removeAwarenessStates(this.awareness, [this.document.clientID], 'provider destroy');
|
|
2141
|
+
// If there is still a connection attempt outstanding then we should resolve
|
|
2142
|
+
// it before calling disconnect, otherwise it will be rejected in the onClose
|
|
2143
|
+
// handler and trigger a retry
|
|
2144
|
+
this.resolveConnectionAttempt();
|
|
2145
|
+
this.disconnect();
|
|
2133
2146
|
this.awareness.off('update', this.awarenessUpdateHandler);
|
|
2134
2147
|
this.document.off('update', this.documentUpdateHandler);
|
|
2135
2148
|
this.removeAllListeners();
|