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

simple-chat-client

v1.1.0

Published

Client for Simple Chat server

Downloads

8

Readme

Simple-Chat-Client

Simple-Chat-Client is an entity that connects to an Simple-Chat server.

simple-chat-client package includes set of features to connect and authenticate securely and reliably.

It supports Node.js, browsers and React Native. See below for differences. In connection WebSockets are used. Library is using Socket.Io.

Installation

Use npm or yarn to install the package

npm i --save simple-chat-client
yarn add simple-chat-client

Example usage

import SimpleChatClient from 'simple-chat-client';

const chatClient = new SimpleChatClient({
        host: 'http://localhost',
        port: 3333,
        userId: 'user_id',
        accessToken: 'access_token',
      });

chatClient.start();

chatClient.on("error", (err) => {
  console.log(err.message);
});

chatClient.on('message', (chatMessage: Message, ack: () => void) => {
    ack(); //Need to acknowledge that message received
    ...
    });
  });

const message = {
  to: 'chat_id',
  body: {
    text: 'test',
  },
  timestamp: 123123123123,
};

chatClient?.sendMessage(message)

Params

Following parameters are exposed in Object instance:

status: ConnectionStatus

enum ConnectionStatus {
  CONNECTED = 'connected',
  DISCONNECTED = 'disconnected',
}

API Reference

The following methods are exported by the simple-chat-client module:


start(): void

Create a connection with the server. This should be called on a created object instance. This could be called also before message listeners added.


disconnect(): void

Disconnect from the server.


sendMessage: (message: Message) => Promise<string>

Send messages to chat users. Possible messages are text messages and typing. Users can send typing events without message body or with the message body.

Returns:

message-id saved on the server.

interface Message {
  id?: string;
  to: string;
  timestamp: number;
  body?: {
    [key: string]: any;
  };
  typing?: boolean;
  from?: string;
}

loadArchive: (chatId: string, limit: number, after?: string | null) => Promise<Message[]>

Load chat message archive from a server. To load the latest messages, after should be empty. If it is needed to load messages after a specific message, after should be provided.

Note: if after is not provided last messages will be provided.

Params:

  • chatId (string) -- chat id from which to fetch messages
  • limit (number) -- how many messages to fetch
  • after (string) (optional) -- chat id from which to fetch messages.

Returns:

Message list.


joinChat: (chatId: string, temp?: boolean) => Promise<boolean>

Join chat permanently or temporarily. Temporary means that on disconnect chat join will be removed.

Note: if temp provided as true then the user will be joined temporary, and on disconnection will be automatically removed from chat.

Note: if temp provided as true then system should manually leave chat when the user navigates out of the chat.

Params:

  • chatId (string) -- chat id to which join
  • temp (boolean) (optional)-- flag to join chat temporary

Returns:

boolean if successfully joined or not.


leaveChat: (chatId: string) => Promise<boolean>

Leave chat. When user left chat he will not receive any notifications and messages

Params:

  • chatId (string) -- chat id which to leave

Returns:

boolean if successfully left or not.


createChat: (type: ChatTypes, users: string[]) => Promise<string>

Create chat which will be used in communication. Possible types of the chat are Multi-User chat, and Single User chat For single-user chat it is needed to provide a list of two users who will be participants in the chat.

Params:

  • type (ChatTypes) -- type of the chat.
  • users (string[]) (optional) -- user list for SUC chat. Should contain only two user ids.
enum ChatTypes {
  SUC = '@suc',
  MUC = '@muc',
}

Returns:

string id of the newly created chat.


Available events

Below events are available to listen:

Event connected

chatClient.on('connected', () => {
  console.debug();
});

Event disconnected

chatClient.on('disconnected', () => {
  console.debug();
});

Event error

chatClient.on('error', (error: Error) => {
  console.log(error.message);
});

Event reconnect

chatClient.on('reconnect', (attempt: number) => {
  console.log(attempt);
});

Event reconnect_attempt

chatClient.on('reconnect_attempt', (attempt: number) => {
  console.debug();
});

Event reconnect_error

chatClient.on('reconnect_error', (error: Error) => {
  console.log(error.message);
});

Event reconnect_failed

chatClient.on('reconnect_failed', () => {
  console.log(error.message);
});

Event message

chatClient.on("message", (chatMessage: Message, ack: () => void) => {
    ack(); //Need to acknowledge that message received
    ...
    });
  });

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT