提交 7ab93165 编写于 作者: D DCloud_LXH

fix(App): socket closeSocket

上级 e9456f1e
......@@ -142,7 +142,7 @@ class SocketTask implements UniApp.SocketTask {
})
}
send(args: UniApp.SendSocketMessageOptions) {
send(args: UniApp.SendSocketMessageOptions, callopt: boolean = true) {
if (this.readyState !== this.OPEN) {
callOptions(args, 'sendSocketMessage:fail WebSocket is not connected')
}
......@@ -157,13 +157,13 @@ class SocketTask implements UniApp.SocketTask {
}
: args.data,
})
callOptions(args, 'sendSocketMessage:ok')
callopt && callOptions(args, 'sendSocketMessage:ok')
} catch (error) {
callOptions(args, `sendSocketMessage:fail ${error}`)
callopt && callOptions(args, `sendSocketMessage:fail ${error}`)
}
}
close(args: UniApp.CloseSocketOptions) {
close(args?: UniApp.CloseSocketOptions, callopt: boolean = true) {
this.readyState = this.CLOSING
try {
this._socket.close(
......@@ -172,9 +172,9 @@ class SocketTask implements UniApp.SocketTask {
args,
})
)
callOptions(args, 'closeSocket:ok')
callopt && callOptions(args!, 'closeSocket:ok')
} catch (error) {
callOptions(args, `closeSocket:fail ${error}`)
callopt && callOptions(args!, `closeSocket:fail ${error}`)
}
}
......@@ -226,10 +226,10 @@ export const sendSocketMessage = defineAsyncApi<API_TYPE_SEND_SOCKET_MESSAGE>(
(args, { resolve, reject }) => {
const socketTask = socketTasks[0]
if (!socketTask || socketTask.readyState !== socketTask.OPEN) {
reject('sendSocketMessage:fail WebSocket is not connected')
reject('WebSocket is not connected')
return
}
socketTask.send({ data: args.data })
socketTask.send({ data: args.data }, false)
resolve()
},
SendSocketMessageProtocol
......@@ -237,15 +237,14 @@ export const sendSocketMessage = defineAsyncApi<API_TYPE_SEND_SOCKET_MESSAGE>(
export const closeSocket = defineAsyncApi<API_TYPE_CLOSE_SOCKET>(
API_CLOSE_SOCKET,
(args, { resolve, reject }) => {
(args: AsyncApiOptions<API_TYPE_CLOSE_SOCKET>, { resolve, reject }) => {
const socketTask = socketTasks[0]
if (!socketTask) {
reject('closeSocket:fail WebSocket is not connected')
reject('WebSocket is not connected')
return
}
socketTask.readyState = socketTask.CLOSING
const { code, reason } = args
socketTask.close({ code, reason })
socketTask.close(args, false)
resolve()
},
CloseSocketProtocol
......
......@@ -922,10 +922,10 @@
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==
"@dcloudio/types@^2.3.1":
"@dcloudio/types@^2.3.2":
version "2.3.2"
resolved "https://registry.yarnpkg.com/@dcloudio/types/-/types-2.3.2.tgz#8c4c7e22ad650588935d07754c1f1552d86b7a97"
integrity sha512-ZyAkqPwlPtXtGcf7qYkB/iX4nER/JcNeCXR2VPqXxBmagE8wjRYtkKjso1YUsFyDIoaNBBY1CtzV3iKa6oREeg==
resolved "https://registry.nlark.com/@dcloudio/types/download/@dcloudio/types-2.3.2.tgz#8c4c7e22ad650588935d07754c1f1552d86b7a97"
integrity sha1-jEx+Iq1lBYiTXQd1TB8VUthrepc=
"@eslint/eslintrc@^0.4.2":
version "0.4.2"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册