npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

daejeon

v1.1.0

Published

daejeon is a nodejs websocket server library which provides an easy process

Readme

daejeon

daejeon is a nodejs websocket server library which provides an easy process. only JSON type is allowed. the features are simple - Server, Client and Room


Install

npm i --save daejeon


Example ( Chat )

you can see the all of features while this example.

TS

import { Server, Client, Room } from 'daejeon';

const server = new Server({port: 8888});
const chatRoom = new Room('chat-room');

server.onServerStarted(() => {
    console.log('running');
});

server.onClientConnected((client: Client) => {
    chatRoom.enter(client);
});

server.onMessageReceived((client: Client, jsonMessage: object) => {
    chatRoom.sendAll(jsonMessage, client);
});

server.onClientError((client: Client, error: Error) => {
    console.error(error);
});

server.onClientClosed((client: Client, reason?: string) => {
    chatRoom.kick(client);
    chatRoom.sendAll({closeMsg: client.id + ' has been outed'});
});

server.start();

JS

var daejeon = require('daejeon');
var server = new daejeon.Server({ port: 8888 });
var chatRoom = new daejeon.Room('chat-room');

server.onServerStarted(function () {
    console.log('running');
});
server.onClientConnected(function (client) {
    chatRoom.enter(client);
});
server.onMessageReceived(function (client, jsonMessage) {
    chatRoom.sendAll(jsonMessage, client);
});
server.onClientError(function (client, error) {
    console.error(error);
});
server.onClientClosed(function (client, reason) {
    chatRoom.kick(client);
    chatRoom.sendAll({ closeMsg: client.id + ' has been outed' });
});

server.start();

Example ( Server Test )

test client is provided. you can test your server in server-side code.

it will proceed test cases you want in regular sequence.

basically TestClient extends 'Client' class.

const testClient = new TestClient('ws://localhost:8888');
testClient.onMessageReceived(jsonMessage => {
    console.log(jsonMessage);
});

testClient.startTest([
    { // SEQ 1
        delayForBegin: 1000,
        jsonMessage: {
            data: 'Hi. I am client1!'
        }
    },
    { // SEQ 2
        jsonMessage: {
            data: 'I am hungry'
        },
        delayForEnd: 500
    } // ...
], handler);

function handler(success: TestMessage[], failure: TestMessage[]) {
    if (failure.length > 0) {
        console.error(failure);
    }
}

API

this library is based on ‘ws’. so it shares ‘WebSocket’ type. please refer to that on npm-ws about ‘WebSocket’ type.

Class: Server

constructor (options)

  • options <WebSocket.ServerOptions>

serverOptions <WebSocket.ServerOptions>

returns server options you input at start.

clients <Client[]>

returns connected client list.

start ()

starts server.

stop ()

closes server.

kick ()

  • client <Client> kicks a connected client.

clear ()

kicks all connected clients.

onServerStarted (callback)

  • callback <Function>

called when server started.

onClientConnected (callback)

  • callback <Function>
    • client <Client>

called when a client is connected.

onMessageReceived (callback)

  • callback <Function>
    • client <Client>
    • jsonMessage <object>

called when the server receive a message. only JSON type data is allowed. so it will not call in case of parsing exception but calls ‘onError’.

onClientClosed (callback)

  • callback <Function>
    • client <Client>
    • reason <string> | <undefined>

called when the client is disconnected.

onClientError (callback)

  • callback <Function>
    • client <Client>
    • error <Error>

called when error occurred in client side.

Class: Client

constructor (ws [, id])

  • ws <WebSocket>
  • id <string> ‘id’ is set to UUIDv4 by default.

id <string>

returns unique id. by default UUIDv4.

ip <string> returns client’ ip address.

session <object>

returns session object. the session can be used to store custom data you need.

send (jsonMessage) : <boolean>

  • jsonMessage <object> sends message to this client. only JSON type data is allowed. if not, server will not send the message to other clients.

close ()

closes this client. ( its web socket also )

onClosed (callback)

called when this client is closing.

Class: Room

construntor (id)

  • id <string> ‘id’ should be unique room name. this id is not used in this library by default.

id <string>

returns id of this room.

enter (client)

  • client <Client> adds the client to this room.

kick (client) : <boolean>

  • client <Client> kicks the client.

kickAll ()

kicks all clients joined this room.

sendAll (jsonMessage [, ignore]) : <boolean[]>

  • jsonMessage <object>
  • ignore : <Client[]> | <undefined>

sends message to all joined this room excepting the ignored clients. only JSON type data is allowed.


Welcome your feedback

Thank you for reading!