Fix mismatch between single-emit and broadcast encoding

This commit is contained in:
Calvin Montgomery 2018-06-19 21:50:03 -07:00
parent 4cad31d82c
commit 85947d326e
2 changed files with 16 additions and 2 deletions

View File

@ -233,8 +233,8 @@ function encode(frame, payload) {
function inRoom(room) { function inRoom(room) {
return { return {
emit(frame, ...args) { emit(frame, payload) {
const encoded = encode(frame, args); const encoded = encode(frame, payload);
for (let wrapper of rooms.get(room)) { for (let wrapper of rooms.get(room)) {
wrapper._uwsSocket.send(encoded); wrapper._uwsSocket.send(encoded);

View File

@ -1,6 +1,7 @@
const { EventEmitter } = require('events'); const { EventEmitter } = require('events');
const assert = require('assert'); const assert = require('assert');
const { UWSServer } = require('../../lib/io/uws'); const { UWSServer } = require('../../lib/io/uws');
const inRoom = require('../../lib/io/uws')['in'];
const WebSocket = require('uws'); const WebSocket = require('uws');
describe('UWSServer', () => { describe('UWSServer', () => {
@ -115,6 +116,19 @@ describe('UWSServer', () => {
}); });
}); });
it('broadcasts to a room', done => {
server.on('connection', s => {
s.join('testroom');
inRoom('testroom').emit('test', { foo: 'bar' });
});
socket = connect();
socket.test.on('test', data => {
assert.deepStrictEqual(data, { foo: 'bar' });
done();
});
});
it('responds with an ack frame', done => { it('responds with an ack frame', done => {
server.on('connection', s => { server.on('connection', s => {
s.on('test', (data, ack) => { s.on('test', (data, ack) => {