wpw-final/frontend/src/hub/index.ts
2022-12-02 20:40:23 +07:00

28 lines
708 B
TypeScript

import {
createXHRClient,
createXHRConnection,
TBinaryProtocol,
TJSONProtocol,
XHRConnection,
type ConnectOptions,
} from 'thrift';
import { App, inject } from 'vue';
import { defaultClientOptions } from './defaults';
import { defaultHubInit, ThriftHub } from './hub';
import { ServiceType } from './service_type';
export type ClientOptions = ConnectOptions & {
host: string;
port: number;
};
const hubProvideKey = 'thrift_hub';
export function useHub(): ThriftHub {
return inject(hubProvideKey) || defaultHubInit();
}
export default {
install: (app: App, opts: Map<ServiceType, ClientOptions> = defaultClientOptions) => {
app.provide(hubProvideKey, defaultHubInit(opts));
},
};