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

@ravex/client

v0.1.1

Published

connect to ravex from the frontend

Readme

@ravex/client

Ravex Client

A robust, fully-typed WebSocket client for the Ravex real-time chat system. Built on top of socket.io-client, it provides a clean, promise-based API with comprehensive TypeScript support for all chat operations.

Installation

npm install @ravex/client
# or
pnpm add @ravex/client
# or
yarn add @ravex/client

Quick Start

import { ChatClient } from '@ravex/client'
import type { User } from '@ravex/types'

const currentUser: User = {
  id: 'user-123',
  username: 'johndoe',
  status: 'online',
  socketIds: []
}

// 1. Initialize the client
const client = new ChatClient({
  url: 'http://localhost:3000',
  auth: { user: currentUser }
})

// 2. Setup event listeners
client.onMessage((message) => {
  console.log('New message received:', message)
})

// 3. Send a message to a room
await client.sendMessage({
  roomId: 'room-abc',
  content: 'Hello everyone!'
})

API Reference

Initialization

new ChatClient(options?: ChatClientOptions)

Creates a new chat client instance. Automatically connects on instantiation. Call disconnect() to close the connection, or pass autoConnect: false via socket.io-client options if you want manual control.

ChatClientOptions properties:

  • url (string): The base URL of the socket.io server. Defaults to ''.
  • namespace (string): The namespace to connect to. Defaults to '/'.
  • auth (Object | Function): Authentication payload sent during connection handshake. Usually contains the { user: User } object.
  • transports (string[]): Socket.io transports. Defaults to ['websocket', 'polling'].
  • withCredentials (boolean): Whether to send cross-origin credentials. Defaults to true.
  • autoConnect (boolean): Whether to auto connect on startup. Defaults to true.

Connection Management

  • client.connect(): void - Initiates the connection to the server.
  • client.disconnect(): void - Disconnects from the server.
  • client.isConnected: boolean - Returns true if fully connected.
  • client.rawSocket: Socket - Access the underlying socket.io-client instance.

Messaging (Promise-based)

All messaging actions return a Promise that resolves when the server acknowledges the operation.

  • sendMessage(payload: SendMessagePayload): Promise<Message> Sends a new message to a room.
  • editMessage(payload: EditMessagePayload): Promise<Message> Edits an existing message (if permitted by server configuration).
  • deleteMessage(messageId: string, roomId: string): Promise<void> Deletes a message.
  • markAsRead(messageId: string, roomId: string): void Marks a specific message as read.
  • sendReaction(messageId: string, roomId: string, emoji: string): Promise<void> Adds or toggles an emoji reaction on a message.
  • getHistory(roomId: string, limit?: number, before?: string): Promise<Message[]> Fetches historical messages for a room (requires a persistence adapter on the server).

Rooms (Promise-based)

  • createRoom(payload: CreateRoomPayload): Promise<Room> Creates a new room and automatically joins the creator.
  • joinRoom(roomId: string): Promise<Room> Joins an existing room.
  • leaveRoom(roomId: string): Promise<void> Leaves a room.
  • deleteRoom(roomId: string): Promise<void> Deletes a room (admin only).
  • getRoomMembers(roomId: string): Promise<Partial<User>[]> Gets the list of active members in a room.
  • listRooms(): Promise<Room[]> Lists all rooms the current user is a member of.

Presence & Typing

  • setStatus(status: 'online' | 'away' | 'busy'): void Manually sets the user's presence status.
  • ping(): void Sends a manual heartbeat ping to the server to prevent being marked as 'away'.
  • startTyping(roomId: string): void Broadcasts a typing indicator to the room.
  • stopTyping(roomId: string): void Clears the typing indicator.

Event Listeners

Use these methods to subscribe to real-time events. Each method returns an unsubscribe function.

const unsubscribe = client.onMessage((msg) => console.log(msg))
// Later...
unsubscribe()

Message Events

  • onMessage(listener: (message: Message) => void)
  • onMessageEdited(listener: (data: { messageId, roomId, content, editedAt, editedBy }) => void)
  • onMessageDeleted(listener: (data: { messageId, roomId, deletedBy }) => void)
  • onReaction(listener: (data: { messageId, roomId, userId, username, emoji, reactedAt }) => void)
  • onReadReceipt(listener: (data: { messageId, roomId, readBy, readAt }) => void)

Typing Events

  • onTypingStart(listener: (data: { userId, username, roomId }) => void)
  • onTypingStop(listener: (data: { userId, username, roomId }) => void)

Presence Events

  • onUserOnline(listener: (data: { id, username }) => void)
  • onUserOffline(listener: (data: { id, username, lastSeen }) => void)
  • onUserStatus(listener: (data: { id, username, status, lastSeen }) => void)

Room Events

  • onRoomUserJoined(listener: (data: { roomId, user }) => void)
  • onRoomUserLeft(listener: (data: { roomId, user }) => void)
  • onRoomDeleted(listener: (data: { roomId }) => void)
  • onKickedFromRoom(listener: (data: { roomId, reason }) => void)

Error Events

  • onError(listener: (data: { code: string, message: string }) => void)

(Advanced: You can also use client.on(), client.off(), and client.once() for fully-typed generic socket event bindings).