@onyx-p/imlib-web 1.5.5 → 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.
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);
@@ -28611,16 +28632,7 @@ const getAllUnreadMentionedCount = () => {
28611
28632
  };
28612
28633
  const getConversationState = options => {
28613
28634
  logger.debug('getConversationState');
28614
- const state = imClient.getConversationState(options);
28615
- if (state) {
28616
- return Promise.resolve({
28617
- code: ErrorCode.SUCCESS,
28618
- data: state
28619
- });
28620
- }
28621
- return Promise.resolve({
28622
- code: ErrorCode.UNKNOWN
28623
- });
28635
+ return imClient.getConversationState(options);
28624
28636
  };
28625
28637
  const getAllConversationState = () => {
28626
28638
  logger.debug('getAllConversationState');
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);
@@ -28617,16 +28638,7 @@
28617
28638
  };
28618
28639
  const getConversationState = options => {
28619
28640
  logger.debug('getConversationState');
28620
- const state = imClient.getConversationState(options);
28621
- if (state) {
28622
- return Promise.resolve({
28623
- code: exports.ErrorCode.SUCCESS,
28624
- data: state
28625
- });
28626
- }
28627
- return Promise.resolve({
28628
- code: exports.ErrorCode.UNKNOWN
28629
- });
28641
+ return imClient.getConversationState(options);
28630
28642
  };
28631
28643
  const getAllConversationState = () => {
28632
28644
  logger.debug('getAllConversationState');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onyx-p/imlib-web",
3
- "version": "1.5.5",
3
+ "version": "1.5.7",
4
4
  "main": "index.umd.js",
5
5
  "module": "index.esm.js",
6
6
  "types": "types/index.d.ts",
package/types/index.d.ts CHANGED
@@ -101,7 +101,7 @@ export declare const getAllUnreadMentionedCount: () => IPromiseResult<number>;
101
101
  /**
102
102
  * 获取本地单个会话的状态
103
103
  */
104
- export declare const getConversationState: (options: IConversationOption) => IPromiseResult<IConversationState>;
104
+ export declare const getConversationState: (options: IConversationOption) => IConversationState | null;
105
105
  /**
106
106
  * 获取本地全部会话的状态
107
107
  * @description