Deko is a simple WebSocket client for Deno.
Warning
If you want to connect WebSocket on browsers, use
WebSocket
instead.
- Easy to use.
- Supports custom headers.
- Passes the Autobahn testsuite. 1
- Follows RFC 6455 WebSocket implementation.
This package is available on jsr.io.
Use deno add
command to add this package to your project:
deno add @babia/deko
Then, import it in your source file:
import { Deko } from "@babia/deko";
Or use jsr:
specifier if you want to use an install step.
import { Deko } from "jsr:@babia/deko@^0.1.2";
import { Deko, OpCode } from "@babia/deko";
const client = new Deko({ uri: "websocket url goes here" });
client.onOpen = () => {
console.log("Connected to WebSocket server!");
};
await client.connect();
import { Deko, OpCode } from "@babia/deko";
const client = new Deko({ uri: "websocket url goes here" });
client.onMessage = (_, message) => {
if (message.opcode === OpCode.TextFrame) {
console.log(new TextDecoder().decode(message.payload));
}
};
await client.connect();
import { Deko, OpCode } from "@babia/deko";
const client = new Deko({ uri: "websocket url goes here" });
await client.connect();
setTimeout(async () => {
await client.sendMessage("Hello World!");
}, 5000); // Sends message after 5 seconds
This repository/package is under MIT License. See LICENSE.