Skip to content

uditrajput03/ws-relay

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WebSocket Relay Server with Analytics Dashboard

Overview

This project provides a WebSocket relay server that allows clients to connect to specific channels and relay messages between them. It includes a real-time analytics dashboard with authentication to monitor connections, messages, and channel activity.

Features

  • WebSocket Relay Functionality

    • Channel-based message relaying
    • Automatic channel creation and cleanup
    • Multiple clients can connect to the same channel
    • Messages from one client are relayed to all other clients in the same channel
  • Analytics Dashboard

    • Password-protected admin interface
    • Real-time statistics and metrics
    • Monitor active connections and channels
    • Track message relay activity
    • View client connection details
  • Security

    • Simple password authentication for dashboard
    • Session management
    • Configurable admin password

Installation

Prerequisites

  • Node.js (v14 or higher recommended)
  • npm (v6 or higher)

Steps

  1. Clone this repository:
git clone https://github.com/uditrajput03/ws-relay.git
cd ws-relay
  1. Install dependencies:
npm install
  1. Configure the server (optional):
# Set custom port and admin password as environment variables
export PORT=9000
export ADMIN_PASSWORD=your-secure-password
  1. Start the server:
npm start

The server will start on the configured port (default: 8080).

Usage

Connecting with websocat

You can use websocat to connect to the relay server:

Client-1:

websocat ws://your-server:8080/my-channel -

Client-2:

websocat ws://your-server:8080/my-channel -

Messages typed in one terminal will be relayed to the other terminal, and vice versa.

Custom Clients

To create your own WebSocket clients that connect to the relay:

const socket = new WebSocket('ws://your-server:8080/my-channel');

socket.onopen = () => {
  console.log('Connected to relay server');
};

socket.onmessage = (event) => {
  console.log('Received message:', event.data);
};

// Send a message
socket.send('Hello from my client!');

Accessing the Dashboard

  1. Navigate to http://your-server:8080/dashboard in your browser
  2. Enter the admin password (default: admin123)
  3. View real-time statistics and monitor connections

Dashboard Features

  • Summary Cards: Quick overview of total connections, active connections, channels, and messages
  • Channel Metrics: View connections and message counts for each channel
  • Active Clients: List of all currently connected clients with details
  • Recent Activity: Log of recent connection and disconnection events

Configuration Options

Environment Variable Description Default Value
PORT Server port number 8080
ADMIN_PASSWORD Dashboard login password admin123

Security Considerations

  • Change the default password: Always change the default admin password before deploying to production
  • Use HTTPS in production: For production environments, set up HTTPS to secure connections
  • Set secure cookies: Update the session configuration with cookie: { secure: true } when using HTTPS

Deployment

For production deployment, consider:

  1. Using a process manager like PM2:
npm install -g pm2
pm2 start server.js --name "websocket-relay"
  1. Setting up a reverse proxy (Nginx/Apache) to handle HTTPS and load balancing

License

MIT License

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.


Created by uditrajput03 | Last updated: 2025-07-11

About

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors