lunel-cli 0.1.85 → 0.1.87
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/transport/v2.js +9 -6
- package/package.json +1 -1
package/dist/transport/v2.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { WebSocket } from "ws";
|
|
2
|
-
import
|
|
2
|
+
import { createRequire } from "module";
|
|
3
3
|
import { V2_FRAME_ENCRYPTED_MESSAGE, buildSessionV2WsUrl, decodeV2BinaryFrame, encodeV2EncryptedFrame, isProtocolRequest, isProtocolResponse, isV2HandshakeFrame, } from "./protocol.js";
|
|
4
|
+
const require = createRequire(import.meta.url);
|
|
5
|
+
const sodium = require("libsodium-wrappers");
|
|
4
6
|
function toUint8Array(data) {
|
|
5
7
|
if (data instanceof Uint8Array)
|
|
6
8
|
return data;
|
|
@@ -47,9 +49,9 @@ export class V2SessionTransport {
|
|
|
47
49
|
this.state = "open";
|
|
48
50
|
resolve();
|
|
49
51
|
});
|
|
50
|
-
ws.on("message", async (data) => {
|
|
52
|
+
ws.on("message", async (data, isBinary) => {
|
|
51
53
|
try {
|
|
52
|
-
await this.handleMessage(data);
|
|
54
|
+
await this.handleMessage(data, isBinary);
|
|
53
55
|
}
|
|
54
56
|
catch (error) {
|
|
55
57
|
this.options.debugLog?.("[transport:v2] message handling failed", error);
|
|
@@ -101,9 +103,10 @@ export class V2SessionTransport {
|
|
|
101
103
|
}
|
|
102
104
|
this.ws = null;
|
|
103
105
|
}
|
|
104
|
-
async handleMessage(data) {
|
|
105
|
-
if (
|
|
106
|
-
const
|
|
106
|
+
async handleMessage(data, isBinary) {
|
|
107
|
+
if (!isBinary) {
|
|
108
|
+
const text = typeof data === "string" ? data : Buffer.from(data).toString("utf-8");
|
|
109
|
+
const raw = JSON.parse(text);
|
|
107
110
|
if ("type" in raw) {
|
|
108
111
|
await this.options.handlers.onSystemMessage(raw);
|
|
109
112
|
if (raw.type === "peer_connected") {
|