webmaxsocket 1.1.2 → 1.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/lib/client.js +9 -1
- package/lib/socketTransport.js +10 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -742,6 +742,8 @@ DEBUG=1 node example.js
|
|
|
742
742
|
|
|
743
743
|
6. **`cid` при отправке сообщений (TCP/Socket):** сервер проверяет **signed int32**. Не передавайте `Date.now()` (миллисекунды ~1e12) — будет «Ошибка валидации». Либо не указывайте `cid` (клиент подставит свой), либо передайте целое в диапазоне **−2³¹ … 2³¹−1**.
|
|
744
744
|
|
|
745
|
+
7. **TCP и keep-alive (PING):** сервер периодически шлёт `PING`. На WebSocket клиент отвечает `sendPong`; на **TCP** раньше ответ не отправлялся — соединение могло обрываться через несколько минут, после чего процесс Node **завершался** (нечем держать event loop). Сейчас на TCP автоматически шлётся тот же ответ, что и у WebSocket (`PING` с пустым payload).
|
|
746
|
+
|
|
745
747
|
## 🔗 Ссылки / Links
|
|
746
748
|
|
|
747
749
|
- [GitHub Repository](https://github.com/Tellarion/webmaxsocket)
|
package/lib/client.js
CHANGED
|
@@ -929,8 +929,16 @@ class WebMaxClient extends EventEmitter {
|
|
|
929
929
|
break;
|
|
930
930
|
|
|
931
931
|
case Opcode.PING:
|
|
932
|
+
// Иначе сервер рвёт TCP через ~минуты; WebSocket здесь шлёт sendPong (тот же opcode PING + {})
|
|
933
|
+
if (
|
|
934
|
+
this._socketTransport &&
|
|
935
|
+
this._socketTransport.socket &&
|
|
936
|
+
!this._socketTransport.socket.destroyed
|
|
937
|
+
) {
|
|
938
|
+
this._socketTransport.sendOneWay(Opcode.PING, {});
|
|
939
|
+
}
|
|
932
940
|
break;
|
|
933
|
-
|
|
941
|
+
|
|
934
942
|
default:
|
|
935
943
|
this.emit('raw_message', data);
|
|
936
944
|
}
|
package/lib/socketTransport.js
CHANGED
|
@@ -156,6 +156,16 @@ class MaxSocketTransport {
|
|
|
156
156
|
};
|
|
157
157
|
}
|
|
158
158
|
|
|
159
|
+
/**
|
|
160
|
+
* Однонаправленная отправка без ожидания ответа (ответ на серверный PING — как WebSocket sendPong).
|
|
161
|
+
*/
|
|
162
|
+
sendOneWay(opcode, payload = {}, cmd = 0) {
|
|
163
|
+
if (!this.socket || this.socket.destroyed) return;
|
|
164
|
+
const msg = this._makeMessage(opcode, payload, cmd);
|
|
165
|
+
const packet = packPacket(msg.ver, msg.cmd, msg.seq, msg.opcode, msg.payload);
|
|
166
|
+
this.socket.write(packet);
|
|
167
|
+
}
|
|
168
|
+
|
|
159
169
|
_startRecvLoop() {
|
|
160
170
|
const readNext = async () => {
|
|
161
171
|
if (!this.socket || this.socket.destroyed) return;
|