@balancy/wasm 1.2.1 → 1.2.3
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/Balancy.wasm +0 -0
- package/dist/index.cjs.js +207 -43
- package/dist/index.es.js +207 -43
- package/dist/index.umd.js +207 -43
- package/dist/node/index.cjs.js +207 -43
- package/dist/node/index.es.js +207 -43
- package/dist/node/index.umd.js +207 -43
- package/package.json +1 -1
package/dist/Balancy.wasm
CHANGED
|
Binary file
|
package/dist/index.cjs.js
CHANGED
|
@@ -1343,46 +1343,9 @@ var Balancy = function() {
|
|
|
1343
1343
|
return;
|
|
1344
1344
|
}
|
|
1345
1345
|
var contentType = response.headers.get("content-type") || "";
|
|
1346
|
-
var
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
".jpeg",
|
|
1350
|
-
".gif",
|
|
1351
|
-
".bmp",
|
|
1352
|
-
".webp",
|
|
1353
|
-
".ico",
|
|
1354
|
-
".mp3",
|
|
1355
|
-
".mp4",
|
|
1356
|
-
".wav",
|
|
1357
|
-
".avi",
|
|
1358
|
-
".mov",
|
|
1359
|
-
".pdf",
|
|
1360
|
-
".zip",
|
|
1361
|
-
".rar",
|
|
1362
|
-
".7z",
|
|
1363
|
-
".exe",
|
|
1364
|
-
".dll",
|
|
1365
|
-
".so",
|
|
1366
|
-
".dylib",
|
|
1367
|
-
".ttf",
|
|
1368
|
-
".otf",
|
|
1369
|
-
".woff",
|
|
1370
|
-
".woff2"
|
|
1371
|
-
];
|
|
1372
|
-
var textMimeTypes = [
|
|
1373
|
-
"application/json",
|
|
1374
|
-
"text/",
|
|
1375
|
-
"application/xml",
|
|
1376
|
-
"application/javascript",
|
|
1377
|
-
"application/x-javascript"
|
|
1378
|
-
];
|
|
1379
|
-
var hasBinaryExtension = binaryExtensions.some(function(ext) {
|
|
1380
|
-
return urlString.toLowerCase().includes(ext);
|
|
1381
|
-
});
|
|
1382
|
-
var isTextMimeType = textMimeTypes.some(function(type) {
|
|
1383
|
-
return contentType.toLowerCase().includes(type);
|
|
1384
|
-
});
|
|
1385
|
-
var isBinary = contentType.includes("application/octet-stream") || hasBinaryExtension || !isTextMimeType && !contentType.includes("charset");
|
|
1346
|
+
var contentTypeLower = contentType.toLowerCase();
|
|
1347
|
+
var isTextContent = contentTypeLower.includes("application/json") || contentTypeLower.includes("text/") || contentTypeLower.includes("application/xml") || contentTypeLower.includes("application/javascript");
|
|
1348
|
+
var isBinary = !isTextContent;
|
|
1386
1349
|
if (isBinary) {
|
|
1387
1350
|
response.arrayBuffer().then(function(arrayBuffer) {
|
|
1388
1351
|
var dataSize = arrayBuffer.byteLength;
|
|
@@ -1469,6 +1432,203 @@ var Balancy = function() {
|
|
|
1469
1432
|
invokeErrorCallback(-1, error.message, "Network fetch failed");
|
|
1470
1433
|
});
|
|
1471
1434
|
}
|
|
1435
|
+
function js_websocket_connect(connectionId, url, authData) {
|
|
1436
|
+
if (!Module.balancyWebSockets) {
|
|
1437
|
+
Module.balancyWebSockets = new Map;
|
|
1438
|
+
}
|
|
1439
|
+
var urlStr = UTF8ToString(url);
|
|
1440
|
+
var authDataStr = UTF8ToString(authData);
|
|
1441
|
+
var wsUrl = urlStr;
|
|
1442
|
+
if (wsUrl.startsWith("http://")) {
|
|
1443
|
+
wsUrl = wsUrl.replace("http://", "ws://");
|
|
1444
|
+
} else if (wsUrl.startsWith("https://")) {
|
|
1445
|
+
wsUrl = wsUrl.replace("https://", "wss://");
|
|
1446
|
+
}
|
|
1447
|
+
if (location.protocol === "http:" && wsUrl.startsWith("wss://")) {
|
|
1448
|
+
wsUrl = wsUrl.replace("wss://", "ws://");
|
|
1449
|
+
}
|
|
1450
|
+
if (!wsUrl.endsWith("/")) {
|
|
1451
|
+
wsUrl += "/";
|
|
1452
|
+
}
|
|
1453
|
+
wsUrl += "socket.io/?EIO=4&transport=websocket";
|
|
1454
|
+
try {
|
|
1455
|
+
var socket = new WebSocket(wsUrl);
|
|
1456
|
+
socket.binaryType = "arraybuffer";
|
|
1457
|
+
var connection = {
|
|
1458
|
+
socket: socket,
|
|
1459
|
+
authData: authDataStr,
|
|
1460
|
+
subscribedEvents: new Set
|
|
1461
|
+
};
|
|
1462
|
+
Module.balancyWebSockets.set(connectionId, connection);
|
|
1463
|
+
socket.onopen = function() {
|
|
1464
|
+
var emptyMsg = "";
|
|
1465
|
+
var emptyLen = lengthBytesUTF8(emptyMsg) + 1;
|
|
1466
|
+
var emptyPtr = _malloc(emptyLen);
|
|
1467
|
+
stringToUTF8(emptyMsg, emptyPtr, emptyLen);
|
|
1468
|
+
_emscripten_websocket_on_connection_status(connectionId, true, emptyPtr);
|
|
1469
|
+
_free(emptyPtr);
|
|
1470
|
+
};
|
|
1471
|
+
socket.onclose = function() {
|
|
1472
|
+
var closeMsg = "Connection closed";
|
|
1473
|
+
var closeLen = lengthBytesUTF8(closeMsg) + 1;
|
|
1474
|
+
var closePtr = _malloc(closeLen);
|
|
1475
|
+
stringToUTF8(closeMsg, closePtr, closeLen);
|
|
1476
|
+
_emscripten_websocket_on_connection_status(connectionId, false, closePtr);
|
|
1477
|
+
_free(closePtr);
|
|
1478
|
+
Module.balancyWebSockets.delete(connectionId);
|
|
1479
|
+
};
|
|
1480
|
+
socket.onerror = function(error) {
|
|
1481
|
+
console.error("[WebSocket] Connection failed:", error);
|
|
1482
|
+
var errorMsg = "WebSocket connection failed";
|
|
1483
|
+
var errorLen = lengthBytesUTF8(errorMsg) + 1;
|
|
1484
|
+
var errorPtr = _malloc(errorLen);
|
|
1485
|
+
stringToUTF8(errorMsg, errorPtr, errorLen);
|
|
1486
|
+
_emscripten_websocket_on_connection_status(connectionId, false, errorPtr);
|
|
1487
|
+
_free(errorPtr);
|
|
1488
|
+
};
|
|
1489
|
+
socket.onmessage = function(event) {
|
|
1490
|
+
if (typeof event.data !== "string") return;
|
|
1491
|
+
var message = event.data;
|
|
1492
|
+
if (message.startsWith("0")) {
|
|
1493
|
+
try {
|
|
1494
|
+
var authJson = JSON.parse(connection.authData);
|
|
1495
|
+
var connectMessage = "40" + JSON.stringify({
|
|
1496
|
+
game_id: authJson.gameId,
|
|
1497
|
+
user_id: authJson.userId,
|
|
1498
|
+
env: authJson.environment,
|
|
1499
|
+
token: authJson.token,
|
|
1500
|
+
device_id: authJson.deviceId || ""
|
|
1501
|
+
});
|
|
1502
|
+
socket.send(connectMessage);
|
|
1503
|
+
} catch (e) {
|
|
1504
|
+
console.error("[WebSocket] Failed to send auth:", e);
|
|
1505
|
+
socket.send("40");
|
|
1506
|
+
}
|
|
1507
|
+
return;
|
|
1508
|
+
}
|
|
1509
|
+
if (message.startsWith("2")) {
|
|
1510
|
+
socket.send("3");
|
|
1511
|
+
return;
|
|
1512
|
+
}
|
|
1513
|
+
if (message.startsWith("40")) {
|
|
1514
|
+
return;
|
|
1515
|
+
}
|
|
1516
|
+
if (message.startsWith("41")) {
|
|
1517
|
+
return;
|
|
1518
|
+
}
|
|
1519
|
+
if (message.startsWith("42")) {
|
|
1520
|
+
var afterType = message.substring(2);
|
|
1521
|
+
var ackId = 0;
|
|
1522
|
+
var hasAckId = false;
|
|
1523
|
+
var jsonPart = afterType;
|
|
1524
|
+
var jsonStart = afterType.indexOf("[");
|
|
1525
|
+
if (jsonStart > 0) {
|
|
1526
|
+
var ackIdStr = afterType.substring(0, jsonStart);
|
|
1527
|
+
var parsedAckId = parseInt(ackIdStr);
|
|
1528
|
+
if (!isNaN(parsedAckId)) {
|
|
1529
|
+
hasAckId = true;
|
|
1530
|
+
ackId = parsedAckId;
|
|
1531
|
+
jsonPart = afterType.substring(jsonStart);
|
|
1532
|
+
}
|
|
1533
|
+
}
|
|
1534
|
+
try {
|
|
1535
|
+
var eventArray = JSON.parse(jsonPart);
|
|
1536
|
+
if (eventArray && eventArray.length >= 1) {
|
|
1537
|
+
var eventName = eventArray[0];
|
|
1538
|
+
var eventData = eventArray.length > 1 ? JSON.stringify(eventArray[1]) : "{}";
|
|
1539
|
+
if (eventName === "system:ping") {
|
|
1540
|
+
if (hasAckId) {
|
|
1541
|
+
socket.send("43" + ackId + "[]");
|
|
1542
|
+
}
|
|
1543
|
+
return;
|
|
1544
|
+
}
|
|
1545
|
+
if (eventName === "profile:updated") {
|
|
1546
|
+
if (hasAckId) {
|
|
1547
|
+
socket.send("43" + ackId + "[]");
|
|
1548
|
+
}
|
|
1549
|
+
if (connection.subscribedEvents.has(eventName) || connection.subscribedEvents.size === 0) {
|
|
1550
|
+
var eventNameLen = lengthBytesUTF8(eventName) + 1;
|
|
1551
|
+
var eventNamePtr = _malloc(eventNameLen);
|
|
1552
|
+
stringToUTF8(eventName, eventNamePtr, eventNameLen);
|
|
1553
|
+
var eventDataLen = lengthBytesUTF8(eventData) + 1;
|
|
1554
|
+
var eventDataPtr = _malloc(eventDataLen);
|
|
1555
|
+
stringToUTF8(eventData, eventDataPtr, eventDataLen);
|
|
1556
|
+
_emscripten_websocket_on_socketio_event(connectionId, eventNamePtr, eventDataPtr, false, 0);
|
|
1557
|
+
_free(eventNamePtr);
|
|
1558
|
+
_free(eventDataPtr);
|
|
1559
|
+
}
|
|
1560
|
+
return;
|
|
1561
|
+
}
|
|
1562
|
+
if (connection.subscribedEvents.has(eventName) || connection.subscribedEvents.size === 0) {
|
|
1563
|
+
var eventNameLen = lengthBytesUTF8(eventName) + 1;
|
|
1564
|
+
var eventNamePtr = _malloc(eventNameLen);
|
|
1565
|
+
stringToUTF8(eventName, eventNamePtr, eventNameLen);
|
|
1566
|
+
var eventDataLen = lengthBytesUTF8(eventData) + 1;
|
|
1567
|
+
var eventDataPtr = _malloc(eventDataLen);
|
|
1568
|
+
stringToUTF8(eventData, eventDataPtr, eventDataLen);
|
|
1569
|
+
_emscripten_websocket_on_socketio_event(connectionId, eventNamePtr, eventDataPtr, hasAckId, ackId);
|
|
1570
|
+
_free(eventNamePtr);
|
|
1571
|
+
_free(eventDataPtr);
|
|
1572
|
+
} else {
|
|
1573
|
+
if (hasAckId) {
|
|
1574
|
+
socket.send("43" + ackId + "[]");
|
|
1575
|
+
}
|
|
1576
|
+
}
|
|
1577
|
+
}
|
|
1578
|
+
} catch (e) {
|
|
1579
|
+
console.error("[WebSocket] Failed to parse event:", e);
|
|
1580
|
+
}
|
|
1581
|
+
return;
|
|
1582
|
+
}
|
|
1583
|
+
if (message.startsWith("44")) {
|
|
1584
|
+
var errorJson = message.substring(2);
|
|
1585
|
+
console.error("[WebSocket] Socket.IO error:", errorJson);
|
|
1586
|
+
var errorLen = lengthBytesUTF8(errorJson) + 1;
|
|
1587
|
+
var errorPtr = _malloc(errorLen);
|
|
1588
|
+
stringToUTF8(errorJson, errorPtr, errorLen);
|
|
1589
|
+
_emscripten_websocket_on_socketio_error(connectionId, 44, errorPtr);
|
|
1590
|
+
_free(errorPtr);
|
|
1591
|
+
return;
|
|
1592
|
+
}
|
|
1593
|
+
};
|
|
1594
|
+
} catch (e) {
|
|
1595
|
+
console.error("[WebSocket] Failed to create WebSocket:", e);
|
|
1596
|
+
var errorMsg = "Failed to create WebSocket: " + e.toString();
|
|
1597
|
+
var errorLen = lengthBytesUTF8(errorMsg) + 1;
|
|
1598
|
+
var errorPtr = _malloc(errorLen);
|
|
1599
|
+
stringToUTF8(errorMsg, errorPtr, errorLen);
|
|
1600
|
+
_emscripten_websocket_on_connection_status(connectionId, false, errorPtr);
|
|
1601
|
+
_free(errorPtr);
|
|
1602
|
+
}
|
|
1603
|
+
}
|
|
1604
|
+
function js_websocket_disconnect(connectionId) {
|
|
1605
|
+
if (!Module.balancyWebSockets) return;
|
|
1606
|
+
var connection = Module.balancyWebSockets.get(connectionId);
|
|
1607
|
+
if (connection && connection.socket) {
|
|
1608
|
+
try {
|
|
1609
|
+
connection.socket.close();
|
|
1610
|
+
} catch (e) {}
|
|
1611
|
+
}
|
|
1612
|
+
Module.balancyWebSockets.delete(connectionId);
|
|
1613
|
+
}
|
|
1614
|
+
function js_websocket_subscribe(connectionId, eventName) {
|
|
1615
|
+
if (!Module.balancyWebSockets) return;
|
|
1616
|
+
var eventNameStr = UTF8ToString(eventName);
|
|
1617
|
+
var connection = Module.balancyWebSockets.get(connectionId);
|
|
1618
|
+
if (connection) {
|
|
1619
|
+
connection.subscribedEvents.add(eventNameStr);
|
|
1620
|
+
}
|
|
1621
|
+
}
|
|
1622
|
+
function js_websocket_send_message(connectionId, eventName, data) {
|
|
1623
|
+
if (!Module.balancyWebSockets) return;
|
|
1624
|
+
var eventNameStr = UTF8ToString(eventName);
|
|
1625
|
+
var dataStr = UTF8ToString(data);
|
|
1626
|
+
var connection = Module.balancyWebSockets.get(connectionId);
|
|
1627
|
+
if (connection && connection.socket) {
|
|
1628
|
+
var message = '42["' + eventNameStr + '",' + dataStr + "]";
|
|
1629
|
+
connection.socket.send(message);
|
|
1630
|
+
}
|
|
1631
|
+
}
|
|
1472
1632
|
function js_websocket_send_ack(connectionId, ackId, responseData) {
|
|
1473
1633
|
if (!Module.balancyWebSockets) return;
|
|
1474
1634
|
var responseDataStr = UTF8ToString(responseData);
|
|
@@ -7311,7 +7471,11 @@ var Balancy = function() {
|
|
|
7311
7471
|
invoke_viiiiiiiiiiiiiii: invoke_viiiiiiiiiiiiiii,
|
|
7312
7472
|
invoke_viijii: invoke_viijii,
|
|
7313
7473
|
js_fetch: js_fetch,
|
|
7474
|
+
js_websocket_connect: js_websocket_connect,
|
|
7475
|
+
js_websocket_disconnect: js_websocket_disconnect,
|
|
7314
7476
|
js_websocket_send_ack: js_websocket_send_ack,
|
|
7477
|
+
js_websocket_send_message: js_websocket_send_message,
|
|
7478
|
+
js_websocket_subscribe: js_websocket_subscribe,
|
|
7315
7479
|
random_get: _random_get
|
|
7316
7480
|
};
|
|
7317
7481
|
var wasmExports;
|
|
@@ -7431,9 +7595,9 @@ var Balancy = function() {
|
|
|
7431
7595
|
Module["__Z37jsbalancyInventory_GetTotalItemsCountPN7Balancy5Utils15JsonBasedObjectE"] = createExportWrapper("_Z37jsbalancyInventory_GetTotalItemsCountPN7Balancy5Utils15JsonBasedObjectE", 1);
|
|
7432
7596
|
Module["_balancyGenenal_LevelCompleted"] = createExportWrapper("balancyGenenal_LevelCompleted", 0);
|
|
7433
7597
|
Module["_balancyGenenal_LevelFailed"] = createExportWrapper("balancyGenenal_LevelFailed", 0);
|
|
7434
|
-
Module["_emscripten_websocket_on_connection_status"] = createExportWrapper("emscripten_websocket_on_connection_status", 3);
|
|
7435
|
-
Module["_emscripten_websocket_on_socketio_event"] = createExportWrapper("emscripten_websocket_on_socketio_event", 5);
|
|
7436
|
-
Module["_emscripten_websocket_on_socketio_error"] = createExportWrapper("emscripten_websocket_on_socketio_error", 3);
|
|
7598
|
+
var _emscripten_websocket_on_connection_status = Module["_emscripten_websocket_on_connection_status"] = createExportWrapper("emscripten_websocket_on_connection_status", 3);
|
|
7599
|
+
var _emscripten_websocket_on_socketio_event = Module["_emscripten_websocket_on_socketio_event"] = createExportWrapper("emscripten_websocket_on_socketio_event", 5);
|
|
7600
|
+
var _emscripten_websocket_on_socketio_error = Module["_emscripten_websocket_on_socketio_error"] = createExportWrapper("emscripten_websocket_on_socketio_error", 3);
|
|
7437
7601
|
var _malloc = Module["_malloc"] = createExportWrapper("malloc", 1);
|
|
7438
7602
|
var ___getTypeName = createExportWrapper("__getTypeName", 1);
|
|
7439
7603
|
Module["_downloadSucceededBinary"] = createExportWrapper("downloadSucceededBinary", 3);
|
package/dist/index.es.js
CHANGED
|
@@ -1338,46 +1338,9 @@ var Balancy = function() {
|
|
|
1338
1338
|
return;
|
|
1339
1339
|
}
|
|
1340
1340
|
var contentType = response.headers.get("content-type") || "";
|
|
1341
|
-
var
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
".jpeg",
|
|
1345
|
-
".gif",
|
|
1346
|
-
".bmp",
|
|
1347
|
-
".webp",
|
|
1348
|
-
".ico",
|
|
1349
|
-
".mp3",
|
|
1350
|
-
".mp4",
|
|
1351
|
-
".wav",
|
|
1352
|
-
".avi",
|
|
1353
|
-
".mov",
|
|
1354
|
-
".pdf",
|
|
1355
|
-
".zip",
|
|
1356
|
-
".rar",
|
|
1357
|
-
".7z",
|
|
1358
|
-
".exe",
|
|
1359
|
-
".dll",
|
|
1360
|
-
".so",
|
|
1361
|
-
".dylib",
|
|
1362
|
-
".ttf",
|
|
1363
|
-
".otf",
|
|
1364
|
-
".woff",
|
|
1365
|
-
".woff2"
|
|
1366
|
-
];
|
|
1367
|
-
var textMimeTypes = [
|
|
1368
|
-
"application/json",
|
|
1369
|
-
"text/",
|
|
1370
|
-
"application/xml",
|
|
1371
|
-
"application/javascript",
|
|
1372
|
-
"application/x-javascript"
|
|
1373
|
-
];
|
|
1374
|
-
var hasBinaryExtension = binaryExtensions.some(function(ext) {
|
|
1375
|
-
return urlString.toLowerCase().includes(ext);
|
|
1376
|
-
});
|
|
1377
|
-
var isTextMimeType = textMimeTypes.some(function(type) {
|
|
1378
|
-
return contentType.toLowerCase().includes(type);
|
|
1379
|
-
});
|
|
1380
|
-
var isBinary = contentType.includes("application/octet-stream") || hasBinaryExtension || !isTextMimeType && !contentType.includes("charset");
|
|
1341
|
+
var contentTypeLower = contentType.toLowerCase();
|
|
1342
|
+
var isTextContent = contentTypeLower.includes("application/json") || contentTypeLower.includes("text/") || contentTypeLower.includes("application/xml") || contentTypeLower.includes("application/javascript");
|
|
1343
|
+
var isBinary = !isTextContent;
|
|
1381
1344
|
if (isBinary) {
|
|
1382
1345
|
response.arrayBuffer().then(function(arrayBuffer) {
|
|
1383
1346
|
var dataSize = arrayBuffer.byteLength;
|
|
@@ -1464,6 +1427,203 @@ var Balancy = function() {
|
|
|
1464
1427
|
invokeErrorCallback(-1, error.message, "Network fetch failed");
|
|
1465
1428
|
});
|
|
1466
1429
|
}
|
|
1430
|
+
function js_websocket_connect(connectionId, url, authData) {
|
|
1431
|
+
if (!Module.balancyWebSockets) {
|
|
1432
|
+
Module.balancyWebSockets = new Map;
|
|
1433
|
+
}
|
|
1434
|
+
var urlStr = UTF8ToString(url);
|
|
1435
|
+
var authDataStr = UTF8ToString(authData);
|
|
1436
|
+
var wsUrl = urlStr;
|
|
1437
|
+
if (wsUrl.startsWith("http://")) {
|
|
1438
|
+
wsUrl = wsUrl.replace("http://", "ws://");
|
|
1439
|
+
} else if (wsUrl.startsWith("https://")) {
|
|
1440
|
+
wsUrl = wsUrl.replace("https://", "wss://");
|
|
1441
|
+
}
|
|
1442
|
+
if (location.protocol === "http:" && wsUrl.startsWith("wss://")) {
|
|
1443
|
+
wsUrl = wsUrl.replace("wss://", "ws://");
|
|
1444
|
+
}
|
|
1445
|
+
if (!wsUrl.endsWith("/")) {
|
|
1446
|
+
wsUrl += "/";
|
|
1447
|
+
}
|
|
1448
|
+
wsUrl += "socket.io/?EIO=4&transport=websocket";
|
|
1449
|
+
try {
|
|
1450
|
+
var socket = new WebSocket(wsUrl);
|
|
1451
|
+
socket.binaryType = "arraybuffer";
|
|
1452
|
+
var connection = {
|
|
1453
|
+
socket: socket,
|
|
1454
|
+
authData: authDataStr,
|
|
1455
|
+
subscribedEvents: new Set
|
|
1456
|
+
};
|
|
1457
|
+
Module.balancyWebSockets.set(connectionId, connection);
|
|
1458
|
+
socket.onopen = function() {
|
|
1459
|
+
var emptyMsg = "";
|
|
1460
|
+
var emptyLen = lengthBytesUTF8(emptyMsg) + 1;
|
|
1461
|
+
var emptyPtr = _malloc(emptyLen);
|
|
1462
|
+
stringToUTF8(emptyMsg, emptyPtr, emptyLen);
|
|
1463
|
+
_emscripten_websocket_on_connection_status(connectionId, true, emptyPtr);
|
|
1464
|
+
_free(emptyPtr);
|
|
1465
|
+
};
|
|
1466
|
+
socket.onclose = function() {
|
|
1467
|
+
var closeMsg = "Connection closed";
|
|
1468
|
+
var closeLen = lengthBytesUTF8(closeMsg) + 1;
|
|
1469
|
+
var closePtr = _malloc(closeLen);
|
|
1470
|
+
stringToUTF8(closeMsg, closePtr, closeLen);
|
|
1471
|
+
_emscripten_websocket_on_connection_status(connectionId, false, closePtr);
|
|
1472
|
+
_free(closePtr);
|
|
1473
|
+
Module.balancyWebSockets.delete(connectionId);
|
|
1474
|
+
};
|
|
1475
|
+
socket.onerror = function(error) {
|
|
1476
|
+
console.error("[WebSocket] Connection failed:", error);
|
|
1477
|
+
var errorMsg = "WebSocket connection failed";
|
|
1478
|
+
var errorLen = lengthBytesUTF8(errorMsg) + 1;
|
|
1479
|
+
var errorPtr = _malloc(errorLen);
|
|
1480
|
+
stringToUTF8(errorMsg, errorPtr, errorLen);
|
|
1481
|
+
_emscripten_websocket_on_connection_status(connectionId, false, errorPtr);
|
|
1482
|
+
_free(errorPtr);
|
|
1483
|
+
};
|
|
1484
|
+
socket.onmessage = function(event) {
|
|
1485
|
+
if (typeof event.data !== "string") return;
|
|
1486
|
+
var message = event.data;
|
|
1487
|
+
if (message.startsWith("0")) {
|
|
1488
|
+
try {
|
|
1489
|
+
var authJson = JSON.parse(connection.authData);
|
|
1490
|
+
var connectMessage = "40" + JSON.stringify({
|
|
1491
|
+
game_id: authJson.gameId,
|
|
1492
|
+
user_id: authJson.userId,
|
|
1493
|
+
env: authJson.environment,
|
|
1494
|
+
token: authJson.token,
|
|
1495
|
+
device_id: authJson.deviceId || ""
|
|
1496
|
+
});
|
|
1497
|
+
socket.send(connectMessage);
|
|
1498
|
+
} catch (e) {
|
|
1499
|
+
console.error("[WebSocket] Failed to send auth:", e);
|
|
1500
|
+
socket.send("40");
|
|
1501
|
+
}
|
|
1502
|
+
return;
|
|
1503
|
+
}
|
|
1504
|
+
if (message.startsWith("2")) {
|
|
1505
|
+
socket.send("3");
|
|
1506
|
+
return;
|
|
1507
|
+
}
|
|
1508
|
+
if (message.startsWith("40")) {
|
|
1509
|
+
return;
|
|
1510
|
+
}
|
|
1511
|
+
if (message.startsWith("41")) {
|
|
1512
|
+
return;
|
|
1513
|
+
}
|
|
1514
|
+
if (message.startsWith("42")) {
|
|
1515
|
+
var afterType = message.substring(2);
|
|
1516
|
+
var ackId = 0;
|
|
1517
|
+
var hasAckId = false;
|
|
1518
|
+
var jsonPart = afterType;
|
|
1519
|
+
var jsonStart = afterType.indexOf("[");
|
|
1520
|
+
if (jsonStart > 0) {
|
|
1521
|
+
var ackIdStr = afterType.substring(0, jsonStart);
|
|
1522
|
+
var parsedAckId = parseInt(ackIdStr);
|
|
1523
|
+
if (!isNaN(parsedAckId)) {
|
|
1524
|
+
hasAckId = true;
|
|
1525
|
+
ackId = parsedAckId;
|
|
1526
|
+
jsonPart = afterType.substring(jsonStart);
|
|
1527
|
+
}
|
|
1528
|
+
}
|
|
1529
|
+
try {
|
|
1530
|
+
var eventArray = JSON.parse(jsonPart);
|
|
1531
|
+
if (eventArray && eventArray.length >= 1) {
|
|
1532
|
+
var eventName = eventArray[0];
|
|
1533
|
+
var eventData = eventArray.length > 1 ? JSON.stringify(eventArray[1]) : "{}";
|
|
1534
|
+
if (eventName === "system:ping") {
|
|
1535
|
+
if (hasAckId) {
|
|
1536
|
+
socket.send("43" + ackId + "[]");
|
|
1537
|
+
}
|
|
1538
|
+
return;
|
|
1539
|
+
}
|
|
1540
|
+
if (eventName === "profile:updated") {
|
|
1541
|
+
if (hasAckId) {
|
|
1542
|
+
socket.send("43" + ackId + "[]");
|
|
1543
|
+
}
|
|
1544
|
+
if (connection.subscribedEvents.has(eventName) || connection.subscribedEvents.size === 0) {
|
|
1545
|
+
var eventNameLen = lengthBytesUTF8(eventName) + 1;
|
|
1546
|
+
var eventNamePtr = _malloc(eventNameLen);
|
|
1547
|
+
stringToUTF8(eventName, eventNamePtr, eventNameLen);
|
|
1548
|
+
var eventDataLen = lengthBytesUTF8(eventData) + 1;
|
|
1549
|
+
var eventDataPtr = _malloc(eventDataLen);
|
|
1550
|
+
stringToUTF8(eventData, eventDataPtr, eventDataLen);
|
|
1551
|
+
_emscripten_websocket_on_socketio_event(connectionId, eventNamePtr, eventDataPtr, false, 0);
|
|
1552
|
+
_free(eventNamePtr);
|
|
1553
|
+
_free(eventDataPtr);
|
|
1554
|
+
}
|
|
1555
|
+
return;
|
|
1556
|
+
}
|
|
1557
|
+
if (connection.subscribedEvents.has(eventName) || connection.subscribedEvents.size === 0) {
|
|
1558
|
+
var eventNameLen = lengthBytesUTF8(eventName) + 1;
|
|
1559
|
+
var eventNamePtr = _malloc(eventNameLen);
|
|
1560
|
+
stringToUTF8(eventName, eventNamePtr, eventNameLen);
|
|
1561
|
+
var eventDataLen = lengthBytesUTF8(eventData) + 1;
|
|
1562
|
+
var eventDataPtr = _malloc(eventDataLen);
|
|
1563
|
+
stringToUTF8(eventData, eventDataPtr, eventDataLen);
|
|
1564
|
+
_emscripten_websocket_on_socketio_event(connectionId, eventNamePtr, eventDataPtr, hasAckId, ackId);
|
|
1565
|
+
_free(eventNamePtr);
|
|
1566
|
+
_free(eventDataPtr);
|
|
1567
|
+
} else {
|
|
1568
|
+
if (hasAckId) {
|
|
1569
|
+
socket.send("43" + ackId + "[]");
|
|
1570
|
+
}
|
|
1571
|
+
}
|
|
1572
|
+
}
|
|
1573
|
+
} catch (e) {
|
|
1574
|
+
console.error("[WebSocket] Failed to parse event:", e);
|
|
1575
|
+
}
|
|
1576
|
+
return;
|
|
1577
|
+
}
|
|
1578
|
+
if (message.startsWith("44")) {
|
|
1579
|
+
var errorJson = message.substring(2);
|
|
1580
|
+
console.error("[WebSocket] Socket.IO error:", errorJson);
|
|
1581
|
+
var errorLen = lengthBytesUTF8(errorJson) + 1;
|
|
1582
|
+
var errorPtr = _malloc(errorLen);
|
|
1583
|
+
stringToUTF8(errorJson, errorPtr, errorLen);
|
|
1584
|
+
_emscripten_websocket_on_socketio_error(connectionId, 44, errorPtr);
|
|
1585
|
+
_free(errorPtr);
|
|
1586
|
+
return;
|
|
1587
|
+
}
|
|
1588
|
+
};
|
|
1589
|
+
} catch (e) {
|
|
1590
|
+
console.error("[WebSocket] Failed to create WebSocket:", e);
|
|
1591
|
+
var errorMsg = "Failed to create WebSocket: " + e.toString();
|
|
1592
|
+
var errorLen = lengthBytesUTF8(errorMsg) + 1;
|
|
1593
|
+
var errorPtr = _malloc(errorLen);
|
|
1594
|
+
stringToUTF8(errorMsg, errorPtr, errorLen);
|
|
1595
|
+
_emscripten_websocket_on_connection_status(connectionId, false, errorPtr);
|
|
1596
|
+
_free(errorPtr);
|
|
1597
|
+
}
|
|
1598
|
+
}
|
|
1599
|
+
function js_websocket_disconnect(connectionId) {
|
|
1600
|
+
if (!Module.balancyWebSockets) return;
|
|
1601
|
+
var connection = Module.balancyWebSockets.get(connectionId);
|
|
1602
|
+
if (connection && connection.socket) {
|
|
1603
|
+
try {
|
|
1604
|
+
connection.socket.close();
|
|
1605
|
+
} catch (e) {}
|
|
1606
|
+
}
|
|
1607
|
+
Module.balancyWebSockets.delete(connectionId);
|
|
1608
|
+
}
|
|
1609
|
+
function js_websocket_subscribe(connectionId, eventName) {
|
|
1610
|
+
if (!Module.balancyWebSockets) return;
|
|
1611
|
+
var eventNameStr = UTF8ToString(eventName);
|
|
1612
|
+
var connection = Module.balancyWebSockets.get(connectionId);
|
|
1613
|
+
if (connection) {
|
|
1614
|
+
connection.subscribedEvents.add(eventNameStr);
|
|
1615
|
+
}
|
|
1616
|
+
}
|
|
1617
|
+
function js_websocket_send_message(connectionId, eventName, data) {
|
|
1618
|
+
if (!Module.balancyWebSockets) return;
|
|
1619
|
+
var eventNameStr = UTF8ToString(eventName);
|
|
1620
|
+
var dataStr = UTF8ToString(data);
|
|
1621
|
+
var connection = Module.balancyWebSockets.get(connectionId);
|
|
1622
|
+
if (connection && connection.socket) {
|
|
1623
|
+
var message = '42["' + eventNameStr + '",' + dataStr + "]";
|
|
1624
|
+
connection.socket.send(message);
|
|
1625
|
+
}
|
|
1626
|
+
}
|
|
1467
1627
|
function js_websocket_send_ack(connectionId, ackId, responseData) {
|
|
1468
1628
|
if (!Module.balancyWebSockets) return;
|
|
1469
1629
|
var responseDataStr = UTF8ToString(responseData);
|
|
@@ -7306,7 +7466,11 @@ var Balancy = function() {
|
|
|
7306
7466
|
invoke_viiiiiiiiiiiiiii: invoke_viiiiiiiiiiiiiii,
|
|
7307
7467
|
invoke_viijii: invoke_viijii,
|
|
7308
7468
|
js_fetch: js_fetch,
|
|
7469
|
+
js_websocket_connect: js_websocket_connect,
|
|
7470
|
+
js_websocket_disconnect: js_websocket_disconnect,
|
|
7309
7471
|
js_websocket_send_ack: js_websocket_send_ack,
|
|
7472
|
+
js_websocket_send_message: js_websocket_send_message,
|
|
7473
|
+
js_websocket_subscribe: js_websocket_subscribe,
|
|
7310
7474
|
random_get: _random_get
|
|
7311
7475
|
};
|
|
7312
7476
|
var wasmExports;
|
|
@@ -7426,9 +7590,9 @@ var Balancy = function() {
|
|
|
7426
7590
|
Module["__Z37jsbalancyInventory_GetTotalItemsCountPN7Balancy5Utils15JsonBasedObjectE"] = createExportWrapper("_Z37jsbalancyInventory_GetTotalItemsCountPN7Balancy5Utils15JsonBasedObjectE", 1);
|
|
7427
7591
|
Module["_balancyGenenal_LevelCompleted"] = createExportWrapper("balancyGenenal_LevelCompleted", 0);
|
|
7428
7592
|
Module["_balancyGenenal_LevelFailed"] = createExportWrapper("balancyGenenal_LevelFailed", 0);
|
|
7429
|
-
Module["_emscripten_websocket_on_connection_status"] = createExportWrapper("emscripten_websocket_on_connection_status", 3);
|
|
7430
|
-
Module["_emscripten_websocket_on_socketio_event"] = createExportWrapper("emscripten_websocket_on_socketio_event", 5);
|
|
7431
|
-
Module["_emscripten_websocket_on_socketio_error"] = createExportWrapper("emscripten_websocket_on_socketio_error", 3);
|
|
7593
|
+
var _emscripten_websocket_on_connection_status = Module["_emscripten_websocket_on_connection_status"] = createExportWrapper("emscripten_websocket_on_connection_status", 3);
|
|
7594
|
+
var _emscripten_websocket_on_socketio_event = Module["_emscripten_websocket_on_socketio_event"] = createExportWrapper("emscripten_websocket_on_socketio_event", 5);
|
|
7595
|
+
var _emscripten_websocket_on_socketio_error = Module["_emscripten_websocket_on_socketio_error"] = createExportWrapper("emscripten_websocket_on_socketio_error", 3);
|
|
7432
7596
|
var _malloc = Module["_malloc"] = createExportWrapper("malloc", 1);
|
|
7433
7597
|
var ___getTypeName = createExportWrapper("__getTypeName", 1);
|
|
7434
7598
|
Module["_downloadSucceededBinary"] = createExportWrapper("downloadSucceededBinary", 3);
|