@hypen-space/core 0.4.25 → 0.4.27
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/index.browser.js +21 -1
- package/dist/index.browser.js.map +3 -3
- package/dist/index.js +21 -1
- package/dist/index.js.map +3 -3
- package/dist/remote/client.d.ts +10 -0
- package/dist/remote/client.js +21 -1
- package/dist/remote/client.js.map +3 -3
- package/dist/remote/index.js +75 -5
- package/dist/remote/index.js.map +4 -4
- package/dist/remote/server.d.ts +7 -0
- package/dist/remote/server.js +55 -5
- package/dist/remote/server.js.map +3 -3
- package/dist/remote/types.d.ts +18 -1
- package/package.json +2 -1
- package/src/remote/client.ts +35 -0
- package/src/remote/server.ts +69 -3
- package/src/remote/types.ts +21 -0
- package/wasm-browser/hypen_engine_bg.wasm +0 -0
- package/wasm-browser/package.json +1 -1
- package/wasm-node/hypen_engine_bg.wasm +0 -0
- package/wasm-node/package.json +1 -1
package/dist/remote/server.d.ts
CHANGED
|
@@ -46,6 +46,7 @@ export declare class RemoteServer {
|
|
|
46
46
|
private nextClientId;
|
|
47
47
|
private server;
|
|
48
48
|
private sessionManager;
|
|
49
|
+
private _syncActions;
|
|
49
50
|
/**
|
|
50
51
|
* Set the module for this app
|
|
51
52
|
*/
|
|
@@ -78,6 +79,12 @@ export declare class RemoteServer {
|
|
|
78
79
|
* Configure session management
|
|
79
80
|
*/
|
|
80
81
|
session(config: SessionConfig): this;
|
|
82
|
+
/**
|
|
83
|
+
* Enable action synchronization across all connected clients.
|
|
84
|
+
* When enabled, an action dispatched by any client is also dispatched
|
|
85
|
+
* to every other client's engine, keeping all clients in sync.
|
|
86
|
+
*/
|
|
87
|
+
syncActions(): this;
|
|
81
88
|
/**
|
|
82
89
|
* Register connection callback
|
|
83
90
|
*/
|
package/dist/remote/server.js
CHANGED
|
@@ -1637,6 +1637,7 @@ class RemoteServer {
|
|
|
1637
1637
|
nextClientId = 1;
|
|
1638
1638
|
server = null;
|
|
1639
1639
|
sessionManager = null;
|
|
1640
|
+
_syncActions = false;
|
|
1640
1641
|
module(name, module) {
|
|
1641
1642
|
this._moduleName = name;
|
|
1642
1643
|
this._module = module;
|
|
@@ -1658,6 +1659,10 @@ class RemoteServer {
|
|
|
1658
1659
|
this._sessionConfig = config2;
|
|
1659
1660
|
return this;
|
|
1660
1661
|
}
|
|
1662
|
+
syncActions() {
|
|
1663
|
+
this._syncActions = true;
|
|
1664
|
+
return this;
|
|
1665
|
+
}
|
|
1661
1666
|
onConnection(callback) {
|
|
1662
1667
|
this._onConnectionCallbacks.push(callback);
|
|
1663
1668
|
return this;
|
|
@@ -1773,7 +1778,8 @@ class RemoteServer {
|
|
|
1773
1778
|
revision: 0,
|
|
1774
1779
|
connectedAt,
|
|
1775
1780
|
sessionId: "",
|
|
1776
|
-
helloReceived: false
|
|
1781
|
+
helloReceived: false,
|
|
1782
|
+
stateSubscribed: false
|
|
1777
1783
|
};
|
|
1778
1784
|
this.clients.set(ws, clientData);
|
|
1779
1785
|
clientData.helloTimeout = setTimeout(() => {
|
|
@@ -1879,19 +1885,39 @@ class RemoteServer {
|
|
|
1879
1885
|
if (!data)
|
|
1880
1886
|
return;
|
|
1881
1887
|
data.revision++;
|
|
1882
|
-
const
|
|
1888
|
+
const patchMessage = {
|
|
1883
1889
|
type: "patch",
|
|
1884
1890
|
module: this._moduleName,
|
|
1885
1891
|
patches,
|
|
1886
1892
|
revision: data.revision
|
|
1887
1893
|
};
|
|
1888
|
-
ws.send(JSON.stringify(
|
|
1894
|
+
ws.send(JSON.stringify(patchMessage));
|
|
1895
|
+
if (data.stateSubscribed) {
|
|
1896
|
+
const stateMessage = {
|
|
1897
|
+
type: "stateUpdate",
|
|
1898
|
+
module: this._moduleName,
|
|
1899
|
+
state: data.moduleInstance.getState(),
|
|
1900
|
+
revision: data.revision
|
|
1901
|
+
};
|
|
1902
|
+
ws.send(JSON.stringify(stateMessage));
|
|
1903
|
+
}
|
|
1889
1904
|
if (this.sessionManager?.getConcurrentPolicy() === "allow-multiple" && data.sessionId) {
|
|
1890
1905
|
const connections = this.sessionManager.getConnections(data.sessionId);
|
|
1891
1906
|
if (connections) {
|
|
1892
1907
|
for (const conn of connections) {
|
|
1893
1908
|
if (conn !== ws) {
|
|
1894
|
-
conn
|
|
1909
|
+
const otherWs = conn;
|
|
1910
|
+
const otherData = this.clients.get(otherWs);
|
|
1911
|
+
otherWs.send(JSON.stringify(patchMessage));
|
|
1912
|
+
if (otherData?.stateSubscribed) {
|
|
1913
|
+
const stateMessage = {
|
|
1914
|
+
type: "stateUpdate",
|
|
1915
|
+
module: this._moduleName,
|
|
1916
|
+
state: data.moduleInstance.getState(),
|
|
1917
|
+
revision: data.revision
|
|
1918
|
+
};
|
|
1919
|
+
otherWs.send(JSON.stringify(stateMessage));
|
|
1920
|
+
}
|
|
1895
1921
|
}
|
|
1896
1922
|
}
|
|
1897
1923
|
}
|
|
@@ -1960,6 +1986,30 @@ class RemoteServer {
|
|
|
1960
1986
|
case "dispatchAction": {
|
|
1961
1987
|
const actionMsg = msg;
|
|
1962
1988
|
clientData.engine.dispatchAction(actionMsg.action, actionMsg.payload);
|
|
1989
|
+
if (this._syncActions) {
|
|
1990
|
+
for (const [otherWs, otherClient] of this.clients) {
|
|
1991
|
+
if (otherWs === ws || !otherClient.helloReceived)
|
|
1992
|
+
continue;
|
|
1993
|
+
otherClient.engine.dispatchAction(actionMsg.action, actionMsg.payload);
|
|
1994
|
+
}
|
|
1995
|
+
}
|
|
1996
|
+
break;
|
|
1997
|
+
}
|
|
1998
|
+
case "updateState": {
|
|
1999
|
+
const stateMsg = msg;
|
|
2000
|
+
clientData.moduleInstance.updateState(stateMsg.state);
|
|
2001
|
+
if (this._syncActions) {
|
|
2002
|
+
for (const [otherWs, otherClient] of this.clients) {
|
|
2003
|
+
if (otherWs === ws || !otherClient.helloReceived)
|
|
2004
|
+
continue;
|
|
2005
|
+
otherClient.moduleInstance.updateState(stateMsg.state);
|
|
2006
|
+
}
|
|
2007
|
+
}
|
|
2008
|
+
break;
|
|
2009
|
+
}
|
|
2010
|
+
case "subscribeState": {
|
|
2011
|
+
clientData.stateSubscribed = true;
|
|
2012
|
+
log4.info(`Client ${clientData.id} subscribed to state updates`);
|
|
1963
2013
|
break;
|
|
1964
2014
|
}
|
|
1965
2015
|
default:
|
|
@@ -2076,4 +2126,4 @@ export {
|
|
|
2076
2126
|
RemoteServer
|
|
2077
2127
|
};
|
|
2078
2128
|
|
|
2079
|
-
//# debugId=
|
|
2129
|
+
//# debugId=E039307432F8950364756E2164756E21
|