tc-bridge
v1.0.0
Published
特斯联云桌面通信bridge
Downloads
4
Readme
云桌面通信【tc-bridge】
适用范围
tc-bridge 使用原生 js 封装,适用所有前端项目
浏览器支持
支持 ie10 及以上版本
安装
yarn 安装
yarn add tc-bridge
npm 安装
npm install tc-bridge
API
post
参数
- messageData
- eventType:
string
两个应用间约定的通信类型 - data:
Record<string, unknown>
通信数据 - appId:
string
子应用的 ID(可找主应用开发对接),主应用可不传 - targetWindow:
window
接收消息的目标应用 Window 对象
- eventType:
- callback:
(data: Record<string, unknown>) => any
; 回调函数
- messageData
用法
const app = {
eventType: "addApp",
data: {
name: "cloud",
icon: "cloudDesktop",
url: "http://192.168.118.168:53069/",
action: "add",
type: "thirdParty"
},
appId: "cloud",
targetWindow: window.parent,
};
tcBridge.post(app, (err, data) => {
// 处理后续流程
});
postPromise
参数
- messageData
- eventType:
string
两个应用间约定的通信类型 - data:
Record<string, unknown>
通信数据 - appId:
string
子应用的 ID(可找主应用开发对接),主应用可不传 - targetWindow:
window
接收消息的目标应用 Window 对象
- eventType:
- messageData
用法
const app = {
eventType: "addApp",
data: {
name: "cloud",
icon: "cloudDesktop",
url: "http://192.168.118.168:53069/",
action: "add",
type: "thirdParty"
},
appId: "cloud",
targetWindow: window.parent,
};
tcBridge.postPromise(app)
.then(data => {
// 处理后续流程
})
addEventListener
参数
- callbackValue
- listenerType:
"once" | "long"
监听类型,监听一次或者长监听 - eventType:
string
两个应用间约定的通信类型 - func?:
(data: CallbackData) => any
回调函数 - promiseFunc?:
(data: any) => Promise<any>
异步回调函数
- listenerType:
- callbackValue
用法
const callbackValue = {
listenerType: "long",
eventType: "addApp",
func: (data) => {
// 处理后续流程
}
};
tcBridge.addEventListener(callbackValue);