@smartdesk/bus-sdk
v0.1.1
Published
SmartDesk message bus SDK for renderer and plugin applications
Downloads
245
Readme
@smartdesk/bus-sdk
SmartDesk 平台应用接入消息总线的客户端 SDK。
当应用被 SmartDesk 平台加载时,SDK 会根据当前运行环境自动找到平台提供的消息总线连接,并向业务代码提供统一的 EndpointBus API。
安装
npm install @smartdesk/bus-sdk
// 或
yarn add @smartdesk/bus-sdk
// 或
pnpm add @smartdesk/bus-sdk使用
应用依赖 SmartDesk 平台消息总线,使用 connectMessageBus():
import { connectMessageBus } from '@smartdesk/bus-sdk';
const bus = connectMessageBus();常用能力
await bus.registerService({
address: 'ep://app/my-app/open-file',
handler: async (message) => {
await openFile(message.payload.fileId);
return { ok: true };
},
});
await bus.request({
to: 'ep://app/my-app/open-file',
payload: {
fileId: '123',
},
});
await bus.subscribe({
topic: 'ep://platform/theme-changed',
handler: (message) => {
applyTheme(message.payload.theme);
},
});注意
该 SDK 可以在普通前端项目中安装和打包,但真正连接消息总线需要 SmartDesk 平台运行环境。
