wsi
Asynchronously iterate over WebSocket
events.
import iterable from "jsr:@korkje/wsi";
const socket = new WebSocket("wss://echo.websocket.events");
for await (const data of iterable(socket)) {
console.log(data);
socket.send("hello");
}
Also exports open
and closed
, which create Promise
s that resolve when the socket opens/closes.
import iterable, { open } from "jsr:@korkje/wsi";
const socket = new WebSocket("wss://echo.websocket.events");
await open(socket); // Socket is open
socket.send("hello");
for await (const data of iterable(socket)) {
console.log(data);
socket.send("hello");
}