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