-
Notifications
You must be signed in to change notification settings - Fork 11.7k
/
index.ts
43 lines (36 loc) · 1.38 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { config, getBackendSrv, getGrafanaLiveSrv, setGrafanaLiveSrv } from '@grafana/runtime';
import { liveTimer } from 'app/features/dashboard/dashgrid/liveTimer';
import { contextSrv } from '../../core/services/context_srv';
import { loadUrlToken } from '../../core/utils/urlToken';
import { CentrifugeService } from './centrifuge/service';
import { CentrifugeServiceWorkerProxy } from './centrifuge/serviceWorkerProxy';
import { GrafanaLiveService } from './live';
export const sessionId =
(window as any)?.grafanaBootData?.user?.id +
'/' +
Date.now().toString(16) +
'/' +
Math.random().toString(36).substring(2, 15);
export function initGrafanaLive() {
const centrifugeServiceDeps = {
appUrl: `${window.location.origin}${config.appSubUrl}`,
orgId: contextSrv.user.orgId,
orgRole: contextSrv.user.orgRole,
liveEnabled: config.liveEnabled,
sessionId,
dataStreamSubscriberReadiness: liveTimer.ok.asObservable(),
grafanaAuthToken: loadUrlToken(),
};
const centrifugeSrv = config.featureToggles['live-service-web-worker']
? new CentrifugeServiceWorkerProxy(centrifugeServiceDeps)
: new CentrifugeService(centrifugeServiceDeps);
setGrafanaLiveSrv(
new GrafanaLiveService({
centrifugeSrv,
backendSrv: getBackendSrv(),
})
);
}
export function getGrafanaLiveCentrifugeSrv() {
return getGrafanaLiveSrv() as GrafanaLiveService;
}