Skip to content

Commit

Permalink
fix: 解决部分情况SocketTask.send回调不正确的问题 fixed #744
Browse files Browse the repository at this point in the history
  • Loading branch information
zhetengbiji committed Nov 12, 2019
1 parent 816ca86 commit 8723cea
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/platforms/h5/service/api/network/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ class SocketTask {
const data = options.data
const ws = this._webSocket
try {
if (ws.readyState !== ws.OPEN) {
throw new Error('SocketTask.readyState is not OPEN')
}
ws.send(data)
this._callback(options, 'sendSocketMessage:ok')
} catch (error) {
Expand Down Expand Up @@ -118,11 +121,11 @@ class SocketTask {
}
}
}
eventNames.forEach(item => {
const name = item[0].toUpperCase() + item.substr(1)
SocketTask.prototype[`on${name}`] = function (callback) {
this._callbacks[item].push(callback)
}
eventNames.forEach(item => {
const name = item[0].toUpperCase() + item.substr(1)
SocketTask.prototype[`on${name}`] = function (callback) {
this._callbacks[item].push(callback)
}
})
/**
* 创建一个 WebSocket 连接
Expand Down

0 comments on commit 8723cea

Please sign in to comment.