@openim/client-sdk
Version:
JavaScript/TypeScript Client SDK for OpenIM
1 lines • 141 kB
JavaScript
import e from"loglevel";import t from"spark-md5";import{decode as n,encode as s}from"base64-arraybuffer";import{PbCoder as i,SdkWsProto as r}from"@openim/protocol";function o(e,t){if(!{}.hasOwnProperty.call(e,t))throw new TypeError("attempted to use private field on non-instance");return e}var a=0;function c(e){return"__private_"+a+++"_"+e}function d(){return d=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var s in n)({}).hasOwnProperty.call(n,s)&&(e[s]=n[s])}return e},d.apply(null,arguments)}function u(e,t){if(null==e)return{};var n={};for(var s in e)if({}.hasOwnProperty.call(e,s)){if(t.includes(s))continue;n[s]=e[s]}return n}const g=async e=>{if(!e.ok)throw new Error(e.statusText);const t=await e.json();if(0!==t.errCode)throw new Error(t.errMsg);return t.data},p={txt:"text/plain",html:"text/html",css:"text/css",js:"text/javascript",json:"application/json",csv:"text/csv",jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",gif:"image/gif",bmp:"image/bmp",svg:"image/svg+xml",mp3:"audio/mpeg",mp4:"video/mp4",wav:"audio/wav",pdf:"application/pdf",doc:"application/msword",docx:"application/vnd.openxmlformats-officedocument.wordprocessingml.document",xls:"application/vnd.ms-excel",xlsx:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",ppt:"application/vnd.ms-powerpoint",pptx:"application/vnd.openxmlformats-officedocument.presentationml.presentation",xml:"application/xml",zip:"application/zip",tar:"application/x-tar","7z":"application/x-7z-compressed",rar:"application/vnd.rar",ogg:"audio/ogg",midi:"audio/midi",webm:"audio/webm",avi:"video/x-msvideo",mpeg:"video/mpeg",ts:"video/mp2t",mov:"video/quicktime",wmv:"video/x-ms-wmv",flv:"video/x-flv",mkv:"video/x-matroska",webp:"image/webp",heic:"image/heic",psd:"image/vnd.adobe.photoshop",ai:"application/postscript",eps:"application/postscript",ttf:"font/ttf",otf:"font/otf",woff:"font/woff",woff2:"font/woff2",jsonld:"application/ld+json",ics:"text/calendar",sh:"application/x-sh",php:"application/x-httpd-php",jar:"application/java-archive"};var l,h;!function(e){e.InitSDK="InitSDK",e.Login="Login",e.Logout="Logout",e.GetLoginStatus="GetLoginStatus",e.GetLoginUserID="GetLoginUserID",e.ForceReconnect="ForceReconnect",e.GetSelfUserInfo="GetSelfUserInfo",e.SetSelfInfo="SetSelfInfo",e.GetUsersInfo="GetUsersInfo",e.SubscribeUsersStatus="SubscribeUsersStatus",e.UnsubscribeUsersStatus="UnsubscribeUsersStatus",e.GetSubscribeUsersStatus="GetSubscribeUsersStatus",e.SetAppBackgroundStatus="SetAppBackgroundStatus",e.NetworkStatusChanged="NetworkStatusChanged",e.SetGlobalRecvMessageOpt="SetGlobalRecvMessageOpt",e.AcceptFriendApplication="AcceptFriendApplication",e.AddBlack="AddBlack",e.AddFriend="AddFriend",e.CheckFriend="CheckFriend",e.DeleteFriend="DeleteFriend",e.GetBlackList="GetBlackList",e.GetFriendApplicationListAsApplicant="GetFriendApplicationListAsApplicant",e.GetFriendApplicationListAsRecipient="GetFriendApplicationListAsRecipient",e.GetFriendList="GetFriendList",e.GetFriendListPage="GetFriendListPage",e.GetSpecifiedFriendsInfo="GetSpecifiedFriendsInfo",e.RefuseFriendApplication="RefuseFriendApplication",e.RemoveBlack="RemoveBlack",e.SearchFriends="SearchFriends",e.UpdateFriends="UpdateFriends",e.CreateGroup="CreateGroup",e.JoinGroup="JoinGroup",e.InviteUserToGroup="InviteUserToGroup",e.GetJoinedGroupList="GetJoinedGroupList",e.GetJoinedGroupListPage="GetJoinedGroupListPage",e.SearchGroups="SearchGroups",e.GetSpecifiedGroupsInfo="GetSpecifiedGroupsInfo",e.SetGroupInfo="SetGroupInfo",e.GetGroupApplicationListAsRecipient="GetGroupApplicationListAsRecipient",e.GetGroupApplicationListAsApplicant="GetGroupApplicationListAsApplicant",e.AcceptGroupApplication="AcceptGroupApplication",e.RefuseGroupApplication="RefuseGroupApplication",e.GetGroupMemberList="GetGroupMemberList",e.GetSpecifiedGroupMembersInfo="GetSpecifiedGroupMembersInfo",e.SearchGroupMembers="SearchGroupMembers",e.SetGroupMemberInfo="SetGroupMemberInfo",e.GetGroupMemberOwnerAndAdmin="GetGroupMemberOwnerAndAdmin",e.GetGroupMemberListByJoinTimeFilter="GetGroupMemberListByJoinTimeFilter",e.KickGroupMember="KickGroupMember",e.ChangeGroupMemberMute="ChangeGroupMemberMute",e.ChangeGroupMute="ChangeGroupMute",e.TransferGroupOwner="TransferGroupOwner",e.DismissGroup="DismissGroup",e.QuitGroup="QuitGroup",e.GetUsersInGroup="GetUsersInGroup",e.IsJoinGroup="IsJoinGroup",e.GetAllConversationList="GetAllConversationList",e.GetConversationListSplit="GetConversationListSplit",e.GetOneConversation="GetOneConversation",e.GetMultipleConversation="GetMultipleConversation",e.GetConversationIDBySessionType="GetConversationIDBySessionType",e.GetTotalUnreadMsgCount="GetTotalUnreadMsgCount",e.MarkConversationMessageAsRead="MarkConversationMessageAsRead",e.SetConversationDraft="SetConversationDraft",e.PinConversation="PinConversation",e.SetConversationRecvMessageOpt="SetConversationRecvMessageOpt",e.SetConversationPrivateChat="SetConversationPrivateChat",e.SetConversationBurnDuration="SetConversationBurnDuration",e.ResetConversationGroupAtType="ResetConversationGroupAtType",e.HideConversation="HideConversation",e.HideAllConversation="HideAllConversation",e.ClearConversationAndDeleteAllMsg="ClearConversationAndDeleteAllMsg",e.DeleteConversationAndDeleteAllMsg="DeleteConversationAndDeleteAllMsg",e.ChangeInputStates="ChangeInputStates",e.GetInputStates="GetInputStates",e.CreateTextMessage="CreateTextMessage",e.CreateTextAtMessage="CreateTextAtMessage",e.CreateImageMessageByFile="CreateImageMessageByFile",e.CreateImageMessageByURL="CreateImageMessageByURL",e.CreateSoundMessageByFile="CreateSoundMessageByFile",e.CreateSoundMessageByURL="CreateSoundMessageByURL",e.CreateVideoMessageByFile="CreateVideoMessageByFile",e.CreateVideoMessageByURL="CreateVideoMessageByURL",e.CreateFileMessageByFile="CreateFileMessageByFile",e.CreateFileMessageByURL="CreateFileMessageByURL",e.CreateMergerMessage="CreateMergerMessage",e.CreateForwardMessage="CreateForwardMessage",e.CreateLocationMessage="CreateLocationMessage",e.CreateQuoteMessage="CreateQuoteMessage",e.CreateCardMessage="CreateCardMessage",e.CreateCustomMessage="CreateCustomMessage",e.CreateFaceMessage="CreateFaceMessage",e.SendMessage="SendMessage",e.SendMessageNotOss="SendMessageNotOss",e.UploadFile="UploadFile",e.TypingStatusUpdate="TypingStatusUpdate",e.RevokeMessage="RevokeMessage",e.DeleteMessage="DeleteMessage",e.DeleteMessageFromLocalStorage="DeleteMessageFromLocalStorage",e.DeleteAllMsgFromLocal="DeleteAllMsgFromLocal",e.DeleteAllMsgFromLocalAndSvr="DeleteAllMsgFromLocalAndSvr",e.SearchLocalMessages="SearchLocalMessages",e.GetAdvancedHistoryMessageList="GetAdvancedHistoryMessageList",e.GetAdvancedHistoryMessageListReverse="GetAdvancedHistoryMessageListReverse",e.FindMessageList="FindMessageList",e.InsertGroupMessageToLocalStorage="InsertGroupMessageToLocalStorage",e.InsertSingleMessageToLocalStorage="InsertSingleMessageToLocalStorage",e.SetMessageLocalEx="SetMessageLocalEx",e.SetConversation="SetConversation"}(l||(l={})),function(e){e.GetFriendVersion="GetFriendVersion",e.GetGroupVersion="GetGroupVersion",e.GetJoinedGroupIDList="GetJoinedGroupIDList",e.GetGroupMemberVersion="GetGroupMemberVersion",e.GetConversationVersion="GetConversationVersion",e.GetConversationsHasReadAndMaxSeq="GetConversationsHasReadAndMaxSeq",e.GetDesignatedFriendsApplication="GetDesignatedFriendsApplication",e.GetDesignatedGroupApplication="GetDesignatedGroupApplication",e.GetDesignatedBlackUser="GetDesignatedBlackUser",e.GetActiveConversations="GetActiveConversations",e.GetDesignatedConversation="GetDesignatedConversation",e.GetNotNotifyConversationIDs="GetNotNotifyConversationIDs",e.GetFullFriendUserIDs="GetFullFriendUserIDs",e.GetFullGroupMemberUserIDs="GetFullGroupMemberUserIDs"}(h||(h={}));const f={[l.AddFriend]:"/friend/add_friend",[l.CheckFriend]:"/friend/is_friend",[l.DeleteFriend]:"/friend/delete_friend",[l.AcceptFriendApplication]:"/friend/add_friend_response",[l.RefuseFriendApplication]:"/friend/add_friend_response",[l.GetFriendListPage]:"/friend/get_friend_list",[l.GetSpecifiedFriendsInfo]:"/friend/get_designated_friends",[l.GetFriendApplicationListAsApplicant]:"/friend/get_self_friend_apply_list",[l.GetFriendApplicationListAsRecipient]:"/friend/get_friend_apply_list",[l.UpdateFriends]:"/friend/update_friends",[l.AddBlack]:"/friend/add_black",[l.RemoveBlack]:"/friend/remove_black",[l.GetBlackList]:"/friend/get_black_list",[l.CreateGroup]:"/group/create_group",[l.JoinGroup]:"/group/join_group",[l.InviteUserToGroup]:"/group/invite_user_to_group",[l.GetJoinedGroupListPage]:"/group/get_joined_group_list",[l.GetSpecifiedGroupsInfo]:"/group/get_groups_info",[l.SetGroupInfo]:"/group/set_group_info_ex",[l.GetGroupApplicationListAsApplicant]:"/group/get_user_req_group_applicationList",[l.GetGroupApplicationListAsRecipient]:"/group/get_recv_group_applicationList",[l.AcceptGroupApplication]:"/group/group_application_response",[l.RefuseGroupApplication]:"/group/group_application_response",[l.GetGroupMemberList]:"/group/get_group_member_list",[l.GetSpecifiedGroupMembersInfo]:"/group/get_group_members_info",[l.SetGroupMemberInfo]:"/group/set_group_member_info",[l.KickGroupMember]:"/group/kick_group",[l.TransferGroupOwner]:"/group/transfer_group",[l.DismissGroup]:"/group/dismiss_group",[l.QuitGroup]:"/group/quit_group",[l.GetSelfUserInfo]:"/user/get_users_info",[l.SetSelfInfo]:"/user/update_user_info_ex",[l.GetUsersInfo]:"/user/get_users_info",[l.SubscribeUsersStatus]:"/user/subscribe_users_status",[l.UnsubscribeUsersStatus]:"/user/subscribe_users_status",[l.GetSubscribeUsersStatus]:"/user/get_subscribe_users_status",[l.SetGlobalRecvMessageOpt]:"/user/set_global_msg_recv_opt",[l.RevokeMessage]:"/msg/revoke_msg",[l.DeleteMessage]:"/msg/delete_msgs",[l.DeleteConversationAndDeleteAllMsg]:"/msg/clear_conversation_msg",[l.DeleteAllMsgFromLocalAndSvr]:"/msg/user_clear_all_msg",[l.MarkConversationMessageAsRead]:"/msg/mark_conversation_as_read",[l.SetConversation]:"/conversation/set_conversations",[h.GetFriendVersion]:"/friend/get_incremental_friends",[h.GetGroupVersion]:"/group/get_incremental_join_groups",[h.GetJoinedGroupIDList]:"/group/get_full_join_group_ids",[h.GetGroupMemberVersion]:"/group/get_incremental_group_members_batch",[h.GetConversationVersion]:"/conversation/get_incremental_conversations",[h.GetConversationsHasReadAndMaxSeq]:"/conversation/get_conversations_has_read_and_max_seq",[h.GetDesignatedFriendsApplication]:"/friend/get_designated_friend_apply",[h.GetDesignatedGroupApplication]:"/group/get_specified_user_group_request_info",[h.GetDesignatedBlackUser]:"/friend/get_specified_blacks",[h.GetActiveConversations]:"/jssdk/get_active_conversations",[h.GetDesignatedConversation]:"/jssdk/get_conversations",[h.GetNotNotifyConversationIDs]:"/conversation/get_not_notify_conversation_ids",[h.GetFullFriendUserIDs]:"/friend/get_full_friend_user_ids",[h.GetFullGroupMemberUserIDs]:"/group/get_full_group_member_user_ids"};var m,v,I,M,D,y,S,C,T,G,b;!function(e){e.OnConnectFailed="OnConnectFailed",e.OnConnectSuccess="OnConnectSuccess",e.OnConnecting="OnConnecting",e.OnKickedOffline="OnKickedOffline",e.OnSelfInfoUpdated="OnSelfInfoUpdated",e.OnUserTokenExpired="OnUserTokenExpired",e.OnUserTokenInvalid="OnUserTokenInvalid",e.OnProgress="OnProgress",e.OnRecvNewMessage="OnRecvNewMessage",e.OnRecvNewMessages="OnRecvNewMessages",e.OnRecvOfflineNewMessage="onRecvOfflineNewMessage",e.OnRecvOfflineNewMessages="onRecvOfflineNewMessages",e.OnNewRecvMessageRevoked="OnNewRecvMessageRevoked",e.OnRecvC2CReadReceipt="OnRecvC2CReadReceipt",e.OnRecvGroupReadReceipt="OnRecvGroupReadReceipt",e.OnConversationChanged="OnConversationChanged",e.OnNewConversation="OnNewConversation",e.OnConversationUserInputStatusChanged="OnConversationUserInputStatusChanged",e.OnSyncServerFailed="OnSyncServerFailed",e.OnSyncServerFinish="OnSyncServerFinish",e.OnSyncServerProgress="OnSyncServerProgress",e.OnSyncServerStart="OnSyncServerStart",e.OnTotalUnreadMessageCountChanged="OnTotalUnreadMessageCountChanged",e.OnBlackAdded="OnBlackAdded",e.OnBlackDeleted="OnBlackDeleted",e.OnFriendApplicationAccepted="OnFriendApplicationAccepted",e.OnFriendApplicationAdded="OnFriendApplicationAdded",e.OnFriendApplicationDeleted="OnFriendApplicationDeleted",e.OnFriendApplicationRejected="OnFriendApplicationRejected",e.OnFriendInfoChanged="OnFriendInfoChanged",e.OnFriendAdded="OnFriendAdded",e.OnFriendDeleted="OnFriendDeleted",e.OnJoinedGroupAdded="OnJoinedGroupAdded",e.OnJoinedGroupDeleted="OnJoinedGroupDeleted",e.OnGroupDismissed="OnGroupDismissed",e.OnGroupMemberAdded="OnGroupMemberAdded",e.OnGroupMemberDeleted="OnGroupMemberDeleted",e.OnGroupApplicationAdded="OnGroupApplicationAdded",e.OnGroupApplicationDeleted="OnGroupApplicationDeleted",e.OnGroupInfoChanged="OnGroupInfoChanged",e.OnGroupMemberInfoChanged="OnGroupMemberInfoChanged",e.OnGroupApplicationAccepted="OnGroupApplicationAccepted",e.OnGroupApplicationRejected="OnGroupApplicationRejected",e.UploadComplete="UploadComplete",e.OnRecvCustomBusinessMessage="OnRecvCustomBusinessMessage",e.OnUserStatusChanged="OnUserStatusChanged",e.OnUploadLogsProgress="OnUploadLogsProgress",e.OnReceiveNewInvitation="OnReceiveNewInvitation",e.OnInviteeAccepted="OnInviteeAccepted",e.OnInviteeRejected="OnInviteeRejected",e.OnInvitationCancelled="OnInvitationCancelled",e.OnHangUp="OnHangUp",e.OnInvitationTimeout="OnInvitationTimeout",e.OnInviteeAcceptedByOtherDevice="OnInviteeAcceptedByOtherDevice",e.OnInviteeRejectedByOtherDevice="OnInviteeRejectedByOtherDevice",e.OnStreamChange="OnStreamChange",e.OnRoomParticipantConnected="OnRoomParticipantConnected",e.OnRoomParticipantDisconnected="OnRoomParticipantDisconnected",e.OnReceiveCustomSignal="OnReceiveCustomSignal",e.UnUsedEvent="UnUsedEvent"}(m||(m={})),function(e){e[e.NetworkError=1e4]="NetworkError",e[e.NetworkTimeoutError=10001]="NetworkTimeoutError",e[e.ArgsError=10002]="ArgsError",e[e.CtxDeadlineExceededError=10003]="CtxDeadlineExceededError",e[e.ResourceLoadNotCompleteError=10004]="ResourceLoadNotCompleteError",e[e.UnknownCode=10005]="UnknownCode",e[e.SdkInternalError=10006]="SdkInternalError",e[e.NoUpdateError=10007]="NoUpdateError",e[e.UserIDNotFoundError=10100]="UserIDNotFoundError",e[e.LoginOutError=10101]="LoginOutError",e[e.LoginRepeatError=10102]="LoginRepeatError",e[e.FileNotFoundError=10200]="FileNotFoundError",e[e.MsgDeCompressionError=10201]="MsgDeCompressionError",e[e.MsgDecodeBinaryWsError=10202]="MsgDecodeBinaryWsError",e[e.MsgBinaryTypeNotSupportError=10203]="MsgBinaryTypeNotSupportError",e[e.MsgRepeatError=10204]="MsgRepeatError",e[e.MsgContentTypeNotSupportError=10205]="MsgContentTypeNotSupportError",e[e.MsgHasNoSeqError=10206]="MsgHasNoSeqError",e[e.NotSupportOptError=10301]="NotSupportOptError",e[e.NotSupportTypeError=10302]="NotSupportTypeError",e[e.UnreadCountError=10303]="UnreadCountError",e[e.GroupIDNotFoundError=10400]="GroupIDNotFoundError",e[e.GroupTypeErr=10401]="GroupTypeErr"}(v||(v={})),function(e){e[e.GetNewestSeq=1001]="GetNewestSeq",e[e.PullMsgByRange=1002]="PullMsgByRange",e[e.SendMsg=1003]="SendMsg",e[e.SendSignalMsg=1004]="SendSignalMsg",e[e.PullMsgBySeqList=1005]="PullMsgBySeqList",e[e.GetConvMaxReadSeq=1006]="GetConvMaxReadSeq",e[e.PushMsg=2001]="PushMsg",e[e.KickOnlineMsg=2002]="KickOnlineMsg",e[e.LogoutMsg=2003]="LogoutMsg",e[e.SetBackgroundStatus=2004]="SetBackgroundStatus",e[e.WsSubUserOnlineStatus=2005]="WsSubUserOnlineStatus",e[e.WSServerConfigMsg=2100]="WSServerConfigMsg",e[e.WSDataError=3001]="WSDataError"}(I||(I={})),function(e){e[e.Text=101]="Text",e[e.Picture=102]="Picture",e[e.Sound=103]="Sound",e[e.Video=104]="Video",e[e.File=105]="File",e[e.AtText=106]="AtText",e[e.Merger=107]="Merger",e[e.Card=108]="Card",e[e.Location=109]="Location",e[e.Custom=110]="Custom",e[e.Typing=113]="Typing",e[e.Quote=114]="Quote",e[e.Face=115]="Face",e[e.AdvancedText=117]="AdvancedText",e[e.CustomMsgNotTriggerConversation=119]="CustomMsgNotTriggerConversation",e[e.CustomMsgOnlineOnly=120]="CustomMsgOnlineOnly",e[e.ReactionMessageModifier=121]="ReactionMessageModifier",e[e.ReactionMessageDeleter=122]="ReactionMessageDeleter"}(M||(M={})),function(e){e[e.NotificationBegin=1e3]="NotificationBegin",e[e.FriendNotificationBegin=1200]="FriendNotificationBegin",e[e.FriendApplicationApprovedNotification=1201]="FriendApplicationApprovedNotification",e[e.FriendApplicationRejectedNotification=1202]="FriendApplicationRejectedNotification",e[e.FriendApplicationNotification=1203]="FriendApplicationNotification",e[e.FriendAddedNotification=1204]="FriendAddedNotification",e[e.FriendDeletedNotification=1205]="FriendDeletedNotification",e[e.FriendRemarkSetNotification=1206]="FriendRemarkSetNotification",e[e.BlackAddedNotification=1207]="BlackAddedNotification",e[e.BlackDeletedNotification=1208]="BlackDeletedNotification",e[e.FriendInfoUpdatedNotification=1209]="FriendInfoUpdatedNotification",e[e.FriendsInfoUpdateNotification=1210]="FriendsInfoUpdateNotification",e[e.FriendNotificationEnd=1299]="FriendNotificationEnd",e[e.ConversationChangeNotification=1300]="ConversationChangeNotification",e[e.UserNotificationBegin=1301]="UserNotificationBegin",e[e.UserInfoUpdatedNotification=1303]="UserInfoUpdatedNotification",e[e.UserStatusChangeNotification=1304]="UserStatusChangeNotification",e[e.UserCommandAddNotification=1305]="UserCommandAddNotification",e[e.UserCommandDeleteNotification=1306]="UserCommandDeleteNotification",e[e.UserCommandUpdateNotification=1307]="UserCommandUpdateNotification",e[e.UserNotificationEnd=1399]="UserNotificationEnd",e[e.OANotification=1400]="OANotification",e[e.GroupNotificationBegin=1500]="GroupNotificationBegin",e[e.GroupCreatedNotification=1501]="GroupCreatedNotification",e[e.GroupInfoSetNotification=1502]="GroupInfoSetNotification",e[e.JoinGroupApplicationNotification=1503]="JoinGroupApplicationNotification",e[e.MemberQuitNotification=1504]="MemberQuitNotification",e[e.GroupApplicationAcceptedNotification=1505]="GroupApplicationAcceptedNotification",e[e.GroupApplicationRejectedNotification=1506]="GroupApplicationRejectedNotification",e[e.GroupOwnerTransferredNotification=1507]="GroupOwnerTransferredNotification",e[e.MemberKickedNotification=1508]="MemberKickedNotification",e[e.MemberInvitedNotification=1509]="MemberInvitedNotification",e[e.MemberEnterNotification=1510]="MemberEnterNotification",e[e.GroupDismissedNotification=1511]="GroupDismissedNotification",e[e.GroupMemberMutedNotification=1512]="GroupMemberMutedNotification",e[e.GroupMemberCancelMutedNotification=1513]="GroupMemberCancelMutedNotification",e[e.GroupMutedNotification=1514]="GroupMutedNotification",e[e.GroupCancelMutedNotification=1515]="GroupCancelMutedNotification",e[e.GroupMemberInfoSetNotification=1516]="GroupMemberInfoSetNotification",e[e.GroupMemberSetToAdminNotification=1517]="GroupMemberSetToAdminNotification",e[e.GroupMemberSetToOrdinaryUserNotification=1518]="GroupMemberSetToOrdinaryUserNotification",e[e.GroupInfoSetAnnouncementNotification=1519]="GroupInfoSetAnnouncementNotification",e[e.GroupInfoSetNameNotification=1520]="GroupInfoSetNameNotification",e[e.GroupNotificationEnd=1599]="GroupNotificationEnd",e[e.SignalingNotificationBegin=1600]="SignalingNotificationBegin",e[e.SignalingNotification=1601]="SignalingNotification",e[e.RoomParticipantsConnectedNotification=1602]="RoomParticipantsConnectedNotification",e[e.RoomParticipantsDisconnectedNotification=1603]="RoomParticipantsDisconnectedNotification",e[e.StreamChangedNotification=1604]="StreamChangedNotification",e[e.CustomSignalNotification=1605]="CustomSignalNotification",e[e.SignalingNotificationEnd=1649]="SignalingNotificationEnd",e[e.SuperGroupNotificationBegin=1650]="SuperGroupNotificationBegin",e[e.SuperGroupUpdateNotification=1651]="SuperGroupUpdateNotification",e[e.MsgDeleteNotification=1652]="MsgDeleteNotification",e[e.ReactionMessageModifierNotification=1653]="ReactionMessageModifierNotification",e[e.ReactionMessageDeleteNotification=1654]="ReactionMessageDeleteNotification",e[e.SuperGroupNotificationEnd=1699]="SuperGroupNotificationEnd",e[e.ConversationPrivateChatNotification=1701]="ConversationPrivateChatNotification",e[e.ConversationUnreadNotification=1702]="ConversationUnreadNotification",e[e.ClearConversationNotification=1703]="ClearConversationNotification",e[e.WorkMomentNotificationBegin=1900]="WorkMomentNotificationBegin",e[e.WorkMomentNotification=1901]="WorkMomentNotification",e[e.BusinessNotificationBegin=2e3]="BusinessNotificationBegin",e[e.BusinessNotification=2001]="BusinessNotification",e[e.BusinessNotificationEnd=2099]="BusinessNotificationEnd",e[e.RevokeNotification=2101]="RevokeNotification",e[e.HasReadReceiptNotification=2150]="HasReadReceiptNotification",e[e.GroupHasReadReceiptNotification=2155]="GroupHasReadReceiptNotification",e[e.DeleteMsgsNotification=2102]="DeleteMsgsNotification",e[e.HasReadReceipt=2200]="HasReadReceipt",e[e.HasGroupReadReceipt=2300]="HasGroupReadReceipt",e[e.NotificationEnd=5e3]="NotificationEnd"}(D||(D={})),function(e){e[e.UserMsgType=100]="UserMsgType",e[e.SysMsgType=200]="SysMsgType"}(y||(y={})),function(e){e[e.MsgStatusDefault=0]="MsgStatusDefault",e[e.MsgStatusSending=1]="MsgStatusSending",e[e.MsgStatusSendSuccess=2]="MsgStatusSendSuccess",e[e.MsgStatusSendFailed=3]="MsgStatusSendFailed",e[e.MsgStatusHasDeleted=4]="MsgStatusHasDeleted",e[e.MsgStatusFiltered=5]="MsgStatusFiltered"}(S||(S={})),function(e){e.IsHistory="history",e.IsPersistent="persistent",e.IsUnreadCount="unreadCount",e.IsConversationUpdate="conversationUpdate",e.IsOfflinePush="offlinePush",e.IsSenderSync="senderSync",e.IsNotPrivate="notPrivate",e.IsSenderConversationUpdate="senderConversationUpdate"}(C||(C={})),function(e){e[e.GroupOk=0]="GroupOk",e[e.GroupBanChat=1]="GroupBanChat",e[e.GroupStatusDismissed=2]="GroupStatusDismissed",e[e.GroupStatusMuted=3]="GroupStatusMuted"}(T||(T={})),function(e){e[e.WorkMomentCommentNotification=0]="WorkMomentCommentNotification",e[e.WorkMomentLikeNotification=1]="WorkMomentLikeNotification",e[e.WorkMomentAtUserNotification=2]="WorkMomentAtUserNotification"}(G||(G={})),function(e){e[e.TokenExpiredError=1501]="TokenExpiredError",e[e.TokenInvalidError=1502]="TokenInvalidError",e[e.TokenMalformedError=1503]="TokenMalformedError",e[e.TokenNotValidYetError=1504]="TokenNotValidYetError",e[e.TokenUnknownError=1505]="TokenUnknownError",e[e.TokenKickedError=1506]="TokenKickedError",e[e.TokenNotExistError=1507]="TokenNotExistError"}(b||(b={}));const w={[b.TokenExpiredError]:m.OnUserTokenExpired,[b.TokenInvalidError]:m.OnUserTokenInvalid,[b.TokenMalformedError]:m.OnUserTokenInvalid,[b.TokenNotValidYetError]:m.OnUserTokenInvalid,[b.TokenUnknownError]:m.OnUserTokenInvalid,[b.TokenKickedError]:m.OnKickedOffline,[b.TokenNotExistError]:m.OnUserTokenInvalid};var A,N,R,U,F,O,k,q,E,L,x,P,B,V,_,H,j,J;!function(e){e[e.Nomal=0]="Nomal",e[e.NotReceive=1]="NotReceive",e[e.NotNotify=2]="NotNotify"}(A||(A={})),function(e){e[e.Allowed=0]="Allowed",e[e.NotAllowed=1]="NotAllowed"}(N||(N={})),function(e){e[e.Group=2]="Group",e[e.WorkingGroup=2]="WorkingGroup"}(R||(R={})),function(e){e[e.Invitation=2]="Invitation",e[e.Search=3]="Search",e[e.QrCode=4]="QrCode"}(U||(U={})),function(e){e[e.Nomal=20]="Nomal",e[e.Admin=60]="Admin",e[e.Owner=100]="Owner"}(F||(F={})),function(e){e[e.ApplyNeedInviteNot=0]="ApplyNeedInviteNot",e[e.AllNeed=1]="AllNeed",e[e.AllNot=2]="AllNot"}(O||(O={})),function(e){e[e.Sending=1]="Sending",e[e.Succeed=2]="Succeed",e[e.Failed=3]="Failed"}(k||(k={})),function(e){e[e.iOS=1]="iOS",e[e.Android=2]="Android",e[e.Windows=3]="Windows",e[e.MacOSX=4]="MacOSX",e[e.Web=5]="Web",e[e.Linux=7]="Linux",e[e.AndroidPad=8]="AndroidPad",e[e.iPad=9]="iPad"}(q||(q={})),function(e){e[e.Silent=5]="Silent",e[e.Error=4]="Error",e[e.Warn=3]="Warn",e[e.Info=2]="Info",e[e.Debug=1]="Debug",e[e.Trace=0]="Trace"}(E||(E={})),function(e){e[e.Unprocessed=0]="Unprocessed",e[e.Agree=1]="Agree",e[e.Reject=-1]="Reject"}(L||(L={})),function(e){e[e.TextMessage=101]="TextMessage",e[e.PictureMessage=102]="PictureMessage",e[e.VoiceMessage=103]="VoiceMessage",e[e.VideoMessage=104]="VideoMessage",e[e.FileMessage=105]="FileMessage",e[e.AtTextMessage=106]="AtTextMessage",e[e.MergeMessage=107]="MergeMessage",e[e.CardMessage=108]="CardMessage",e[e.LocationMessage=109]="LocationMessage",e[e.CustomMessage=110]="CustomMessage",e[e.TypingMessage=113]="TypingMessage",e[e.QuoteMessage=114]="QuoteMessage",e[e.FaceMessage=115]="FaceMessage",e[e.FriendAdded=1201]="FriendAdded",e[e.OANotification=1400]="OANotification",e[e.GroupCreated=1501]="GroupCreated",e[e.MemberQuit=1504]="MemberQuit",e[e.GroupOwnerTransferred=1507]="GroupOwnerTransferred",e[e.MemberKicked=1508]="MemberKicked",e[e.MemberInvited=1509]="MemberInvited",e[e.MemberEnter=1510]="MemberEnter",e[e.GroupDismissed=1511]="GroupDismissed",e[e.GroupMemberMuted=1512]="GroupMemberMuted",e[e.GroupMemberCancelMuted=1513]="GroupMemberCancelMuted",e[e.GroupMuted=1514]="GroupMuted",e[e.GroupCancelMuted=1515]="GroupCancelMuted",e[e.GroupAnnouncementUpdated=1519]="GroupAnnouncementUpdated",e[e.GroupNameUpdated=1520]="GroupNameUpdated",e[e.BurnMessageChange=1701]="BurnMessageChange",e[e.RevokeMessage=2101]="RevokeMessage"}(x||(x={})),function(e){e[e.Single=1]="Single",e[e.Group=3]="Group",e[e.Notification=4]="Notification"}(P||(P={})),function(e){e[e.Nomal=0]="Nomal",e[e.Baned=1]="Baned",e[e.Dismissed=2]="Dismissed",e[e.Muted=3]="Muted"}(T||(T={})),function(e){e[e.AtNormal=0]="AtNormal",e[e.AtMe=1]="AtMe",e[e.AtAll=2]="AtAll",e[e.AtAllAtMe=3]="AtAllAtMe",e[e.AtGroupNotice=4]="AtGroupNotice"}(B||(B={})),function(e){e[e.All=0]="All",e[e.Owner=1]="Owner",e[e.Admin=2]="Admin",e[e.Nomal=3]="Nomal",e[e.AdminAndNomal=4]="AdminAndNomal",e[e.AdminAndOwner=5]="AdminAndOwner"}(V||(V={})),function(e){e[e.isBlack=0]="isBlack",e[e.isFriend=1]="isFriend"}(_||(_={})),function(e){e[e.Logout=1]="Logout",e[e.Logging=2]="Logging",e[e.Logged=3]="Logged"}(H||(H={})),function(e){e[e.Online=1]="Online",e[e.Offline=0]="Offline"}(j||(j={})),function(e){e[e.ViewHistory=0]="ViewHistory",e[e.ViewSearch=1]="ViewSearch"}(J||(J={}));const W=()=>(36*Math.random()).toString(36).slice(2)+(new Date).getTime().toString(),$=e=>{const n=(new Date).getTime().toString(),s=Math.floor(Math.random()*(new Date).getTime());return t.hash(n+e+s)},Q=e=>{if(e.sessionType===P.Single){const t=[e.sendID,e.recvID].sort();return`si_${t[0]}_${t[1]}`}return e.sessionType===P.Group?`sg_${e.groupID}`:e.sessionType===P.Notification?`sn_${e.sendID}_${e.recvID}`:""},K=e=>{if(e.sessionType===P.Single){const t=[e.sourceID,e.userID].sort();return`si_${t[0]}_${t[1]}`}return e.sessionType===P.Group?`sg_${e.sourceID}`:e.sessionType===P.Notification?`sn_${e.sourceID}_${e.userID}`:""},z=(e,t)=>!(t in e&&!e[t]),Y={[I.GetNewestSeq]:i.GetMaxSeqResp.decode,[I.PullMsgByRange]:i.PullMessageBySeqsResp.decode,[I.SendMsg]:i.UserSendMsgResp.decode,[I.PullMsgBySeqList]:i.GetSeqMessageResp.decode,[I.PushMsg]:i.PushMessages.decode,[I.SetBackgroundStatus]:i.SetAppBackgroundStatusResp.decode,[I.WsSubUserOnlineStatus]:i.SubUserOnlineStatusTips.decode,[I.GetConvMaxReadSeq]:i.GetConversationsHasReadAndMaxSeqResp.decode,[h.GetActiveConversations]:i.GetActiveConversationsResp.decode,[h.GetDesignatedConversation]:i.GetConversationsResp.decode},X=(e,t)=>{if(!e)return null;const s=n(e),i=Y[t];return i?i(new Uint8Array(s)):null},Z=(e,t,n)=>{const s=(new Date).getTime(),i=e.userTrigger.cache.getSelfUserInfo();return{clientMsgID:$(e.userID),createTime:s,sendTime:s,sessionType:0,sendID:e.userID,msgFrom:t,contentType:n,senderPlatformID:e.platform,senderNickname:null==i?void 0:i.nickname,senderFaceUrl:null==i?void 0:i.faceURL,seq:0,isRead:!1,status:k.Sending}};class ee extends Error{constructor(e,t){super(t),this.errCode=void 0,this.name=this.constructor.name,this.errCode=e,Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)}}const te=(e,t,n,s)=>{const i={event:t,operationID:n,data:null,errMsg:"",errCode:0};return e===H.Logout?Promise.reject(d({},i,{errCode:v.ResourceLoadNotCompleteError,errMsg:"Resource load not complete"})):s().then((e=null)=>d({},i,{data:e})).catch(e=>d({},i,{errCode:e.errCode||v.SdkInternalError,errMsg:e.message||"Internal Error"}))},ne="UTF-8",se="ASCII",ie=ne,re=65533,oe=function e(t,n){if(t<128)n.push(t);else{const s=[127,2047,65535,2097151];let i=0;for(;;){if(i++,i===s.length)return console.error("UTF-8 Write - attempted to encode illegally high code point - "+t),void e(re,n);if(t<=s[i]){i+=1;let e,s=0;for(e=0;e<i;e++)s<<=1,s|=1;for(s<<=8-i,s|=t>>6*(i-1),n.push(s),e=1;e<i;e++)s=128,s|=t>>6*(i-(e+1))&191,n.push(s);return}}}},ae=function(e,t,n,s){const i=t.getUint8(n);if(e.bytesRead=1,e.charVal=0,128&i){let r=0,o=i;for(;128&o;)r++,o<<=1;if(1===r)return console.error("UTF-8 read - found continuation byte at beginning of character"),void(e.charVal=re);if(r>s)return console.error("UTF-8 read - attempted to read "+r+" byte character, "+(s-r)+" bytes past end of buffer"),void(e.charVal=re);e.charVal=i&255>>r+1;for(let s=1;s<r;s++){if(o=t.getUint8(n+s),128!=(192&o))return console.error("UTF-8 read - attempted to read "+r+" byte character, found non-continuation at byte "+s),e.charVal=re,void(e.bytesRead=1);if(e.charVal<<=6,e.charVal|=63&o,!(1!==s||e.charVal>>8-(r+1)-1))return console.error("UTF-8 read - found overlong encoding"),e.charVal=re,void(e.bytesRead=1);e.bytesRead++}if(e.charVal>1114111)return console.error("UTF-8 read - found illegally high code point "+e.charVal),e.charVal=re,void(e.bytesRead=1)}else e.charVal=i},ce=function(e){const t=[];for(let n=0;n<e.length;n++)oe(e.charCodeAt(n),t);return t},de=function(e){const t=[];for(let n=0;n<e.length;n++){let s=e.charCodeAt(n);s>255&&(s="?".charCodeAt(0)),t.push(s)}return t},ue=function(e,t,n,s){const i=void 0===n;let r=t||0;if(!i&&r+n>e.byteLength)throw new Error("Attempted to read "+(r+n-e.byteLength)+" bytes past end of buffer");const o=[],a={};for(;r<e.byteLength&&(i||n>r-t)&&(ae(a,e,r,i?e.byteLength-(r+t):n-(r-t)),r+=a.bytesRead,!i||a.charVal!==s);)o.push(String.fromCharCode(a.charVal));return{str:o.join(""),byteLength:r-t}},ge=function(e,t,n,s){const i=[];let r=0;t=t||0;let o=!1;void 0===n&&(o=!0,n=e.byteLength-e.byteOffset);for(let a=0;a<n;a++){const n=e.getUint8(a+t);if(r++,o&&n===s)break;i.push(String.fromCharCode(n))}return{str:i.join(""),byteLength:r}};var pe=/*#__PURE__*/c("readString"),le=/*#__PURE__*/c("writeString"),he=/*#__PURE__*/c("checkEncoding");function fe(e){if(void 0===e&&(e=ie),!o(this,le)[le].has(e))throw new Error("Unknown string encoding '"+e+"'");return e}var me=new class{constructor(){Object.defineProperty(this,he,{value:fe}),Object.defineProperty(this,pe,{writable:!0,value:new Map([[se,ge],[ne,ue]])}),Object.defineProperty(this,le,{writable:!0,value:new Map([[se,de],[ne,ce]])})}addStringCodec(e,t,n){o(this,pe)[pe].put(e,t),o(this,le)[le].put(e,n)}stringByteLength(e,t){return t=o(this,he)[he](t),o(this,le)[le].get(t)(e).length}getString(e,t,n,s){return this.getStringData(e,t,n,s).str}getStringData(e,t,n,s){return s=o(this,he)[he](s),n||(n=e.byteLength-t),o(this,pe)[pe].get(s)(e,t,n)}getStringNT(e,t,n,s=0){return this.getStringDataNT(e,t,n,s).str}getStringDataNT(e,t,n,s=0){return n=o(this,he)[he](n),o(this,pe)[pe].get(n)(e,t,void 0,s)}setString(e,t,n,s){s=o(this,he)[he](s);const i=o(this,le)[le].get(s)(n);let r;for(r=0;r<i.length&&t+r<e.byteLength;r++)e.setUint8(t+r,i[r]);return r}setStringNT(e,t,n,s){let i=this.setString(e,t,n,s);return t+i>=e.byteLength&&(i-=1),e.setUint8(t+i,0),i+1}};const ve=e=>(new TextDecoder).decode(e),Ie=e=>(new TextEncoder).encode(e);var Me;!function(e){e[e.CONNECTING=0]="CONNECTING",e[e.OPEN=1]="OPEN",e[e.CLOSING=2]="CLOSING",e[e.CLOSED=3]="CLOSED"}(Me||(Me={}));class De{constructor(e,t,n,s,i,r,o,a=5e3,c=Infinity,u){var g=this;this.url=void 0,this.onMessage=void 0,this.onClose=void 0,this.onReconnecting=void 0,this.onReconnectFailed=void 0,this.onReconnectSuccess=void 0,this.reconnectInterval=void 0,this.maxReconnectAttempts=void 0,this.ws=void 0,this.connectParams=void 0,this.reconnectAttempts=void 0,this.shouldReconnect=void 0,this.isProcessingMessage=!1,this.consecutiveHeartbeatFailures=0,this.connectTimeoutId=null,this.platformNamespace=void 0,this.envListenersInstalled=!1,this.heartbeatConfig={interval:1e4,timeout:5e3,maxFailures:3},this.heartbeatWorker=null,this.legacyTimer=null,this.heartbeatTimeoutId=null,this.workerUrl=null,this.lastPongAt=0,this.forceImmediateReconnect=!1,this.checkPlatform=()=>{if("undefined"!=typeof WebSocket)try{if("undefined"!=typeof window&&window.WebSocket)return"web";if("undefined"!=typeof global&&global.WebSocket)return"web"}catch(e){}return"undefined"!=typeof my&&"function"==typeof my.connectSocket?"my":"undefined"!=typeof uni&&"function"==typeof uni.connectSocket?"uni":"undefined"!=typeof wx&&"function"==typeof wx.connectSocket?"wx":"unknow"},this.urlFormat=()=>{let e="?";for(const[t,n]of Object.entries(this.connectParams))e+=`${t}=${n}&`;return this.url+e.slice(0,-1)},this.startHeartbeat=()=>{if(this.heartbeatWorker&&this.stopHeartbeat(),this.consecutiveHeartbeatFailures=0,"undefined"!=typeof Worker){const e="\n let timerId = null;\n let heartbeatInterval;\n\n self.onmessage = (e) => {\n if (e.data.type === 'start') {\n heartbeatInterval = e.data.interval;\n if (timerId) return;\n \n timerId = self.setInterval(() => {\n self.postMessage({ type: 'ping' });\n }, heartbeatInterval);\n } else if (e.data.type === 'stop') {\n if (timerId) {\n self.clearInterval(timerId);\n timerId = null;\n }\n }\n };\n ";try{const t=new Blob([e],{type:"application/javascript"});this.workerUrl=URL.createObjectURL(t),this.heartbeatWorker=new Worker(this.workerUrl),this.heartbeatWorker.onmessage=e=>{"ping"===e.data.type&&this.sendPing()},this.heartbeatWorker.postMessage({type:"start",interval:this.heartbeatConfig.interval})}catch(e){this.heartbeatWorker=null,this.workerUrl&&(URL.revokeObjectURL(this.workerUrl),this.workerUrl=null),this.legacyTimer=setInterval(()=>{this.sendPing()},this.heartbeatConfig.interval)}}else this.legacyTimer=setInterval(()=>{this.sendPing()},this.heartbeatConfig.interval)},this.connect=(e=1e4)=>"unknow"===this.platformNamespace?Promise.reject(new Error("WebSocket is not supported")):new Promise((t,n)=>{if(this.connectTimeoutId&&(clearTimeout(this.connectTimeoutId),this.connectTimeoutId=null),this.connectTimeoutId=setTimeout(()=>{this.ws&&(this.ws.close(),this.onClose()),n(new Error(`Connection timeout after ${e}ms`))},e),this.ws&&this.ws.readyState!==Me.CLOSED)this.ws.readyState===this.ws.OPEN?(this.connectTimeoutId&&(clearTimeout(this.connectTimeoutId),this.connectTimeoutId=null),t()):(this.connectTimeoutId&&(clearTimeout(this.connectTimeoutId),this.connectTimeoutId=null),n(new Error("WebSocket is in an unknown state")));else{const e=()=>{this.connectTimeoutId&&(clearTimeout(this.connectTimeoutId),this.connectTimeoutId=null),this.reconnectAttempts&&this.onReconnectSuccess(),this.reconnectAttempts=0,this.consecutiveHeartbeatFailures=0,this.lastPongAt=Date.now(),this.startHeartbeat(),t()},s=e=>{this.connectTimeoutId&&(clearTimeout(this.connectTimeoutId),this.connectTimeoutId=null),n(e)};if("web"===this.platformNamespace)this.ws=new WebSocket(this.urlFormat()),this.ws.onopen=e,this.ws.onerror=s;else{const t={url:this.urlFormat(),complete:()=>{}};"my"===this.platformNamespace&&(t.multiple=!0),"uni"===this.platformNamespace&&(this.ws=uni.connectSocket(t)),"wx"===this.platformNamespace&&(this.ws=wx.connectSocket(t)),"my"===this.platformNamespace&&(this.ws=my.connectSocket(t)),this.ws.onOpen(e),this.ws.onError(s)}this.setupEventListeners(),this.installEnvListeners()}}),this.setupEventListeners=()=>{if(!this.ws)return;const e=e=>this.onBinaryMessage(e.data),t=e=>{if(this.shouldReconnect&&this.reconnectAttempts<this.maxReconnectAttempts){if(this.isProcessingMessage)return void setTimeout(()=>t(),100);const e=()=>{this.onReconnecting(),this.connectParams.operationID=W(),this.connect().catch(()=>{this.onReconnectFailed()}),this.reconnectAttempts++};if(this.forceImmediateReconnect)this.forceImmediateReconnect=!1,e();else{const t=Math.min(this.reconnectInterval*Math.pow(1.5,this.reconnectAttempts),6e4),n=.25*t*(2*Math.random()-1),s=Math.max(t+n,1e3);setTimeout(()=>{e()},s)}}this.stopHeartbeat(),this.heartbeatTimeoutId&&(clearTimeout(this.heartbeatTimeoutId),this.heartbeatTimeoutId=null),this.connectTimeoutId&&(clearTimeout(this.connectTimeoutId),this.connectTimeoutId=null)};"web"===this.platformNamespace?(this.ws.onmessage=e,this.ws.onclose=t):(this.ws.onMessage(e),this.ws.onClose(t))},this.onBinaryMessage=async function(e){if("string"!=typeof e&&"my"===g.platformNamespace&&(e=e.data),"string"==typeof e&&"pong"===JSON.parse(e).type)return g.heartbeatTimeoutId&&(clearTimeout(g.heartbeatTimeoutId),g.heartbeatTimeoutId=null),g.consecutiveHeartbeatFailures=0,void(g.lastPongAt=Date.now());g.isProcessingMessage=!0,await g.onMessage(e,g.connectParams.operationID),g.isProcessingMessage=!1},this.sendPing=()=>{var e;if((null==(e=this.ws)?void 0:e.readyState)===Me.OPEN){if(this.consecutiveHeartbeatFailures>=this.heartbeatConfig.maxFailures)return console.warn(`Heartbeat failed ${this.consecutiveHeartbeatFailures} times, closing connection`),this.ws.close(),this.onClose(),void this.stopHeartbeat();this.heartbeatTimeoutId&&clearTimeout(this.heartbeatTimeoutId),this.heartbeatTimeoutId=setTimeout(()=>{var e;this.consecutiveHeartbeatFailures++,console.warn(`Heartbeat timeout, consecutive failures: ${this.consecutiveHeartbeatFailures}`),this.consecutiveHeartbeatFailures>=this.heartbeatConfig.maxFailures&&(null==(e=this.ws)||e.close(),this.onClose(),this.stopHeartbeat())},this.heartbeatConfig.timeout);const e=JSON.stringify({type:"ping"});this.ws.send("web"===this.platformNamespace?e:{data:e})}else this.heartbeatTimeoutId&&(clearTimeout(this.heartbeatTimeoutId),this.heartbeatTimeoutId=null)},this.forceHealthCheck=(e=!1)=>{this.ws&&this.ws.readyState===Me.OPEN&&(e&&(this.consecutiveHeartbeatFailures=Math.max(this.heartbeatConfig.maxFailures-1,0)),this.sendPing())},this.handleVisibilityChange=()=>{try{"visible"===("undefined"!=typeof document?document.visibilityState:"visible")&&this.forceHealthCheck(!0)}catch(e){}},this.handleOnline=()=>{if(!this.ws||this.ws.readyState!==Me.OPEN)return this.reconnectAttempts=0,this.onReconnecting(),this.connectParams.operationID=W(),void this.connect().catch(()=>{this.onReconnectFailed()});const e=Date.now();this.lastPongAt&&e-this.lastPongAt>this.heartbeatConfig.interval+this.heartbeatConfig.timeout*this.heartbeatConfig.maxFailures&&this.forceHealthCheck(!0)},this.handleOffline=()=>{this.stopHeartbeat()},this.installEnvListeners=()=>{if(!this.envListenersInstalled&&"web"===this.platformNamespace)try{"undefined"!=typeof document&&document.addEventListener&&document.addEventListener("visibilitychange",this.handleVisibilityChange),"undefined"!=typeof window&&window.addEventListener&&(window.addEventListener("online",this.handleOnline),window.addEventListener("offline",this.handleOffline),window.addEventListener("pageshow",this.handleVisibilityChange),window.addEventListener("focus",this.handleVisibilityChange)),this.envListenersInstalled=!0}catch(e){}},this.removeEnvListeners=()=>{if(this.envListenersInstalled&&"web"===this.platformNamespace){try{"undefined"!=typeof document&&document.removeEventListener&&document.removeEventListener("visibilitychange",this.handleVisibilityChange),"undefined"!=typeof window&&window.removeEventListener&&(window.removeEventListener("online",this.handleOnline),window.removeEventListener("offline",this.handleOffline),window.removeEventListener("pageshow",this.handleVisibilityChange),window.removeEventListener("focus",this.handleVisibilityChange))}catch(e){}this.envListenersInstalled=!1}},this.sendMessage=e=>{var t;const n=Ie(JSON.stringify(e));(null==(t=this.ws)?void 0:t.readyState)===Me.OPEN?this.ws.send("web"===this.platformNamespace?n:{data:Uint8Array.from(n).buffer}):console.error("WebSocket is not open. Message not sent.")},this.close=()=>{var e;this.shouldReconnect=!1,this.connectTimeoutId&&(clearTimeout(this.connectTimeoutId),this.connectTimeoutId=null),this.heartbeatTimeoutId&&(clearTimeout(this.heartbeatTimeoutId),this.heartbeatTimeoutId=null),(null==(e=this.ws)?void 0:e.readyState)===Me.OPEN&&(this.ws.close(),this.onClose()),this.stopHeartbeat(),this.removeEnvListeners()},this.forceReconnect=(e=!0)=>{if(this.shouldReconnect=!0,this.reconnectAttempts=0,this.consecutiveHeartbeatFailures=0,e&&(this.forceImmediateReconnect=!0),!this.ws||this.ws.readyState===Me.CLOSED)return this.onReconnecting(),this.connectParams.operationID=W(),void this.connect().catch(()=>{this.onReconnectFailed()});this.stopHeartbeat();try{this.ws.close()}catch(e){this.onReconnecting(),this.connectParams.operationID=W(),this.connect().catch(()=>{this.onReconnectFailed()})}},this.reset=()=>{this.shouldReconnect=!0,this.reconnectAttempts=0,this.consecutiveHeartbeatFailures=0,this.connectTimeoutId&&(clearTimeout(this.connectTimeoutId),this.connectTimeoutId=null),this.heartbeatTimeoutId&&(clearTimeout(this.heartbeatTimeoutId),this.heartbeatTimeoutId=null),this.stopHeartbeat(),this.removeEnvListeners()},this.url=e,this.onMessage=n,this.onClose=s,this.onReconnecting=i,this.onReconnectFailed=r,this.onReconnectSuccess=o,this.reconnectInterval=a,this.maxReconnectAttempts=c,this.connectParams=t,this.reconnectInterval=a,this.maxReconnectAttempts=c,this.reconnectAttempts=0,this.shouldReconnect=!0,this.platformNamespace=this.checkPlatform(),u&&(this.heartbeatConfig=d({},this.heartbeatConfig,u))}stopHeartbeat(){this.heartbeatTimeoutId&&(clearTimeout(this.heartbeatTimeoutId),this.heartbeatTimeoutId=null),this.heartbeatWorker&&(this.heartbeatWorker.postMessage({type:"stop"}),this.heartbeatWorker.terminate(),this.workerUrl&&(URL.revokeObjectURL(this.workerUrl),this.workerUrl=null),this.heartbeatWorker=null),this.legacyTimer&&(clearInterval(this.legacyTimer),this.legacyTimer=null)}}class ye{constructor(){this.events=void 0,this.events={}}emit(e,t){return this.events[e]&&this.events[e].forEach(e=>e(t)),this}on(e,t){return this.events[e]?this.events[e].push(t):this.events[e]=[t],this}off(e,t){if(e&&"function"==typeof t&&this.events[e]){const n=this.events[e];if(!n||0===n.length)return;const s=n.findIndex(e=>e===t);-1!==s&&n.splice(s,1)}return this}}const Se=["friendUser"],Ce=["blackUserInfo"],Te=e=>{var t,n,s,i,r,o,a,c,d,u,g,p,l,h;return{createTime:null==(t=e.groupInfo)?void 0:t.createTime,creatorUserID:null==(n=e.groupInfo)?void 0:n.creatorUserID,ex:e.ex,groupFaceURL:null==(s=e.groupInfo)?void 0:s.faceURL,groupID:null==(i=e.groupInfo)?void 0:i.groupID,groupName:null==(r=e.groupInfo)?void 0:r.groupName,groupType:null==(o=e.groupInfo)?void 0:o.groupType,handleResult:e.handleResult,handleUserID:e.handleUserID,handledMsg:e.handleMsg,handledTime:e.handleTime,introduction:null==(a=e.groupInfo)?void 0:a.introduction,memberCount:null==(c=e.groupInfo)?void 0:c.memberCount,nickname:null==(d=e.userInfo)?void 0:d.nickname,notification:null==(u=e.groupInfo)?void 0:u.notification,ownerUserID:null==(g=e.groupInfo)?void 0:g.ownerUserID,reqMsg:e.reqMsg,reqTime:e.reqTime,joinSource:e.joinSource,status:null==(p=e.groupInfo)?void 0:p.status,userFaceURL:null==(l=e.userInfo)?void 0:l.faceURL,userID:null==(h=e.userInfo)?void 0:h.userID}},Ge=e=>({clientMsgID:e.clientMsgID,serverMsgID:e.serverMsgID,createTime:e.createTime,sendTime:e.sendTime,sessionType:e.sessionType,sendID:e.sendID,recvID:e.recvID,msgFrom:e.msgFrom,contentType:e.contentType,senderPlatformID:e.senderPlatformID,senderNickname:e.senderNickname,senderFaceUrl:e.senderFaceURL,groupID:e.groupID,content:e.content.length?ve(e.content):"",seq:e.seq,isRead:e.isRead,status:S.MsgStatusSendSuccess,isExternalExtensions:!1,offlinePush:e.offlinePushInfo,attachedInfo:e.attachedInfo,ex:e.ex,localEx:""}),be=t=>{const n=d({},t);try{switch(t.contentType){case M.Text:n.textElem=JSON.parse(n.content);break;case M.Picture:n.pictureElem=JSON.parse(n.content);break;case M.Sound:n.soundElem=JSON.parse(n.content);break;case M.Video:n.videoElem=JSON.parse(n.content);break;case M.File:n.fileElem=JSON.parse(n.content);break;case M.AtText:n.atTextElem=JSON.parse(n.content);break;case M.Location:n.locationElem=JSON.parse(n.content);break;case M.Custom:case M.CustomMsgNotTriggerConversation:case M.CustomMsgOnlineOnly:n.customElem=JSON.parse(n.content);break;case M.Typing:n.typingElem=JSON.parse(n.content);break;case M.Merger:n.mergeElem=JSON.parse(n.content);break;case M.Face:n.faceElem=JSON.parse(n.content);break;case M.Quote:n.quoteElem=JSON.parse(n.content);break;case M.Card:n.cardElem=JSON.parse(n.content);break;default:n.notificationElem=JSON.parse(n.content)}}catch(t){e.warn("messageElemFormater messageElem parse failed",n)}if(t.attachedInfo)try{n.attachedInfoElem=JSON.parse(n.attachedInfo),n.attachedInfo=""}catch(t){e.warn("messageElemFormater attachedInfoElem failed",n.attachedInfo)}return n.content="",n},we=e=>{const t=ve(e),n=JSON.parse(t);return JSON.parse(n.detail)},Ae=async({conversation:e,group:t,friend:n,user:s,lastMsg:i,maxSeq:r,readSeq:o},a,c)=>{var d,u;let g,p="",l=i?JSON.stringify(be(Ge(i))):"";var h,f,m;if((null==e?void 0:e.conversationType)===P.Group?(g=null!=(h=null==t?void 0:t.groupName)?h:"",p=null!=(f=null==t?void 0:t.faceURL)?f:""):(g=(null==n?void 0:n.remark)||(null==s?void 0:s.nickname)||"",p=null!=(m=null==s?void 0:s.faceURL)?m:""),(null==i?void 0:i.status)===S.MsgStatusHasDeleted){const t=await a({conversationID:null==e?void 0:e.conversationID,seq:i.seq,operationID:W()});t&&(l=JSON.stringify(be(t)))}return{conversationID:e.conversationID,conversationType:e.conversationType,userID:e.userID,groupID:e.groupID,showName:g,faceURL:p,recvMsgOpt:e.recvMsgOpt,unreadCount:r-o,groupAtType:e.groupAtType,latestMsg:l,latestMsgSendTime:null!=(d=null!=(u=null==i?void 0:i.sendTime)?u:c)?d:0,draftText:"",draftTextTime:0,burnDuration:e.burnDuration,msgDestructTime:e.msgDestructTime,isPinned:e.isPinned,isPrivateChat:e.isPrivateChat,isMsgDestruct:e.isMsgDestruct,attachedInfo:e.attachedInfo,ex:e.ex}},Ne=e=>{let{friendUser:t}=e;return d({},u(e,Se),{userID:t.userID,nickname:t.nickname,faceURL:t.faceURL,attachedInfo:""})},Re=e=>{let{blackUserInfo:t}=e;return d({},u(e,Ce),{userID:t.userID,nickname:t.nickname,faceURL:t.faceURL})};class Ue{constructor(e){this.store=void 0,this.options=void 0,this.expiryListeners=[],this.cleanupTimer=void 0,this.options=e,this.store=new Map,this.options.cleanupInterval>0&&(this.cleanupTimer=setInterval(()=>{this.deleteExpired()},this.options.cleanupInterval))}onExpiry(e){this.expiryListeners.push(e)}triggerExpiry(e,t){this.expiryListeners.forEach(n=>n(e,t)),this.delete(e)}set(e,t){this.delete(e);const n=Date.now();let s=null;this.options.ttl>0&&(s=setTimeout(()=>{clearTimeout(s),this.triggerExpiry(e,t)},this.options.ttl)),this.store.set(e,{value:t,timer:s,created:n})}get(e){const t=this.store.get(e);if(t&&Date.now()-t.created<this.options.ttl)return t.value}delete(e){const t=this.store.get(e);return!!t&&(t.timer&&clearTimeout(t.timer),this.store.delete(e),!0)}clear(){this.store.forEach((e,t)=>{e.timer&&clearTimeout(e.timer)}),this.store.clear()}deleteExpired(){const e=Date.now();this.store.forEach((t,n)=>{t.created+this.options.ttl<=e&&this.triggerExpiry(n,t.value)})}dispose(){this.cleanupTimer&&clearInterval(this.cleanupTimer),this.clear()}}const Fe=15e3;var Oe;!function(e){e.Success="stateCodeSuccess",e.End="stateCodeEnd"}(Oe||(Oe={}));class ke{constructor(e){var t=this;this.ctx=void 0,this.send=void 0,this.state=void 0,this.platformIDs=[],this.platformIDSet=new Map,this.reset=()=>{this.send.clear(),this.state.clear()},this.changeInputStates=async function({conversationID:e,focus:n,operationID:s}){const r=await t.ctx.messageTrigger.getOneConversationAndTryChange(e,s);if(!r)throw new Error("conversation not exist");if(n){if(t.send.get(e)===Oe.Success)return;t.send.set(e,Oe.Success)}else{if(!t.send.get(e))return;if(t.send.get(e)===Oe.End)return;t.send.set(e,Oe.End)}const o=Z(t.ctx,y.UserMsgType,x.TypingMessage);o.recvID=r.userID,o.groupID=r.groupID,o.sessionType=r.conversationType,o.content=JSON.stringify({msgTips:n?"yes":"no"});const a={};Object.values(C).forEach(e=>a[e]=!1);const c=i.MsgData.encode(d({},o,{content:Ie(o.content),senderFaceURL:o.senderFaceUrl,options:a,offlinePushInfo:void 0,atUserIDList:[],keyVersion:0,dstUserIDs:[]})).finish();await t.ctx.sendReqWaitResp({data:c,operationID:s,reqIdentifier:I.SendMsg})},this.onNewMessage=async function(e){const n=e.typingElem;if(e.sendID===t.ctx.userID)return;if(!t.platformIDSet.has(e.senderPlatformID))return;const s=Date.now()+10,i=K({sourceID:e.groupID||e.sendID,sessionType:e.sessionType,userID:t.ctx.userID}),r=JSON.stringify({conversationID:i,platformID:e.senderPlatformID,userID:e.sendID});"yes"===(null==n?void 0:n.msgTips)?(t.state.get(r)||setTimeout(()=>t.triggerChange(i,e.sendID)),t.state.set(r,s)):t.triggerChange(i,e.sendID)},this.triggerChange=(e,t)=>{this.ctx.triggerEvent({event:m.OnConversationUserInputStatusChanged,data:{conversationID:e,userID:t,platformIDs:this.getInputStates(e,t)}})},this.getInputStates=(e,t)=>{const n=[];return this.platformIDs.forEach(s=>{const i=JSON.stringify({conversationID:e,platformID:s,userID:t});this.state.get(i)&&n.push(s)}),n},this.ctx=e,this.send=new Ue({ttl:1e4,cleanupInterval:Fe}),this.state=new Ue({ttl:Fe,cleanupInterval:Fe}),[1,2,3,4,5,7,8,9].forEach(e=>{this.platformIDSet.set(e),this.platformIDs.push(e)}),this.platformIDs.sort((e,t)=>e-t),this.state.onExpiry(e=>{const{conversationID:t,userID:n}=JSON.parse(e);this.triggerChange(t,n)})}}class qe{constructor(t){var n=this;this.instance=void 0,this.totalUnreadCount=0,this.cachedNotNotifyConversationIDs=new Set,this.cachedConversations=new Map,this.cachedMessages=new Map,this.cachedFilterMessageSeqs=new