tmp
This commit is contained in:
+13
-11
@@ -195,21 +195,23 @@ Page({
|
||||
const user = app.globalData.user
|
||||
const socket = app.globalData.chatSocket
|
||||
|
||||
// 先判空再判连接状态,避免 socket 不存在时读取 isConnected 报错
|
||||
if (!socket) {
|
||||
this.handleAIError('网络连接失败,请检查网络设置')
|
||||
return
|
||||
}
|
||||
|
||||
if (!socket.isConnected) {
|
||||
socket.connect()
|
||||
}
|
||||
|
||||
if (socket) {
|
||||
socket.send({
|
||||
type: type,
|
||||
content: content,
|
||||
userId: user ? user._id : '',
|
||||
appId: app.globalData.appId
|
||||
})
|
||||
} else {
|
||||
// 处理连接失败的情况
|
||||
this.handleAIError('网络连接失败,请检查网络设置')
|
||||
}
|
||||
socket.send({
|
||||
type: type,
|
||||
content: content,
|
||||
// 身份以 token 为准,服务端不再接受凭 userId 明文接入
|
||||
token: (user && user.security && user.security.token) || '',
|
||||
appId: app.globalData.appId
|
||||
})
|
||||
},
|
||||
|
||||
handleAIError(errorMessage) {
|
||||
|
||||
Reference in New Issue
Block a user