@holoscript/core 6.0.3 → 7.0.0
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/README.md +40 -40
- package/dist/codebase/index.d.ts +25 -0
- package/dist/compiler/index.d.ts +82 -0
- package/dist/constants.d.ts +4 -0
- package/dist/coordinators/index.d.ts +189 -0
- package/dist/entries/interop.d.ts +9 -0
- package/dist/entries/scripting.d.ts +7 -0
- package/dist/index.d.ts +520 -19
- package/dist/paper-0c-spike/index.d.ts +29 -0
- package/dist/reconstruction/index.d.ts +78 -0
- package/dist/self-improvement/index.d.ts +0 -48
- package/dist/storage/index.d.ts +24 -0
- package/dist/tools/index.d.ts +33 -0
- package/dist/traitDocs/traitDocs.d.ts +69 -0
- package/dist/traits/index.d.ts +61 -0
- package/package.json +102 -19
- package/dist/GLTFPipeline-3KLWWUQO.cjs +0 -34
- package/dist/GLTFPipeline-LYII2ZVQ.js +0 -13
- package/dist/HoloScriptPlusParser-BZR5DELQ.js +0 -692
- package/dist/HoloScriptPlusParser-SBMYDNXO.cjs +0 -697
- package/dist/USDZExporter-MHEHXZB4.cjs +0 -709
- package/dist/USDZExporter-YA55ZS35.js +0 -707
- package/dist/chunk-26TLYBFD.js +0 -309
- package/dist/chunk-27LWW5FU.cjs +0 -410
- package/dist/chunk-2UX5LRAP.cjs +0 -833
- package/dist/chunk-32TWR3HE.js +0 -70
- package/dist/chunk-3FXV5S25.cjs +0 -633
- package/dist/chunk-3FYZOR7S.cjs +0 -69
- package/dist/chunk-3KEU5QYY.cjs +0 -175
- package/dist/chunk-4FCZDTD5.js +0 -610
- package/dist/chunk-4KJ2R7VP.cjs +0 -507
- package/dist/chunk-4SMUJFHL.js +0 -1213
- package/dist/chunk-54FHG2MX.js +0 -655
- package/dist/chunk-56IF4NTA.js +0 -56
- package/dist/chunk-5GLCTO44.js +0 -161
- package/dist/chunk-5TOFIR6L.js +0 -407
- package/dist/chunk-65RFOWZI.js +0 -765
- package/dist/chunk-6OQBLABR.js +0 -5240
- package/dist/chunk-6WNCRE6F.js +0 -126
- package/dist/chunk-74YCHHTE.js +0 -1872
- package/dist/chunk-7H5UNJZD.cjs +0 -1973
- package/dist/chunk-7KPI4EKH.cjs +0 -701
- package/dist/chunk-7LCYLPW2.cjs +0 -663
- package/dist/chunk-7N3JIJMT.js +0 -1395
- package/dist/chunk-7X2IEJIE.cjs +0 -2526
- package/dist/chunk-A6GO3DPZ.cjs +0 -1002
- package/dist/chunk-AC4BSHFV.js +0 -765
- package/dist/chunk-AIUXRS74.cjs +0 -3681
- package/dist/chunk-ARNKA274.cjs +0 -130
- package/dist/chunk-AW7WAELW.js +0 -975
- package/dist/chunk-BKIGPPVM.js +0 -629
- package/dist/chunk-BO2OKHIY.js +0 -6055
- package/dist/chunk-BU5ZAFMC.js +0 -115
- package/dist/chunk-BY3B7ZYV.cjs +0 -457
- package/dist/chunk-C2QHVHZF.js +0 -4066
- package/dist/chunk-C7BNX4XJ.js +0 -1043
- package/dist/chunk-CLYEIWA5.cjs +0 -408
- package/dist/chunk-CMYAWUX3.js +0 -4455
- package/dist/chunk-CN4NOESF.cjs +0 -416
- package/dist/chunk-CNVM7J3M.js +0 -883
- package/dist/chunk-CO2VM2DK.js +0 -1965
- package/dist/chunk-CQDOF3G7.cjs +0 -1404
- package/dist/chunk-DH5G2JUA.cjs +0 -614
- package/dist/chunk-DIEDKX5B.cjs +0 -660
- package/dist/chunk-DN7UFU63.cjs +0 -172
- package/dist/chunk-DXVCEFZB.js +0 -2027
- package/dist/chunk-EGIZHYJP.cjs +0 -85
- package/dist/chunk-EJA7G2C4.cjs +0 -428
- package/dist/chunk-ELLQPFAF.js +0 -830
- package/dist/chunk-EMO7HAKJ.cjs +0 -1875
- package/dist/chunk-ENV7K6XA.js +0 -282
- package/dist/chunk-EPWRXL6S.js +0 -2522
- package/dist/chunk-EUFLX2PI.js +0 -56956
- package/dist/chunk-F5LVGHNT.js +0 -449
- package/dist/chunk-FEFHPUEM.cjs +0 -6122
- package/dist/chunk-FF3Q7ADR.js +0 -380
- package/dist/chunk-GC3YU46J.js +0 -762
- package/dist/chunk-H6WMMLQK.cjs +0 -4492
- package/dist/chunk-H7XMORZI.js +0 -2731
- package/dist/chunk-HAN4V3PF.cjs +0 -2037
- package/dist/chunk-HBZYCASG.js +0 -4208
- package/dist/chunk-HF4OFY25.cjs +0 -4097
- package/dist/chunk-HHS6FMOU.cjs +0 -3813
- package/dist/chunk-HJJLD366.js +0 -1169
- package/dist/chunk-HKCVM6OK.cjs +0 -2237
- package/dist/chunk-HUFNKFA6.js +0 -698
- package/dist/chunk-I3XGTIHM.cjs +0 -1505
- package/dist/chunk-I6XZ5DZF.cjs +0 -488
- package/dist/chunk-IHOUYQIA.js +0 -406
- package/dist/chunk-ILRBGFVD.cjs +0 -72
- package/dist/chunk-KDB6BUMB.js +0 -3666
- package/dist/chunk-KUJRR4FJ.js +0 -657
- package/dist/chunk-KYM4XRFG.js +0 -421
- package/dist/chunk-L3Z2HIWJ.cjs +0 -793
- package/dist/chunk-LBPEZQAF.js +0 -2232
- package/dist/chunk-LER4WXW5.cjs +0 -286
- package/dist/chunk-LK5IAVH6.cjs +0 -1173
- package/dist/chunk-M6FU6S22.js +0 -2911
- package/dist/chunk-MWEFR6YQ.js +0 -1857
- package/dist/chunk-N5FTS757.cjs +0 -415
- package/dist/chunk-NCUHGRTZ.js +0 -752
- package/dist/chunk-NKRKT6V2.js +0 -69
- package/dist/chunk-NLPSZT4C.js +0 -630
- package/dist/chunk-NRUB55IT.cjs +0 -771
- package/dist/chunk-NTMZSDXM.cjs +0 -633
- package/dist/chunk-ODGMVILH.js +0 -9662
- package/dist/chunk-PBA6NXCT.cjs +0 -1216
- package/dist/chunk-PHENW4MQ.js +0 -65
- package/dist/chunk-PJMOXFPR.cjs +0 -1861
- package/dist/chunk-PLMYCCA4.js +0 -504
- package/dist/chunk-PPULB4GG.cjs +0 -9728
- package/dist/chunk-PQLGZKMC.cjs +0 -755
- package/dist/chunk-Q56TT7IL.js +0 -483
- package/dist/chunk-QHVVVN47.cjs +0 -2033
- package/dist/chunk-QWKUKVRE.js +0 -2026
- package/dist/chunk-RE3OKSYF.cjs +0 -424
- package/dist/chunk-RT7LJRSF.cjs +0 -57378
- package/dist/chunk-SPDELRRV.cjs +0 -319
- package/dist/chunk-SUCBB66F.js +0 -229
- package/dist/chunk-TSWTWZ42.cjs +0 -4214
- package/dist/chunk-UITWA6DV.cjs +0 -2829
- package/dist/chunk-UQW6SLM5.js +0 -172
- package/dist/chunk-V2ILLPHK.cjs +0 -237
- package/dist/chunk-V42NTCFH.js +0 -3645
- package/dist/chunk-VJ3L7CHT.cjs +0 -169
- package/dist/chunk-VJVCD5T5.cjs +0 -769
- package/dist/chunk-VK5AXKO3.js +0 -746
- package/dist/chunk-VSXOIUCF.cjs +0 -473
- package/dist/chunk-VZNKJZTT.cjs +0 -749
- package/dist/chunk-W76ETJTI.js +0 -678
- package/dist/chunk-WFJIDI2N.cjs +0 -424
- package/dist/chunk-WN3YF33G.cjs +0 -118
- package/dist/chunk-WUXIRGZP.cjs +0 -2915
- package/dist/chunk-WYH4GVZ5.js +0 -1488
- package/dist/chunk-X4YVN7H3.cjs +0 -888
- package/dist/chunk-X67XRI2T.js +0 -410
- package/dist/chunk-XDXZM3ZP.cjs +0 -1046
- package/dist/chunk-XH7SE4HH.cjs +0 -72
- package/dist/chunk-XNMEH2BI.js +0 -126
- package/dist/chunk-XSF76QRU.js +0 -468
- package/dist/chunk-XSUZMPVQ.cjs +0 -682
- package/dist/chunk-XUILI4KB.cjs +0 -430
- package/dist/chunk-Y5MUAYTO.js +0 -167
- package/dist/chunk-Y7VK5TH3.cjs +0 -129
- package/dist/chunk-YCMQQQ5U.cjs +0 -5244
- package/dist/chunk-YYXH45E2.js +0 -426
- package/dist/chunk-ZGTGVSTZ.js +0 -422
- package/dist/chunk-ZL6VJ6SN.js +0 -421
- package/dist/cli/holoscript-runner.cjs +0 -2258
- package/dist/cli/holoscript-runner.js +0 -2233
- package/dist/codebase/index.cjs +0 -336
- package/dist/codebase/index.js +0 -331
- package/dist/compiler/agent-inference.cjs +0 -29
- package/dist/compiler/agent-inference.js +0 -6
- package/dist/compiler/android-xr.cjs +0 -20
- package/dist/compiler/android-xr.js +0 -10
- package/dist/compiler/android.cjs +0 -21
- package/dist/compiler/android.js +0 -11
- package/dist/compiler/ar.cjs +0 -21
- package/dist/compiler/ar.js +0 -9
- package/dist/compiler/babylon.cjs +0 -18
- package/dist/compiler/babylon.js +0 -12
- package/dist/compiler/coco.cjs +0 -27
- package/dist/compiler/coco.js +0 -4
- package/dist/compiler/domain-block-utils.cjs +0 -595
- package/dist/compiler/domain-block-utils.js +0 -9
- package/dist/compiler/dtdl.cjs +0 -25
- package/dist/compiler/dtdl.js +0 -9
- package/dist/compiler/gltf-pipeline.cjs +0 -39
- package/dist/compiler/gltf-pipeline.js +0 -4
- package/dist/compiler/godot.cjs +0 -16
- package/dist/compiler/godot.js +0 -10
- package/dist/compiler/incremental.cjs +0 -30
- package/dist/compiler/incremental.js +0 -5
- package/dist/compiler/index.cjs +0 -1522
- package/dist/compiler/index.js +0 -1321
- package/dist/compiler/ios.cjs +0 -21
- package/dist/compiler/ios.js +0 -11
- package/dist/compiler/multi-layer.cjs +0 -27
- package/dist/compiler/multi-layer.js +0 -12
- package/dist/compiler/nodetoy.cjs +0 -23
- package/dist/compiler/nodetoy.js +0 -4
- package/dist/compiler/openxr.cjs +0 -16
- package/dist/compiler/openxr.js +0 -10
- package/dist/compiler/playcanvas.cjs +0 -17
- package/dist/compiler/playcanvas.js +0 -11
- package/dist/compiler/r3f.cjs +0 -35
- package/dist/compiler/r3f.js +0 -13
- package/dist/compiler/remotion.cjs +0 -23
- package/dist/compiler/remotion.js +0 -4
- package/dist/compiler/reproducibility.cjs +0 -39
- package/dist/compiler/reproducibility.js +0 -4
- package/dist/compiler/sdf.cjs +0 -22
- package/dist/compiler/sdf.js +0 -10
- package/dist/compiler/semantic-scene.cjs +0 -31
- package/dist/compiler/semantic-scene.js +0 -4
- package/dist/compiler/state.cjs +0 -18
- package/dist/compiler/state.js +0 -8
- package/dist/compiler/trait-composition.cjs +0 -27
- package/dist/compiler/trait-composition.js +0 -6
- package/dist/compiler/unity.cjs +0 -16
- package/dist/compiler/unity.js +0 -10
- package/dist/compiler/unreal.cjs +0 -20
- package/dist/compiler/unreal.js +0 -10
- package/dist/compiler/urdf.cjs +0 -46
- package/dist/compiler/urdf.js +0 -10
- package/dist/compiler/usd-physics.cjs +0 -24
- package/dist/compiler/usd-physics.js +0 -7
- package/dist/compiler/visionos.cjs +0 -16
- package/dist/compiler/visionos.js +0 -10
- package/dist/compiler/vrchat.cjs +0 -20
- package/dist/compiler/vrchat.js +0 -10
- package/dist/compiler/vrr.cjs +0 -22
- package/dist/compiler/vrr.js +0 -10
- package/dist/compiler/wasm.cjs +0 -34
- package/dist/compiler/wasm.js +0 -10
- package/dist/compiler/webgpu.cjs +0 -16
- package/dist/compiler/webgpu.js +0 -10
- package/dist/debugger.cjs +0 -21
- package/dist/debugger.js +0 -8
- package/dist/entries/interop.cjs +0 -62
- package/dist/entries/interop.js +0 -5
- package/dist/entries/scripting.cjs +0 -67
- package/dist/entries/scripting.js +0 -10
- package/dist/index.cjs +0 -61703
- package/dist/index.js +0 -58652
- package/dist/math/vec3.cjs +0 -57
- package/dist/math/vec3.js +0 -4
- package/dist/parser.cjs +0 -26
- package/dist/parser.js +0 -9
- package/dist/playwright-7DTEQCBD.cjs +0 -98673
- package/dist/playwright-BIZXMLD2.js +0 -98660
- package/dist/post-quantum-JTTAAGO3.cjs +0 -6
- package/dist/post-quantum-RVPVDEPI.js +0 -4
- package/dist/runtime.cjs +0 -16
- package/dist/runtime.js +0 -7
- package/dist/storage/index.cjs +0 -37
- package/dist/storage/index.js +0 -4
- package/dist/traits/index.cjs +0 -14331
- package/dist/traits/index.js +0 -12126
- package/dist/type-checker.cjs +0 -18
- package/dist/type-checker.js +0 -5
- package/dist/wot/index.cjs +0 -29
- package/dist/wot/index.js +0 -4
package/dist/chunk-ENV7K6XA.js
DELETED
|
@@ -1,282 +0,0 @@
|
|
|
1
|
-
import { logger } from './chunk-PHENW4MQ.js';
|
|
2
|
-
import { calculatePosition } from '@holoscript/engine/orbital';
|
|
3
|
-
|
|
4
|
-
// src/traits/MitosisTrait.ts
|
|
5
|
-
var mitosisHandler = {
|
|
6
|
-
name: "mitosis",
|
|
7
|
-
defaultConfig: {
|
|
8
|
-
strategy: "collaborative",
|
|
9
|
-
max_children: 5,
|
|
10
|
-
auto_cleanup: true
|
|
11
|
-
},
|
|
12
|
-
onAttach(node, config, context) {
|
|
13
|
-
const state = {
|
|
14
|
-
parent_id: ("parent_id" in config ? config.parent_id : null) || null,
|
|
15
|
-
active_children: [],
|
|
16
|
-
tasks_delegated: 0,
|
|
17
|
-
completed_tasks: 0,
|
|
18
|
-
last_sync_time: Date.now()
|
|
19
|
-
};
|
|
20
|
-
node.__mitosisState = state;
|
|
21
|
-
context.emit?.("mitosis_init", {
|
|
22
|
-
nodeId: node.id,
|
|
23
|
-
strategy: config.strategy,
|
|
24
|
-
parent_id: state.parent_id
|
|
25
|
-
});
|
|
26
|
-
},
|
|
27
|
-
onDetach(node, config, context) {
|
|
28
|
-
const state = node.__mitosisState;
|
|
29
|
-
if (state && config.auto_cleanup) {
|
|
30
|
-
for (const childId of state.active_children) {
|
|
31
|
-
context.emit?.("mitosis_despawn_child", { childId });
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
delete node.__mitosisState;
|
|
35
|
-
},
|
|
36
|
-
onEvent(node, config, context, event) {
|
|
37
|
-
const state = node.__mitosisState;
|
|
38
|
-
if (!state) return;
|
|
39
|
-
if (event.type === "mitosis_spawned") {
|
|
40
|
-
const childId = event.childId;
|
|
41
|
-
const parentId = event.parentId;
|
|
42
|
-
if (node.id === parentId) {
|
|
43
|
-
state.active_children.push(childId);
|
|
44
|
-
state.tasks_delegated++;
|
|
45
|
-
context.emit?.("on_mitosis_spawned", { childId, parentId: node.id });
|
|
46
|
-
}
|
|
47
|
-
} else if (event.type === "mitosis_child_complete") {
|
|
48
|
-
const childId = "childId" in event ? event.childId : "";
|
|
49
|
-
const parentId = "parentId" in event ? event.parentId : "";
|
|
50
|
-
const result = "result" in event ? event.result : void 0;
|
|
51
|
-
if (node.id === parentId) {
|
|
52
|
-
state.completed_tasks++;
|
|
53
|
-
state.last_sync_time = Date.now();
|
|
54
|
-
context.emit?.("mitosis_synced", {
|
|
55
|
-
parentId: node.id,
|
|
56
|
-
childId,
|
|
57
|
-
result
|
|
58
|
-
});
|
|
59
|
-
if (config.strategy === "collaborative") {
|
|
60
|
-
if (result && typeof result === "object") {
|
|
61
|
-
Object.assign(node.properties || {}, result);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
} else if (event.type === "mitosis_child_failed") {
|
|
66
|
-
context.emit?.("on_mitosis_error", {
|
|
67
|
-
parentId: node.id,
|
|
68
|
-
childId: event.childId,
|
|
69
|
-
error: event.error
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
var orbitalHandler = {
|
|
75
|
-
name: "orbital",
|
|
76
|
-
defaultConfig: {},
|
|
77
|
-
/**
|
|
78
|
-
* Called when trait is attached to a node
|
|
79
|
-
*/
|
|
80
|
-
onAttach(node, _config, _context) {
|
|
81
|
-
logger.info(`[OrbitalTrait] Attached to ${node.name}`);
|
|
82
|
-
},
|
|
83
|
-
/**
|
|
84
|
-
* Called every frame to update orbital position
|
|
85
|
-
*/
|
|
86
|
-
onUpdate(node, config, context, _delta) {
|
|
87
|
-
const properties = node.properties || {};
|
|
88
|
-
const mergedConfig = { ...properties, ...config };
|
|
89
|
-
if (!mergedConfig || !mergedConfig.semiMajorAxis) {
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
const julianDate = context.julianDate || 0;
|
|
93
|
-
const visualScale = context.getScaleMultiplier() * 50;
|
|
94
|
-
const satelliteScale = 5;
|
|
95
|
-
const rawPosition = calculatePosition(mergedConfig, julianDate);
|
|
96
|
-
const currentScale = mergedConfig.parent ? visualScale * satelliteScale : visualScale;
|
|
97
|
-
let finalPosition = {
|
|
98
|
-
x: rawPosition.x * currentScale,
|
|
99
|
-
y: rawPosition.z * currentScale,
|
|
100
|
-
z: rawPosition.y * currentScale
|
|
101
|
-
};
|
|
102
|
-
if (mergedConfig.parent) {
|
|
103
|
-
let parentNode = context.getNode?.(mergedConfig.parent);
|
|
104
|
-
if (!parentNode && typeof mergedConfig.parent === "object" && mergedConfig.parent && mergedConfig.parent.position) {
|
|
105
|
-
parentNode = mergedConfig.parent;
|
|
106
|
-
}
|
|
107
|
-
if (parentNode && parentNode.position) {
|
|
108
|
-
finalPosition = {
|
|
109
|
-
x: finalPosition.x + (parentNode.position.x || 0),
|
|
110
|
-
y: finalPosition.y + (parentNode.position.y || 0),
|
|
111
|
-
z: finalPosition.z + (parentNode.position.z || 0)
|
|
112
|
-
};
|
|
113
|
-
} else {
|
|
114
|
-
if (typeof mergedConfig.parent === "string") {
|
|
115
|
-
logger.warn(`[OrbitalTrait] Parent "${mergedConfig.parent}" not found for ${node.name}`);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
node.position = finalPosition;
|
|
120
|
-
context.emit("position_update", { position: finalPosition });
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
// src/network/WebSocketTransport.ts
|
|
125
|
-
var WebSocketTransport = class {
|
|
126
|
-
constructor(config) {
|
|
127
|
-
this.ws = null;
|
|
128
|
-
this.messageQueue = [];
|
|
129
|
-
this.reconnectAttempts = 0;
|
|
130
|
-
this.messageHandlers = /* @__PURE__ */ new Map();
|
|
131
|
-
this.isConnected = false;
|
|
132
|
-
this.heartbeatTimer = null;
|
|
133
|
-
this.messageId = 0;
|
|
134
|
-
const defaults = {
|
|
135
|
-
maxReconnectAttempts: 10,
|
|
136
|
-
initialBackoffMs: 1e3,
|
|
137
|
-
maxBackoffMs: 3e4,
|
|
138
|
-
heartbeatIntervalMs: 3e4
|
|
139
|
-
};
|
|
140
|
-
this.config = { ...defaults, ...config };
|
|
141
|
-
this.peerId = config.peerId || this.generatePeerId();
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* Connect to WebSocket server
|
|
145
|
-
*/
|
|
146
|
-
async connect() {
|
|
147
|
-
return new Promise((resolve, reject) => {
|
|
148
|
-
try {
|
|
149
|
-
this.ws = new WebSocket(this.config.serverUrl);
|
|
150
|
-
this.ws.onopen = () => {
|
|
151
|
-
logger.info(`WebSocket connected to ${this.config.serverUrl}`);
|
|
152
|
-
this.isConnected = true;
|
|
153
|
-
this.reconnectAttempts = 0;
|
|
154
|
-
this.sendMessage({
|
|
155
|
-
type: "auth",
|
|
156
|
-
payload: { peerId: this.peerId, roomId: this.config.roomId }
|
|
157
|
-
});
|
|
158
|
-
this.startHeartbeat();
|
|
159
|
-
this.flushMessageQueue();
|
|
160
|
-
resolve();
|
|
161
|
-
};
|
|
162
|
-
this.ws.onmessage = (evt) => {
|
|
163
|
-
try {
|
|
164
|
-
const msg = JSON.parse(evt.data);
|
|
165
|
-
const handler = this.messageHandlers.get(msg.type);
|
|
166
|
-
if (handler) handler(msg);
|
|
167
|
-
} catch (err) {
|
|
168
|
-
logger.error("Failed to parse WebSocket message", {
|
|
169
|
-
error: err instanceof Error ? err.message : String(err)
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
};
|
|
173
|
-
this.ws.onerror = () => {
|
|
174
|
-
logger.error("WebSocket error");
|
|
175
|
-
reject(new Error("WebSocket connection failed"));
|
|
176
|
-
};
|
|
177
|
-
this.ws.onclose = () => {
|
|
178
|
-
logger.warn("WebSocket disconnected");
|
|
179
|
-
this.isConnected = false;
|
|
180
|
-
this.stopHeartbeat();
|
|
181
|
-
this.attemptReconnect();
|
|
182
|
-
};
|
|
183
|
-
} catch (err) {
|
|
184
|
-
reject(err);
|
|
185
|
-
}
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
/**
|
|
189
|
-
* Send a network message
|
|
190
|
-
*/
|
|
191
|
-
sendMessage(msg) {
|
|
192
|
-
const fullMessage = {
|
|
193
|
-
...msg,
|
|
194
|
-
id: `${this.peerId}-${this.messageId++}`,
|
|
195
|
-
peerId: this.peerId,
|
|
196
|
-
roomId: this.config.roomId,
|
|
197
|
-
timestamp: Date.now()
|
|
198
|
-
};
|
|
199
|
-
if (this.isConnected && this.ws?.readyState === WebSocket.OPEN) {
|
|
200
|
-
this.ws.send(JSON.stringify(fullMessage));
|
|
201
|
-
} else {
|
|
202
|
-
this.messageQueue.push(fullMessage);
|
|
203
|
-
if (this.messageQueue.length > 1e3) {
|
|
204
|
-
this.messageQueue.shift();
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
/**
|
|
209
|
-
* Register message handler
|
|
210
|
-
*/
|
|
211
|
-
onMessage(type, handler) {
|
|
212
|
-
this.messageHandlers.set(type, handler);
|
|
213
|
-
}
|
|
214
|
-
/**
|
|
215
|
-
* Disconnect from server
|
|
216
|
-
*/
|
|
217
|
-
disconnect() {
|
|
218
|
-
this.stopHeartbeat();
|
|
219
|
-
if (this.ws) {
|
|
220
|
-
this.ws.close();
|
|
221
|
-
this.ws = null;
|
|
222
|
-
}
|
|
223
|
-
this.isConnected = false;
|
|
224
|
-
}
|
|
225
|
-
/**
|
|
226
|
-
* Check if connected
|
|
227
|
-
*/
|
|
228
|
-
getIsConnected() {
|
|
229
|
-
return this.isConnected;
|
|
230
|
-
}
|
|
231
|
-
// Private helpers
|
|
232
|
-
attemptReconnect() {
|
|
233
|
-
const maxAttempts = this.config.maxReconnectAttempts ?? 10;
|
|
234
|
-
if (this.reconnectAttempts >= maxAttempts) {
|
|
235
|
-
logger.error("Max reconnection attempts exceeded");
|
|
236
|
-
return;
|
|
237
|
-
}
|
|
238
|
-
const initialBackoff = this.config.initialBackoffMs ?? 1e3;
|
|
239
|
-
const maxBackoff = this.config.maxBackoffMs ?? 3e4;
|
|
240
|
-
const backoff = Math.min(
|
|
241
|
-
initialBackoff * Math.pow(2, this.reconnectAttempts),
|
|
242
|
-
maxBackoff
|
|
243
|
-
);
|
|
244
|
-
this.reconnectAttempts++;
|
|
245
|
-
logger.info(
|
|
246
|
-
`Reconnecting in ${backoff}ms (attempt ${this.reconnectAttempts}/${maxAttempts})`
|
|
247
|
-
);
|
|
248
|
-
setTimeout(() => {
|
|
249
|
-
this.connect().catch((err) => {
|
|
250
|
-
logger.error("Reconnection failed", {
|
|
251
|
-
error: err instanceof Error ? err.message : String(err)
|
|
252
|
-
});
|
|
253
|
-
this.attemptReconnect();
|
|
254
|
-
});
|
|
255
|
-
}, backoff);
|
|
256
|
-
}
|
|
257
|
-
flushMessageQueue() {
|
|
258
|
-
while (this.messageQueue.length > 0 && this.isConnected && this.ws?.readyState === WebSocket.OPEN) {
|
|
259
|
-
const msg = this.messageQueue.shift();
|
|
260
|
-
if (msg) this.ws.send(JSON.stringify(msg));
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
startHeartbeat() {
|
|
264
|
-
const interval = this.config.heartbeatIntervalMs ?? 3e4;
|
|
265
|
-
this.heartbeatTimer = setInterval(() => {
|
|
266
|
-
this.sendMessage({ type: "heartbeat", payload: {} });
|
|
267
|
-
}, interval);
|
|
268
|
-
}
|
|
269
|
-
stopHeartbeat() {
|
|
270
|
-
if (this.heartbeatTimer) {
|
|
271
|
-
clearInterval(this.heartbeatTimer);
|
|
272
|
-
this.heartbeatTimer = null;
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
generatePeerId() {
|
|
276
|
-
return `peer-${Math.random().toString(36).substr(2, 9)}`;
|
|
277
|
-
}
|
|
278
|
-
};
|
|
279
|
-
|
|
280
|
-
export { WebSocketTransport, mitosisHandler, orbitalHandler };
|
|
281
|
-
//# sourceMappingURL=chunk-ENV7K6XA.js.map
|
|
282
|
-
//# sourceMappingURL=chunk-ENV7K6XA.js.map
|