Skip to content

Commit 5a13f00

Browse files
committed
fix bug in the way the transport notifies client subscribers of connection changes
1 parent 2f86d92 commit 5a13f00

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

src/client/client.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ class _ClientImpl {
351351
subscribe(fn) {
352352
const id = Object.keys(this.subscribers).length;
353353
this.subscribers[id] = fn;
354-
this.transport.subscribe(this.notifySubscribers);
354+
this.transport.subscribe(() => this.notifySubscribers());
355355
this.notifySubscribers();
356356

357357
// Return a handle that allows the caller to unsubscribe.

src/client/client.test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,19 @@ describe('subscribe', () => {
631631
);
632632
expect(fn2).not.toBeCalled();
633633
});
634+
635+
test('transport notifies subscribers', () => {
636+
const client = Client({
637+
game: {},
638+
multiplayer: true,
639+
});
640+
const fn = jest.fn();
641+
client.subscribe(fn);
642+
client.start();
643+
fn.mockClear();
644+
client.transport.callback();
645+
expect(fn).toHaveBeenCalled();
646+
});
634647
});
635648

636649
test('override game state', () => {

0 commit comments

Comments
 (0)