• Stars
    star
    322
  • Rank 125,498 (Top 3 %)
  • Language Vue
  • License
    MIT License
  • Created about 3 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Admin UI for Socket.IO

Socket.IO Admin UI

dashboard screenshot

Table of contents

How to use

Server-side

First, install the @socket.io/admin-ui package:

npm i @socket.io/admin-ui

And then invoke the instrument method on your Socket.IO server:

const { createServer } = require("http");
const { Server } = require("socket.io");
const { instrument } = require("@socket.io/admin-ui");

const httpServer = createServer();

const io = new Server(httpServer, {
  cors: {
    origin: ["https://admin.socket.io"],
    credentials: true
  }
});

instrument(io, {
  auth: false
});

httpServer.listen(3000);

The module is compatible with:

  • Socket.IO v4 server
  • Socket.IO v3 server (>= 3.1.0), but without the operations on rooms (join, leave, disconnection)

Client-side

You can then head up to https://admin.socket.io, or host the files found in the ui/dist folder.

Important note: the website at https://admin.socket.io is totally static (hosted on Vercel), we do not (and will never) store any information about yourself or your browser (no tracking, no analytics, ...). That being said, hosting the files yourself is totally fine.

You should see the following modal:

login modal screenshot

Please enter the URL of your server (for example, http://localhost:3000 or https://example.com) and the credentials, if applicable (see the auth option below).

Available options

auth

Default value: -

This option is mandatory. You can either disable authentication (please use with caution):

instrument(io, {
  auth: false
});

Or use basic authentication:

instrument(io, {
  auth: {
    type: "basic",
    username: "admin",
    password: "$2b$10$heqvAkYMez.Va6Et2uXInOnkCT6/uQj1brkrbyG3LpopDklcq7ZOS" // "changeit" encrypted with bcrypt
  },
});

WARNING! Please note that the bcrypt package does not currently support hashes starting with the $2y$ prefix, which is used by some BCrypt implementations (for example https://bcrypt-generator.com/ or https://www.bcrypt.fr/). You can check the validity of the hash with:

$ node
> require("bcrypt").compareSync("<the password>", "<the hash>")
true

You can generate a valid hash with:

$ node
> require("bcrypt").hashSync("changeit", 10)
'$2b$10$LQUE...'

See also:

namespaceName

Default value: /admin

The name of the namespace which will be created to handle the administrative tasks.

instrument(io, {
  namespaceName: "/custom"
});

This namespace is a classic Socket.IO namespace, you can access it with:

const adminNamespace = io.of("/admin");

More information here.

readonly

Default value: false

Whether to put the admin UI in read-only mode (no join, leave or disconnect allowed).

instrument(io, {
  readonly: true
});

serverId

Default value: require("os").hostname()

The ID of the given server. If you have several Socket.IO servers on the same machine, please give them a distinct ID:

instrument(io, {
  serverId: `${require("os").hostname()}#${process.pid}`
});

store

Default value: new InMemoryStore()

The store is used to store the session IDs so the user do not have to retype the credentials upon reconnection.

If you use basic authentication in a multi-server setup, you should provide a custom store:

const { instrument, RedisStore } = require("@socket.io/admin-ui");

instrument(io, {
  store: new RedisStore(redisClient)
});

mode

Default value: development

In production mode, the server won't send all details about the socket instances and the rooms, thus reducing the memory footprint of the instrumentation.

instrument(io, {
  mode: "production"
});

The production mode can also be enabled with the NODE_ENV environment variable:

NODE_ENV=production node index.js

How it works

You can check the details of the implementation in the lib/index.ts file.

The instrument method simply:

  • creates a namespace and adds an authentication middleware if applicable
  • register listeners for the connection and disconnect event for each existing namespaces to track socket instances
  • register a timer which will periodically send stats from the server to the UI
  • register handlers for the join, leave and _disconnect commands sent from the UI

License

MIT

More Repositories

1

socket.io

Realtime application framework (Node.JS server)
TypeScript
59,936
star
2

socket.io-client

Realtime application framework (client)
TypeScript
10,492
star
3

socket.io-client-java

Full-featured Socket.IO Client Library for Java, which is compatible with Socket.IO v1.0 and later.
Java
5,244
star
4

socket.io-client-swift

Swift
5,128
star
5

engine.io

The engine used in the Socket.IO JavaScript server, which manages the low-level transports such as HTTP long-polling and WebSocket.
JavaScript
4,569
star
6

socket.io-redis-adapter

Adapter to enable broadcasting of events to multiple separate socket.io server nodes.
TypeScript
2,712
star
7

socket.io-client-cpp

C++11 implementation of Socket.IO client
C++
2,181
star
8

socket.io-p2p

JavaScript
1,022
star
9

engine.io-client

The engine used in the Socket.IO JavaScript client, which manages the low-level transports such as HTTP long-polling, WebSocket and WebTransport.
JavaScript
738
star
10

socket.io-redis-emitter

The Socket.IO Redis emitter, allowing to communicate with a group of Socket.IO servers from another Node.js process.
TypeScript
712
star
11

socket.io-protocol

Socket.IO Protocol specification
JavaScript
494
star
12

engine.io-client-java

Engine.IO Client Library for Java
Java
356
star
13

socket.io-website

Socket.IO website and blog
JavaScript
311
star
14

engine.io-protocol

Engine.IO protocol
JavaScript
229
star
15

socket.io-adapter

The Socket.IO in-memory adapter
TypeScript
195
star
16

engine.io-server-java

Engine.IO Server Library for Java
Java
161
star
17

socket.io-parser

JavaScript
133
star
18

socket.io-deno

Socket.IO server for Deno
TypeScript
88
star
19

engine.io-parser

Parser for the engine.io protocol, used by client and server
TypeScript
75
star
20

socket.io-msgpack-parser

Socket.IO parser based on msgpack
JavaScript
62
star
21

socket.io-sticky

A simple and performant way to use Socket.IO within a cluster.
JavaScript
37
star
22

socket.io-mongo-adapter

The Socket.IO MongoDB adapter, allowing to broadcast events between several Socket.IO servers
TypeScript
21
star
23

socket.io-chat-platform

A basic chat platform based on Socket.IO
JavaScript
19
star
24

socket.io-postgres-adapter

The Socket.IO Postgres adapter, allowing to broadcast events between several Socket.IO servers
TypeScript
18
star
25

socket.io-redis-streams-adapter

The Socket.IO adapter based on Redis Streams, allowing to broadcast events between several Socket.IO servers.
TypeScript
17
star
26

socket.io-cluster-adapter

The Socket.IO official cluster adapter, allowing to broadcast events between several Socket.IO servers.
TypeScript
14
star
27

socket.io-json-parser

socket.io parser based on JSON.stringify / JSON.parse
JavaScript
12
star
28

socket.io-minimal-example

Socket.IO minimal example
HTML
8
star
29

socket.io-benchmarks

Benchmarks for Socket.IO
JavaScript
8
star
30

socket.io-fiddle

A minimal example to play with Socket.IO
JavaScript
8
star
31

socket.io-compression-demo

JavaScript
7
star
32

get-started-drawing

7
star
33

lz77-compression-demo

JavaScript
7
star
34

socket.io-mongo-emitter

The Socket.IO MongoDB emitter, allowing to communicate with a group of Socket.IO servers from another Node.js process
TypeScript
6
star
35

socket.io-postgres-emitter

The Socket.IO Postgres emitter, allowing to communicate with a group of Socket.IO servers from another Node.js process.
TypeScript
5
star
36

socket.io-echo-server

Socket.IO echo server
JavaScript
4
star
37

socket.io-sample-playbook

This repository contains an Ansible playbook to set up a basic Socket.IO application.
JavaScript
4
star
38

tap-to-android

3
star
39

socket.io-swift-fiddle

Swift
2
star
40

socket.io-browsers

A reusable list of browsers to test when using defunctzombie/zuul
JavaScript
1
star
41

base64-arraybuffer

Encode/decode base64 data into ArrayBuffers
TypeScript
1
star