From f0d483dee3ec57677b7564933fc5c6d32cebacc1 Mon Sep 17 00:00:00 2001 From: Ionut Andrei Oanca Date: Tue, 7 Sep 2021 01:00:23 +0200 Subject: [PATCH] Update ApiClient instance used by SyncPlay manager --- src/components/syncPlay/core/Manager.js | 18 +++++++++++++----- src/scripts/site.js | 2 ++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/components/syncPlay/core/Manager.js b/src/components/syncPlay/core/Manager.js index 70513b3b3..3f8f4da70 100644 --- a/src/components/syncPlay/core/Manager.js +++ b/src/components/syncPlay/core/Manager.js @@ -47,12 +47,8 @@ class Manager { * @param {Object} apiClient The ApiClient. */ init(apiClient) { - if (!apiClient) { - throw new Error('ApiClient is null!'); - } - // Set ApiClient. - this.apiClient = apiClient; + this.updateApiClient(apiClient); // Get default player wrapper. this.playerWrapper = this.playerFactory.getDefaultWrapper(this); @@ -73,6 +69,18 @@ class Manager { }); } + /** + * Update active ApiClient. + * @param {Object} apiClient The ApiClient. + */ + updateApiClient(apiClient) { + if (!apiClient) { + throw new Error('ApiClient is null!'); + } + + this.apiClient = apiClient; + } + /** * Gets the time sync core. * @returns {TimeSyncCore} The time sync core. diff --git a/src/scripts/site.js b/src/scripts/site.js index c1073fc63..c30311cf8 100644 --- a/src/scripts/site.js +++ b/src/scripts/site.js @@ -172,6 +172,8 @@ function initSyncPlay() { // FIXME: Multiple apiClients? Events.on(ServerConnections, 'apiclientcreated', (e, newApiClient) => SyncPlay.Manager.init(newApiClient)); + Events.on(ServerConnections, 'localusersignedin', () => SyncPlay.Manager.updateApiClient(ServerConnections.currentApiClient())); + Events.on(ServerConnections, 'localusersignedout', () => SyncPlay.Manager.updateApiClient(ServerConnections.currentApiClient())); } async function onAppReady() {