diff --git a/src/components/syncPlay/core/Manager.js b/src/components/syncPlay/core/Manager.js index 70513b3b35..3f8f4da704 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 c1073fc634..c30311cf82 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() {