Unhandled promise rejection {errMsg: "closeSocket:fail task not found"}(env: Windows,mp,1.05.2204250; lib: 2.24.1)
Sun Jul 31 2022 11:31:49 GMT+0800 (中国标准时间) websocket 错误
同时最多发起 5 个 socket 请求,更多请参考文档:https://developers.weixin.qq.com/miniprogram/dev/framework/ability/network.html(env: Windows,mp,1.05.2204250; lib: 2.24.1)
代码是这样的:
const socket = io('wss://api.myserver.com', {
query: {
'token': `${token}`
},
path: '/ws/msg',
transports: [ 'websocket', 'polling' ],
timeout: 5000,
});
socket.on('connect', () => {
console.log('ws 已连接 --- power by socket.io v2.0.3');
});
const { id } = socket;
socket.on(id, (message) => {
console.log('ws 收到服务器消息:', message);
});
socket.on('textMsg', msg => {
console.log('receive:>>', msg)
talkList.value.push(msg.text)
})
socket.on('error', msg => {
console.log('ws error', msg);
});
function sendToServer(content) {
const toUserIds = ['b7e91a0']
uni.setNavigationBarTitle({title: toUserIds[0]})
socket.emit('sendText', {
toUserIds: toUserIds,
content: content,
type: '对话'
});
}
1 个回复
1***@139.com (作者)
您好作者大佬,请问在uni-app中,当离开页面时,比如我想关闭socket连接,应该怎么操作?去阅读了socket.io的官方文档,貌似只有socket.close() 或者 socket.disconnect(),但是没能在这个api中传参数,比如我想具体关闭的指定id的socket连接