Skip to content

Commit d03c5ca

Browse files
authored
Merge pull request #7796 from nielsvanvelzen/eager-api-init
Load device information lazily in connection manager
2 parents 29a6a0f + de26159 commit d03c5ca

4 files changed

Lines changed: 24 additions & 17 deletions

File tree

src/index.jsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { getPlugins } from './scripts/settings/webSettings';
2222
import taskButton from './scripts/taskbutton';
2323
import { pageClassOn, serverAddress } from './utils/dashboard';
2424
import Events from './utils/events';
25+
import { initializeServerConnections } from './scripts/serverNotifications';
2526

2627
import RootApp from './RootApp';
2728

@@ -37,7 +38,6 @@ import './components/themeMediaPlayer';
3738
import './scripts/autoThemes';
3839
import './scripts/mouseManager';
3940
import './scripts/screensavermanager';
40-
import './scripts/serverNotifications';
4141

4242
// Import site styles
4343
import './styles/site.scss';
@@ -110,6 +110,9 @@ build: ${__JF_BUILD_VERSION__}`);
110110
Events.on(apiClient, 'requestfail', appRouter.onRequestFail);
111111
});
112112

113+
// Start server notifications
114+
initializeServerConnections();
115+
113116
// Render the app
114117
await renderApp();
115118

src/lib/jellyfin-apiclient/ServerConnections.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ const capabilities = Dashboard.capabilities(appHost);
152152

153153
export default new ServerConnections(
154154
credentialProvider,
155-
appHost.appName(),
156-
appHost.appVersion(),
157-
appHost.deviceName(),
158-
appHost.deviceId(),
155+
() => appHost.appName(),
156+
() => appHost.appVersion(),
157+
() => appHost.deviceName(),
158+
() => appHost.deviceId(),
159159
capabilities);

src/lib/jellyfin-apiclient/connectionManager.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,15 @@ export default class ConnectionManager {
6363
// Set the minimum version to match the SDK
6464
self._minServerVersion = MINIMUM_VERSION;
6565

66-
self.appVersion = () => appVersion;
66+
self.appVersion = () => typeof appVersion === 'function' ? appVersion() : appVersion;
6767

68-
self.appName = () => appName;
68+
self.appName = () => typeof appName === 'function' ? appName() : appName;
6969

7070
self.capabilities = () => capabilities;
7171

72-
self.deviceId = () => deviceId;
72+
self.deviceName = () => typeof deviceName === 'function' ? deviceName() : deviceName;
73+
74+
self.deviceId = () => typeof deviceId === 'function' ? deviceId() : deviceId;
7375

7476
self.credentialProvider = () => credentialProvider;
7577

@@ -137,7 +139,7 @@ export default class ConnectionManager {
137139
let apiClient = self.getApiClient(server.Id);
138140

139141
if (!apiClient) {
140-
apiClient = new ApiClient(serverUrl, appName, appVersion, deviceName, deviceId);
142+
apiClient = new ApiClient(serverUrl, self.appName(), self.appVersion(), self.deviceName(), self.deviceId());
141143

142144
self._apiClients.push(apiClient);
143145

@@ -232,12 +234,12 @@ export default class ConnectionManager {
232234
headers: {
233235
[AUTHORIZATION_HEADER]: getAuthorizationHeader(
234236
{
235-
name: appName,
236-
version: appVersion
237+
name: self.appName(),
238+
version: self.appVersion()
237239
},
238240
{
239-
id: deviceId,
240-
name: deviceName
241+
id: self.deviceId(),
242+
name: self.deviceName()
241243
},
242244
server.AccessToken
243245
)

src/scripts/serverNotifications.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,12 @@ function bindEvents(apiClient) {
201201
Events.on(apiClient, 'message', onMessageReceived);
202202
}
203203

204-
ServerConnections.getApiClients().forEach(bindEvents);
205-
Events.on(ServerConnections, 'apiclientcreated', function (e, newApiClient) {
206-
bindEvents(newApiClient);
207-
});
204+
export function initializeServerConnections() {
205+
ServerConnections.getApiClients().forEach(bindEvents);
206+
Events.on(ServerConnections, 'apiclientcreated', function (e, newApiClient) {
207+
bindEvents(newApiClient);
208+
});
209+
}
208210

209211
window.ServerNotifications = serverNotifications;
210212

0 commit comments

Comments
 (0)