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