@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.
@@ -1522,6 +1522,7 @@ var MessageType;
1522
1522
  MessageType[MessageType["Auth"] = 2] = "Auth";
1523
1523
  MessageType[MessageType["QueryAwareness"] = 3] = "QueryAwareness";
1524
1524
  MessageType[MessageType["Stateless"] = 5] = "Stateless";
1525
+ MessageType[MessageType["CLOSE"] = 7] = "CLOSE";
1525
1526
  })(MessageType || (MessageType = {}));
1526
1527
  var WebSocketStatus;
1527
1528
  (function (WebSocketStatus) {
@@ -1756,6 +1757,19 @@ class StatelessMessage extends OutgoingMessage {
1756
1757
  }
1757
1758
  }
1758
1759
 
1760
+ class CloseMessage extends OutgoingMessage {
1761
+ constructor() {
1762
+ super(...arguments);
1763
+ this.type = MessageType.CLOSE;
1764
+ this.description = 'Ask the server to close the connection';
1765
+ }
1766
+ get(args) {
1767
+ writeVarString(this.encoder, args.documentName);
1768
+ writeVarUint(this.encoder, this.type);
1769
+ return this.encoder;
1770
+ }
1771
+ }
1772
+
1759
1773
  class HocuspocusProvider extends EventEmitter {
1760
1774
  constructor(configuration) {
1761
1775
  super();
@@ -1900,6 +1914,10 @@ class HocuspocusProvider extends EventEmitter {
1900
1914
  get isAuthenticationRequired() {
1901
1915
  return !!this.configuration.token && !this.isAuthenticated;
1902
1916
  }
1917
+ // not needed, but provides backward compatibility with e.g. lexicla/yjs
1918
+ async connect() {
1919
+ return this.configuration.websocketProvider.connect();
1920
+ }
1903
1921
  disconnect() {
1904
1922
  this.disconnectBroadcastChannel();
1905
1923
  this.configuration.websocketProvider.detach(this);
@@ -1911,7 +1929,6 @@ class HocuspocusProvider extends EventEmitter {
1911
1929
  token: await this.getToken(),
1912
1930
  documentName: this.configuration.name,
1913
1931
  });
1914
- return;
1915
1932
  }
1916
1933
  this.startSync();
1917
1934
  }
@@ -1966,6 +1983,7 @@ class HocuspocusProvider extends EventEmitter {
1966
1983
  this.awareness.off('update', this.awarenessUpdateHandler);
1967
1984
  this.document.off('update', this.documentUpdateHandler);
1968
1985
  this.removeAllListeners();
1986
+ this.send(CloseMessage, { documentName: this.configuration.name });
1969
1987
  if (typeof window === 'undefined') {
1970
1988
  return;
1971
1989
  }