@hocuspocus/provider 3.1.2 → 3.1.4
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 +111 -92
- package/dist/hocuspocus-provider.cjs.map +1 -1
- package/dist/hocuspocus-provider.esm.js +111 -92
- package/dist/hocuspocus-provider.esm.js.map +1 -1
- package/dist/packages/common/src/auth.d.ts +2 -2
- package/dist/packages/common/src/index.d.ts +4 -4
- package/dist/packages/extension-database/src/Database.d.ts +1 -1
- package/dist/packages/extension-database/src/index.d.ts +1 -1
- package/dist/packages/extension-logger/src/Logger.d.ts +1 -1
- package/dist/packages/extension-logger/src/index.d.ts +1 -1
- package/dist/packages/extension-redis/src/index.d.ts +1 -1
- package/dist/packages/extension-sqlite/src/SQLite.d.ts +3 -3
- package/dist/packages/extension-sqlite/src/index.d.ts +1 -1
- package/dist/packages/extension-throttle/src/index.d.ts +1 -1
- package/dist/packages/extension-webhook/src/index.d.ts +3 -3
- package/dist/packages/provider/src/HocuspocusProvider.d.ts +10 -10
- package/dist/packages/provider/src/IncomingMessage.d.ts +3 -3
- package/dist/packages/provider/src/MessageReceiver.d.ts +2 -2
- package/dist/packages/provider/src/OutgoingMessage.d.ts +2 -2
- package/dist/packages/provider/src/OutgoingMessages/AuthenticationMessage.d.ts +3 -3
- package/dist/packages/provider/src/OutgoingMessages/AwarenessMessage.d.ts +4 -4
- package/dist/packages/provider/src/OutgoingMessages/CloseMessage.d.ts +4 -4
- package/dist/packages/provider/src/OutgoingMessages/QueryAwarenessMessage.d.ts +4 -4
- package/dist/packages/provider/src/OutgoingMessages/StatelessMessage.d.ts +3 -3
- package/dist/packages/provider/src/OutgoingMessages/SyncStepOneMessage.d.ts +4 -4
- package/dist/packages/provider/src/OutgoingMessages/SyncStepTwoMessage.d.ts +4 -4
- package/dist/packages/provider/src/OutgoingMessages/UpdateMessage.d.ts +3 -3
- package/dist/packages/provider/src/index.d.ts +3 -3
- package/dist/packages/provider/src/types.d.ts +14 -14
- package/dist/packages/server/src/ClientConnection.d.ts +17 -17
- package/dist/packages/server/src/Connection.d.ts +6 -6
- package/dist/packages/server/src/DirectConnection.d.ts +3 -3
- package/dist/packages/server/src/Document.d.ts +4 -4
- package/dist/packages/server/src/Hocuspocus.d.ts +8 -8
- package/dist/packages/server/src/IncomingMessage.d.ts +3 -3
- package/dist/packages/server/src/MessageReceiver.d.ts +3 -3
- package/dist/packages/server/src/OutgoingMessage.d.ts +3 -3
- package/dist/packages/server/src/Server.d.ts +5 -5
- package/dist/packages/server/src/index.d.ts +9 -9
- package/dist/packages/server/src/types.d.ts +7 -7
- package/dist/packages/server/src/util/getParameters.d.ts +5 -5
- package/dist/packages/transformer/src/Prosemirror.d.ts +3 -3
- package/dist/packages/transformer/src/Tiptap.d.ts +3 -3
- package/dist/packages/transformer/src/index.d.ts +3 -3
- package/dist/packages/transformer/src/types.d.ts +1 -1
- package/dist/playground/frontend/app/SocketContext1.d.ts +2 -0
- package/dist/playground/frontend/app/SocketContext2.d.ts +2 -0
- package/package.json +40 -40
- package/src/EventEmitter.ts +32 -32
- package/src/HocuspocusProvider.ts +566 -498
- package/src/IncomingMessage.ts +47 -50
- package/src/MessageReceiver.ts +135 -132
- package/src/OutgoingMessage.ts +18 -14
- package/src/OutgoingMessages/AuthenticationMessage.ts +18 -16
- package/src/OutgoingMessages/AwarenessMessage.ts +38 -32
- package/src/OutgoingMessages/CloseMessage.ts +11 -11
- package/src/OutgoingMessages/QueryAwarenessMessage.ts +11 -12
- package/src/OutgoingMessages/StatelessMessage.ts +12 -12
- package/src/OutgoingMessages/SyncStepOneMessage.ts +18 -16
- package/src/OutgoingMessages/SyncStepTwoMessage.ts +18 -16
- package/src/OutgoingMessages/UpdateMessage.ts +13 -13
- package/src/index.ts +3 -3
- package/src/types.ts +69 -69
- package/dist/playground/frontend/app/SocketContext.d.ts +0 -2
|
@@ -1109,7 +1109,7 @@ class EventEmitter {
|
|
|
1109
1109
|
emit(event, ...args) {
|
|
1110
1110
|
const callbacks = this.callbacks[event];
|
|
1111
1111
|
if (callbacks) {
|
|
1112
|
-
callbacks.forEach(callback => callback.apply(this, args));
|
|
1112
|
+
callbacks.forEach((callback) => callback.apply(this, args));
|
|
1113
1113
|
}
|
|
1114
1114
|
return this;
|
|
1115
1115
|
}
|
|
@@ -1118,7 +1118,7 @@ class EventEmitter {
|
|
|
1118
1118
|
const callbacks = this.callbacks[event];
|
|
1119
1119
|
if (callbacks) {
|
|
1120
1120
|
if (fn) {
|
|
1121
|
-
this.callbacks[event] = callbacks.filter(callback => callback !== fn);
|
|
1121
|
+
this.callbacks[event] = callbacks.filter((callback) => callback !== fn);
|
|
1122
1122
|
}
|
|
1123
1123
|
else {
|
|
1124
1124
|
delete this.callbacks[event];
|
|
@@ -1196,7 +1196,7 @@ class CloseMessage extends OutgoingMessage {
|
|
|
1196
1196
|
constructor() {
|
|
1197
1197
|
super(...arguments);
|
|
1198
1198
|
this.type = MessageType.CLOSE;
|
|
1199
|
-
this.description =
|
|
1199
|
+
this.description = "Ask the server to close the connection";
|
|
1200
1200
|
}
|
|
1201
1201
|
get(args) {
|
|
1202
1202
|
writeVarString(this.encoder, args.documentName);
|
|
@@ -1693,7 +1693,7 @@ class MessageReceiver {
|
|
|
1693
1693
|
reason: readVarString(message.decoder),
|
|
1694
1694
|
// @ts-ignore
|
|
1695
1695
|
target: provider.configuration.websocketProvider.webSocket,
|
|
1696
|
-
type:
|
|
1696
|
+
type: "close",
|
|
1697
1697
|
};
|
|
1698
1698
|
provider.onClose();
|
|
1699
1699
|
provider.configuration.onClose({ event });
|
|
@@ -1703,7 +1703,8 @@ class MessageReceiver {
|
|
|
1703
1703
|
throw new Error(`Can’t apply message of unknown type: ${type}`);
|
|
1704
1704
|
}
|
|
1705
1705
|
// Reply
|
|
1706
|
-
if (message.length() > emptyMessageLength + 1) {
|
|
1706
|
+
if (message.length() > emptyMessageLength + 1) {
|
|
1707
|
+
// length of documentName (considered in emptyMessageLength plus length of yjs sync type, set in applySyncMessage)
|
|
1707
1708
|
// @ts-ignore
|
|
1708
1709
|
provider.send(OutgoingMessage, { encoder: message.encoder });
|
|
1709
1710
|
}
|
|
@@ -1759,11 +1760,11 @@ class AuthenticationMessage extends OutgoingMessage {
|
|
|
1759
1760
|
constructor() {
|
|
1760
1761
|
super(...arguments);
|
|
1761
1762
|
this.type = MessageType.Auth;
|
|
1762
|
-
this.description =
|
|
1763
|
+
this.description = "Authentication";
|
|
1763
1764
|
}
|
|
1764
1765
|
get(args) {
|
|
1765
|
-
if (typeof args.token ===
|
|
1766
|
-
throw new Error(
|
|
1766
|
+
if (typeof args.token === "undefined") {
|
|
1767
|
+
throw new Error("The authentication message requires `token` as an argument.");
|
|
1767
1768
|
}
|
|
1768
1769
|
writeVarString(this.encoder, args.documentName);
|
|
1769
1770
|
writeVarUint(this.encoder, this.type);
|
|
@@ -1776,14 +1777,14 @@ class AwarenessMessage extends OutgoingMessage {
|
|
|
1776
1777
|
constructor() {
|
|
1777
1778
|
super(...arguments);
|
|
1778
1779
|
this.type = MessageType.Awareness;
|
|
1779
|
-
this.description =
|
|
1780
|
+
this.description = "Awareness states update";
|
|
1780
1781
|
}
|
|
1781
1782
|
get(args) {
|
|
1782
|
-
if (typeof args.awareness ===
|
|
1783
|
-
throw new Error(
|
|
1783
|
+
if (typeof args.awareness === "undefined") {
|
|
1784
|
+
throw new Error("The awareness message requires awareness as an argument");
|
|
1784
1785
|
}
|
|
1785
|
-
if (typeof args.clients ===
|
|
1786
|
-
throw new Error(
|
|
1786
|
+
if (typeof args.clients === "undefined") {
|
|
1787
|
+
throw new Error("The awareness message requires clients as an argument");
|
|
1787
1788
|
}
|
|
1788
1789
|
writeVarString(this.encoder, args.documentName);
|
|
1789
1790
|
writeVarUint(this.encoder, this.type);
|
|
@@ -1803,13 +1804,13 @@ class StatelessMessage extends OutgoingMessage {
|
|
|
1803
1804
|
constructor() {
|
|
1804
1805
|
super(...arguments);
|
|
1805
1806
|
this.type = MessageType.Stateless;
|
|
1806
|
-
this.description =
|
|
1807
|
+
this.description = "A stateless message";
|
|
1807
1808
|
}
|
|
1808
1809
|
get(args) {
|
|
1809
1810
|
var _a;
|
|
1810
1811
|
writeVarString(this.encoder, args.documentName);
|
|
1811
1812
|
writeVarUint(this.encoder, this.type);
|
|
1812
|
-
writeVarString(this.encoder, (_a = args.payload) !== null && _a !== void 0 ? _a :
|
|
1813
|
+
writeVarString(this.encoder, (_a = args.payload) !== null && _a !== void 0 ? _a : "");
|
|
1813
1814
|
return this.encoder;
|
|
1814
1815
|
}
|
|
1815
1816
|
}
|
|
@@ -1818,11 +1819,11 @@ class SyncStepOneMessage extends OutgoingMessage {
|
|
|
1818
1819
|
constructor() {
|
|
1819
1820
|
super(...arguments);
|
|
1820
1821
|
this.type = MessageType.Sync;
|
|
1821
|
-
this.description =
|
|
1822
|
+
this.description = "First sync step";
|
|
1822
1823
|
}
|
|
1823
1824
|
get(args) {
|
|
1824
|
-
if (typeof args.document ===
|
|
1825
|
-
throw new Error(
|
|
1825
|
+
if (typeof args.document === "undefined") {
|
|
1826
|
+
throw new Error("The sync step one message requires document as an argument");
|
|
1826
1827
|
}
|
|
1827
1828
|
writeVarString(this.encoder, args.documentName);
|
|
1828
1829
|
writeVarUint(this.encoder, this.type);
|
|
@@ -1835,7 +1836,7 @@ class UpdateMessage extends OutgoingMessage {
|
|
|
1835
1836
|
constructor() {
|
|
1836
1837
|
super(...arguments);
|
|
1837
1838
|
this.type = MessageType.Sync;
|
|
1838
|
-
this.description =
|
|
1839
|
+
this.description = "A document update";
|
|
1839
1840
|
}
|
|
1840
1841
|
get(args) {
|
|
1841
1842
|
writeVarString(this.encoder, args.documentName);
|
|
@@ -1856,7 +1857,7 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
1856
1857
|
var _a, _b, _c;
|
|
1857
1858
|
super();
|
|
1858
1859
|
this.configuration = {
|
|
1859
|
-
name:
|
|
1860
|
+
name: "",
|
|
1860
1861
|
// @ts-ignore
|
|
1861
1862
|
document: undefined,
|
|
1862
1863
|
// @ts-ignore
|
|
@@ -1893,35 +1894,44 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
1893
1894
|
this.boundPageHide = this.pageHide.bind(this);
|
|
1894
1895
|
this.boundOnOpen = this.onOpen.bind(this);
|
|
1895
1896
|
this.boundOnClose = this.onClose.bind(this);
|
|
1896
|
-
this.forwardConnect = (e) => this.emit(
|
|
1897
|
-
this.forwardClose = (e) => this.emit(
|
|
1898
|
-
this.forwardDisconnect = (e) => this.emit(
|
|
1899
|
-
this.forwardDestroy = (e) => this.emit(
|
|
1897
|
+
this.forwardConnect = (e) => this.emit("connect", e);
|
|
1898
|
+
this.forwardClose = (e) => this.emit("close", e);
|
|
1899
|
+
this.forwardDisconnect = (e) => this.emit("disconnect", e);
|
|
1900
|
+
this.forwardDestroy = (e) => this.emit("destroy", e);
|
|
1900
1901
|
this.setConfiguration(configuration);
|
|
1901
|
-
this.configuration.document = configuration.document
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
this.
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
this.on(
|
|
1909
|
-
this.on(
|
|
1910
|
-
this.on(
|
|
1911
|
-
this.on(
|
|
1912
|
-
this.on(
|
|
1913
|
-
this.on(
|
|
1914
|
-
|
|
1915
|
-
|
|
1902
|
+
this.configuration.document = configuration.document
|
|
1903
|
+
? configuration.document
|
|
1904
|
+
: new Y.Doc();
|
|
1905
|
+
this.configuration.awareness =
|
|
1906
|
+
configuration.awareness !== undefined
|
|
1907
|
+
? configuration.awareness
|
|
1908
|
+
: new Awareness(this.document);
|
|
1909
|
+
this.on("open", this.configuration.onOpen);
|
|
1910
|
+
this.on("message", this.configuration.onMessage);
|
|
1911
|
+
this.on("outgoingMessage", this.configuration.onOutgoingMessage);
|
|
1912
|
+
this.on("synced", this.configuration.onSynced);
|
|
1913
|
+
this.on("destroy", this.configuration.onDestroy);
|
|
1914
|
+
this.on("awarenessUpdate", this.configuration.onAwarenessUpdate);
|
|
1915
|
+
this.on("awarenessChange", this.configuration.onAwarenessChange);
|
|
1916
|
+
this.on("stateless", this.configuration.onStateless);
|
|
1917
|
+
this.on("unsyncedChanges", this.configuration.onUnsyncedChanges);
|
|
1918
|
+
this.on("authenticated", this.configuration.onAuthenticated);
|
|
1919
|
+
this.on("authenticationFailed", this.configuration.onAuthenticationFailed);
|
|
1920
|
+
(_a = this.awareness) === null || _a === void 0 ? void 0 : _a.on("update", () => {
|
|
1921
|
+
this.emit("awarenessUpdate", {
|
|
1922
|
+
states: awarenessStatesToArray(this.awareness.getStates()),
|
|
1923
|
+
});
|
|
1916
1924
|
});
|
|
1917
|
-
(_b = this.awareness) === null || _b === void 0 ? void 0 : _b.on(
|
|
1918
|
-
this.emit(
|
|
1925
|
+
(_b = this.awareness) === null || _b === void 0 ? void 0 : _b.on("change", () => {
|
|
1926
|
+
this.emit("awarenessChange", {
|
|
1927
|
+
states: awarenessStatesToArray(this.awareness.getStates()),
|
|
1928
|
+
});
|
|
1919
1929
|
});
|
|
1920
|
-
this.document.on(
|
|
1921
|
-
(_c = this.awareness) === null || _c === void 0 ? void 0 : _c.on(
|
|
1930
|
+
this.document.on("update", this.boundDocumentUpdateHandler);
|
|
1931
|
+
(_c = this.awareness) === null || _c === void 0 ? void 0 : _c.on("update", this.boundAwarenessUpdateHandler);
|
|
1922
1932
|
this.registerEventListeners();
|
|
1923
|
-
if (this.configuration.forceSyncInterval
|
|
1924
|
-
|
|
1933
|
+
if (this.configuration.forceSyncInterval &&
|
|
1934
|
+
typeof this.configuration.forceSyncInterval === "number") {
|
|
1925
1935
|
this.intervals.forceSync = setInterval(this.forceSync.bind(this), this.configuration.forceSyncInterval);
|
|
1926
1936
|
}
|
|
1927
1937
|
if (this.manageSocket) {
|
|
@@ -1952,11 +1962,11 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
1952
1962
|
}
|
|
1953
1963
|
resetUnsyncedChanges() {
|
|
1954
1964
|
this.unsyncedChanges = 1;
|
|
1955
|
-
this.emit(
|
|
1965
|
+
this.emit("unsyncedChanges", { number: this.unsyncedChanges });
|
|
1956
1966
|
}
|
|
1957
1967
|
incrementUnsyncedChanges() {
|
|
1958
1968
|
this.unsyncedChanges += 1;
|
|
1959
|
-
this.emit(
|
|
1969
|
+
this.emit("unsyncedChanges", { number: this.unsyncedChanges });
|
|
1960
1970
|
}
|
|
1961
1971
|
decrementUnsyncedChanges() {
|
|
1962
1972
|
if (this.unsyncedChanges > 0) {
|
|
@@ -1965,25 +1975,31 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
1965
1975
|
if (this.unsyncedChanges === 0) {
|
|
1966
1976
|
this.synced = true;
|
|
1967
1977
|
}
|
|
1968
|
-
this.emit(
|
|
1978
|
+
this.emit("unsyncedChanges", { number: this.unsyncedChanges });
|
|
1969
1979
|
}
|
|
1970
1980
|
forceSync() {
|
|
1971
1981
|
this.resetUnsyncedChanges();
|
|
1972
|
-
this.send(SyncStepOneMessage, {
|
|
1982
|
+
this.send(SyncStepOneMessage, {
|
|
1983
|
+
document: this.document,
|
|
1984
|
+
documentName: this.configuration.name,
|
|
1985
|
+
});
|
|
1973
1986
|
}
|
|
1974
1987
|
pageHide() {
|
|
1975
1988
|
if (this.awareness) {
|
|
1976
|
-
removeAwarenessStates(this.awareness, [this.document.clientID],
|
|
1989
|
+
removeAwarenessStates(this.awareness, [this.document.clientID], "page hide");
|
|
1977
1990
|
}
|
|
1978
1991
|
}
|
|
1979
1992
|
registerEventListeners() {
|
|
1980
|
-
if (typeof window ===
|
|
1993
|
+
if (typeof window === "undefined" || !("addEventListener" in window)) {
|
|
1981
1994
|
return;
|
|
1982
1995
|
}
|
|
1983
|
-
window.addEventListener(
|
|
1996
|
+
window.addEventListener("pagehide", this.boundPageHide);
|
|
1984
1997
|
}
|
|
1985
1998
|
sendStateless(payload) {
|
|
1986
|
-
this.send(StatelessMessage, {
|
|
1999
|
+
this.send(StatelessMessage, {
|
|
2000
|
+
documentName: this.configuration.name,
|
|
2001
|
+
payload,
|
|
2002
|
+
});
|
|
1987
2003
|
}
|
|
1988
2004
|
documentUpdateHandler(update, origin) {
|
|
1989
2005
|
if (origin === this) {
|
|
@@ -2015,28 +2031,28 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
2015
2031
|
}
|
|
2016
2032
|
this.isSynced = state;
|
|
2017
2033
|
if (state) {
|
|
2018
|
-
this.emit(
|
|
2034
|
+
this.emit("synced", { state });
|
|
2019
2035
|
}
|
|
2020
2036
|
}
|
|
2021
2037
|
receiveStateless(payload) {
|
|
2022
|
-
this.emit(
|
|
2038
|
+
this.emit("stateless", { payload });
|
|
2023
2039
|
}
|
|
2024
2040
|
// not needed, but provides backward compatibility with e.g. lexical/yjs
|
|
2025
2041
|
async connect() {
|
|
2026
2042
|
if (this.manageSocket) {
|
|
2027
2043
|
return this.configuration.websocketProvider.connect();
|
|
2028
2044
|
}
|
|
2029
|
-
console.warn(
|
|
2045
|
+
console.warn("HocuspocusProvider::connect() is deprecated and does not do anything. Please connect/disconnect on the websocketProvider, or attach/deattach providers.");
|
|
2030
2046
|
}
|
|
2031
2047
|
disconnect() {
|
|
2032
2048
|
if (this.manageSocket) {
|
|
2033
2049
|
return this.configuration.websocketProvider.disconnect();
|
|
2034
2050
|
}
|
|
2035
|
-
console.warn(
|
|
2051
|
+
console.warn("HocuspocusProvider::disconnect() is deprecated and does not do anything. Please connect/disconnect on the websocketProvider, or attach/deattach providers.");
|
|
2036
2052
|
}
|
|
2037
2053
|
async onOpen(event) {
|
|
2038
2054
|
this.isAuthenticated = false;
|
|
2039
|
-
this.emit(
|
|
2055
|
+
this.emit("open", { event });
|
|
2040
2056
|
let token;
|
|
2041
2057
|
try {
|
|
2042
2058
|
token = await this.getToken();
|
|
@@ -2046,13 +2062,13 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
2046
2062
|
return;
|
|
2047
2063
|
}
|
|
2048
2064
|
this.send(AuthenticationMessage, {
|
|
2049
|
-
token: token !== null && token !== void 0 ? token :
|
|
2065
|
+
token: token !== null && token !== void 0 ? token : "",
|
|
2050
2066
|
documentName: this.configuration.name,
|
|
2051
2067
|
});
|
|
2052
2068
|
this.startSync();
|
|
2053
2069
|
}
|
|
2054
2070
|
async getToken() {
|
|
2055
|
-
if (typeof this.configuration.token ===
|
|
2071
|
+
if (typeof this.configuration.token === "function") {
|
|
2056
2072
|
const token = await this.configuration.token();
|
|
2057
2073
|
return token;
|
|
2058
2074
|
}
|
|
@@ -2060,7 +2076,10 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
2060
2076
|
}
|
|
2061
2077
|
startSync() {
|
|
2062
2078
|
this.resetUnsyncedChanges();
|
|
2063
|
-
this.send(SyncStepOneMessage, {
|
|
2079
|
+
this.send(SyncStepOneMessage, {
|
|
2080
|
+
document: this.document,
|
|
2081
|
+
documentName: this.configuration.name,
|
|
2082
|
+
});
|
|
2064
2083
|
if (this.awareness && this.awareness.getLocalState() !== null) {
|
|
2065
2084
|
this.send(AwarenessMessage, {
|
|
2066
2085
|
awareness: this.awareness,
|
|
@@ -2073,14 +2092,14 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
2073
2092
|
if (!this._isAttached)
|
|
2074
2093
|
return;
|
|
2075
2094
|
const messageSender = new MessageSender(message, args);
|
|
2076
|
-
this.emit(
|
|
2095
|
+
this.emit("outgoingMessage", { message: messageSender.message });
|
|
2077
2096
|
messageSender.send(this.configuration.websocketProvider);
|
|
2078
2097
|
}
|
|
2079
2098
|
onMessage(event) {
|
|
2080
2099
|
const message = new IncomingMessage(event.data);
|
|
2081
2100
|
const documentName = message.readVarString();
|
|
2082
2101
|
message.writeVarString(documentName);
|
|
2083
|
-
this.emit(
|
|
2102
|
+
this.emit("message", { event, message: new IncomingMessage(event.data) });
|
|
2084
2103
|
new MessageReceiver(message).apply(this, true);
|
|
2085
2104
|
}
|
|
2086
2105
|
onClose() {
|
|
@@ -2088,68 +2107,68 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
2088
2107
|
this.synced = false;
|
|
2089
2108
|
// update awareness (all users except local left)
|
|
2090
2109
|
if (this.awareness) {
|
|
2091
|
-
removeAwarenessStates(this.awareness, Array.from(this.awareness.getStates().keys()).filter(client => client !== this.document.clientID), this);
|
|
2110
|
+
removeAwarenessStates(this.awareness, Array.from(this.awareness.getStates().keys()).filter((client) => client !== this.document.clientID), this);
|
|
2092
2111
|
}
|
|
2093
2112
|
}
|
|
2094
2113
|
destroy() {
|
|
2095
|
-
this.emit(
|
|
2114
|
+
this.emit("destroy");
|
|
2096
2115
|
if (this.intervals.forceSync) {
|
|
2097
2116
|
clearInterval(this.intervals.forceSync);
|
|
2098
2117
|
}
|
|
2099
2118
|
if (this.awareness) {
|
|
2100
|
-
removeAwarenessStates(this.awareness, [this.document.clientID],
|
|
2101
|
-
this.awareness.off(
|
|
2119
|
+
removeAwarenessStates(this.awareness, [this.document.clientID], "provider destroy");
|
|
2120
|
+
this.awareness.off("update", this.boundAwarenessUpdateHandler);
|
|
2102
2121
|
this.awareness.destroy();
|
|
2103
2122
|
}
|
|
2104
|
-
this.document.off(
|
|
2123
|
+
this.document.off("update", this.boundDocumentUpdateHandler);
|
|
2105
2124
|
this.removeAllListeners();
|
|
2106
2125
|
this.detach();
|
|
2107
2126
|
if (this.manageSocket) {
|
|
2108
2127
|
this.configuration.websocketProvider.destroy();
|
|
2109
2128
|
}
|
|
2110
|
-
if (typeof window ===
|
|
2129
|
+
if (typeof window === "undefined" || !("removeEventListener" in window)) {
|
|
2111
2130
|
return;
|
|
2112
2131
|
}
|
|
2113
|
-
window.removeEventListener(
|
|
2132
|
+
window.removeEventListener("pagehide", this.boundPageHide);
|
|
2114
2133
|
}
|
|
2115
2134
|
detach() {
|
|
2116
|
-
this.configuration.websocketProvider.off(
|
|
2117
|
-
this.configuration.websocketProvider.off(
|
|
2118
|
-
this.configuration.websocketProvider.off(
|
|
2119
|
-
this.configuration.websocketProvider.off(
|
|
2120
|
-
this.configuration.websocketProvider.off(
|
|
2121
|
-
this.configuration.websocketProvider.off(
|
|
2122
|
-
this.configuration.websocketProvider.off(
|
|
2123
|
-
this.configuration.websocketProvider.off(
|
|
2124
|
-
this.configuration.websocketProvider.off(
|
|
2125
|
-
this.configuration.websocketProvider.off(
|
|
2135
|
+
this.configuration.websocketProvider.off("connect", this.configuration.onConnect);
|
|
2136
|
+
this.configuration.websocketProvider.off("connect", this.forwardConnect);
|
|
2137
|
+
this.configuration.websocketProvider.off("open", this.boundOnOpen);
|
|
2138
|
+
this.configuration.websocketProvider.off("close", this.boundOnClose);
|
|
2139
|
+
this.configuration.websocketProvider.off("close", this.configuration.onClose);
|
|
2140
|
+
this.configuration.websocketProvider.off("close", this.forwardClose);
|
|
2141
|
+
this.configuration.websocketProvider.off("disconnect", this.configuration.onDisconnect);
|
|
2142
|
+
this.configuration.websocketProvider.off("disconnect", this.forwardDisconnect);
|
|
2143
|
+
this.configuration.websocketProvider.off("destroy", this.configuration.onDestroy);
|
|
2144
|
+
this.configuration.websocketProvider.off("destroy", this.forwardDestroy);
|
|
2126
2145
|
this.configuration.websocketProvider.detach(this);
|
|
2127
2146
|
this._isAttached = false;
|
|
2128
2147
|
}
|
|
2129
2148
|
attach() {
|
|
2130
2149
|
if (this._isAttached)
|
|
2131
2150
|
return;
|
|
2132
|
-
this.configuration.websocketProvider.on(
|
|
2133
|
-
this.configuration.websocketProvider.on(
|
|
2134
|
-
this.configuration.websocketProvider.on(
|
|
2135
|
-
this.configuration.websocketProvider.on(
|
|
2136
|
-
this.configuration.websocketProvider.on(
|
|
2137
|
-
this.configuration.websocketProvider.on(
|
|
2138
|
-
this.configuration.websocketProvider.on(
|
|
2139
|
-
this.configuration.websocketProvider.on(
|
|
2140
|
-
this.configuration.websocketProvider.on(
|
|
2141
|
-
this.configuration.websocketProvider.on(
|
|
2151
|
+
this.configuration.websocketProvider.on("connect", this.configuration.onConnect);
|
|
2152
|
+
this.configuration.websocketProvider.on("connect", this.forwardConnect);
|
|
2153
|
+
this.configuration.websocketProvider.on("open", this.boundOnOpen);
|
|
2154
|
+
this.configuration.websocketProvider.on("close", this.boundOnClose);
|
|
2155
|
+
this.configuration.websocketProvider.on("close", this.configuration.onClose);
|
|
2156
|
+
this.configuration.websocketProvider.on("close", this.forwardClose);
|
|
2157
|
+
this.configuration.websocketProvider.on("disconnect", this.configuration.onDisconnect);
|
|
2158
|
+
this.configuration.websocketProvider.on("disconnect", this.forwardDisconnect);
|
|
2159
|
+
this.configuration.websocketProvider.on("destroy", this.configuration.onDestroy);
|
|
2160
|
+
this.configuration.websocketProvider.on("destroy", this.forwardDestroy);
|
|
2142
2161
|
this.configuration.websocketProvider.attach(this);
|
|
2143
2162
|
this._isAttached = true;
|
|
2144
2163
|
}
|
|
2145
2164
|
permissionDeniedHandler(reason) {
|
|
2146
|
-
this.emit(
|
|
2165
|
+
this.emit("authenticationFailed", { reason });
|
|
2147
2166
|
this.isAuthenticated = false;
|
|
2148
2167
|
}
|
|
2149
2168
|
authenticatedHandler(scope) {
|
|
2150
2169
|
this.isAuthenticated = true;
|
|
2151
2170
|
this.authorizedScope = scope;
|
|
2152
|
-
this.emit(
|
|
2171
|
+
this.emit("authenticated", { scope });
|
|
2153
2172
|
}
|
|
2154
2173
|
setAwarenessField(key, value) {
|
|
2155
2174
|
if (!this.awareness) {
|