hst-request-websocket
v1.3.0
Published
基于发布订阅的w返回管理
Downloads
1
Readme
使用方法
import { HstRequestWebsocket } from "hstRequestWebsocket"
// 拦截器
let hstRequestWebsocket = new HstRequestWebsocket({
eventRegistryAdapter: {
on: eventRegistry.on,
}
})
// websocket 请求拦截
hstRequestWebsocket.interceptors.response.use(({data, config}) => {
// 订阅事件
if (data === EventResult.NOADDR && config.retryConfig.num < config.retryConfig.max) {
config.retryConfig.num ++
logger.warn(`start retry receive media: ${config.retryConfig.num}`)
return hstRequestWebsocket.request(config)
}
return data
}, (err) => {
})
function request19001 () {
hstRequestWebsocket({
eventName: 'sendDemo',
requestFn: () => {// 请求发出函数
websocket.send({
cmdId: '10001'
})
}
}).then((res) => {
}).catch((err) => {
})
// 请求回复
eventRegistry.trigger('sendDemo', {code: 0, msg: 'success'})
}