@hocuspocus/provider 1.0.0-alpha.36 → 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 +12 -7
- package/dist/hocuspocus-provider.cjs.map +1 -1
- package/dist/hocuspocus-provider.esm.js +12 -7
- 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 +5 -1
- package/dist/packages/provider/src/HocuspocusProvider.d.ts +4 -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 +16 -7
|
@@ -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);
|
|
@@ -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) {
|
|
@@ -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
|
}
|