@hocuspocus/provider 1.0.2 → 1.1.1

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.
@@ -1528,6 +1528,7 @@ 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["Stateless"] = 5] = "Stateless";
1531
1532
  })(MessageType || (MessageType = {}));
1532
1533
  var WebSocketStatus;
1533
1534
  (function (WebSocketStatus) {
@@ -1573,6 +1574,9 @@ class MessageReceiver {
1573
1574
  case MessageType.QueryAwareness:
1574
1575
  this.applyQueryAwarenessMessage(provider);
1575
1576
  break;
1577
+ case MessageType.Stateless:
1578
+ provider.receiveStateless(readVarString(message.decoder));
1579
+ break;
1576
1580
  default:
1577
1581
  throw new Error(`Can’t apply message of unknown type: ${type}`);
1578
1582
  }
@@ -1735,6 +1739,20 @@ class UpdateMessage extends OutgoingMessage {
1735
1739
  }
1736
1740
  }
1737
1741
 
1742
+ class StatelessMessage extends OutgoingMessage {
1743
+ constructor() {
1744
+ super(...arguments);
1745
+ this.type = MessageType.Stateless;
1746
+ this.description = 'A stateless message';
1747
+ }
1748
+ get(args) {
1749
+ var _a;
1750
+ writeVarUint(this.encoder, this.type);
1751
+ writeVarString(this.encoder, (_a = args.payload) !== null && _a !== void 0 ? _a : '');
1752
+ return this.encoder;
1753
+ }
1754
+ }
1755
+
1738
1756
  class HocuspocusProvider extends EventEmitter {
1739
1757
  constructor(configuration) {
1740
1758
  super();
@@ -1782,6 +1800,7 @@ class HocuspocusProvider extends EventEmitter {
1782
1800
  onDestroy: () => null,
1783
1801
  onAwarenessUpdate: () => null,
1784
1802
  onAwarenessChange: () => null,
1803
+ onStateless: () => null,
1785
1804
  quiet: false,
1786
1805
  };
1787
1806
  this.subscribedToBroadcastChannel = false;
@@ -1818,6 +1837,7 @@ class HocuspocusProvider extends EventEmitter {
1818
1837
  this.on('destroy', this.configuration.onDestroy);
1819
1838
  this.on('awarenessUpdate', this.configuration.onAwarenessUpdate);
1820
1839
  this.on('awarenessChange', this.configuration.onAwarenessChange);
1840
+ this.on('stateless', this.configuration.onStateless);
1821
1841
  this.awareness.on('update', () => {
1822
1842
  this.emit('awarenessUpdate', { states: awarenessStatesToArray(this.awareness.getStates()) });
1823
1843
  });
@@ -1974,6 +1994,9 @@ class HocuspocusProvider extends EventEmitter {
1974
1994
  window.addEventListener('online', this.boundConnect);
1975
1995
  window.addEventListener('beforeunload', this.boundBeforeUnload);
1976
1996
  }
1997
+ sendStateless(payload) {
1998
+ this.send(StatelessMessage, { payload });
1999
+ }
1977
2000
  documentUpdateHandler(update, origin) {
1978
2001
  if (origin === this) {
1979
2002
  return;
@@ -2020,6 +2043,9 @@ class HocuspocusProvider extends EventEmitter {
2020
2043
  this.emit('synced', { state });
2021
2044
  this.emit('sync', { state });
2022
2045
  }
2046
+ receiveStateless(payload) {
2047
+ this.emit('stateless', { payload });
2048
+ }
2023
2049
  get isAuthenticationRequired() {
2024
2050
  return !!this.configuration.token && !this.isAuthenticated;
2025
2051
  }