sturdy-websocket
sturdy-websocket copied to clipboard
how use this lib in nodejs
@rj03hou A bit of a late reply, but I found a solution through ws
npm install ws
import SturdyWebSocket from "sturdy-websocket";
import WebSocket from "ws";
const ws = new SturdyWebSocket.default("wss://whateverwebsocket", {
wsConstructor: WebSocket
});
ws.onopen = () => {
console.log("Connected!")
}
This works since WebSocket needs a constructor in the global scope and Node.js doesn't provide one. By using the ws library you can bypass this and it should work.
@rj03hou A bit of a late reply, but I found a solution through ws
npm install ws
import SturdyWebSocket from "sturdy-websocket"; import WebSocket from "ws"; const ws = new SturdyWebSocket.default("wss://whateverwebsocket", { wsConstructor: WebSocket }); ws.onopen = () => { console.log("Connected!") }
This works since WebSocket needs a constructor in the global scope and Node.js doesn't provide one. By using the ws library you can bypass this and it should work.
sturdy-websocket version is ? i have no default function in the libiary
@rj03hou A bit of a late reply, but I found a solution through ws
npm install ws
import SturdyWebSocket from "sturdy-websocket"; import WebSocket from "ws"; const ws = new SturdyWebSocket.default("wss://whateverwebsocket", { wsConstructor: WebSocket }); ws.onopen = () => { console.log("Connected!") }
This works since WebSocket needs a constructor in the global scope and Node.js doesn't provide one. By using the ws library you can bypass this and it should work.
sturdy-websocket version is ? i have no default function in the libiary
version 0.2.1 works for me and include the default function