socketio-wildcard
Advanced tools
Comparing version 0.2.0 to 0.3.0
25
index.js
'use strict' | ||
var Emitter = require('events').EventEmitter | ||
var emit = Emitter.prototype.emit | ||
var BuiltInEmitter = require('events').EventEmitter | ||
function onevent (packet) { | ||
var args | ||
args = packet.data || [] | ||
if (packet.id != null) { | ||
args.push(this.ack(packet.id)) | ||
module.exports = function (CustomEmitter) { | ||
var Emitter = CustomEmitter || BuiltInEmitter | ||
var emit = Emitter.prototype.emit | ||
function onevent (packet) { | ||
var args = packet.data || [] | ||
if (packet.id != null) { | ||
args.push(this.ack(packet.id)) | ||
} | ||
emit.call(this, '*', packet) | ||
return emit.apply(this, args) | ||
} | ||
emit.call(this, '*', packet) | ||
return emit.apply(this, args) | ||
} | ||
module.exports = function () { | ||
return function (socket, next) { | ||
@@ -20,4 +21,4 @@ if (socket.onevent !== onevent) { | ||
} | ||
return next() | ||
return next ? next() : null | ||
} | ||
} |
{ | ||
"name": "socketio-wildcard", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "socket.io with a wildcard event", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -27,2 +27,4 @@ socketio-wildcard | ||
### Server | ||
```js | ||
@@ -41,5 +43,21 @@ var io = require('socket.io')(); | ||
### Client | ||
```js | ||
var io = require('socket.io-client'); | ||
var socket = io('http://localhost'); | ||
// piggyback using the event-emitter bundled with socket.io client | ||
var patch = require('socketio-wildcard')(io.Manager); | ||
patch(socket); | ||
socket.on('*', function(){ /* … */ }) | ||
``` | ||
Changelog | ||
--------- | ||
### [0.3.0] - 2015-12-21 | ||
- allow custom event emitter | ||
- support socket.io client | ||
### [0.2.0] - 2015-11-29 | ||
@@ -46,0 +64,0 @@ - wildcard listener for all events get called first ([@Michael77](https://github.com/Michael77)) |
@@ -9,3 +9,3 @@ /*global describe, before, it*/ | ||
describe('socket.io wildcard', function () { | ||
describe('server', function () { | ||
var nsp | ||
@@ -82,1 +82,37 @@ | ||
}) | ||
describe('client', function () { | ||
before(function () { | ||
io.listen(8001) | ||
io.on('connection', function (socket) { | ||
socket.emit('foo', { bar: 'baz' }) | ||
}) | ||
}) | ||
it('should work', function (done) { | ||
var patch = wildcard(connect.Manager) | ||
var client = connect('http://localhost:8001/') | ||
patch(client) | ||
var seq = [] | ||
function check (d) { | ||
seq.push(d) | ||
if (seq.length === 2) { | ||
assert.deepEqual(seq, ['*', 'foo']) | ||
done() | ||
} | ||
} | ||
client.on('*', function (packet) { | ||
assert.equal(packet.data[0], 'foo') | ||
assert.deepEqual(packet.data[1], { bar: 'baz' }) | ||
check('*') | ||
}) | ||
client.on('foo', function (data) { | ||
assert.deepEqual(data, { bar: 'baz' }) | ||
check('foo') | ||
}) | ||
}) | ||
}) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7571
116
68