Built and signed on GitHub ActionsBuilt and signed on GitHub Actions
Built and signed on GitHub Actions
latest
babiabeo/dekoA simple WebSocket client for Deno runtime
This package works with Deno![This package works with Deno This package works with Deno](/logos/deno.svg?__frsh_c=325fc0b4951a6a64ccc59d061f4fc90aba37dcd3)
JSR Score
100%
Published
11 months ago (0.1.3)
Deko
Deko is a simple WebSocket client for Deno.
Warning
If you want to connect WebSocket on browsers, use
WebSocket
instead.
Features
- Easy to use.
- Supports custom headers.
- Passes the Autobahn testsuite. ^report
- Follows RFC 6455 WebSocket implementation.
Usage
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";
Examples
Open event handle
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();
Receives a text message from WebSocket server
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();
Sends a message to WebSocket server
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
License
This repository/package is under MIT License. See LICENSE.
Built and signed on
View transparency logGitHub Actions
Add Package
deno add jsr:@babia/deko
Import symbol
import * as deko from "@babia/deko";
---- OR ----
Import directly with a jsr specifier
import * as deko from "jsr:@babia/deko";