"use strict";(self["webpackChunkblivechat"]=self["webpackChunkblivechat"]||[]).push([[950],{7950:function(e,t,a){a.r(t),a.d(t,{default:function(){return n}});a(7658);var r=a(7389),o=a(8697),i=a(8310),s=a(7664);class n extends s.ZP{constructor(e){super(),this.CMD_CALLBACK_MAP=l,this.roomId=e,this.roomOwnerUid=-1,this.hostServerList=[{host:"broadcastlv.chat.bilibili.com",port:2243,wss_port:443,ws_port:2244}],this.hostServerToken=null,this.buvid=""}async initRoom(){let e;try{e=(await r.x1.get("/api/room_info",{params:{roomId:this.roomId}})).data}catch{return!0}return this.roomId=e.roomId,this.roomOwnerUid=e.ownerUid,0!==e.hostServerList.length&&(this.hostServerList=e.hostServerList),this.hostServerToken=e.hostServerToken,this.buvid=e.buvid,!0}async onBeforeWsConnect(){let e=Math.max(3,(this.hostServerList||[]).length);return this.retryCount>0&&this.retryCount%e===0&&(this.needInitRoom=!0),super.onBeforeWsConnect()}getWsUrl(){let e=this.hostServerList[this.retryCount%this.hostServerList.length];return`wss://${e.host}:${e.wss_port}/sub`}sendAuth(){let e={uid:0,roomid:this.roomId,protover:3,platform:"web",type:2,buvid:this.buvid};null!==this.hostServerToken&&(e.key=this.hostServerToken),this.websocket.send(this.makePacket(e,s.SS))}async danmuMsgMirrorCallback(e){e._isMirror=!0,this.danmuMsgCallback(e)}async danmuMsgCallback(e){let t,a,r,s=e.info,n=s[0][15],l=n?.user?.base?.face??"";l||(l=await o.E$(u,g)),s[3]?(t=s[3][3],a=s[3][0],r=s[3][1]):(t=a=0,r="");let d,m,u=s[2][0],h=s[2][2],c=s[7];d=u===this.roomOwnerUid?3:h?2:0!==c?1:0;try{m=n.extra,"object"!==typeof m&&(m=JSON.parse(m))}catch{m={}}let p=s[1],_=m.reply_uname??"",f=p;""!==_&&(f=`@${_} ${f}`);let g=s[2][1],v=new i.rf({avatarUrl:l,timestamp:s[0][4]/1e3,authorName:g,authorType:d,content:f,privilegeType:c,isGiftDanmaku:Boolean(s[0][9])||o.e0(p),authorLevel:s[4][0],isNewbie:s[2][5]<1e4,isMobileVerified:Boolean(s[2][6]),medalLevel:t===this.roomId?a:0,emoticon:s[0][13].url||null,isMirror:Boolean(e._isMirror),uid:s[2][0]?s[2][0].toString():g,medalName:t===this.roomId?r:""});this.msgHandler.onAddText(v)}sendGiftCallback(e){let t,a,r,s=e.data,n="gold"===s.coin_type;s.medal_info?(t=s.medal_info.target_id,a=s.medal_info.medal_level,r=s.medal_info.medal_name):(t=a=0,r=""),s=new i.He({avatarUrl:o.cS(s.face),timestamp:s.timestamp,authorName:s.uname,totalCoin:n?s.total_coin:0,totalFreeCoin:n?0:s.total_coin,giftName:s.giftName,num:s.num,giftId:s.giftId,giftIconUrl:s.gift_info.img_basic,uid:s.uid?s.uid.toString():s.uname,privilegeType:s.guard_level,medalLevel:t===this.roomOwnerUid?a:0,medalName:t===this.roomOwnerUid?r:""}),this.msgHandler.onAddGift(s)}async userToastV2Callback(e){let t=e.data;if(2==t.option.source)return;let{sender_uinfo:{uid:a,base:{name:r}},guard_info:{start_time:s,guard_level:n},pay_info:{num:l,unit:d,price:m}}=t;t=new i.DZ({avatarUrl:await o.E$(a,r),timestamp:s,authorName:r,privilegeType:n,num:l,unit:d,total_coin:m*l,uid:a?a.toString():r,medalLevel:0,medalName:""}),this.msgHandler.onAddMember(t)}superChatMessageCallback(e){let t,a,r,s=e.data;s.medal_info?(t=s.medal_info.anchor_roomid,a=s.medal_info.medal_level,r=s.medal_info.medal_name):(t=a=0,r=""),s=new i._R({id:s.id.toString(),avatarUrl:o.cS(s.user_info.face),timestamp:s.start_time,authorName:s.user_info.uname,price:s.price,content:s.message,uid:s.uid?s.uid.toString():s.user_info.uname,privilegeType:s.user_info.guard_level,medalLevel:t===this.roomId?a:0,medalName:t===this.roomId?r:""}),this.msgHandler.onAddSuperChat(s)}superChatMessageDeleteCallback(e){let t=[];for(let r of e.data.ids)t.push(r.toString());let a=new i.EP({ids:t});this.msgHandler.onDelSuperChat(a)}}const l={DANMU_MSG:n.prototype.danmuMsgCallback,DANMU_MSG_MIRROR:n.prototype.danmuMsgMirrorCallback,SEND_GIFT:n.prototype.sendGiftCallback,USER_TOAST_MSG_V2:n.prototype.userToastV2Callback,SUPER_CHAT_MESSAGE:n.prototype.superChatMessageCallback,SUPER_CHAT_MESSAGE_DELETE:n.prototype.superChatMessageDeleteCallback}}}]);
//# sourceMappingURL=950.836ff3ea.js.map