mirror of
https://github.com/grafana/grafana.git
synced 2024-12-01 04:59:15 -06:00
e8a30f651e
* 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
41 lines
1.3 KiB
TypeScript
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;
|
|
}
|