isdata-customer-sdk 0.1.65 → 0.1.66

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.
@@ -30932,10 +30932,28 @@ class ChatClientMgr {
30932
30932
  }
30933
30933
  }
30934
30934
  async initChatAIs() {
30935
- this.chatAIClient = await this.handler.getChatClient({
30936
- appSKID: this.appSKID,
30937
- onReady: this.onChatAIReady.bind(this)
30938
- });
30935
+ if (window.imClient) {
30936
+ this.chatAIClient = window.imClient;
30937
+ } else {
30938
+ let classDatas = await this.handler.getChatClientClasses();
30939
+ const {
30940
+ TencentCloudChat,
30941
+ TIMUploadPlugin
30942
+ } = classDatas;
30943
+ window.imClient = TencentCloudChat.create({
30944
+ SDKAppID: this.appSKID,
30945
+ // 替换为你的 SDKAppID
30946
+ storage: {
30947
+ enable: true // 启用存储(可选,根据需求)
30948
+ }
30949
+ });
30950
+ window.imClient.registerPlugin({
30951
+ "tim-upload-plugin": TIMUploadPlugin
30952
+ });
30953
+ window.imClient.on(TencentCloudChat.EVENT.SDK_READY, this.onChatAIReady.bind(this));
30954
+ window.imClient.charAIs = {};
30955
+ this.chatAIClient = window.imClient;
30956
+ }
30939
30957
  if (!this.chatAIClient.charAIs) {
30940
30958
  this.chatAIClient.charAIs = {};
30941
30959
  }
@@ -30947,19 +30965,7 @@ class ChatClientMgr {
30947
30965
  robot.chatID = robotKey;
30948
30966
  let userSig = await this.handler.getPortalUserSig(robotKey, this.imType, this.groupID);
30949
30967
  if (!userSig) {
30950
- let sigIDObject = await this.handler.genTestUserSig({
30951
- SDKAppID: this.appSKID,
30952
- userID: robotKey
30953
- });
30954
- userSig = sigIDObject.userSig;
30955
- if (userSig) {
30956
- await this.chatAIClient.login({
30957
- userID: robotKey,
30958
- userSig: userSig
30959
- });
30960
- await this.chatAIClient.logout();
30961
- await this.handler.addIMMapping(robotKey, this.imType, userSig, this.groupID);
30962
- }
30968
+ userSig = await this.generateUserSigAndUpdate(robotKey);
30963
30969
  }
30964
30970
  robot.userSig = userSig;
30965
30971
  this.chatAIClient.charAIs[robotKey] = {
@@ -30970,6 +30976,22 @@ class ChatClientMgr {
30970
30976
  });
30971
30977
  }
30972
30978
  }
30979
+ async generateUserSigAndUpdate(robotKey) {
30980
+ let sigIDObject = await this.handler.genTestUserSig({
30981
+ SDKAppID: this.appSKID,
30982
+ userID: robotKey
30983
+ });
30984
+ let userSig = sigIDObject.userSig;
30985
+ if (userSig) {
30986
+ await this.chatAIClient.login({
30987
+ userID: robotKey,
30988
+ userSig: userSig
30989
+ });
30990
+ await this.chatAIClient.logout();
30991
+ await this.handler.addIMMapping(robotKey, this.imType, userSig, this.groupID);
30992
+ }
30993
+ return userSig;
30994
+ }
30973
30995
  onChatAIReady(event) {
30974
30996
  let robotID = this.chatAIClient.lastRobotID;
30975
30997
  let robotInfo = this.getAIRobotInfoByID(robotID);
@@ -31008,10 +31030,30 @@ class ChatClientMgr {
31008
31030
  if (this.chatAIClient.lastRobotID) {
31009
31031
  await this.chatAIClient.logout();
31010
31032
  }
31011
- await this.chatAIClient.login({
31012
- userID: robotID,
31013
- userSig: robotInfo.userSig
31014
- });
31033
+ try {
31034
+ await this.chatAIClient.login({
31035
+ userID: robotID,
31036
+ userSig: robotInfo.userSig
31037
+ });
31038
+ } catch (err) {
31039
+ console.log(`[AI chat]${robotInfo.name}登录失败`, err);
31040
+ let code = err.code;
31041
+ if (code == 70001) {
31042
+ console.log(`[AI chat]${robotInfo.name}UserSig过期,重新生成userSig`);
31043
+ let newUserSig = await this.generateUserSigAndUpdate(robotID);
31044
+ try {
31045
+ await this.chatAIClient.login({
31046
+ userID: robotID,
31047
+ userSig: newUserSig
31048
+ });
31049
+ this.sendMessageToChatServer(robotID, messageOption);
31050
+ return;
31051
+ } catch (err) {
31052
+ console.log(`[AI chat]${robotInfo.name}重新登录失败`, err);
31053
+ return;
31054
+ }
31055
+ }
31056
+ }
31015
31057
  }
31016
31058
  this.chatAIClient.lastRobotID = robotID;
31017
31059
  if (this.chatAIClient && this.chatAIClient.isReady()) {