Skip to content

Latest commit

 

History

History
93 lines (61 loc) · 1.97 KB

README.md

File metadata and controls

93 lines (61 loc) · 1.97 KB

Deko

Built with the Deno Standard Library

Deko is a simple WebSocket client for Deno.

Warning

If you want to connect WebSocket on browsers, use WebSocket instead.

Features

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.

Footnotes

  1. https://babiabeo.github.io/autobahn/deko/