Skip to content

babiabeo/deko

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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/