mirror of
https://github.com/hansjone/dsh-im-ops.git
synced 2026-10-09 05:20:46 +08:00
42 lines
1.5 KiB
JavaScript
42 lines
1.5 KiB
JavaScript
import { createProductionController } from './production.mjs';
|
|
import { installWeixinRpc } from './rpc.mjs';
|
|
|
|
export const name = 'dsh-weixin-host';
|
|
export const inject = ['connection', 'credentials', 'typertGateway'];
|
|
|
|
export async function apply(ctx, config = {}) {
|
|
if (config?.controller) {
|
|
return installWeixinRpc(ctx, config.controller, config.rpcOptions, config.rpcAuthority);
|
|
}
|
|
|
|
const production = await createProductionController(ctx, config, config.internals);
|
|
const unregisterDelivery = config.deliveryService && production.deliveryAdapter
|
|
? config.deliveryService.registerAdapter(production.deliveryAdapter) : undefined;
|
|
const disposeRpc = installWeixinRpc(
|
|
ctx,
|
|
production.controller,
|
|
config.rpcOptions,
|
|
config.rpcAuthority,
|
|
);
|
|
ctx.effect(() => async () => {
|
|
await unregisterDelivery?.();
|
|
await production.close();
|
|
}, 'dsh-weixin: close account connections');
|
|
return disposeRpc;
|
|
}
|
|
|
|
export function createWeixinHostPlugin(config) {
|
|
return Object.freeze({ name, inject, apply: (ctx) => apply(ctx, config) });
|
|
}
|
|
|
|
export { createConnectionSupervisor, ConnectionSupervisor } from './connection-supervisor.mjs';
|
|
export { createProductionController } from './production.mjs';
|
|
export {
|
|
WEIXIN_ENDPOINTS,
|
|
WEIXIN_RPC_CHANNEL,
|
|
WEIXIN_RPC_ENDPOINTS,
|
|
createWeixinRpcHandler,
|
|
installWeixinRpc,
|
|
} from './rpc.mjs';
|
|
export { WeixinController } from '../../../../src/channels/weixin/weixin-controller.mjs';
|
|
export { WeixinRuntime } from '../../../../src/channels/weixin/weixin-runtime.mjs';
|