mirror of
https://github.com/ading2210/libcurl.js.git
synced 2025-05-12 05:50:01 -04:00
24 lines
No EOL
651 B
JavaScript
24 lines
No EOL
651 B
JavaScript
function test() {
|
|
let message_len = 128*1024;
|
|
|
|
return new Promise((resolve, reject) => {
|
|
let ws = new libcurl.WebSocket("wss://echo.websocket.org");
|
|
ws.addEventListener("open", () => {
|
|
ws.send("hello".repeat(message_len));
|
|
});
|
|
|
|
let messages = 0;
|
|
ws.addEventListener("message", (event) => {
|
|
messages += 1;
|
|
if (messages >= 2) {
|
|
if (event.data !== "hello".repeat(message_len)) reject("unexpected response");
|
|
if (messages >= 11) resolve();
|
|
ws.send("hello".repeat(message_len));
|
|
}
|
|
});
|
|
|
|
ws.addEventListener("error", () => {
|
|
reject("ws error occurred");
|
|
});
|
|
})
|
|
} |