@kookapp/kook-bridge-channel
v1.0.8
Published
``` npm install @kookapp/kook-bridge-channel ```
Downloads
9
Keywords
Readme
KOOK-Bridge-Channel
安装
npm install @kookapp/kook-bridge-channel
Server 端
import { createChannelServer } from 'kook-bridge-channel'
const server = createChannelServer({ originList: ['实际应用的 location.origin'] })
server.on('request', ({ eventName, data }, send) => {
// router
// switch eventName ...
// response send()
})
server.on('subscribe', ({ eventName, data }, send, { client }) => {
// switch eventName ...
// client.subscribeNotify
// 示例:
function callback() {
client.subscribeNotify(eventName, { date: Date.now() })
}
eleButton.addEventListener('click', callback)
client.listenDestroy(() => {
eleButton.removeEventListener('click', callback)
})
})
Client 端
import { createChannelClient } from 'kook-bridge-channel'
const client = createChannelClient()
await client.createChannel({ originList: ['实际应用的 location.origin'] })
client.request(eventName, data).then(() => {})
client.subscribe(eventName, (data) => {
console.log(eventName, data)
})
client.on('error', () => {
// 心跳超时可以尝试重新创建 Channel ( request 响应超时同样可以尝试重新创建 Channel )
// ** 新 channel 之前的 subscribe 需要重新订阅
// client.closeChannel()
// client.createChannel({ originList: [] })
})
中间层传递创建 Channel 消息
import { KOOKChannelHelper } from 'kook-bridge-channel'
KOOKChannelHelper.createPipe(win1, win2, { originList: [] })
History version
- v1.0.8
- 升级依赖
@kookapp/k-jsbridge
版本
- 升级依赖
- v1.0.7
- 修改 npm 依赖
- v1.0.6
- 增加 test 测试页面
- 增加 subscribe 逻辑
- 增加 server client 超时 destroy 逻辑
- v1.0.5
- 修复移动端环境判断必须是在顶级窗口才可使用 Bridge
- v1.0.4
- 修改移动端
BridgeClient.createChannel
统一返回 Promise - 修复 Electron
KOOKChannelHelper.createPipe
无法正确处理创建 channel
- 修改移动端