@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
|
@@ -1816,6 +1816,9 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
1816
1816
|
connectionChecker: null,
|
|
1817
1817
|
};
|
|
1818
1818
|
this.connectionAttempt = null;
|
|
1819
|
+
this.boundConnect = this.connect.bind(this);
|
|
1820
|
+
this.boundBeforeUnload = this.beforeUnload.bind(this);
|
|
1821
|
+
this.boundBroadcastChannelSubscriber = this.broadcastChannelSubscriber.bind(this);
|
|
1819
1822
|
this.setConfiguration(configuration);
|
|
1820
1823
|
this.configuration.document = configuration.document ? configuration.document : new Y__namespace.Doc();
|
|
1821
1824
|
this.configuration.awareness = configuration.awareness ? configuration.awareness : new Awareness(this.document);
|
|
@@ -1957,14 +1960,15 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
1957
1960
|
}
|
|
1958
1961
|
this.send(SyncStepOneMessage, { document: this.document });
|
|
1959
1962
|
}
|
|
1963
|
+
beforeUnload() {
|
|
1964
|
+
removeAwarenessStates(this.awareness, [this.document.clientID], 'window unload');
|
|
1965
|
+
}
|
|
1960
1966
|
registerEventListeners() {
|
|
1961
1967
|
if (typeof window === 'undefined') {
|
|
1962
1968
|
return;
|
|
1963
1969
|
}
|
|
1964
|
-
window.addEventListener('online', this.
|
|
1965
|
-
window.addEventListener('beforeunload',
|
|
1966
|
-
removeAwarenessStates(this.awareness, [this.document.clientID], 'window unload');
|
|
1967
|
-
});
|
|
1970
|
+
window.addEventListener('online', this.boundConnect);
|
|
1971
|
+
window.addEventListener('beforeunload', this.boundBeforeUnload);
|
|
1968
1972
|
}
|
|
1969
1973
|
documentUpdateHandler(update, origin) {
|
|
1970
1974
|
if (origin === this) {
|
|
@@ -2133,7 +2137,8 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
2133
2137
|
if (typeof window === 'undefined') {
|
|
2134
2138
|
return;
|
|
2135
2139
|
}
|
|
2136
|
-
window.removeEventListener('online', this.
|
|
2140
|
+
window.removeEventListener('online', this.boundConnect);
|
|
2141
|
+
window.removeEventListener('beforeunload', this.boundBeforeUnload);
|
|
2137
2142
|
}
|
|
2138
2143
|
get broadcastChannel() {
|
|
2139
2144
|
return `${this.serverUrl}/${this.configuration.name}`;
|
|
@@ -2148,7 +2153,7 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
2148
2153
|
}
|
|
2149
2154
|
subscribeToBroadcastChannel() {
|
|
2150
2155
|
if (!this.subscribedToBroadcastChannel) {
|
|
2151
|
-
subscribe(this.broadcastChannel, this.
|
|
2156
|
+
subscribe(this.broadcastChannel, this.boundBroadcastChannelSubscriber);
|
|
2152
2157
|
this.subscribedToBroadcastChannel = true;
|
|
2153
2158
|
}
|
|
2154
2159
|
this.mux(() => {
|
|
@@ -2166,7 +2171,7 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
2166
2171
|
states: new Map(),
|
|
2167
2172
|
}, true);
|
|
2168
2173
|
if (this.subscribedToBroadcastChannel) {
|
|
2169
|
-
unsubscribe(this.broadcastChannel, this.
|
|
2174
|
+
unsubscribe(this.broadcastChannel, this.boundBroadcastChannelSubscriber);
|
|
2170
2175
|
this.subscribedToBroadcastChannel = false;
|
|
2171
2176
|
}
|
|
2172
2177
|
}
|