From 8723ceaffbc6ca363d057d7812aee52c621c2e71 Mon Sep 17 00:00:00 2001 From: qiang Date: Tue, 12 Nov 2019 16:36:47 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=E9=83=A8=E5=88=86?= =?UTF-8?q?=E6=83=85=E5=86=B5SocketTask.send=E5=9B=9E=E8=B0=83=E4=B8=8D?= =?UTF-8?q?=E6=AD=A3=E7=A1=AE=E7=9A=84=E9=97=AE=E9=A2=98=20fixed=20#744?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/platforms/h5/service/api/network/socket.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/platforms/h5/service/api/network/socket.js b/src/platforms/h5/service/api/network/socket.js index 5bd2ae3efac..3345d339517 100644 --- a/src/platforms/h5/service/api/network/socket.js +++ b/src/platforms/h5/service/api/network/socket.js @@ -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) { @@ -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 连接