@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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as Y from 'yjs';
|
|
2
2
|
import { retry } from '@lifeomic/attempt';
|
|
3
|
-
import { readAuthMessage, writeAuthentication, Unauthorized, Forbidden } from '@hocuspocus/common';
|
|
3
|
+
import { readAuthMessage, writeAuthentication, awarenessStatesToArray, WsReadyStates, Unauthorized, Forbidden } from '@hocuspocus/common';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Utility module to work with key-value stores.
|
|
@@ -1724,15 +1724,6 @@ class UpdateMessage extends OutgoingMessage {
|
|
|
1724
1724
|
}
|
|
1725
1725
|
}
|
|
1726
1726
|
|
|
1727
|
-
var awarenessStatesToArray = (states) => {
|
|
1728
|
-
return Array.from(states.entries()).map(([key, value]) => {
|
|
1729
|
-
return {
|
|
1730
|
-
clientId: key,
|
|
1731
|
-
...value,
|
|
1732
|
-
};
|
|
1733
|
-
});
|
|
1734
|
-
};
|
|
1735
|
-
|
|
1736
1727
|
var WebSocketStatus;
|
|
1737
1728
|
(function (WebSocketStatus) {
|
|
1738
1729
|
WebSocketStatus["Connecting"] = "connecting";
|
|
@@ -1900,6 +1891,12 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
1900
1891
|
var _a;
|
|
1901
1892
|
(_a = this.connectionAttempt) === null || _a === void 0 ? void 0 : _a.resolve();
|
|
1902
1893
|
this.connectionAttempt = null;
|
|
1894
|
+
this.status = WebSocketStatus.Connected;
|
|
1895
|
+
this.emit('status', { status: 'connected' });
|
|
1896
|
+
this.emit('connect');
|
|
1897
|
+
}
|
|
1898
|
+
stopConnectionAttempt() {
|
|
1899
|
+
this.connectionAttempt = null;
|
|
1903
1900
|
}
|
|
1904
1901
|
rejectConnectionAttempt() {
|
|
1905
1902
|
var _a;
|
|
@@ -2006,11 +2003,15 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
2006
2003
|
//
|
|
2007
2004
|
}
|
|
2008
2005
|
}
|
|
2009
|
-
onOpen(event) {
|
|
2006
|
+
async onOpen(event) {
|
|
2010
2007
|
this.emit('open', { event });
|
|
2011
|
-
if (this.
|
|
2012
|
-
this.
|
|
2008
|
+
if (this.isAuthenticationRequired) {
|
|
2009
|
+
this.send(AuthenticationMessage, {
|
|
2010
|
+
token: await this.getToken(),
|
|
2011
|
+
});
|
|
2012
|
+
return;
|
|
2013
2013
|
}
|
|
2014
|
+
this.startSync();
|
|
2014
2015
|
}
|
|
2015
2016
|
async getToken() {
|
|
2016
2017
|
if (typeof this.configuration.token === 'function') {
|
|
@@ -2019,18 +2020,6 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
2019
2020
|
}
|
|
2020
2021
|
return this.configuration.token;
|
|
2021
2022
|
}
|
|
2022
|
-
async webSocketConnectionEstablished() {
|
|
2023
|
-
this.status = WebSocketStatus.Connected;
|
|
2024
|
-
this.emit('status', { status: 'connected' });
|
|
2025
|
-
this.emit('connect');
|
|
2026
|
-
if (this.isAuthenticationRequired) {
|
|
2027
|
-
this.send(AuthenticationMessage, {
|
|
2028
|
-
token: await this.getToken(),
|
|
2029
|
-
});
|
|
2030
|
-
return;
|
|
2031
|
-
}
|
|
2032
|
-
this.startSync();
|
|
2033
|
-
}
|
|
2034
2023
|
startSync() {
|
|
2035
2024
|
this.send(SyncStepOneMessage, { document: this.document });
|
|
2036
2025
|
if (this.awareness.getLocalState() !== null) {
|
|
@@ -2041,10 +2030,11 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
2041
2030
|
}
|
|
2042
2031
|
}
|
|
2043
2032
|
send(Message, args, broadcast = false) {
|
|
2033
|
+
var _a;
|
|
2044
2034
|
if (broadcast) {
|
|
2045
2035
|
this.mux(() => { this.broadcast(Message, args); });
|
|
2046
2036
|
}
|
|
2047
|
-
if (this.
|
|
2037
|
+
if (((_a = this.webSocket) === null || _a === void 0 ? void 0 : _a.readyState) === WsReadyStates.Open) {
|
|
2048
2038
|
const messageSender = new MessageSender(Message, args);
|
|
2049
2039
|
this.emit('outgoingMessage', { message: messageSender.message });
|
|
2050
2040
|
messageSender.send(this.webSocket);
|
|
@@ -2108,10 +2098,10 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
2108
2098
|
}
|
|
2109
2099
|
clearInterval(this.intervals.connectionChecker);
|
|
2110
2100
|
removeAwarenessStates(this.awareness, [this.document.clientID], 'provider destroy');
|
|
2111
|
-
// If there is still a connection attempt outstanding then we should
|
|
2101
|
+
// If there is still a connection attempt outstanding then we should stop
|
|
2112
2102
|
// it before calling disconnect, otherwise it will be rejected in the onClose
|
|
2113
2103
|
// handler and trigger a retry
|
|
2114
|
-
this.
|
|
2104
|
+
this.stopConnectionAttempt();
|
|
2115
2105
|
this.disconnect();
|
|
2116
2106
|
this.awareness.off('update', this.awarenessUpdateHandler);
|
|
2117
2107
|
this.document.off('update', this.documentUpdateHandler);
|
|
@@ -2185,5 +2175,5 @@ class HocuspocusCloudProvider extends HocuspocusProvider {
|
|
|
2185
2175
|
}
|
|
2186
2176
|
}
|
|
2187
2177
|
|
|
2188
|
-
export { HocuspocusCloudProvider, HocuspocusProvider, MessageType, WebSocketStatus
|
|
2178
|
+
export { HocuspocusCloudProvider, HocuspocusProvider, MessageType, WebSocketStatus };
|
|
2189
2179
|
//# sourceMappingURL=hocuspocus-provider.esm.js.map
|