From 5a13f0084703327e01f4dbefaf4f2aee2011733d Mon Sep 17 00:00:00 2001 From: Nicolo Davis Date: Fri, 25 Oct 2019 23:12:06 +0800 Subject: [PATCH] fix bug in the way the transport notifies client subscribers of connection changes --- src/client/client.js | 2 +- src/client/client.test.js | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/client/client.js b/src/client/client.js index 8e90bf5f1..f0aee4118 100644 --- a/src/client/client.js +++ b/src/client/client.js @@ -351,7 +351,7 @@ class _ClientImpl { subscribe(fn) { const id = Object.keys(this.subscribers).length; this.subscribers[id] = fn; - this.transport.subscribe(this.notifySubscribers); + this.transport.subscribe(() => this.notifySubscribers()); this.notifySubscribers(); // Return a handle that allows the caller to unsubscribe. diff --git a/src/client/client.test.js b/src/client/client.test.js index 125a818f5..ce6c582fe 100644 --- a/src/client/client.test.js +++ b/src/client/client.test.js @@ -631,6 +631,19 @@ describe('subscribe', () => { ); expect(fn2).not.toBeCalled(); }); + + test('transport notifies subscribers', () => { + const client = Client({ + game: {}, + multiplayer: true, + }); + const fn = jest.fn(); + client.subscribe(fn); + client.start(); + fn.mockClear(); + client.transport.callback(); + expect(fn).toHaveBeenCalled(); + }); }); test('override game state', () => {