grafana/public/app/features/live/index.ts
ArturWierzbicki e8a30f651e
Live: Extract scopes from CentrifugeSrv (#41051)
* Refactor: remove `scopes` from CentrifugeSrv, remove dependencies on window/config/user context

* Refactor: add GrafanaLiveChannelConfigService to wrap direct access to *Scope classes

* Refactor: added GrafanaLiveService acting like a proxy to GrafanaLiveSrv + LiveChannelConfigSrv

* Refactor: live module instantiation

* Refactor: import fixes

* Fix: URL construction in centrifugeSrv
2021-10-28 21:48:57 +04:00

41 lines
1.3 KiB
TypeScript

import { config, getBackendSrv, getGrafanaLiveSrv, setGrafanaLiveSrv } from '@grafana/runtime';
import { CentrifugeSrv } from './centrifuge/service';
import { registerLiveFeatures } from './features';
import { GrafanaLiveService } from './live';
import { GrafanaLiveChannelConfigService } from './channel-config';
import { GrafanaLiveChannelConfigSrv } from './channel-config/types';
import { contextSrv } from '../../core/services/context_srv';
const grafanaLiveScopesSingleton = new GrafanaLiveChannelConfigService();
export const getGrafanaLiveScopes = (): GrafanaLiveChannelConfigSrv => grafanaLiveScopesSingleton;
export const sessionId =
(window as any)?.grafanaBootData?.user?.id +
'/' +
Date.now().toString(16) +
'/' +
Math.random().toString(36).substring(2, 15);
export function initGrafanaLive() {
const centrifugeSrv = new CentrifugeSrv({
appUrl: `${window.location.origin}${config.appSubUrl}`,
orgId: contextSrv.user.orgId,
orgRole: contextSrv.user.orgRole,
liveEnabled: config.liveEnabled,
sessionId,
});
setGrafanaLiveSrv(
new GrafanaLiveService({
scopes: getGrafanaLiveScopes(),
centrifugeSrv,
backendSrv: getBackendSrv(),
})
);
registerLiveFeatures();
}
export function getGrafanaLiveCentrifugeSrv() {
return getGrafanaLiveSrv() as GrafanaLiveService;
}