@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
|
@@ -1552,7 +1552,13 @@ exports.MessageType = void 0;
|
|
|
1552
1552
|
MessageType[MessageType["Awareness"] = 1] = "Awareness";
|
|
1553
1553
|
MessageType[MessageType["Auth"] = 2] = "Auth";
|
|
1554
1554
|
MessageType[MessageType["QueryAwareness"] = 3] = "QueryAwareness";
|
|
1555
|
-
})(exports.MessageType || (exports.MessageType = {}));
|
|
1555
|
+
})(exports.MessageType || (exports.MessageType = {}));
|
|
1556
|
+
exports.WebSocketStatus = void 0;
|
|
1557
|
+
(function (WebSocketStatus) {
|
|
1558
|
+
WebSocketStatus["Connecting"] = "connecting";
|
|
1559
|
+
WebSocketStatus["Connected"] = "connected";
|
|
1560
|
+
WebSocketStatus["Disconnected"] = "disconnected";
|
|
1561
|
+
})(exports.WebSocketStatus || (exports.WebSocketStatus = {}));
|
|
1556
1562
|
|
|
1557
1563
|
class OutgoingMessage {
|
|
1558
1564
|
constructor() {
|
|
@@ -1748,12 +1754,6 @@ class UpdateMessage extends OutgoingMessage {
|
|
|
1748
1754
|
}
|
|
1749
1755
|
}
|
|
1750
1756
|
|
|
1751
|
-
exports.WebSocketStatus = void 0;
|
|
1752
|
-
(function (WebSocketStatus) {
|
|
1753
|
-
WebSocketStatus["Connecting"] = "connecting";
|
|
1754
|
-
WebSocketStatus["Connected"] = "connected";
|
|
1755
|
-
WebSocketStatus["Disconnected"] = "disconnected";
|
|
1756
|
-
})(exports.WebSocketStatus || (exports.WebSocketStatus = {}));
|
|
1757
1757
|
class HocuspocusProvider extends EventEmitter {
|
|
1758
1758
|
constructor(configuration) {
|
|
1759
1759
|
super();
|
|
@@ -1903,7 +1903,7 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
1903
1903
|
// Reset the status
|
|
1904
1904
|
this.synced = false;
|
|
1905
1905
|
this.status = exports.WebSocketStatus.Connecting;
|
|
1906
|
-
this.emit('status', { status:
|
|
1906
|
+
this.emit('status', { status: exports.WebSocketStatus.Connecting });
|
|
1907
1907
|
// Store resolve/reject for later use
|
|
1908
1908
|
this.connectionAttempt = {
|
|
1909
1909
|
resolve,
|
|
@@ -1915,6 +1915,12 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
1915
1915
|
var _a;
|
|
1916
1916
|
(_a = this.connectionAttempt) === null || _a === void 0 ? void 0 : _a.resolve();
|
|
1917
1917
|
this.connectionAttempt = null;
|
|
1918
|
+
this.status = exports.WebSocketStatus.Connected;
|
|
1919
|
+
this.emit('status', { status: exports.WebSocketStatus.Connected });
|
|
1920
|
+
this.emit('connect');
|
|
1921
|
+
}
|
|
1922
|
+
stopConnectionAttempt() {
|
|
1923
|
+
this.connectionAttempt = null;
|
|
1918
1924
|
}
|
|
1919
1925
|
rejectConnectionAttempt() {
|
|
1920
1926
|
var _a;
|
|
@@ -2021,11 +2027,15 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
2021
2027
|
//
|
|
2022
2028
|
}
|
|
2023
2029
|
}
|
|
2024
|
-
onOpen(event) {
|
|
2030
|
+
async onOpen(event) {
|
|
2025
2031
|
this.emit('open', { event });
|
|
2026
|
-
if (this.
|
|
2027
|
-
this.
|
|
2032
|
+
if (this.isAuthenticationRequired) {
|
|
2033
|
+
this.send(AuthenticationMessage, {
|
|
2034
|
+
token: await this.getToken(),
|
|
2035
|
+
});
|
|
2036
|
+
return;
|
|
2028
2037
|
}
|
|
2038
|
+
this.startSync();
|
|
2029
2039
|
}
|
|
2030
2040
|
async getToken() {
|
|
2031
2041
|
if (typeof this.configuration.token === 'function') {
|
|
@@ -2034,18 +2044,6 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
2034
2044
|
}
|
|
2035
2045
|
return this.configuration.token;
|
|
2036
2046
|
}
|
|
2037
|
-
async webSocketConnectionEstablished() {
|
|
2038
|
-
this.status = exports.WebSocketStatus.Connected;
|
|
2039
|
-
this.emit('status', { status: 'connected' });
|
|
2040
|
-
this.emit('connect');
|
|
2041
|
-
if (this.isAuthenticationRequired) {
|
|
2042
|
-
this.send(AuthenticationMessage, {
|
|
2043
|
-
token: await this.getToken(),
|
|
2044
|
-
});
|
|
2045
|
-
return;
|
|
2046
|
-
}
|
|
2047
|
-
this.startSync();
|
|
2048
|
-
}
|
|
2049
2047
|
startSync() {
|
|
2050
2048
|
this.send(SyncStepOneMessage, { document: this.document });
|
|
2051
2049
|
if (this.awareness.getLocalState() !== null) {
|
|
@@ -2056,10 +2054,11 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
2056
2054
|
}
|
|
2057
2055
|
}
|
|
2058
2056
|
send(Message, args, broadcast = false) {
|
|
2057
|
+
var _a;
|
|
2059
2058
|
if (broadcast) {
|
|
2060
2059
|
this.mux(() => { this.broadcast(Message, args); });
|
|
2061
2060
|
}
|
|
2062
|
-
if (this.
|
|
2061
|
+
if (((_a = this.webSocket) === null || _a === void 0 ? void 0 : _a.readyState) === common.WsReadyStates.Open) {
|
|
2063
2062
|
const messageSender = new MessageSender(Message, args);
|
|
2064
2063
|
this.emit('outgoingMessage', { message: messageSender.message });
|
|
2065
2064
|
messageSender.send(this.webSocket);
|
|
@@ -2081,7 +2080,7 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
2081
2080
|
// update awareness (all users except local left)
|
|
2082
2081
|
removeAwarenessStates(this.awareness, Array.from(this.awareness.getStates().keys()).filter(client => client !== this.document.clientID), this);
|
|
2083
2082
|
this.status = exports.WebSocketStatus.Disconnected;
|
|
2084
|
-
this.emit('status', { status:
|
|
2083
|
+
this.emit('status', { status: exports.WebSocketStatus.Disconnected });
|
|
2085
2084
|
this.emit('disconnect', { event });
|
|
2086
2085
|
}
|
|
2087
2086
|
if (event.code === common.Unauthorized.code) {
|
|
@@ -2113,7 +2112,7 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
2113
2112
|
}
|
|
2114
2113
|
// Let’s update the connection status.
|
|
2115
2114
|
this.status = exports.WebSocketStatus.Disconnected;
|
|
2116
|
-
this.emit('status', { status:
|
|
2115
|
+
this.emit('status', { status: exports.WebSocketStatus.Disconnected });
|
|
2117
2116
|
this.emit('disconnect', { event });
|
|
2118
2117
|
}
|
|
2119
2118
|
destroy() {
|
|
@@ -2123,10 +2122,10 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
2123
2122
|
}
|
|
2124
2123
|
clearInterval(this.intervals.connectionChecker);
|
|
2125
2124
|
removeAwarenessStates(this.awareness, [this.document.clientID], 'provider destroy');
|
|
2126
|
-
// If there is still a connection attempt outstanding then we should
|
|
2125
|
+
// If there is still a connection attempt outstanding then we should stop
|
|
2127
2126
|
// it before calling disconnect, otherwise it will be rejected in the onClose
|
|
2128
2127
|
// handler and trigger a retry
|
|
2129
|
-
this.
|
|
2128
|
+
this.stopConnectionAttempt();
|
|
2130
2129
|
this.disconnect();
|
|
2131
2130
|
this.awareness.off('update', this.awarenessUpdateHandler);
|
|
2132
2131
|
this.document.off('update', this.documentUpdateHandler);
|