@onyx-p/imlib-web 1.5.6 → 1.5.7

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.
Files changed (3) hide show
  1. package/index.esm.js +35 -14
  2. package/index.umd.js +35 -14
  3. package/package.json +1 -1
package/index.esm.js CHANGED
@@ -13305,6 +13305,7 @@ class WebSocketServer {
13305
13305
  failedCount = 0;
13306
13306
  reconnectTimer;
13307
13307
  connectResolve;
13308
+ pendingMessages = [];
13308
13309
  constructor(options) {
13309
13310
  this.options = Object.assign(DefaultOptions, options);
13310
13311
  }
@@ -13383,21 +13384,15 @@ class WebSocketServer {
13383
13384
  };
13384
13385
  }
13385
13386
  const messageSeq = this.generateMessageSeq();
13386
- const networkReq = {
13387
- cmdId: cmdId,
13388
- messageSeq: Long.fromNumber(messageSeq),
13389
- deviceId: Long.fromString(accountStore.user.deviceId),
13390
- sessionId: Long.fromString(accountStore.user.sessionId),
13391
- uid: Long.fromString(accountStore.user.uid),
13392
- protocolVersion: SOCKET_PROTOCOL_VER,
13393
- destId: '',
13394
- body: body,
13395
- deviceType: 7
13396
- };
13397
- if (cmdId !== CmdIds$1.Heartbean) {
13398
- logger.info(`websocket send -> cmd: 0x${cmdId.toString(16)}, messageSeq: ${messageSeq}`);
13387
+ if (this.isConnected) {
13388
+ this.doSendRawData(cmdId, body, messageSeq);
13389
+ } else {
13390
+ this.pendingMessages.push({
13391
+ cmdId,
13392
+ body,
13393
+ messageSeq
13394
+ });
13399
13395
  }
13400
- this.socket.send(buildWsPacketData(rpc_baseExports.NetworkRequest.encode(networkReq).finish()));
13401
13396
  const respData = await new Promise(resolve => {
13402
13397
  this.responseCallbacks.set(messageSeq, resolve);
13403
13398
  setTimeout(() => {
@@ -13418,6 +13413,23 @@ class WebSocketServer {
13418
13413
  data: respData
13419
13414
  };
13420
13415
  }
13416
+ doSendRawData(cmdId, body, messageSeq) {
13417
+ const networkReq = {
13418
+ cmdId: cmdId,
13419
+ messageSeq: Long.fromNumber(messageSeq),
13420
+ deviceId: Long.fromString(accountStore.user.deviceId),
13421
+ sessionId: Long.fromString(accountStore.user.sessionId),
13422
+ uid: Long.fromString(accountStore.user.uid),
13423
+ protocolVersion: SOCKET_PROTOCOL_VER,
13424
+ destId: '',
13425
+ body: body,
13426
+ deviceType: 7
13427
+ };
13428
+ if (cmdId !== CmdIds$1.Heartbean) {
13429
+ logger.info(`websocket send -> cmd: 0x${cmdId.toString(16)}, messageSeq: ${messageSeq}`);
13430
+ }
13431
+ this.socket?.send(buildWsPacketData(rpc_baseExports.NetworkRequest.encode(networkReq).finish()));
13432
+ }
13421
13433
  close() {
13422
13434
  this.autoReconnect = false;
13423
13435
  this.doClose();
@@ -13540,6 +13552,14 @@ class WebSocketServer {
13540
13552
  clearTimeout(this.reconnectTimer);
13541
13553
  this.reconnectTimer = null;
13542
13554
  }
13555
+ while (this.pendingMessages.length > 0) {
13556
+ let {
13557
+ cmdId,
13558
+ body,
13559
+ messageSeq
13560
+ } = this.pendingMessages.shift();
13561
+ this.doSendRawData(cmdId, body, messageSeq);
13562
+ }
13543
13563
  }
13544
13564
  onDisconnect(error) {
13545
13565
  if (!isDef(this.socket)) {
@@ -13556,6 +13576,7 @@ class WebSocketServer {
13556
13576
  }
13557
13577
  doClose() {
13558
13578
  if (isDef(this.socket)) {
13579
+ this.pendingMessages.length = 0;
13559
13580
  const socket = this.socket;
13560
13581
  this.socket = null;
13561
13582
  socket.onClose(null);
package/index.umd.js CHANGED
@@ -13311,6 +13311,7 @@
13311
13311
  failedCount = 0;
13312
13312
  reconnectTimer;
13313
13313
  connectResolve;
13314
+ pendingMessages = [];
13314
13315
  constructor(options) {
13315
13316
  this.options = Object.assign(DefaultOptions, options);
13316
13317
  }
@@ -13389,21 +13390,15 @@
13389
13390
  };
13390
13391
  }
13391
13392
  const messageSeq = this.generateMessageSeq();
13392
- const networkReq = {
13393
- cmdId: cmdId,
13394
- messageSeq: Long.fromNumber(messageSeq),
13395
- deviceId: Long.fromString(accountStore.user.deviceId),
13396
- sessionId: Long.fromString(accountStore.user.sessionId),
13397
- uid: Long.fromString(accountStore.user.uid),
13398
- protocolVersion: SOCKET_PROTOCOL_VER,
13399
- destId: '',
13400
- body: body,
13401
- deviceType: 7
13402
- };
13403
- if (cmdId !== CmdIds$1.Heartbean) {
13404
- logger.info(`websocket send -> cmd: 0x${cmdId.toString(16)}, messageSeq: ${messageSeq}`);
13393
+ if (this.isConnected) {
13394
+ this.doSendRawData(cmdId, body, messageSeq);
13395
+ } else {
13396
+ this.pendingMessages.push({
13397
+ cmdId,
13398
+ body,
13399
+ messageSeq
13400
+ });
13405
13401
  }
13406
- this.socket.send(buildWsPacketData(rpc_baseExports.NetworkRequest.encode(networkReq).finish()));
13407
13402
  const respData = await new Promise(resolve => {
13408
13403
  this.responseCallbacks.set(messageSeq, resolve);
13409
13404
  setTimeout(() => {
@@ -13424,6 +13419,23 @@
13424
13419
  data: respData
13425
13420
  };
13426
13421
  }
13422
+ doSendRawData(cmdId, body, messageSeq) {
13423
+ const networkReq = {
13424
+ cmdId: cmdId,
13425
+ messageSeq: Long.fromNumber(messageSeq),
13426
+ deviceId: Long.fromString(accountStore.user.deviceId),
13427
+ sessionId: Long.fromString(accountStore.user.sessionId),
13428
+ uid: Long.fromString(accountStore.user.uid),
13429
+ protocolVersion: SOCKET_PROTOCOL_VER,
13430
+ destId: '',
13431
+ body: body,
13432
+ deviceType: 7
13433
+ };
13434
+ if (cmdId !== CmdIds$1.Heartbean) {
13435
+ logger.info(`websocket send -> cmd: 0x${cmdId.toString(16)}, messageSeq: ${messageSeq}`);
13436
+ }
13437
+ this.socket?.send(buildWsPacketData(rpc_baseExports.NetworkRequest.encode(networkReq).finish()));
13438
+ }
13427
13439
  close() {
13428
13440
  this.autoReconnect = false;
13429
13441
  this.doClose();
@@ -13546,6 +13558,14 @@
13546
13558
  clearTimeout(this.reconnectTimer);
13547
13559
  this.reconnectTimer = null;
13548
13560
  }
13561
+ while (this.pendingMessages.length > 0) {
13562
+ let {
13563
+ cmdId,
13564
+ body,
13565
+ messageSeq
13566
+ } = this.pendingMessages.shift();
13567
+ this.doSendRawData(cmdId, body, messageSeq);
13568
+ }
13549
13569
  }
13550
13570
  onDisconnect(error) {
13551
13571
  if (!isDef(this.socket)) {
@@ -13562,6 +13582,7 @@
13562
13582
  }
13563
13583
  doClose() {
13564
13584
  if (isDef(this.socket)) {
13585
+ this.pendingMessages.length = 0;
13565
13586
  const socket = this.socket;
13566
13587
  this.socket = null;
13567
13588
  socket.onClose(null);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onyx-p/imlib-web",
3
- "version": "1.5.6",
3
+ "version": "1.5.7",
4
4
  "main": "index.umd.js",
5
5
  "module": "index.esm.js",
6
6
  "types": "types/index.d.ts",