@jkob/ws
Example Configuration
const config = {
port: 1350,
host: "wss://example.websocket.server.com",
protocol: "example-protocol",
};
Using on server side
import { getServer } from "@jkob/ws/dist/server";
const server = getServer(config);
await server.start();
await server.stop();
import { getClient } from "@jkob/ws/dist/server";
const client = await getClient(config, "scope");
await client.connect();
client.send("type", "message to clients");
client.close();
Using in web browser
import { getWebClient } from "@jkob/ws/dist/browser":
const client = getWebClient(config, "scope");
await client.connect();
client.send("type", "message to clients");
client.on("type", (message) => {
console.log("received message", message);
});
client.close();