Socket
Socket
Sign inDemoInstall

socket.io-adapter

Package Overview
Dependencies
6
Maintainers
2
Versions
28
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    socket.io-adapter

default socket.io in-memory adapter


Version published
Weekly downloads
4.4M
decreased by-18.9%
Maintainers
2
Install size
236 kB
Created
Weekly downloads
 

Package description

What is socket.io-adapter?

The socket.io-adapter npm package is designed to be used with Socket.IO, a library that enables real-time, bidirectional and event-based communication between web clients and servers. The adapter is responsible for managing rooms and namespaces, as well as broadcasting and emitting events to a subset of clients. It can be extended to support different backends like Redis, allowing for scaling across multiple processes or servers.

What are socket.io-adapter's main functionalities?

Room Management

This feature allows you to manage rooms, which are arbitrary channels that sockets can join and leave. It enables you to emit events to all clients in a specific room.

const { Server } = require('socket.io');
const io = new Server();
io.on('connection', (socket) => {
  socket.join('some room');
  io.to('some room').emit('some event');
});

Namespace Management

Namespaces are a way to divide your clients into different endpoints or paths. This feature allows you to manage these namespaces, enabling targeted communication and organization.

const { Server } = require('socket.io');
const io = new Server();
const nsp = io.of('/my-namespace');
nsp.on('connection', (socket) => {
  console.log('someone connected to my-namespace');
});
nsp.emit('hi', 'everyone!');

Broadcasting Events

Broadcasting enables you to send a message to all connected clients except for the sender. This is useful for notifying all users about the actions of one.

const { Server } = require('socket.io');
const io = new Server();
io.on('connection', (socket) => {
  socket.broadcast.emit('broadcast', 'hello friends!');
});

Other packages similar to socket.io-adapter

Changelog

Source

2.5.4 (2024-02-22)

Bug Fixes

  • ensure the order of the commands (a13f35f)
  • types: ensure compatibility with TypeScript < 4.5 (ca397f3)

Readme

Source

socket.io-adapter

Default socket.io in-memory adapter class.

Compatibility table:

Adapter versionSocket.IO server version
1.x.x1.x.x / 2.x.x
2.x.x3.x.x

How to use

This module is not intended for end-user usage, but can be used as an interface to inherit from other adapters you might want to build.

As an example of an adapter that builds on top of this, please take a look at socket.io-redis.

License

MIT

FAQs

Last updated on 22 Feb 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc