Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

socket.io-emitter

Package Overview
Dependencies
Maintainers
2
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

socket.io-emitter - npm Package Compare versions

Comparing version 3.1.1 to 3.1.2

CHANGELOG.md

5

index.js

@@ -9,2 +9,3 @@

var msgpack = require('notepack.io');
var hasBin = require('has-binary2');
var debug = require('debug')('socket.io-emitter');

@@ -115,3 +116,3 @@

Emitter.prototype.of = function(nsp){
return new Emitter(this.redis, this.prefix, nsp);
return new Emitter(this.redis, this.prefix, (nsp[0] !== "/" ? "/" : "") + nsp);
};

@@ -128,3 +129,3 @@

var args = Array.prototype.slice.call(arguments);
var packet = { type: parser.EVENT, data: args, nsp: this.nsp };
var packet = { type: hasBin(args) ? parser.BINARY_EVENT : parser.EVENT, data: args, nsp: this.nsp };

@@ -131,0 +132,0 @@ var opts = {

15

package.json
{
"name": "socket.io-emitter",
"version": "3.1.1",
"version": "3.1.2",
"description": "",

@@ -14,6 +14,7 @@ "license": "MIT",

"scripts": {
"test": "make test"
"test": "mocha --reporter spec --slow 200 --timeout 5000 --bail"
},
"dependencies": {
"debug": "~3.1.0",
"debug": "~4.1.0",
"has-binary2": "~1.0.2",
"notepack.io": "~2.1.0",

@@ -24,8 +25,8 @@ "redis": "2.6.3",

"devDependencies": {
"expect.js": "~0.3.1",
"mocha": "~3.2.0",
"expect.js": "~0.3.1",
"socket.io": "~2.0.1",
"socket.io-client": "~2.0.1",
"socket.io-redis": "^5.1.0"
"socket.io": "^2.3.0",
"socket.io-client": "^2.3.1",
"socket.io-redis": "^5.4.0"
}
}
# socket.io-emitter
[![Build Status](https://travis-ci.org/socketio/socket.io-emitter.svg?branch=master)](https://travis-ci.org/socketio/socket.io-emitter)
[![Build Status](https://github.com/socketio/socket.io-emitter/workflows/CI/badge.svg)](https://github.com/socketio/socket.io-emitter/actions)
[![NPM version](https://badge.fury.io/js/socket.io-emitter.svg)](http://badge.fury.io/js/socket.io-emitter)
`socket.io-emitter` allows you to communicate with socket.io servers
easily from non-socket.io processes.
`socket.io-emitter` allows you to communicate with Socket.IO servers
easily from another Node.js process (server side).
![Emitter diagram](./assets/emitter.png)
The emitter is also available in other programming languages:
- Java: https://github.com/sunsus/socket.io-java-emitter
- Python: https://pypi.org/project/socket.io-emitter/
- PHP: https://github.com/rase-/socket.io-php-emitter
- Golang: https://github.com/yosuke-furukawa/socket.io-go-emitter
- Perl: https://metacpan.org/pod/SocketIO::Emitter
- Rust: https://github.com/epli2/socketio-rust-emitter
It must be used in conjunction with [socket.io-redis](https://github.com/socketio/socket.io-redis/).
The current version is compatible with both:
- `socket.io-redis@5` (`socket.io@2`)
- `socket.io-redis@6` (`socket.io@3`)
## Table of content
- [How to use](#how-to-use)
- [Examples](#examples)
- [Error handling](#error-handling)
- [API](#api)
- [Emitter(client[, opts])](#emitterclient-opts)
- [Emitter(clientUri[, opts])](#emitterclienturi-opts)
- [Emitter(opts)](#emitteropts)
- [Emitter#to(room:String):Emitter](#emittertoroomstringemitter)
- [Emitter#in(room:String):Emitter](#emitterinroomstringemitter)
- [Emitter#of(namespace:String):Emitter](#emitterofnamespacestringemitter)
- [License](#license)
## How to use
```js
var io = require('socket.io-emitter')({ host: '127.0.0.1', port: 6379 });
setInterval(function(){
const io = require('socket.io-emitter')({ host: '127.0.0.1', port: 6379 });
setInterval(() => {
io.emit('time', new Date);

@@ -22,13 +54,13 @@ }, 5000);

//1. Initialize with host:port string
var io = require('socket.io-emitter')("localhost:6379")
const io = require('socket.io-emitter')("localhost:6379")
// 2. Initlize with host, port object.
var io = require('socket.io-emitter')({ host: '127.0.0.1', port: 6379 });
const io = require('socket.io-emitter')({ host: '127.0.0.1', port: 6379 });
// 3. Can use other node_redis compatible client eg; ioredis.
var Redis = require("ioredis");
var redis = new Redis();
var io = require('socket.io-emitter')(redis);
const Redis = require("ioredis");
const redis = new Redis();
const io = require('socket.io-emitter')(redis);
// Make the emitter works with redis clustered environment.
var Cluster = new Redis.Cluster([
const Cluster = new Redis.Cluster([
{

@@ -43,3 +75,3 @@ host: "localhost",

]);
var io = require('socket.io-emitter')(Cluster);
const io = require('socket.io-emitter')(Cluster);

@@ -51,20 +83,20 @@ ```

```js
var io = require('socket.io-emitter')({ host: '127.0.0.1', port: 6379 });
const io = require('socket.io-emitter')({ host: '127.0.0.1', port: 6379 });
// sending to all clients
io.emit('broadcast', /* ... */);
// sending to all clients
io.emit('broadcast', /* ... */);
// sending to all clients in 'game' room
io.to('game').emit('new-game', /* ... */);
// sending to all clients in 'game' room
io.to('game').emit('new-game', /* ... */);
// sending to individual socketid (private message)
io.to(<socketid>).emit('private', /* ... */);
// sending to individual socketid (private message)
io.to(socketId).emit('private', /* ... */);
var nsp = io.of('/admin');
const nsp = io.of('/admin');
// sending to all clients in 'admin' namespace
nsp.emit('namespace', /* ... */);
// sending to all clients in 'admin' namespace
nsp.emit('namespace', /* ... */);
// sending to all clients in 'admin' namespace and in 'notifications' room
nsp.to('notifications').emit('namespace', /* ... */);
// sending to all clients in 'admin' namespace and in 'notifications' room
nsp.to('notifications').emit('namespace', /* ... */);
```

@@ -79,9 +111,7 @@

```js
var emitter = require('socket.io-emitter')("localhost:6379");
const emitter = require('socket.io-emitter')("localhost:6379");
emitter.redis.on('error', onError);
function onError(err){
emitter.redis.on('error', (err) => {
console.log(err);
}
});
```

@@ -104,3 +134,3 @@

### Emitter(clientUri[, opts]
### Emitter(clientUri[, opts])

@@ -107,0 +137,0 @@ Same as above, but `clientUri` is a string of the format `host:port`

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc