2021-10-28 12:48:57 -05:00
|
|
|
import { config, getBackendSrv, getGrafanaLiveSrv, setGrafanaLiveSrv } from '@grafana/runtime';
|
2022-04-22 08:33:13 -05:00
|
|
|
import { liveTimer } from 'app/features/dashboard/dashgrid/liveTimer';
|
|
|
|
|
2021-10-28 12:48:57 -05:00
|
|
|
import { contextSrv } from '../../core/services/context_srv';
|
2022-09-21 06:09:16 -05:00
|
|
|
import { loadUrlToken } from '../../core/utils/urlToken';
|
2022-04-22 08:33:13 -05:00
|
|
|
|
2021-11-09 11:05:01 -06:00
|
|
|
import { CentrifugeService } from './centrifuge/service';
|
2022-04-22 08:33:13 -05:00
|
|
|
import { CentrifugeServiceWorkerProxy } from './centrifuge/serviceWorkerProxy';
|
|
|
|
import { GrafanaLiveService } from './live';
|
2021-10-28 12:48:57 -05:00
|
|
|
|
|
|
|
export function initGrafanaLive() {
|
2021-11-09 11:05:01 -06:00
|
|
|
const centrifugeServiceDeps = {
|
2021-10-28 12:48:57 -05:00
|
|
|
appUrl: `${window.location.origin}${config.appSubUrl}`,
|
|
|
|
orgId: contextSrv.user.orgId,
|
|
|
|
orgRole: contextSrv.user.orgRole,
|
|
|
|
liveEnabled: config.liveEnabled,
|
2021-11-09 11:05:01 -06:00
|
|
|
dataStreamSubscriberReadiness: liveTimer.ok.asObservable(),
|
2022-09-21 06:09:16 -05:00
|
|
|
grafanaAuthToken: loadUrlToken(),
|
2021-11-09 11:05:01 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
const centrifugeSrv = config.featureToggles['live-service-web-worker']
|
|
|
|
? new CentrifugeServiceWorkerProxy(centrifugeServiceDeps)
|
|
|
|
: new CentrifugeService(centrifugeServiceDeps);
|
|
|
|
|
2021-10-28 12:48:57 -05:00
|
|
|
setGrafanaLiveSrv(
|
|
|
|
new GrafanaLiveService({
|
|
|
|
centrifugeSrv,
|
|
|
|
backendSrv: getBackendSrv(),
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getGrafanaLiveCentrifugeSrv() {
|
|
|
|
return getGrafanaLiveSrv() as GrafanaLiveService;
|
|
|
|
}
|