@hocuspocus/provider 1.0.0-alpha.30 → 1.0.0-alpha.33
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 +19 -30
- package/dist/hocuspocus-provider.cjs.map +1 -1
- package/dist/hocuspocus-provider.esm.js +19 -29
- package/dist/hocuspocus-provider.esm.js.map +1 -1
- package/dist/packages/common/src/awarenessStatesToArray.d.ts +3 -0
- package/dist/packages/common/src/index.d.ts +2 -0
- package/dist/packages/common/src/types.d.ts +10 -0
- package/dist/packages/extension-monitor/src/index.d.ts +2 -2
- package/dist/packages/extension-throttle/src/index.d.ts +6 -2
- package/dist/packages/provider/src/HocuspocusProvider.d.ts +2 -2
- package/dist/packages/provider/src/index.d.ts +0 -1
- package/dist/packages/server/src/MessageReceiver.d.ts +1 -1
- package/dist/packages/server/src/types.d.ts +11 -11
- package/dist/tests/extension-throttle/configuration.d.ts +1 -0
- package/dist/tests/provider/observe.d.ts +1 -0
- package/dist/tests/provider/observeDeep.d.ts +1 -0
- package/package.json +3 -3
- package/src/HocuspocusProvider.ts +23 -24
- package/src/index.ts +0 -1
- package/dist/packages/provider/src/utils/awarenessStatesToArray.d.ts +0 -4
- package/dist/packages/provider/src/utils/index.d.ts +0 -1
- package/src/utils/awarenessStatesToArray.ts +0 -8
- package/src/utils/index.ts +0 -1
|
@@ -1748,15 +1748,6 @@ class UpdateMessage extends OutgoingMessage {
|
|
|
1748
1748
|
}
|
|
1749
1749
|
}
|
|
1750
1750
|
|
|
1751
|
-
var awarenessStatesToArray = (states) => {
|
|
1752
|
-
return Array.from(states.entries()).map(([key, value]) => {
|
|
1753
|
-
return {
|
|
1754
|
-
clientId: key,
|
|
1755
|
-
...value,
|
|
1756
|
-
};
|
|
1757
|
-
});
|
|
1758
|
-
};
|
|
1759
|
-
|
|
1760
1751
|
exports.WebSocketStatus = void 0;
|
|
1761
1752
|
(function (WebSocketStatus) {
|
|
1762
1753
|
WebSocketStatus["Connecting"] = "connecting";
|
|
@@ -1843,10 +1834,10 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
1843
1834
|
this.on('awarenessUpdate', this.configuration.onAwarenessUpdate);
|
|
1844
1835
|
this.on('awarenessChange', this.configuration.onAwarenessChange);
|
|
1845
1836
|
this.awareness.on('update', () => {
|
|
1846
|
-
this.emit('awarenessUpdate', { states: awarenessStatesToArray(this.awareness.getStates()) });
|
|
1837
|
+
this.emit('awarenessUpdate', { states: common.awarenessStatesToArray(this.awareness.getStates()) });
|
|
1847
1838
|
});
|
|
1848
1839
|
this.awareness.on('change', () => {
|
|
1849
|
-
this.emit('awarenessChange', { states: awarenessStatesToArray(this.awareness.getStates()) });
|
|
1840
|
+
this.emit('awarenessChange', { states: common.awarenessStatesToArray(this.awareness.getStates()) });
|
|
1850
1841
|
});
|
|
1851
1842
|
this.document.on('update', this.documentUpdateHandler.bind(this));
|
|
1852
1843
|
this.awareness.on('update', this.awarenessUpdateHandler.bind(this));
|
|
@@ -1924,6 +1915,12 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
1924
1915
|
var _a;
|
|
1925
1916
|
(_a = this.connectionAttempt) === null || _a === void 0 ? void 0 : _a.resolve();
|
|
1926
1917
|
this.connectionAttempt = null;
|
|
1918
|
+
this.status = exports.WebSocketStatus.Connected;
|
|
1919
|
+
this.emit('status', { status: 'connected' });
|
|
1920
|
+
this.emit('connect');
|
|
1921
|
+
}
|
|
1922
|
+
stopConnectionAttempt() {
|
|
1923
|
+
this.connectionAttempt = null;
|
|
1927
1924
|
}
|
|
1928
1925
|
rejectConnectionAttempt() {
|
|
1929
1926
|
var _a;
|
|
@@ -2030,11 +2027,15 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
2030
2027
|
//
|
|
2031
2028
|
}
|
|
2032
2029
|
}
|
|
2033
|
-
onOpen(event) {
|
|
2030
|
+
async onOpen(event) {
|
|
2034
2031
|
this.emit('open', { event });
|
|
2035
|
-
if (this.
|
|
2036
|
-
this.
|
|
2032
|
+
if (this.isAuthenticationRequired) {
|
|
2033
|
+
this.send(AuthenticationMessage, {
|
|
2034
|
+
token: await this.getToken(),
|
|
2035
|
+
});
|
|
2036
|
+
return;
|
|
2037
2037
|
}
|
|
2038
|
+
this.startSync();
|
|
2038
2039
|
}
|
|
2039
2040
|
async getToken() {
|
|
2040
2041
|
if (typeof this.configuration.token === 'function') {
|
|
@@ -2043,18 +2044,6 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
2043
2044
|
}
|
|
2044
2045
|
return this.configuration.token;
|
|
2045
2046
|
}
|
|
2046
|
-
async webSocketConnectionEstablished() {
|
|
2047
|
-
this.status = exports.WebSocketStatus.Connected;
|
|
2048
|
-
this.emit('status', { status: 'connected' });
|
|
2049
|
-
this.emit('connect');
|
|
2050
|
-
if (this.isAuthenticationRequired) {
|
|
2051
|
-
this.send(AuthenticationMessage, {
|
|
2052
|
-
token: await this.getToken(),
|
|
2053
|
-
});
|
|
2054
|
-
return;
|
|
2055
|
-
}
|
|
2056
|
-
this.startSync();
|
|
2057
|
-
}
|
|
2058
2047
|
startSync() {
|
|
2059
2048
|
this.send(SyncStepOneMessage, { document: this.document });
|
|
2060
2049
|
if (this.awareness.getLocalState() !== null) {
|
|
@@ -2065,10 +2054,11 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
2065
2054
|
}
|
|
2066
2055
|
}
|
|
2067
2056
|
send(Message, args, broadcast = false) {
|
|
2057
|
+
var _a;
|
|
2068
2058
|
if (broadcast) {
|
|
2069
2059
|
this.mux(() => { this.broadcast(Message, args); });
|
|
2070
2060
|
}
|
|
2071
|
-
if (this.
|
|
2061
|
+
if (((_a = this.webSocket) === null || _a === void 0 ? void 0 : _a.readyState) === common.WsReadyStates.Open) {
|
|
2072
2062
|
const messageSender = new MessageSender(Message, args);
|
|
2073
2063
|
this.emit('outgoingMessage', { message: messageSender.message });
|
|
2074
2064
|
messageSender.send(this.webSocket);
|
|
@@ -2132,10 +2122,10 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
2132
2122
|
}
|
|
2133
2123
|
clearInterval(this.intervals.connectionChecker);
|
|
2134
2124
|
removeAwarenessStates(this.awareness, [this.document.clientID], 'provider destroy');
|
|
2135
|
-
// If there is still a connection attempt outstanding then we should
|
|
2125
|
+
// If there is still a connection attempt outstanding then we should stop
|
|
2136
2126
|
// it before calling disconnect, otherwise it will be rejected in the onClose
|
|
2137
2127
|
// handler and trigger a retry
|
|
2138
|
-
this.
|
|
2128
|
+
this.stopConnectionAttempt();
|
|
2139
2129
|
this.disconnect();
|
|
2140
2130
|
this.awareness.off('update', this.awarenessUpdateHandler);
|
|
2141
2131
|
this.document.off('update', this.documentUpdateHandler);
|
|
@@ -2211,5 +2201,4 @@ class HocuspocusCloudProvider extends HocuspocusProvider {
|
|
|
2211
2201
|
|
|
2212
2202
|
exports.HocuspocusCloudProvider = HocuspocusCloudProvider;
|
|
2213
2203
|
exports.HocuspocusProvider = HocuspocusProvider;
|
|
2214
|
-
exports.awarenessStatesToArray = awarenessStatesToArray;
|
|
2215
2204
|
//# sourceMappingURL=hocuspocus-provider.cjs.map
|