UNPKG

@bddh/starling-realtime-client

Version:

2 lines (1 loc) 23.6 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var _rollupPluginBabelHelpers=require("./_virtual/_rollupPluginBabelHelpers.js"),CustomJSON=require("@bddh/starling-json"),isEmpty=require("lodash/isEmpty"),omit=require("lodash/omit"),pick=require("lodash/pick"),uuid=require("uuid"),_interface=require("./interface.js"),Server=require("./Server.js"),BrtcClient=require("./BrtcClient.js"),DomControl=require("./DomControl.js"),Cutout=require("./Cutout.js"),RecordController=require("./RecordController.js"),DhRealtimeHuman=function(_handleConnectResponse,_mergeConnectRtcExtrasFromBody,_applyConnectChroma){function DhRealtimeHuman(props){var _ref4,_this=this;_rollupPluginBabelHelpers.classCallCheck(this,DhRealtimeHuman),_rollupPluginBabelHelpers.defineProperty(this,"token",void 0),_rollupPluginBabelHelpers.defineProperty(this,"appKey",void 0),_rollupPluginBabelHelpers.defineProperty(this,"appId",void 0),_rollupPluginBabelHelpers.defineProperty(this,"connectParams",void 0),_rollupPluginBabelHelpers.defineProperty(this,"onDigitalHumanCallback",void 0),_rollupPluginBabelHelpers.defineProperty(this,"dhServer",void 0),_rollupPluginBabelHelpers.defineProperty(this,"rtcServer",void 0),_rollupPluginBabelHelpers.defineProperty(this,"rtcConnectParams",void 0),_rollupPluginBabelHelpers.defineProperty(this,"cutoutInstance",void 0),_rollupPluginBabelHelpers.defineProperty(this,"hasInitChromaEffects",!1),_rollupPluginBabelHelpers.defineProperty(this,"isHuawei",DomControl.checkIsHuawei()),_rollupPluginBabelHelpers.defineProperty(this,"rtcServerUrl",void 0),_rollupPluginBabelHelpers.defineProperty(this,"rtcInternalIp",void 0),_rollupPluginBabelHelpers.defineProperty(this,"recordController",null),_rollupPluginBabelHelpers.defineProperty(this,"wsReadyState",-1),_rollupPluginBabelHelpers.defineProperty(this,"isPreOpenSession",!1),_rollupPluginBabelHelpers.defineProperty(this,"openWsOnly",!1),_rollupPluginBabelHelpers.defineProperty(this,"hasConnectUserFigureEffects",!1),_rollupPluginBabelHelpers.defineProperty(this,"_isMicMuted",!1),_rollupPluginBabelHelpers.defineProperty(this,"mergeConnectRtcExtras",!1),_rollupPluginBabelHelpers.defineProperty(this,"emitRawStatusMessage",!1),_rollupPluginBabelHelpers.defineProperty(this,"resolveMediaServerByDomain",void 0),_rollupPluginBabelHelpers.defineProperty(this,"remoteAutoPlay",!0),_rollupPluginBabelHelpers.defineProperty(this,"onDigitalHumanCallbackPlus",(function(data){var _this$cutoutInstance,_this$rtcServer,content=data.content;data.status===_interface.statusEnum.DH_LIB_FULL_STATUS&&"wsState"===(null==content?void 0:content.type)&&(_this.wsReadyState=content.readyState,3===content.readyState&&(null===(_this$cutoutInstance=_this.cutoutInstance)||void 0===_this$cutoutInstance||_this$cutoutInstance.setPlaying(!1),null===(_this$rtcServer=_this.rtcServer)||void 0===_this$rtcServer||_this$rtcServer.closeRtc(),_this.canShowStaticFrameCover()&&(DomControl.setHumanPlayerWrapperVisible(!1),DomControl.setLastFrameCoverVisible(!0))));_this.onDigitalHumanCallback&&_this.onDigitalHumanCallback(data)})),_rollupPluginBabelHelpers.defineProperty(this,"onRemoteVideoComing",(function(id){_this.rtcConnectParams&&_this.rtcConnectParams.feedId&&id===+_this.rtcConnectParams.feedId&&_this.rtcServer&&_this.rtcServer.client&&_this.rtcServer.client.subscribeStreaming("remotevideo500",+_this.rtcConnectParams.feedId)})),_rollupPluginBabelHelpers.defineProperty(this,"onLocalStream",(function(){(_this.connectParams||{}).pullAudioFromRtc&&_this.rtcServer&&_this.rtcServer.muteMicphone(_this._isMicMuted)})),_rollupPluginBabelHelpers.defineProperty(this,"onRemoteVideoOn",(function(){setTimeout(_rollupPluginBabelHelpers.asyncToGenerator(_rollupPluginBabelHelpers.regeneratorRuntime().mark((function _callee(){var video;return _rollupPluginBabelHelpers.regeneratorRuntime().wrap((function(_context){for(;;)switch(_context.prev=_context.next){case 0:if(video=document.getElementById(DomControl.RTC_VIDEO_ID),!_this.cutoutInstance||!video){_context.next=5;break}return _this.cutoutInstance.setPlaying(!0),_context.next=5,_this.cutoutInstance.updateSource(video);case 5:_this.canShowStaticFrameCover()&&(DomControl.captureLastFrameToCover(),DomControl.setHumanPlayerWrapperVisible(!0),DomControl.setLastFrameCoverVisible(!1));case 6:case"end":return _context.stop()}}),_callee)}))),100)})),_rollupPluginBabelHelpers.defineProperty(this,"onRemoteVideoConnected",(function(id,connected){var _this$rtcConnectParam;if(connected&&!_this.remoteAutoPlay){var feedId=null===(_this$rtcConnectParam=_this.rtcConnectParams)||void 0===_this$rtcConnectParam?void 0:_this$rtcConnectParam.feedId;null!=feedId&&id!==+feedId||_this.onRemoteVideoOn()}})),_rollupPluginBabelHelpers.defineProperty(this,"onRemoteVideoOffLastFrame",(function(){var _this$cutoutInstance2;null===(_this$cutoutInstance2=_this.cutoutInstance)||void 0===_this$cutoutInstance2||_this$cutoutInstance2.setPlaying(!1),_this.canShowStaticFrameCover()&&DomControl.setLastFrameCoverVisible(!0)})),_rollupPluginBabelHelpers.defineProperty(this,"connectListener",(function(data){_this.handleConnectResponse(data).catch((function(e){console.warn("[DhRealtimeHuman] handleConnectResponse failed",e)}))})),_rollupPluginBabelHelpers.defineProperty(this,"createServer",(function(sessionId){var _this$dhServer,params=_rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({token:_this.token,appKey:_this.appKey,appId:_this.appId},sessionId?{sessionId:sessionId}:{}),pick(_this.connectParams,_interface.CONNECT_MAIN_KEY)),{},{parameters:omit(_this.connectParams,_interface.CONNECT_MAIN_KEY),onConnect:_this.connectListener,onDigitalHumanCallback:_this.onDigitalHumanCallbackPlus});null!==(_this$dhServer=_this.dhServer)&&void 0!==_this$dhServer&&_this$dhServer.preConnectSuccess?(_this.dhServer.connectParams=params,_this.dhServer&&_this.dhServer.sendPreConnect(params)):_this.openWsOnly?_this.dhServer&&_this.dhServer.sendConnect(params):_this.dhServer&&_this.dhServer.createSocket(params)})),_rollupPluginBabelHelpers.defineProperty(this,"checkHumanInstansce",(function(){return _this.dhServer?!(_this.isPreOpenSession&&!_this.dhServer.preConnectSuccess)||(_this.onDigitalHumanCallback&&_this.onDigitalHumanCallback({status:_interface.statusEnum.DH_LIB_ERROR,content:{type:_interface.errorTypeEnum.CONNECT_ERROR,msg:{code:4001,errMsg:"webSocket连接中"}}}),!1):(_this.onDigitalHumanCallback&&_this.onDigitalHumanCallback({status:_interface.statusEnum.DH_LIB_ERROR,content:{type:_interface.errorTypeEnum.CONNECT_ERROR,msg:{code:4002,errMsg:"请先初始化数字人实例"}}}),!1)})),_rollupPluginBabelHelpers.defineProperty(this,"sendMessage",(function(message,listener){return _this.dhServer&&_this.dhServer.sendMessage(message,listener)})),_rollupPluginBabelHelpers.defineProperty(this,"interrupt",_rollupPluginBabelHelpers.asyncToGenerator(_rollupPluginBabelHelpers.regeneratorRuntime().mark((function _callee2(){return _rollupPluginBabelHelpers.regeneratorRuntime().wrap((function(_context2){for(;;)switch(_context2.prev=_context2.next){case 0:return _context2.abrupt("return",new Promise((function(resolve){_this.dhServer&&_this.dhServer.sendMessage({requestId:uuid.v4(),action:"TEXT_RENDER",body:"<interrupt></interrupt>",clientTs:(new Date).getTime()},(function(){return resolve()}))})));case 1:case"end":return _context2.stop()}}),_callee2)})))),_rollupPluginBabelHelpers.defineProperty(this,"textRender",(function(renderData){var requestId=renderData.requestId,body=renderData.body,onCallbackMsg=renderData.onCallbackMsg;_this.checkHumanInstansce()&&_this.dhServer&&_this.dhServer.sendMessage({requestId:requestId||uuid.v4(),action:"TEXT_RENDER",body:body,clientTs:(new Date).getTime()},onCallbackMsg)})),_rollupPluginBabelHelpers.defineProperty(this,"textStreamRender",(function(renderData){var requestId=renderData.requestId,body=renderData.body,onCallbackMsg=renderData.onCallbackMsg,first=CustomJSON.parse(body).first;_this.checkHumanInstansce()&&_this.dhServer&&_this.dhServer.sendMessage({requestId:requestId||uuid.v4(),action:"TEXT_STREAM_RENDER",body:body,clientTs:(new Date).getTime()},first?onCallbackMsg:null)})),_rollupPluginBabelHelpers.defineProperty(this,"audioRender",(function(renderData){var body=renderData.body,onCallbackMsg=renderData.onCallbackMsg;_this.checkHumanInstansce()&&_this.dhServer&&_this.dhServer.sendMessage({requestId:uuid.v4(),action:"AUDIO_RENDER",body:body,clientTs:(new Date).getTime()},onCallbackMsg)})),_rollupPluginBabelHelpers.defineProperty(this,"audioStreamRender",(function(renderData){var requestId=renderData.requestId,body=renderData.body,onCallbackMsg=renderData.onCallbackMsg;_this.checkHumanInstansce()&&_this.dhServer&&_this.dhServer.sendMessage({requestId:requestId||uuid.v4(),action:"AUDIO_STREAM_RENDER",body:body,clientTs:(new Date).getTime()},onCallbackMsg)})),_rollupPluginBabelHelpers.defineProperty(this,"textQuery",(function(queryData){var requestId=queryData.requestId,body=queryData.body,onCallbackMsg=queryData.onCallbackMsg;_this.dhServer&&_this.dhServer.sendMessage({requestId:requestId||uuid.v4(),action:"TEXT_QUERY",body:body,clientTs:(new Date).getTime()},onCallbackMsg)})),_rollupPluginBabelHelpers.defineProperty(this,"handleDestroyView",(function(keepLastFrame){var _this$cutoutInstance4,_this$cutoutInstance3;return keepLastFrame?_this.canShowStaticFrameCover()?(DomControl.playHumanVideo(!1),DomControl.setHumanPlayerWrapperVisible(!1),void DomControl.setLastFrameCoverVisible(!0)):void(null===(_this$cutoutInstance4=_this.cutoutInstance)||void 0===_this$cutoutInstance4||_this$cutoutInstance4.setPlaying(!1)):(null===(_this$cutoutInstance3=_this.cutoutInstance)||void 0===_this$cutoutInstance3||_this$cutoutInstance3.destroy(),_this.cutoutInstance=void 0,DomControl.removeHumanDom(),void DomControl.removeLastFrameCoverWrapper())})),_rollupPluginBabelHelpers.defineProperty(this,"destroy",(function(_x){return(_ref4=_ref4||_rollupPluginBabelHelpers.asyncToGenerator(_rollupPluginBabelHelpers.regeneratorRuntime().mark((function _callee3(options){var _this$recordControlle,_ref5$keepLastFrame,keepLastFrame;return _rollupPluginBabelHelpers.regeneratorRuntime().wrap((function(_context3){for(;;)switch(_context3.prev=_context3.next){case 0:return _ref5$keepLastFrame=(options||{}).keepLastFrame,keepLastFrame=void 0!==_ref5$keepLastFrame&&_ref5$keepLastFrame,_this.handleDestroyView(keepLastFrame),_context3.next=4,_this.dhServer&&_this.dhServer.destroySocket();case 4:_this.rtcServer&&_this.rtcServer.closeRtc(),null===(_this$recordControlle=_this.recordController)||void 0===_this$recordControlle||_this$recordControlle.destroy(),_this.dhServer=null,_this.rtcServer=null;case 8:case"end":return _context3.stop()}}),_callee3)})))).apply(this,arguments)})),_rollupPluginBabelHelpers.defineProperty(this,"pauseHuman",(function(){return DomControl.playHumanVideo(!1)})),_rollupPluginBabelHelpers.defineProperty(this,"playHuman",(function(){return DomControl.playHumanVideo(!0)})),_rollupPluginBabelHelpers.defineProperty(this,"muteHuman",(function(){return DomControl.muteHumanVideo(!0)})),_rollupPluginBabelHelpers.defineProperty(this,"unMuteHuman",(function(){var humanVideo=DomControl.muteHumanVideo(!1);try{return _this.isHuawei?(humanVideo.pause(),humanVideo.play()):humanVideo.paused&&humanVideo.play()}catch(e){console.info(e)}}));var _props$isPreOpenSessi=props.isPreOpenSession,isPreOpenSession=void 0!==_props$isPreOpenSessi&&_props$isPreOpenSessi,_props$isOpenWsOnly=props.isOpenWsOnly,isOpenWsOnly=void 0!==_props$isOpenWsOnly&&_props$isOpenWsOnly,wsUrl=props.wsUrl,renderParams=props.renderParams,checkHeartbeatMismatch=props.checkHeartbeatMismatch,_props$emitRawStatusM=props.emitRawStatusMessage,emitRawStatusMessage=void 0!==_props$emitRawStatusM&&_props$emitRawStatusM,onDigitalHumanCallback=props.onDigitalHumanCallback;this.isPreOpenSession=isPreOpenSession,this.openWsOnly=isOpenWsOnly,this.emitRawStatusMessage=emitRawStatusMessage,this.dhServer=new Server.default(wsUrl||"wss://open.xiling.baidu.com/cloud/digital-human-demonstration",{checkHeartbeatMismatch:checkHeartbeatMismatch,emitRawStatusMessage:emitRawStatusMessage}),this.onDigitalHumanCallback=function(data){data.status!==_interface.statusEnum.DH_LIB_FULL_STATUS?onDigitalHumanCallback&&onDigitalHumanCallback(data):(null==renderParams?void 0:renderParams.fullStatus)&&onDigitalHumanCallback&&onDigitalHumanCallback(data)},isPreOpenSession||isOpenWsOnly?this.dhServer.createSocket({onDigitalHumanCallback:this.onDigitalHumanCallbackPlus},isPreOpenSession):this.init(props)}return _rollupPluginBabelHelpers.createClass(DhRealtimeHuman,[{key:"canShowStaticFrameCover",value:function(){return!this.hasInitChromaEffects&&!this.hasConnectUserFigureEffects}},{key:"init",value:function(props){var _this$dhServer2,_connectParams$reConn,_this2=this,wrapperId=props.wrapperId,token=props.token,appKey=props.appKey,appId=props.appId,connectParams=props.connectParams,_props$renderParams=props.renderParams,renderParams=void 0===_props$renderParams?{}:_props$renderParams,rtcConnectParams=props.rtcConnectParams,brtcParams=props.brtcParams,rtcServerUrl=props.rtcServerUrl,rtcInternalIp=props.rtcInternalIp,_props$mergeConnectRt=props.mergeConnectRtcExtras,mergeConnectRtcExtras=void 0!==_props$mergeConnectRt&&_props$mergeConnectRt,_props$emitRawStatusM2=props.emitRawStatusMessage,emitRawStatusMessage=void 0!==_props$emitRawStatusM2&&_props$emitRawStatusM2,remoteAutoPlay=props.remoteAutoPlay,resolveMediaServerByDomain=props.resolveMediaServerByDomain;if(this.mergeConnectRtcExtras=Boolean(mergeConnectRtcExtras),this.emitRawStatusMessage=emitRawStatusMessage,null===(_this$dhServer2=this.dhServer)||void 0===_this$dhServer2||_this$dhServer2.setEmitRawStatusMessage(this.emitRawStatusMessage),this.resolveMediaServerByDomain=resolveMediaServerByDomain,this.remoteAutoPlay=!1!==remoteAutoPlay,this.hasConnectUserFigureEffects=!1,this.token=token,this.appKey=appKey,this.appId=appId,this.rtcServerUrl=rtcServerUrl,this.rtcInternalIp=rtcInternalIp,this.connectParams=_rollupPluginBabelHelpers.objectSpread2({autoChromaKey:(null==renderParams?void 0:renderParams.autoChromaKey)||!1},connectParams),!appId&&!appKey&&!token)throw new Error("appId and appKey or token is required");var closeLog=renderParams.closeLog,audio3AConstraints=renderParams.audio3AConstraints;this.hasInitChromaEffects=!isEmpty(null==renderParams?void 0:renderParams.chromaEffects)||!(null==renderParams||!renderParams.autoChromaKey),DomControl.removeLastFrameCoverWrapper(),DomControl.removeHumanDom();var playerWrapper=(DomControl.createHumanDom({autoChromaKey:!!renderParams.autoChromaKey||!isEmpty(renderParams.chromaEffects),autoplay:!1!==remoteAutoPlay})||{}).playerWrapper,wrapperEle=document.getElementById(wrapperId||"");wrapperEle||console.error("dom with wrapperId is not find"),playerWrapper&&wrapperEle&&wrapperEle.appendChild(playerWrapper),this.canShowStaticFrameCover()&&wrapperEle&&("static"===window.getComputedStyle(wrapperEle).position&&(wrapperEle.style.position="relative"),DomControl.appendLastFrameCoverSibling(wrapperEle)),DomControl.appendRtcDomStyle();var rtcConfig=_rollupPluginBabelHelpers.objectSpread2({remotevideoviewid:wrapperId,showvideobps:!1,usingvideo:!1,usingaudio:!(null==connectParams||!connectParams.pullAudioFromRtc),aspublisher:!(null==connectParams||!connectParams.pullAudioFromRtc),autopublish:!(null==connectParams||!connectParams.pullAudioFromRtc),usingdatachannel:!0,autoplaymuted:!1},brtcParams);this.rtcServer=new BrtcClient.default({closeLog:closeLog,videoWrapperId:DomControl.RTC_VIDEO_ID,rtcConfig:rtcConfig,bizConfig:_rollupPluginBabelHelpers.objectSpread2({autoReConnect:null===(_connectParams$reConn=null==connectParams?void 0:connectParams.reConnect)||void 0===_connectParams$reConn||_connectParams$reConn},void 0!==remoteAutoPlay?{remoteAutoPlay:remoteAutoPlay}:{}),rtcCallback:{onRemoteVideoComing:this.onRemoteVideoComing,onDigitalHumanCallback:this.onDigitalHumanCallback,onLocalStream:this.onLocalStream,onRemoteVideoOn:this.onRemoteVideoOn,onRemoteVideoOff:this.onRemoteVideoOffLastFrame,onRemoteVideoConnected:this.onRemoteVideoConnected}}),(!isEmpty(null==renderParams?void 0:renderParams.chromaEffects)||null!=renderParams&&renderParams.autoChromaKey)&&(this.cutoutInstance=new Cutout.default({sourceId:DomControl.RTC_VIDEO_ID,effects:null==renderParams?void 0:renderParams.chromaEffects})),isEmpty(rtcConnectParams)||(this.rtcConnectParams=rtcConnectParams,this.rtcServer.openRtc(rtcConnectParams)),null!=connectParams&&connectParams.pullAudioFromRtc?this.recordController=null:this.recordController=new RecordController.default({pickAudioMode:null==connectParams?void 0:connectParams.pickAudioMode,audio3AConstraints:audio3AConstraints,asrSample:null==connectParams?void 0:connectParams.asrSample,onAudioData:function(pcmData){1===_this2.wsReadyState&&_this2.sendMessage(pcmData,null)},onError:function(err){_this2.onDigitalHumanCallback&&_this2.onDigitalHumanCallback({status:_interface.statusEnum.DH_LIB_ERROR,content:{type:_interface.errorTypeEnum.CONNECT_ERROR,msg:{code:-1,errMsg:err.message}}})}})}},{key:"handleConnectResponse",value:function(_x2){return(_handleConnectResponse=_handleConnectResponse||_rollupPluginBabelHelpers.asyncToGenerator(_rollupPluginBabelHelpers.regeneratorRuntime().mark((function _callee4(data){var code,body,message,_data,server,appId,token,roomName,userId,feedId,chargeId;return _rollupPluginBabelHelpers.regeneratorRuntime().wrap((function(_context4){for(;;)switch(_context4.prev=_context4.next){case 0:if(code=data.code,body=data.body,message=data.message,0===code&&this.onDigitalHumanCallback&&this.onDigitalHumanCallback({status:_interface.statusEnum.DH_LIB_WS_SUCCESS,content:data}),this.emitRawStatusMessage&&this.onDigitalHumanCallback&&this.onDigitalHumanCallback({status:_interface.statusEnum.DH_LIB_MESSAGE,content:data}),0!==code){_context4.next=18;break}if(_data=CustomJSON.parse(body),!this.mergeConnectRtcExtras||!this.rtcServer){_context4.next=14;break}return _context4.prev=6,_context4.next=9,this.mergeConnectRtcExtrasFromBody(_data);case 9:_context4.next=14;break;case 11:_context4.prev=11,_context4.t0=_context4.catch(6),console.warn("[DhRealtimeHuman] mergeConnectRtcExtrasFromBody failed",_context4.t0);case 14:server=_data.rtcServerUrl,appId=_data.appId,token=_data.clientToken,roomName=_data.roomName,userId=_data.clientId,feedId=_data.feedId,chargeId=_data.chargeId,appId&&roomName&&(this.rtcConnectParams={server:this.rtcServerUrl||server,appId:appId,token:token,roomName:roomName,userId:userId,feedId:feedId,chargeId:chargeId},this.rtcServer&&this.rtcServer.openRtc(this.rtcConnectParams)),_context4.next=19;break;case 18:this.onDigitalHumanCallback&&this.onDigitalHumanCallback({status:_interface.statusEnum.DH_LIB_ERROR,content:{type:_interface.errorTypeEnum.CONNECT_ERROR,msg:{code:code,errMsg:message}}});case 19:case"end":return _context4.stop()}}),_callee4,this,[[6,11]])})))).apply(this,arguments)}},{key:"mergeConnectRtcExtrasFromBody",value:function(_x3){return(_mergeConnectRtcExtrasFromBody=_mergeConnectRtcExtrasFromBody||_rollupPluginBabelHelpers.asyncToGenerator(_rollupPluginBabelHelpers.regeneratorRuntime().mark((function _callee5(body){var _body$userFigure,userFigure,_body$rtcExternalInfo,mediaServerDN,partial,userFigureParams,resolve;return _rollupPluginBabelHelpers.regeneratorRuntime().wrap((function(_context5){for(;;)switch(_context5.prev=_context5.next){case 0:if(this.rtcServer){_context5.next=2;break}return _context5.abrupt("return");case 2:if(_body$userFigure=body.userFigure,userFigure=void 0===_body$userFigure?"":_body$userFigure,_body$rtcExternalInfo=body.rtcExternalInfo,mediaServerDN=(void 0===_body$rtcExternalInfo?{}:_body$rtcExternalInfo).udpDomain||"",partial={},this.rtcInternalIp&&(partial.mediaserverip=this.rtcInternalIp),!userFigure){_context5.next=19;break}if(!(userFigureParams=CustomJSON.parse(userFigure)).effects){_context5.next=17;break}return _context5.prev=9,_context5.next=12,this.applyConnectChroma(userFigureParams.effects);case 12:_context5.next=17;break;case 14:_context5.prev=14,_context5.t0=_context5.catch(9),console.warn("[DhRealtimeHuman] applyConnectChroma failed",_context5.t0);case 17:_context5.next=36;break;case 19:if(!mediaServerDN){_context5.next=36;break}if(resolve=this.resolveMediaServerByDomain){_context5.next=26;break}console.warn("[DhRealtimeHuman] udpDomain 解析需传入 resolveMediaServerByDomain"),partial.mediaserverip="",_context5.next=36;break;case 26:return _context5.prev=26,_context5.next=29,resolve(mediaServerDN);case 29:partial.mediaserverip=_context5.sent,_context5.next=36;break;case 32:_context5.prev=32,_context5.t1=_context5.catch(26),partial.mediaserverip="",console.error("resolveMediaServerByDomain failed",_context5.t1);case 36:this.rtcServer.mergeRtcConfig(partial);case 37:case"end":return _context5.stop()}}),_callee5,this,[[9,14],[26,32]])})))).apply(this,arguments)}},{key:"applyConnectChroma",value:function(_x4){return(_applyConnectChroma=_applyConnectChroma||_rollupPluginBabelHelpers.asyncToGenerator(_rollupPluginBabelHelpers.regeneratorRuntime().mark((function _callee6(effects){var _this$cutoutInstance5,chromaKey,version,video;return _rollupPluginBabelHelpers.regeneratorRuntime().wrap((function(_context6){for(;;)switch(_context6.prev=_context6.next){case 0:if(!this.hasInitChromaEffects){_context6.next=2;break}return _context6.abrupt("return");case 2:if(chromaKey=effects.chromaKey,version=effects.version,null!=chromaKey){_context6.next=5;break}return _context6.abrupt("return");case 5:if(DomControl.ensureCutoutDomMounted()){_context6.next=7;break}return _context6.abrupt("return");case 7:if(this.hasConnectUserFigureEffects=!0,DomControl.removeLastFrameCoverWrapper(),DomControl.setLastFrameCoverVisible(!1),DomControl.setHumanPlayerWrapperVisible(!0),null===(_this$cutoutInstance5=this.cutoutInstance)||void 0===_this$cutoutInstance5||_this$cutoutInstance5.destroy(),this.cutoutInstance=new Cutout.default({sourceId:DomControl.RTC_VIDEO_ID,effects:{version:version,chromaKey:chromaKey}}),!(video=document.getElementById(DomControl.RTC_VIDEO_ID))){_context6.next=17;break}return _context6.next=17,this.cutoutInstance.updateSource(video);case 17:case"end":return _context6.stop()}}),_callee6,this)})))).apply(this,arguments)}},{key:"startRecord",value:function(){var _this$connectParams;null!==(_this$connectParams=this.connectParams)&&void 0!==_this$connectParams&&_this$connectParams.pullAudioFromRtc?this.rtcServer&&this.rtcServer.muteMicphone(!1):this.recordController&&this.recordController.start()}},{key:"stopRecord",value:function(){var _this$connectParams2;if(null!==(_this$connectParams2=this.connectParams)&&void 0!==_this$connectParams2&&_this$connectParams2.pullAudioFromRtc)return this.rtcServer&&this.rtcServer.muteMicphone(!0),void this.sendMessage({action:"AUDIO_QUERY_INTERRUPT",requestId:uuid.v4(),clientTs:Date.now(),body:""},null);this.recordController&&this.recordController.stop(),this.sendMessage({action:"AUDIO_QUERY_INTERRUPT",requestId:uuid.v4(),clientTs:Date.now(),body:""},null)}},{key:"muteMicrophone",value:function(isMute){var _this$connectParams3,_this$rtcServer2;null!==(_this$connectParams3=this.connectParams)&&void 0!==_this$connectParams3&&_this$connectParams3.pullAudioFromRtc&&(this._isMicMuted=isMute,null===(_this$rtcServer2=this.rtcServer)||void 0===_this$rtcServer2||_this$rtcServer2.muteMicphone(isMute))}}]),DhRealtimeHuman}();exports.default=DhRealtimeHuman;