grafana/public/app/features/live/centrifuge/service.worker.ts
Josh Hunt 3c6e0e8ef8
Chore: ESlint import order (#44959)
* Add and configure eslint-plugin-import

* Fix the lint:ts npm command

* Autofix + prettier all the files

* Manually fix remaining files

* Move jquery code in jest-setup to external file to safely reorder imports

* Resolve issue caused by circular dependencies within Prometheus

* Update .betterer.results

* Fix missing // @ts-ignore

* ignore iconBundle.ts

* Fix missing // @ts-ignore
2022-04-22 14:33:13 +01:00

61 lines
1.5 KiB
TypeScript

import './transferHandlers';
import * as comlink from 'comlink';
import { LiveChannelAddress } from '@grafana/data';
import { LiveDataStreamOptions, LiveQueryDataOptions } from '@grafana/runtime';
import { remoteObservableAsObservable } from './remoteObservable';
import { CentrifugeService, CentrifugeSrvDeps } from './service';
let centrifuge: CentrifugeService;
const initialize = (
deps: CentrifugeSrvDeps,
remoteDataStreamSubscriberReadiness: comlink.RemoteObject<
CentrifugeSrvDeps['dataStreamSubscriberReadiness'] & comlink.ProxyMarked
>
) => {
centrifuge = new CentrifugeService({
...deps,
dataStreamSubscriberReadiness: remoteObservableAsObservable(remoteDataStreamSubscriberReadiness),
});
};
const getConnectionState = () => {
return comlink.proxy(centrifuge.getConnectionState());
};
const getDataStream = (options: LiveDataStreamOptions) => {
return comlink.proxy(centrifuge.getDataStream(options));
};
const getQueryData = async (options: LiveQueryDataOptions) => {
return await centrifuge.getQueryData(options);
};
const getStream = (address: LiveChannelAddress) => {
return comlink.proxy(centrifuge.getStream(address));
};
const getPresence = async (address: LiveChannelAddress) => {
return await centrifuge.getPresence(address);
};
const workObj = {
initialize,
getConnectionState,
getDataStream,
getStream,
getQueryData,
getPresence,
};
export type RemoteCentrifugeService = typeof workObj;
comlink.expose(workObj);
export default class {
constructor() {}
}