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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@dipen557/chat-sdk

v1.0.0

Published

WebSocket-based chat system SDK for 100xdevs

Downloads

67

Readme

Chat SDK Documentation

This SDK provides a simple interface to interact with the WebSocket-based chat system.

1. Server Setup

Ensure your WebSocket server is running and accessible. The server should be configured with:

  • WebSocket endpoint at /ws
  • JWT authentication
  • Message history support
  • Room management

Installation

# If using npm
npm install @dipen557/chat-sdk

# If using yarn
yarn add @dipen557/chat-sdk

Basic Usage

import { ChatSDK } from '@dipen557/chat-sdk';

// Initialize the SDK
const chatSDK = new ChatSDK({
  serverUrl: 'ws://your-server-url',
  token: 'your-jwt-token',
  onError: (error) => console.error('Chat error:', error),
  onConnectionChange: (connected) => console.log('Connection status:', connected)
});

// Connect to the chat server
await chatSDK.connect();

// Listen for messages
chatSDK.on('message', (message) => {
  console.log('New message:', message);
});

// Listen for room access updates
chatSDK.on('roomAccess', (roomIds) => {
  console.log('Available rooms:', roomIds);
});

// Join a room
chatSDK.joinRoom('room-id');

// Send a message
chatSDK.sendMessage('room-id', 'Hello, world!');

// Disconnect when done
chatSDK.disconnect();

React Integration Example

import { useEffect, useState } from 'react';
import { ChatSDK, Message } from '@dipen557/chat-sdk';

function ChatComponent() {
  const [messages, setMessages] = useState<Message[]>([]);
  const [sdk, setSDK] = useState<ChatSDK | null>(null);

  useEffect(() => {
    const chatSDK = new ChatSDK({
      serverUrl: 'ws://your-server-url',
      token: 'your-jwt-token'
    });

    chatSDK.on('message', (message) => {
      setMessages(prev => [...prev, message]);
    });

    chatSDK.connect().catch(console.error);
    setSDK(chatSDK);

    return () => {
      chatSDK.disconnect();
    };
  }, []);

  const sendMessage = (content: string) => {
    sdk?.sendMessage('room-id', content);
  };

  return (
    <div>
      {messages.map(msg => (
        <div key={msg.id}>{msg.content}</div>
      ))}
    </div>
  );
}

Events

The SDK emits the following events:

  • message: Fired when a new message is received
  • roomAccess: Fired when room access information is received
  • history: Fired when message history is received after joining a room
  • error: Fired when an error occurs
  • connectionChange: Fired when the connection status changes

API Reference

Constructor

new ChatSDK(options: ChatSDKOptions)

Options:

  • serverUrl: WebSocket server URL
  • token: JWT authentication token
  • onError?: Error callback function
  • onConnectionChange?: Connection status callback function

Methods

connect(): Promise

Connects to the chat server.

joinRoom(roomId: string): void

Joins a specific chat room.

sendMessage(roomId: string, content: string): void

Sends a message to a specific room.

disconnect(): void

Disconnects from the chat server.

Error Handling

The SDK includes automatic reconnection logic with exponential backoff. It will attempt to reconnect up to 5 times when the connection is lost.

TypeScript Support

The SDK is written in TypeScript and includes type definitions for all interfaces and methods.

Security Considerations

  1. Always use HTTPS in production
  2. Never expose JWT tokens in client-side code
  3. Implement proper token refresh mechanisms
  4. Set appropriate WebSocket timeouts
  5. Implement rate limiting on the server side

Browser Support

The SDK supports all modern browsers that implement the WebSocket API:

  • Chrome 6+
  • Firefox 6+
  • Safari 7+
  • Edge 12+
  • Opera 12.1+