@hocuspocus/provider 2.0.0-alpha.0 → 2.0.0-alpha.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.
@@ -1546,6 +1546,7 @@ exports.MessageType = void 0;
1546
1546
  MessageType[MessageType["Auth"] = 2] = "Auth";
1547
1547
  MessageType[MessageType["QueryAwareness"] = 3] = "QueryAwareness";
1548
1548
  MessageType[MessageType["Stateless"] = 5] = "Stateless";
1549
+ MessageType[MessageType["CLOSE"] = 7] = "CLOSE";
1549
1550
  })(exports.MessageType || (exports.MessageType = {}));
1550
1551
  exports.WebSocketStatus = void 0;
1551
1552
  (function (WebSocketStatus) {
@@ -1780,6 +1781,19 @@ class StatelessMessage extends OutgoingMessage {
1780
1781
  }
1781
1782
  }
1782
1783
 
1784
+ class CloseMessage extends OutgoingMessage {
1785
+ constructor() {
1786
+ super(...arguments);
1787
+ this.type = exports.MessageType.CLOSE;
1788
+ this.description = 'Ask the server to close the connection';
1789
+ }
1790
+ get(args) {
1791
+ writeVarString(this.encoder, args.documentName);
1792
+ writeVarUint(this.encoder, this.type);
1793
+ return this.encoder;
1794
+ }
1795
+ }
1796
+
1783
1797
  class HocuspocusProvider extends EventEmitter {
1784
1798
  constructor(configuration) {
1785
1799
  super();
@@ -1924,6 +1938,10 @@ class HocuspocusProvider extends EventEmitter {
1924
1938
  get isAuthenticationRequired() {
1925
1939
  return !!this.configuration.token && !this.isAuthenticated;
1926
1940
  }
1941
+ // not needed, but provides backward compatibility with e.g. lexicla/yjs
1942
+ async connect() {
1943
+ return this.configuration.websocketProvider.connect();
1944
+ }
1927
1945
  disconnect() {
1928
1946
  this.disconnectBroadcastChannel();
1929
1947
  this.configuration.websocketProvider.detach(this);
@@ -1935,7 +1953,6 @@ class HocuspocusProvider extends EventEmitter {
1935
1953
  token: await this.getToken(),
1936
1954
  documentName: this.configuration.name,
1937
1955
  });
1938
- return;
1939
1956
  }
1940
1957
  this.startSync();
1941
1958
  }
@@ -1990,6 +2007,7 @@ class HocuspocusProvider extends EventEmitter {
1990
2007
  this.awareness.off('update', this.awarenessUpdateHandler);
1991
2008
  this.document.off('update', this.documentUpdateHandler);
1992
2009
  this.removeAllListeners();
2010
+ this.send(CloseMessage, { documentName: this.configuration.name });
1993
2011
  if (typeof window === 'undefined') {
1994
2012
  return;
1995
2013
  }