• Stars
    star
    152
  • Rank 244,685 (Top 5 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 4 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

๐Ÿฆ• A simple WebSocket library like ws of node.js library for deno
logo

deno websocket

deno doc GitHub nest badge

๐Ÿฆ• A simple WebSocket library like ws of node.js library for deno

This library is wrapping the ws standard library as a server-side and the native WebSocket API as a client-side. You can receive callbacks at the EventEmitter and can use the same object format on both the server-side and the client-side.

  • Deno >= 1.8.3

Quick Start

Example Demo

demo

Server side

$ deno run --allow-net https://deno.land/x/[email protected]/example/server.ts

Client side

$ deno run --allow-net https://deno.land/x/[email protected]/example/client.ts
ws connected! (type 'close' to quit)
> something

Usage

Server side

import { WebSocketClient, WebSocketServer } from "https://deno.land/x/[email protected]/mod.ts";

const wss = new WebSocketServer(8080);
wss.on("connection", function (ws: WebSocketClient) {
  ws.on("message", function (message: string) {
    console.log(message);
    ws.send(message);
  });
});

Client side

import { WebSocketClient, StandardWebSocketClient } from "https://deno.land/x/[email protected]/mod.ts";
const endpoint = "ws://127.0.0.1:8080";
const ws: WebSocketClient = new StandardWebSocketClient(endpoint);
ws.on("open", function() {
  console.log("ws connected!");
  ws.send("something");
});
ws.on("message", function (message: string) {
  console.log(message);
});

Documentation

WebSocketServer

Event

event detail
connection Emitted when the handshake is complete
error Emitted when an error occurs

Field

field detail type
server.clients A set that stores all connected clients Set<WebSocket>

Method

method detail
close() Close the server

WebSocketClient

Event

event detail
open Emitted when the connection is established
close Emitted when the connection is closed
message Emitted when a message is received from the server
ping Emitted when a ping is received from the server
pong Emitted when a pong is received from the server
error Emitted when an error occurs

Field

field detail type
websocket.isClosed Get the close flag Boolean | undefined

Method

method detail
send(message:string | Unit8Array) Send a message
ping(message:string | Unit8Array) Send the ping
close([code:int[, reason:string]]) Close the connection with the server
forceClose() Forcibly close the connection with the server

LICENSE

MIT LICENSE

More Repositories

1

github-profile-trophy

๐Ÿ† Add dynamically generated GitHub Stat Trophies on your readme
TypeScript
5,108
star
2

lazyhub

:octocat: lazyhub - Terminal UI Client for GitHub using gocui.
Go
192
star
3

gpt-assistants-api-ui

๐Ÿ’ฌ OpenAI Assistants API chat UI ๐Ÿ› ๏ธ It works easily by setting the ASSISTANT ID ๐Ÿ“ Supports file upload and file download ๐Ÿƒ Supports Streaming API ๐ŸชŸ Support to Azure OpenAI
Python
180
star
4

covid19-japan-web-api

๐Ÿ‡ฏ๐Ÿ‡ต Web API to get ๐Ÿฆ COVID-19(coronavirus) information of each prefecture in Japan
Python
127
star
5

ryo-ma

14
star
6

awesome-python-environment

๐ŸA curated list of awesome python environment.
10
star
7

pytl

Command line tool that parses python file, enumerates classes and methods as a tree structure.
Python
4
star
8

coronaui

๐Ÿฆ coronaui - Terminal UI Client for COVID-19 information.
Go
3
star
9

deno-validator

๐Ÿฆ• A simple string validation for deno
TypeScript
2
star
10

helper-call-platform

TypeScript
2
star
11

ood-meteoroid-demo

Python
2
star
12

lazyland

๐Ÿฆ•lazyland - A terminal UI Client for deno land.
Go
2
star
13

newcomer_practice

Java
1
star
14

dim-json-repository

1
star
15

awesome-oak

A curated list of awesome oak that is web application framework for deno.
1
star
16

raspberrypi-vacancy-button

Python
1
star
17

keycloak-nginx-docker-compose

JavaScript
1
star
18

url-proxy

Python
1
star
19

homebrew-lazyhub

Ruby
1
star
20

opendata-package-repository

You can use dim to quickly get a convenient open-dataset with a single command execution
1
star