diff --git a/frontend/app/api_client.ts b/frontend/app/api_client.ts index 0ddd88413..431cea014 100644 --- a/frontend/app/api_client.ts +++ b/frontend/app/api_client.ts @@ -58,17 +58,13 @@ export default class APIClient { private onUpdateJwt: (data: { jwt?: string, spotJwt?: string }) => void; private refreshingTokenPromise: Promise | null = null; - constructor(jwt?: string | null) { + constructor() { this.init = { headers: new Headers({ Accept: 'application/json', 'Content-Type': 'application/json' }) }; - - if (jwt) { - this.setJwt(jwt); - } } setJwt(jwt: string | null): void { diff --git a/frontend/app/components/Session/LivePlayer.tsx b/frontend/app/components/Session/LivePlayer.tsx index 2ecc530ae..8fb770fce 100644 --- a/frontend/app/components/Session/LivePlayer.tsx +++ b/frontend/app/components/Session/LivePlayer.tsx @@ -15,6 +15,7 @@ import { useLocation } from 'react-router-dom'; import { toast } from 'react-toastify'; import { useStore } from 'App/mstore'; import { observer } from 'mobx-react-lite'; +import { sessionService } from 'App/services'; interface Props { customSession?: Session; @@ -54,26 +55,11 @@ function LivePlayer({ name: userName, }, }; - if (isEnterprise) { - new APIClient(userStore.jwt) - .get('/config/assist/credentials') - .then((r) => r.json()) - .then(({ data }) => { - const [player, store] = createLiveWebPlayer( - sessionWithAgentData, - data, - userId, - projectId, - (state) => makeAutoObservable(state), - toast - ); - setContextValue({ player, store }); - playerInst = player; - }); - } else { + + const initPlayer = async (credentials = null) => { const [player, store] = createLiveWebPlayer( sessionWithAgentData, - null, + credentials, userId, projectId, (state) => makeAutoObservable(state), @@ -81,6 +67,12 @@ function LivePlayer({ ); setContextValue({ player, store }); playerInst = player; + }; + + if (isEnterprise) { + sessionService.getAssistCredentials().then(initPlayer); + } else { + void initPlayer(); } return () => { diff --git a/frontend/app/services/SessionService.ts b/frontend/app/services/SessionService.ts index f4f0e91dc..c1e12538a 100644 --- a/frontend/app/services/SessionService.ts +++ b/frontend/app/services/SessionService.ts @@ -121,4 +121,15 @@ export default class SettingsService { .then((j) => j.data || {}) .catch(Promise.reject); } + + async getAssistCredentials(): Promise { + try { + const r = await this.client + .get('/config/assist/credentials'); + const j = await r.json(); + return j.data || {}; + } catch (reason) { + return Promise.reject(reason); + } + } }