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