mirror of https://github.com/calzoneman/sync.git
Fix mismatch between single-emit and broadcast encoding
This commit is contained in:
parent
4cad31d82c
commit
85947d326e
|
@ -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);
|
||||||
|
|
|
@ -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) => {
|
||||||
|
|
Loading…
Reference in New Issue