mirror of
https://github.com/jellyfin/jellyfin-chromecast.git
synced 2024-11-27 08:10:36 +00:00
Create instance of Jellyfin's generated API when setting server info
This commit is contained in:
parent
35dc856d1b
commit
795f86ada1
@ -18,12 +18,22 @@ export abstract class JellyfinApi {
|
||||
// unique id
|
||||
public static deviceId = '';
|
||||
|
||||
// Jellyfin SDK
|
||||
private static jellyfinSdk: Jellyfin | undefined;
|
||||
|
||||
// Jellyfin API
|
||||
public static jellyfinApi: Api;
|
||||
|
||||
public static setServerInfo(
|
||||
userId?: string,
|
||||
accessToken?: string,
|
||||
serverAddress?: string,
|
||||
receiverName = ''
|
||||
): void {
|
||||
const regenApi =
|
||||
this.accessToken !== accessToken ||
|
||||
this.serverAddress !== serverAddress;
|
||||
|
||||
console.debug(
|
||||
`JellyfinApi.setServerInfo: user:${userId}, token:${accessToken}, server:${serverAddress}, name:${receiverName}`
|
||||
);
|
||||
@ -48,6 +58,32 @@ export abstract class JellyfinApi {
|
||||
? senders[0].id
|
||||
: new Date().getTime().toString();
|
||||
}
|
||||
|
||||
if (!this.jellyfinSdk) {
|
||||
this.jellyfinSdk = new Jellyfin({
|
||||
clientInfo: {
|
||||
name: 'Chromecast',
|
||||
version: packageVersion
|
||||
},
|
||||
deviceInfo: {
|
||||
id: this.deviceId,
|
||||
name: this.deviceName
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (!this.jellyfinApi || regenApi) {
|
||||
if (serverAddress && accessToken) {
|
||||
this.jellyfinApi = this.jellyfinSdk.createApi(
|
||||
serverAddress,
|
||||
accessToken
|
||||
);
|
||||
} else {
|
||||
console.error(
|
||||
'Server address or access token not provided - could not create instance of Jellyfin API'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// create the necessary headers for authentication
|
||||
|
Loading…
Reference in New Issue
Block a user