@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.
Files changed (30) hide show
  1. package/dist/hocuspocus-provider.cjs +23 -18
  2. package/dist/hocuspocus-provider.cjs.map +1 -1
  3. package/dist/hocuspocus-provider.esm.js +23 -18
  4. package/dist/hocuspocus-provider.esm.js.map +1 -1
  5. package/dist/packages/extension-database/src/Database.d.ts +3 -5
  6. package/dist/packages/extension-monitor/src/Collector.d.ts +2 -3
  7. package/dist/packages/extension-redis/src/Redis.d.ts +91 -9
  8. package/dist/packages/extension-redis/src/index.d.ts +0 -1
  9. package/dist/packages/provider/src/HocuspocusProvider.d.ts +15 -21
  10. package/dist/packages/provider/src/types.d.ts +33 -0
  11. package/dist/packages/server/src/Document.d.ts +1 -1
  12. package/dist/packages/server/src/Hocuspocus.d.ts +6 -2
  13. package/dist/packages/server/src/MessageReceiver.d.ts +1 -1
  14. package/dist/packages/server/src/OutgoingMessage.d.ts +1 -0
  15. package/dist/packages/server/src/index.d.ts +3 -4
  16. package/dist/packages/server/src/types.d.ts +26 -7
  17. package/dist/tests/{extension-redis-rewrite/closeConnections.d.ts → extension-database/fetch.d.ts} +0 -0
  18. package/dist/tests/{extension-redis-rewrite/getConnectionCount.d.ts → extension-redis/closeConnections.d.ts} +0 -0
  19. package/dist/tests/{extension-redis-rewrite/getDocumentsCount.d.ts → extension-redis/getConnectionCount.d.ts} +0 -0
  20. package/dist/tests/{extension-redis-rewrite/onAwarenessChange.d.ts → extension-redis/getDocumentsCount.d.ts} +0 -0
  21. package/dist/tests/{extension-redis-rewrite/onChange.d.ts → extension-redis/onAwarenessChange.d.ts} +0 -0
  22. package/dist/tests/{extension-redis-rewrite/onStoreDocument.d.ts → extension-redis/onChange.d.ts} +0 -0
  23. package/dist/tests/extension-redis/{onLoadDocument.d.ts → onStoreDocument.d.ts} +0 -0
  24. package/dist/tests/utils/index.d.ts +1 -0
  25. package/dist/tests/utils/randomInteger.d.ts +1 -0
  26. package/package.json +5 -5
  27. package/src/HocuspocusProvider.ts +33 -29
  28. package/src/types.ts +42 -0
  29. package/dist/packages/extension-redis/src/RedisCluster.d.ts +0 -4
  30. package/dist/tests/extension-redis/onSynced.d.ts +0 -1
@@ -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();
@@ -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);
@@ -1903,7 +1906,7 @@ class HocuspocusProvider extends EventEmitter {
1903
1906
  // Reset the status
1904
1907
  this.synced = false;
1905
1908
  this.status = exports.WebSocketStatus.Connecting;
1906
- this.emit('status', { status: 'connecting' });
1909
+ this.emit('status', { status: exports.WebSocketStatus.Connecting });
1907
1910
  // Store resolve/reject for later use
1908
1911
  this.connectionAttempt = {
1909
1912
  resolve,
@@ -1916,7 +1919,7 @@ class HocuspocusProvider extends EventEmitter {
1916
1919
  (_a = this.connectionAttempt) === null || _a === void 0 ? void 0 : _a.resolve();
1917
1920
  this.connectionAttempt = null;
1918
1921
  this.status = exports.WebSocketStatus.Connected;
1919
- this.emit('status', { status: 'connected' });
1922
+ this.emit('status', { status: exports.WebSocketStatus.Connected });
1920
1923
  this.emit('connect');
1921
1924
  }
1922
1925
  stopConnectionAttempt() {
@@ -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.connect.bind(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) {
@@ -2080,7 +2084,7 @@ class HocuspocusProvider extends EventEmitter {
2080
2084
  // update awareness (all users except local left)
2081
2085
  removeAwarenessStates(this.awareness, Array.from(this.awareness.getStates().keys()).filter(client => client !== this.document.clientID), this);
2082
2086
  this.status = exports.WebSocketStatus.Disconnected;
2083
- this.emit('status', { status: 'disconnected' });
2087
+ this.emit('status', { status: exports.WebSocketStatus.Disconnected });
2084
2088
  this.emit('disconnect', { event });
2085
2089
  }
2086
2090
  if (event.code === common.Unauthorized.code) {
@@ -2112,7 +2116,7 @@ class HocuspocusProvider extends EventEmitter {
2112
2116
  }
2113
2117
  // Let’s update the connection status.
2114
2118
  this.status = exports.WebSocketStatus.Disconnected;
2115
- this.emit('status', { status: 'disconnected' });
2119
+ this.emit('status', { status: exports.WebSocketStatus.Disconnected });
2116
2120
  this.emit('disconnect', { event });
2117
2121
  }
2118
2122
  destroy() {
@@ -2133,7 +2137,8 @@ class HocuspocusProvider extends EventEmitter {
2133
2137
  if (typeof window === 'undefined') {
2134
2138
  return;
2135
2139
  }
2136
- window.removeEventListener('online', this.connect.bind(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.broadcastChannelSubscriber.bind(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.broadcastChannelSubscriber.bind(this));
2174
+ unsubscribe(this.broadcastChannel, this.boundBroadcastChannelSubscriber);
2170
2175
  this.subscribedToBroadcastChannel = false;
2171
2176
  }
2172
2177
  }