@hocuspocus/provider 1.0.0-alpha.34 → 1.0.0-alpha.37
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 +23 -18
- package/dist/hocuspocus-provider.cjs.map +1 -1
- package/dist/hocuspocus-provider.esm.js +23 -18
- package/dist/hocuspocus-provider.esm.js.map +1 -1
- package/dist/packages/extension-database/src/Database.d.ts +3 -5
- package/dist/packages/extension-monitor/src/Collector.d.ts +2 -3
- package/dist/packages/extension-redis/src/Redis.d.ts +91 -9
- package/dist/packages/extension-redis/src/index.d.ts +0 -1
- package/dist/packages/provider/src/HocuspocusProvider.d.ts +15 -21
- package/dist/packages/provider/src/types.d.ts +33 -0
- package/dist/packages/server/src/Document.d.ts +1 -1
- package/dist/packages/server/src/Hocuspocus.d.ts +6 -2
- package/dist/packages/server/src/MessageReceiver.d.ts +1 -1
- package/dist/packages/server/src/OutgoingMessage.d.ts +1 -0
- package/dist/packages/server/src/index.d.ts +3 -4
- package/dist/packages/server/src/types.d.ts +26 -7
- package/dist/tests/{extension-redis-rewrite/closeConnections.d.ts → extension-database/fetch.d.ts} +0 -0
- package/dist/tests/{extension-redis-rewrite/getConnectionCount.d.ts → extension-redis/closeConnections.d.ts} +0 -0
- package/dist/tests/{extension-redis-rewrite/getDocumentsCount.d.ts → extension-redis/getConnectionCount.d.ts} +0 -0
- package/dist/tests/{extension-redis-rewrite/onAwarenessChange.d.ts → extension-redis/getDocumentsCount.d.ts} +0 -0
- package/dist/tests/{extension-redis-rewrite/onChange.d.ts → extension-redis/onAwarenessChange.d.ts} +0 -0
- package/dist/tests/{extension-redis-rewrite/onStoreDocument.d.ts → extension-redis/onChange.d.ts} +0 -0
- package/dist/tests/extension-redis/{onLoadDocument.d.ts → onStoreDocument.d.ts} +0 -0
- package/dist/tests/utils/index.d.ts +1 -0
- package/dist/tests/utils/randomInteger.d.ts +1 -0
- package/package.json +5 -5
- package/src/HocuspocusProvider.ts +33 -29
- package/src/types.ts +42 -0
- package/dist/packages/extension-redis/src/RedisCluster.d.ts +0 -4
- package/dist/tests/extension-redis/onSynced.d.ts +0 -1
|
@@ -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();
|
|
@@ -1792,6 +1792,9 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
1792
1792
|
connectionChecker: null,
|
|
1793
1793
|
};
|
|
1794
1794
|
this.connectionAttempt = null;
|
|
1795
|
+
this.boundConnect = this.connect.bind(this);
|
|
1796
|
+
this.boundBeforeUnload = this.beforeUnload.bind(this);
|
|
1797
|
+
this.boundBroadcastChannelSubscriber = this.broadcastChannelSubscriber.bind(this);
|
|
1795
1798
|
this.setConfiguration(configuration);
|
|
1796
1799
|
this.configuration.document = configuration.document ? configuration.document : new Y.Doc();
|
|
1797
1800
|
this.configuration.awareness = configuration.awareness ? configuration.awareness : new Awareness(this.document);
|
|
@@ -1879,7 +1882,7 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
1879
1882
|
// Reset the status
|
|
1880
1883
|
this.synced = false;
|
|
1881
1884
|
this.status = WebSocketStatus.Connecting;
|
|
1882
|
-
this.emit('status', { status:
|
|
1885
|
+
this.emit('status', { status: WebSocketStatus.Connecting });
|
|
1883
1886
|
// Store resolve/reject for later use
|
|
1884
1887
|
this.connectionAttempt = {
|
|
1885
1888
|
resolve,
|
|
@@ -1892,7 +1895,7 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
1892
1895
|
(_a = this.connectionAttempt) === null || _a === void 0 ? void 0 : _a.resolve();
|
|
1893
1896
|
this.connectionAttempt = null;
|
|
1894
1897
|
this.status = WebSocketStatus.Connected;
|
|
1895
|
-
this.emit('status', { status:
|
|
1898
|
+
this.emit('status', { status: WebSocketStatus.Connected });
|
|
1896
1899
|
this.emit('connect');
|
|
1897
1900
|
}
|
|
1898
1901
|
stopConnectionAttempt() {
|
|
@@ -1933,14 +1936,15 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
1933
1936
|
}
|
|
1934
1937
|
this.send(SyncStepOneMessage, { document: this.document });
|
|
1935
1938
|
}
|
|
1939
|
+
beforeUnload() {
|
|
1940
|
+
removeAwarenessStates(this.awareness, [this.document.clientID], 'window unload');
|
|
1941
|
+
}
|
|
1936
1942
|
registerEventListeners() {
|
|
1937
1943
|
if (typeof window === 'undefined') {
|
|
1938
1944
|
return;
|
|
1939
1945
|
}
|
|
1940
|
-
window.addEventListener('online', this.
|
|
1941
|
-
window.addEventListener('beforeunload',
|
|
1942
|
-
removeAwarenessStates(this.awareness, [this.document.clientID], 'window unload');
|
|
1943
|
-
});
|
|
1946
|
+
window.addEventListener('online', this.boundConnect);
|
|
1947
|
+
window.addEventListener('beforeunload', this.boundBeforeUnload);
|
|
1944
1948
|
}
|
|
1945
1949
|
documentUpdateHandler(update, origin) {
|
|
1946
1950
|
if (origin === this) {
|
|
@@ -2056,7 +2060,7 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
2056
2060
|
// update awareness (all users except local left)
|
|
2057
2061
|
removeAwarenessStates(this.awareness, Array.from(this.awareness.getStates().keys()).filter(client => client !== this.document.clientID), this);
|
|
2058
2062
|
this.status = WebSocketStatus.Disconnected;
|
|
2059
|
-
this.emit('status', { status:
|
|
2063
|
+
this.emit('status', { status: WebSocketStatus.Disconnected });
|
|
2060
2064
|
this.emit('disconnect', { event });
|
|
2061
2065
|
}
|
|
2062
2066
|
if (event.code === Unauthorized.code) {
|
|
@@ -2088,7 +2092,7 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
2088
2092
|
}
|
|
2089
2093
|
// Let’s update the connection status.
|
|
2090
2094
|
this.status = WebSocketStatus.Disconnected;
|
|
2091
|
-
this.emit('status', { status:
|
|
2095
|
+
this.emit('status', { status: WebSocketStatus.Disconnected });
|
|
2092
2096
|
this.emit('disconnect', { event });
|
|
2093
2097
|
}
|
|
2094
2098
|
destroy() {
|
|
@@ -2109,7 +2113,8 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
2109
2113
|
if (typeof window === 'undefined') {
|
|
2110
2114
|
return;
|
|
2111
2115
|
}
|
|
2112
|
-
window.removeEventListener('online', this.
|
|
2116
|
+
window.removeEventListener('online', this.boundConnect);
|
|
2117
|
+
window.removeEventListener('beforeunload', this.boundBeforeUnload);
|
|
2113
2118
|
}
|
|
2114
2119
|
get broadcastChannel() {
|
|
2115
2120
|
return `${this.serverUrl}/${this.configuration.name}`;
|
|
@@ -2124,7 +2129,7 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
2124
2129
|
}
|
|
2125
2130
|
subscribeToBroadcastChannel() {
|
|
2126
2131
|
if (!this.subscribedToBroadcastChannel) {
|
|
2127
|
-
subscribe(this.broadcastChannel, this.
|
|
2132
|
+
subscribe(this.broadcastChannel, this.boundBroadcastChannelSubscriber);
|
|
2128
2133
|
this.subscribedToBroadcastChannel = true;
|
|
2129
2134
|
}
|
|
2130
2135
|
this.mux(() => {
|
|
@@ -2142,7 +2147,7 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
2142
2147
|
states: new Map(),
|
|
2143
2148
|
}, true);
|
|
2144
2149
|
if (this.subscribedToBroadcastChannel) {
|
|
2145
|
-
unsubscribe(this.broadcastChannel, this.
|
|
2150
|
+
unsubscribe(this.broadcastChannel, this.boundBroadcastChannelSubscriber);
|
|
2146
2151
|
this.subscribedToBroadcastChannel = false;
|
|
2147
2152
|
}
|
|
2148
2153
|
}
|