@hocuspocus/provider 1.0.0-alpha.32 → 1.0.0-alpha.35
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 +27 -28
- package/dist/hocuspocus-provider.cjs.map +1 -1
- package/dist/hocuspocus-provider.esm.js +28 -29
- package/dist/hocuspocus-provider.esm.js.map +1 -1
- package/dist/packages/common/src/index.d.ts +1 -0
- package/dist/packages/common/src/types.d.ts +10 -0
- package/dist/packages/extension-monitor/src/Collector.d.ts +0 -2
- package/dist/packages/extension-monitor/src/index.d.ts +2 -2
- package/dist/packages/provider/src/HocuspocusProvider.d.ts +13 -23
- package/dist/packages/provider/src/types.d.ts +33 -0
- package/dist/packages/server/src/types.d.ts +0 -11
- package/package.json +5 -5
- package/src/HocuspocusProvider.ts +38 -43
- package/src/types.ts +42 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as Y from 'yjs';
|
|
2
2
|
import { retry } from '@lifeomic/attempt';
|
|
3
|
-
import { readAuthMessage, writeAuthentication, awarenessStatesToArray, 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.
|
|
@@ -1528,7 +1528,13 @@ var MessageType;
|
|
|
1528
1528
|
MessageType[MessageType["Awareness"] = 1] = "Awareness";
|
|
1529
1529
|
MessageType[MessageType["Auth"] = 2] = "Auth";
|
|
1530
1530
|
MessageType[MessageType["QueryAwareness"] = 3] = "QueryAwareness";
|
|
1531
|
-
})(MessageType || (MessageType = {}));
|
|
1531
|
+
})(MessageType || (MessageType = {}));
|
|
1532
|
+
var WebSocketStatus;
|
|
1533
|
+
(function (WebSocketStatus) {
|
|
1534
|
+
WebSocketStatus["Connecting"] = "connecting";
|
|
1535
|
+
WebSocketStatus["Connected"] = "connected";
|
|
1536
|
+
WebSocketStatus["Disconnected"] = "disconnected";
|
|
1537
|
+
})(WebSocketStatus || (WebSocketStatus = {}));
|
|
1532
1538
|
|
|
1533
1539
|
class OutgoingMessage {
|
|
1534
1540
|
constructor() {
|
|
@@ -1724,12 +1730,6 @@ class UpdateMessage extends OutgoingMessage {
|
|
|
1724
1730
|
}
|
|
1725
1731
|
}
|
|
1726
1732
|
|
|
1727
|
-
var WebSocketStatus;
|
|
1728
|
-
(function (WebSocketStatus) {
|
|
1729
|
-
WebSocketStatus["Connecting"] = "connecting";
|
|
1730
|
-
WebSocketStatus["Connected"] = "connected";
|
|
1731
|
-
WebSocketStatus["Disconnected"] = "disconnected";
|
|
1732
|
-
})(WebSocketStatus || (WebSocketStatus = {}));
|
|
1733
1733
|
class HocuspocusProvider extends EventEmitter {
|
|
1734
1734
|
constructor(configuration) {
|
|
1735
1735
|
super();
|
|
@@ -1879,7 +1879,7 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
1879
1879
|
// Reset the status
|
|
1880
1880
|
this.synced = false;
|
|
1881
1881
|
this.status = WebSocketStatus.Connecting;
|
|
1882
|
-
this.emit('status', { status:
|
|
1882
|
+
this.emit('status', { status: WebSocketStatus.Connecting });
|
|
1883
1883
|
// Store resolve/reject for later use
|
|
1884
1884
|
this.connectionAttempt = {
|
|
1885
1885
|
resolve,
|
|
@@ -1891,6 +1891,12 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
1891
1891
|
var _a;
|
|
1892
1892
|
(_a = this.connectionAttempt) === null || _a === void 0 ? void 0 : _a.resolve();
|
|
1893
1893
|
this.connectionAttempt = null;
|
|
1894
|
+
this.status = WebSocketStatus.Connected;
|
|
1895
|
+
this.emit('status', { status: WebSocketStatus.Connected });
|
|
1896
|
+
this.emit('connect');
|
|
1897
|
+
}
|
|
1898
|
+
stopConnectionAttempt() {
|
|
1899
|
+
this.connectionAttempt = null;
|
|
1894
1900
|
}
|
|
1895
1901
|
rejectConnectionAttempt() {
|
|
1896
1902
|
var _a;
|
|
@@ -1997,11 +2003,15 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
1997
2003
|
//
|
|
1998
2004
|
}
|
|
1999
2005
|
}
|
|
2000
|
-
onOpen(event) {
|
|
2006
|
+
async onOpen(event) {
|
|
2001
2007
|
this.emit('open', { event });
|
|
2002
|
-
if (this.
|
|
2003
|
-
this.
|
|
2008
|
+
if (this.isAuthenticationRequired) {
|
|
2009
|
+
this.send(AuthenticationMessage, {
|
|
2010
|
+
token: await this.getToken(),
|
|
2011
|
+
});
|
|
2012
|
+
return;
|
|
2004
2013
|
}
|
|
2014
|
+
this.startSync();
|
|
2005
2015
|
}
|
|
2006
2016
|
async getToken() {
|
|
2007
2017
|
if (typeof this.configuration.token === 'function') {
|
|
@@ -2010,18 +2020,6 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
2010
2020
|
}
|
|
2011
2021
|
return this.configuration.token;
|
|
2012
2022
|
}
|
|
2013
|
-
async webSocketConnectionEstablished() {
|
|
2014
|
-
this.status = WebSocketStatus.Connected;
|
|
2015
|
-
this.emit('status', { status: 'connected' });
|
|
2016
|
-
this.emit('connect');
|
|
2017
|
-
if (this.isAuthenticationRequired) {
|
|
2018
|
-
this.send(AuthenticationMessage, {
|
|
2019
|
-
token: await this.getToken(),
|
|
2020
|
-
});
|
|
2021
|
-
return;
|
|
2022
|
-
}
|
|
2023
|
-
this.startSync();
|
|
2024
|
-
}
|
|
2025
2023
|
startSync() {
|
|
2026
2024
|
this.send(SyncStepOneMessage, { document: this.document });
|
|
2027
2025
|
if (this.awareness.getLocalState() !== null) {
|
|
@@ -2032,10 +2030,11 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
2032
2030
|
}
|
|
2033
2031
|
}
|
|
2034
2032
|
send(Message, args, broadcast = false) {
|
|
2033
|
+
var _a;
|
|
2035
2034
|
if (broadcast) {
|
|
2036
2035
|
this.mux(() => { this.broadcast(Message, args); });
|
|
2037
2036
|
}
|
|
2038
|
-
if (this.
|
|
2037
|
+
if (((_a = this.webSocket) === null || _a === void 0 ? void 0 : _a.readyState) === WsReadyStates.Open) {
|
|
2039
2038
|
const messageSender = new MessageSender(Message, args);
|
|
2040
2039
|
this.emit('outgoingMessage', { message: messageSender.message });
|
|
2041
2040
|
messageSender.send(this.webSocket);
|
|
@@ -2057,7 +2056,7 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
2057
2056
|
// update awareness (all users except local left)
|
|
2058
2057
|
removeAwarenessStates(this.awareness, Array.from(this.awareness.getStates().keys()).filter(client => client !== this.document.clientID), this);
|
|
2059
2058
|
this.status = WebSocketStatus.Disconnected;
|
|
2060
|
-
this.emit('status', { status:
|
|
2059
|
+
this.emit('status', { status: WebSocketStatus.Disconnected });
|
|
2061
2060
|
this.emit('disconnect', { event });
|
|
2062
2061
|
}
|
|
2063
2062
|
if (event.code === Unauthorized.code) {
|
|
@@ -2089,7 +2088,7 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
2089
2088
|
}
|
|
2090
2089
|
// Let’s update the connection status.
|
|
2091
2090
|
this.status = WebSocketStatus.Disconnected;
|
|
2092
|
-
this.emit('status', { status:
|
|
2091
|
+
this.emit('status', { status: WebSocketStatus.Disconnected });
|
|
2093
2092
|
this.emit('disconnect', { event });
|
|
2094
2093
|
}
|
|
2095
2094
|
destroy() {
|
|
@@ -2099,10 +2098,10 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
2099
2098
|
}
|
|
2100
2099
|
clearInterval(this.intervals.connectionChecker);
|
|
2101
2100
|
removeAwarenessStates(this.awareness, [this.document.clientID], 'provider destroy');
|
|
2102
|
-
// If there is still a connection attempt outstanding then we should
|
|
2101
|
+
// If there is still a connection attempt outstanding then we should stop
|
|
2103
2102
|
// it before calling disconnect, otherwise it will be rejected in the onClose
|
|
2104
2103
|
// handler and trigger a retry
|
|
2105
|
-
this.
|
|
2104
|
+
this.stopConnectionAttempt();
|
|
2106
2105
|
this.disconnect();
|
|
2107
2106
|
this.awareness.off('update', this.awarenessUpdateHandler);
|
|
2108
2107
|
this.document.off('update', this.documentUpdateHandler);
|