1import { CentrifugeService, CentrifugeSrvDeps } from './service'; 2import * as comlink from 'comlink'; 3import './transferHandlers'; 4import { remoteObservableAsObservable } from './remoteObservable'; 5import { LiveChannelAddress } from '@grafana/data'; 6import { LiveDataStreamOptions } from '@grafana/runtime'; 7 8let centrifuge: CentrifugeService; 9 10const initialize = ( 11 deps: CentrifugeSrvDeps, 12 remoteDataStreamSubscriberReadiness: comlink.RemoteObject< 13 CentrifugeSrvDeps['dataStreamSubscriberReadiness'] & comlink.ProxyMarked 14 > 15) => { 16 centrifuge = new CentrifugeService({ 17 ...deps, 18 dataStreamSubscriberReadiness: remoteObservableAsObservable(remoteDataStreamSubscriberReadiness), 19 }); 20}; 21 22const getConnectionState = () => { 23 return comlink.proxy(centrifuge.getConnectionState()); 24}; 25 26const getDataStream = (options: LiveDataStreamOptions) => { 27 return comlink.proxy(centrifuge.getDataStream(options)); 28}; 29 30const getStream = (address: LiveChannelAddress) => { 31 return comlink.proxy(centrifuge.getStream(address)); 32}; 33 34const getPresence = async (address: LiveChannelAddress) => { 35 return await centrifuge.getPresence(address); 36}; 37 38const workObj = { 39 initialize, 40 getConnectionState, 41 getDataStream, 42 getStream, 43 getPresence, 44}; 45 46export type RemoteCentrifugeService = typeof workObj; 47 48comlink.expose(workObj); 49 50export default class { 51 constructor() {} 52} 53