@hocuspocus/provider 1.0.0-alpha.36 → 1.0.0-alpha.39
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 +26 -10
- package/dist/hocuspocus-provider.cjs.map +1 -1
- package/dist/hocuspocus-provider.esm.js +26 -10
- package/dist/hocuspocus-provider.esm.js.map +1 -1
- package/dist/packages/extension-database/src/Database.d.ts +3 -5
- package/dist/packages/extension-redis/src/Redis.d.ts +6 -2
- package/dist/packages/provider/src/HocuspocusProvider.d.ts +6 -0
- package/dist/packages/server/src/Document.d.ts +1 -1
- package/dist/packages/server/src/Hocuspocus.d.ts +4 -0
- 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/types.d.ts +20 -2
- package/dist/tests/extension-database/fetch.d.ts +1 -0
- package/package.json +2 -2
- package/src/HocuspocusProvider.ts +26 -9
- package/src/MessageReceiver.ts +8 -2
|
@@ -1620,9 +1620,14 @@ class MessageReceiver {
|
|
|
1620
1620
|
// Apply update
|
|
1621
1621
|
const syncMessageType = readSyncMessage(message.decoder, message.encoder, provider.document, provider);
|
|
1622
1622
|
// Synced once we receive Step2
|
|
1623
|
-
if (emitSynced && syncMessageType === messageYjsSyncStep2) {
|
|
1623
|
+
if (emitSynced && (syncMessageType === messageYjsSyncStep2)) {
|
|
1624
1624
|
provider.synced = true;
|
|
1625
1625
|
}
|
|
1626
|
+
if (syncMessageType === messageYjsUpdate || syncMessageType === messageYjsSyncStep2) {
|
|
1627
|
+
if (provider.unsyncedChanges > 0) {
|
|
1628
|
+
provider.unsyncedChanges -= 1;
|
|
1629
|
+
}
|
|
1630
|
+
}
|
|
1626
1631
|
}
|
|
1627
1632
|
applyAwarenessMessage(provider) {
|
|
1628
1633
|
const { message } = this;
|
|
@@ -1808,6 +1813,7 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
1808
1813
|
this.shouldConnect = true;
|
|
1809
1814
|
this.status = exports.WebSocketStatus.Disconnected;
|
|
1810
1815
|
this.isSynced = false;
|
|
1816
|
+
this.unsyncedChanges = 0;
|
|
1811
1817
|
this.isAuthenticated = false;
|
|
1812
1818
|
this.lastMessageReceived = 0;
|
|
1813
1819
|
this.mux = createMutex();
|
|
@@ -1816,6 +1822,9 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
1816
1822
|
connectionChecker: null,
|
|
1817
1823
|
};
|
|
1818
1824
|
this.connectionAttempt = null;
|
|
1825
|
+
this.boundConnect = this.connect.bind(this);
|
|
1826
|
+
this.boundBeforeUnload = this.beforeUnload.bind(this);
|
|
1827
|
+
this.boundBroadcastChannelSubscriber = this.broadcastChannelSubscriber.bind(this);
|
|
1819
1828
|
this.setConfiguration(configuration);
|
|
1820
1829
|
this.configuration.document = configuration.document ? configuration.document : new Y__namespace.Doc();
|
|
1821
1830
|
this.configuration.awareness = configuration.awareness ? configuration.awareness : new Awareness(this.document);
|
|
@@ -1861,6 +1870,7 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
1861
1870
|
if (this.status === exports.WebSocketStatus.Connected) {
|
|
1862
1871
|
return;
|
|
1863
1872
|
}
|
|
1873
|
+
this.unsyncedChanges = 0; // set to 0 in case we got reconnected
|
|
1864
1874
|
this.shouldConnect = true;
|
|
1865
1875
|
this.subscribeToBroadcastChannel();
|
|
1866
1876
|
try {
|
|
@@ -1896,8 +1906,8 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
1896
1906
|
ws.onmessage = this.onMessage.bind(this);
|
|
1897
1907
|
ws.onclose = this.onClose.bind(this);
|
|
1898
1908
|
ws.onopen = this.onOpen.bind(this);
|
|
1899
|
-
ws.onerror = () => {
|
|
1900
|
-
reject();
|
|
1909
|
+
ws.onerror = (err) => {
|
|
1910
|
+
reject(err);
|
|
1901
1911
|
};
|
|
1902
1912
|
this.webSocket = ws;
|
|
1903
1913
|
// Reset the status
|
|
@@ -1933,6 +1943,9 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
1933
1943
|
get awareness() {
|
|
1934
1944
|
return this.configuration.awareness;
|
|
1935
1945
|
}
|
|
1946
|
+
get hasUnsyncedChanges() {
|
|
1947
|
+
return this.unsyncedChanges > 0;
|
|
1948
|
+
}
|
|
1936
1949
|
checkConnection() {
|
|
1937
1950
|
var _a;
|
|
1938
1951
|
// Don’t check the connection when it’s not even established
|
|
@@ -1957,19 +1970,21 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
1957
1970
|
}
|
|
1958
1971
|
this.send(SyncStepOneMessage, { document: this.document });
|
|
1959
1972
|
}
|
|
1973
|
+
beforeUnload() {
|
|
1974
|
+
removeAwarenessStates(this.awareness, [this.document.clientID], 'window unload');
|
|
1975
|
+
}
|
|
1960
1976
|
registerEventListeners() {
|
|
1961
1977
|
if (typeof window === 'undefined') {
|
|
1962
1978
|
return;
|
|
1963
1979
|
}
|
|
1964
|
-
window.addEventListener('online', this.
|
|
1965
|
-
window.addEventListener('beforeunload',
|
|
1966
|
-
removeAwarenessStates(this.awareness, [this.document.clientID], 'window unload');
|
|
1967
|
-
});
|
|
1980
|
+
window.addEventListener('online', this.boundConnect);
|
|
1981
|
+
window.addEventListener('beforeunload', this.boundBeforeUnload);
|
|
1968
1982
|
}
|
|
1969
1983
|
documentUpdateHandler(update, origin) {
|
|
1970
1984
|
if (origin === this) {
|
|
1971
1985
|
return;
|
|
1972
1986
|
}
|
|
1987
|
+
this.unsyncedChanges += 1;
|
|
1973
1988
|
this.send(UpdateMessage, { update }, true);
|
|
1974
1989
|
}
|
|
1975
1990
|
awarenessUpdateHandler({ added, updated, removed }, origin) {
|
|
@@ -2133,7 +2148,8 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
2133
2148
|
if (typeof window === 'undefined') {
|
|
2134
2149
|
return;
|
|
2135
2150
|
}
|
|
2136
|
-
window.removeEventListener('online', this.
|
|
2151
|
+
window.removeEventListener('online', this.boundConnect);
|
|
2152
|
+
window.removeEventListener('beforeunload', this.boundBeforeUnload);
|
|
2137
2153
|
}
|
|
2138
2154
|
get broadcastChannel() {
|
|
2139
2155
|
return `${this.serverUrl}/${this.configuration.name}`;
|
|
@@ -2148,7 +2164,7 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
2148
2164
|
}
|
|
2149
2165
|
subscribeToBroadcastChannel() {
|
|
2150
2166
|
if (!this.subscribedToBroadcastChannel) {
|
|
2151
|
-
subscribe(this.broadcastChannel, this.
|
|
2167
|
+
subscribe(this.broadcastChannel, this.boundBroadcastChannelSubscriber);
|
|
2152
2168
|
this.subscribedToBroadcastChannel = true;
|
|
2153
2169
|
}
|
|
2154
2170
|
this.mux(() => {
|
|
@@ -2166,7 +2182,7 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
2166
2182
|
states: new Map(),
|
|
2167
2183
|
}, true);
|
|
2168
2184
|
if (this.subscribedToBroadcastChannel) {
|
|
2169
|
-
unsubscribe(this.broadcastChannel, this.
|
|
2185
|
+
unsubscribe(this.broadcastChannel, this.boundBroadcastChannelSubscriber);
|
|
2170
2186
|
this.subscribedToBroadcastChannel = false;
|
|
2171
2187
|
}
|
|
2172
2188
|
}
|