Skip to content

korkje/wsi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

wsi JSR

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 Promises 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");
}