@bddh/starling-realtime-client 2.0.11-beta.4 → 2.0.11-beta.5
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/cjs/BrtcClient.js +1 -1
- package/cjs/Client.js +1 -1
- package/cjs/Cutout.js +1 -1
- package/cjs/DomControl.js +1 -1
- package/cjs/RecordController.js +1 -1
- package/cjs/Server.d.ts +1 -0
- package/cjs/Server.js +1 -1
- package/cjs/_virtual/_rollupPluginBabelHelpers.js +1 -1
- package/cjs/index.js +1 -1
- package/cjs/interface.js +1 -1
- package/es/BrtcClient.js +1 -1
- package/es/Client.js +1 -1
- package/es/Cutout.js +1 -1
- package/es/DomControl.js +1 -1
- package/es/RecordController.js +1 -1
- package/es/Server.d.ts +1 -0
- package/es/Server.js +1 -1
- package/es/_virtual/_rollupPluginBabelHelpers.js +1 -1
- package/es/index.js +1 -1
- package/es/interface.js +1 -1
- package/package.json +4 -4
- package/LICENSE +0 -21
package/cjs/BrtcClient.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("./_virtual/_rollupPluginBabelHelpers.js"),e=require("@bddh/starling-brtc"),o=require("@bddh/starling-timeout-controller"),n=require("@bddh/starling-json"),i=require("lodash/isEmpty"),c=require("lodash/isFunction"),r=require("./interface.js"),a=function(){function a(l){var s=this;t.classCallCheck(this,a),t.defineProperty(this,"client",void 0),t.defineProperty(this,"isRtcVideoOn",!1),t.defineProperty(this,"rtcConnection",void 0),t.defineProperty(this,"rtcConfig",void 0),t.defineProperty(this,"bizConfig",void 0),t.defineProperty(this,"rtcCallback",void 0),t.defineProperty(this,"restarting",!1),t.defineProperty(this,"timeoutEvent",void 0),t.defineProperty(this,"timeoutStarted",!1),t.defineProperty(this,"reopenTimer",void 0),t.defineProperty(this,"restartCount",0),t.defineProperty(this,"closeLog",!0),t.defineProperty(this,"stopped",!1),t.defineProperty(this,"haveVideoOn",!1),t.defineProperty(this,"rtcStateCallback",null),t.defineProperty(this,"startRtcTimeout",(function(){s.timeoutStarted||(s.timeoutEvent.start(),s.timeoutStarted=!0)})),t.defineProperty(this,"clearRtcTimeout",(function(){s.timeoutStarted&&(s.timeoutEvent.clear(),s.timeoutStarted=!1)})),t.defineProperty(this,"mergeRtcConfig",(function(t){s.rtcConfig&&t&&Object.keys(t).length&&Object.assign(s.rtcConfig,t)})),t.defineProperty(this,"openRtc",(function(t){if(s.stopped=!1,s.restarting)!s.closeLog&&console.warn("rtc restarting");else if(t&&(s.rtcConnection=t),s.rtcConnection&&!i(s.rtcConnection)){var o,a=s.rtcConnection,l=a.server,d=a.appId,u=a.token,f=a.roomName,m=a.userId,C=s.rtcCallback||{},b=C.onRemotedata,g=C.onLocalStream,p=C.onRemoteVideoComing,y=C.onLocalVideoPublished,h=C.onLocalVideoPublishing,v=C.onRemoteVideoOn,R=C.onRemoteVideoOff,S=C.onRemoteVideoLoading,L=C.onSuccess,k=C.onError,P=C.onLocalVideoConnected,V=C.onRemoteVideoConnected,E=C.onRemoteMediaState,T=C.onPlayingError,O=C.onDigitalHumanCallback;null===(o=s.client)||void 0===o||o.destroy(),s.client=void 0,s.startRtcTimeout(),s.rtcStateCallback=function(t){var e=t.body,o=t.action;O&&O({status:r.statusEnum.DH_LIB_FULL_STATUS,content:{type:"rtcState",action:o,body:e}})},s.client=new e({roomName:f,token:u,userId:m,appId:d,server:l,rtcConfig:s.rtcConfig,callback:{onRemoteVideoConnected:function(e,o){var n;if(!o&&!s.haveVideoOn)var i=setTimeout((function(){s.restartCount<3?(s.restartCount=++s.restartCount,s.restartRtc&&s.restartRtc(t)):(s.restartCount=0,s.closeRtc()),clearTimeout(i)}),500);if(o&&!1!==(null===(n=s.bizConfig)||void 0===n?void 0:n.remoteAutoPlay)){var a=document.getElementById("remotevideo500");if(a){a.muted=!1;var l=a.play();void 0!==l&&l.catch((function(){a.muted=!0,a.play().catch((function(t){!s.closeLog&&console.info("videoElement play error",t),T&&T(a),O&&O({status:r.statusEnum.DH_LIB_ERROR,content:{type:r.errorTypeEnum.LOCAL_VIDEO_ERROR}}),s.rtcStateCallback&&s.rtcStateCallback({action:"localVideoError",body:!0})})),O&&O({status:r.statusEnum.DH_LIB_STATUS,content:{type:r.errorTypeEnum.LOCAL_VIDEO_MUTED}}),s.rtcStateCallback&&s.rtcStateCallback({action:"localVideoMuted",body:!0})}))}else!s.closeLog&&console.error("videoElement is null!")}!s.closeLog&&console.info("remoteVideoConnected",e,o,s.restartCount),s.rtcStateCallback&&s.rtcStateCallback({action:"remoteVideoConnected",body:{id:e,connected:o,restartCount:s.restartCount}}),c(V)&&V(e,o)},onRemoteVideoOn:function(t){s.haveVideoOn=!0,!s.closeLog&&console.info("remotevideoon by id: ",t),s.clearRtcTimeout();var e=document.querySelector("#starlingRtcContainer"),o=e&&e.lastChild;o&&(o.style.display="none"),s.rtcStateCallback&&s.rtcStateCallback({action:"remotevideoon",body:t}),O&&O({status:r.statusEnum.DH_LIB_OPEN}),c(v)&&v(t)},onRemoteMediaState:function(t,e,o){!s.closeLog&&console.info("remoteMediaState",t,e,o),s.rtcStateCallback&&s.rtcStateCallback({action:"remoteMediaState",body:{id:t,medium:e,connected:o}}),c(E)&&E(t,e,o)},onLocalVideoConnected:function(t){!s.closeLog&&console.info("localVideoConnected",t),s.rtcStateCallback&&s.rtcStateCallback({action:"localVideoConnected",body:{connected:t}}),c(P)&&P(t)},onRemotedata:function(t){if(s.rtcConfig&&s.rtcConfig.usingdatachannel){var e=n.parse(t);!s.closeLog&&console.info("RTC - receive:",e),c(b)&&b(e)}},onLocalStream:function(t,e){!s.closeLog&&console.info("rtc - onlocalstream by name: "+e),s.rtcStateCallback&&s.rtcStateCallback({action:"onlocalstream",body:{stream:t,name:e}}),c(g)&&g(t,e)},onLocalVideoPublished:function(){!s.closeLog&&console.info("LocalVideoPublished 本地视频发布成功"),s.rtcStateCallback&&s.rtcStateCallback({action:"localvideopublished_ok",body:!0}),c(y)&&y()},onLocalVideoPublishing:function(){!s.closeLog&&console.info("LocalVideoPublishing 本地视频发布成功"),s.rtcStateCallback&&s.rtcStateCallback({action:"localvideopublishing",body:!0}),c(h)&&h()},onRemoteVideoComing:function(t){!s.closeLog&&console.info("remotevideocoming",t),s.rtcStateCallback&&s.rtcStateCallback({action:"remotevideocoming",body:t}),c(p)&&p(t)},onRemoteVideoLoading:function(t){!s.closeLog&&console.info("remotevideoloading by id: ",t),s.rtcStateCallback&&s.rtcStateCallback({action:"remotevideoloading",body:t}),c(S)&&S(t)},onRemoteVideoOff:function(t){if(!s.stopped){var e=document.getElementById("remotevideo500");e&&e.pause(),!s.closeLog&&console.info("remotevideooff: ",t),s.isRtcVideoOn=!1,s.rtcStateCallback&&s.rtcStateCallback({action:"remotevideooff",body:t}),O&&O({status:r.statusEnum.DH_LIB_CLOSE}),c(R)&&R(t),s.startRtcTimeout()}},onSuccess:function(){!s.closeLog&&console.info("rtc - success"),s.rtcStateCallback&&s.rtcStateCallback({action:"success",body:!0}),c(L)&&L()},onError:function(e){s.stopped||(s.isRtcVideoOn=!1,!s.closeLog&&console.error("rtc - error:",e),s.rtcStateCallback&&s.rtcStateCallback({action:"error",body:e}),O&&O({status:r.statusEnum.DH_LIB_ERROR,content:{type:r.errorTypeEnum.RTC_ERROR}}),c(k)&&k(e),(e.includes("Lost connection to the server")||e.includes("Is the server down"))&&s.restartRtc&&s.restartRtc(t))}}})}})),t.defineProperty(this,"closeRtc",(function(){var t;s.stopped=!0,s.clearRtcTimeout(),clearTimeout(s.reopenTimer),null===(t=s.client)||void 0===t||t.destroy(),s.client=void 0,s.restarting=!1})),t.defineProperty(this,"restartRtc",(function(t){s.stopped||!s.restarting&&s.bizConfig&&s.bizConfig.autoReConnect&&(s.rtcStateCallback&&s.rtcStateCallback({action:"restartRtc",body:t}),s.restarting=!0,s.closeRtc(),s.reopenTimer=setTimeout((function(){!s.closeLog&&console.error("拉流失败,开始重启"),s.restarting=!1,s.openRtc(t)}),2e3))}));var d=l.rtcConnection,u=l.rtcConfig,f=l.closeLog,m=void 0===f||f,C=l.rtcCallback,b=l.bizConfig;this.rtcConnection=d,this.rtcConfig=u,this.rtcCallback=C,this.closeLog=m,this.bizConfig=b,this.timeoutEvent=new o.TimeoutController(6e4,(function(){if(s.timeoutStarted=!1,!s.stopped)return s.rtcConnection?void(s.restartRtc&&s.restartRtc(s.rtcConnection)):!s.closeLog&&console.warn("remotevideoon事件超时, rtcConnectionRef is null")}))}return t.createClass(a,[{key:"muteMicphone",value:function(t){this.client&&this.client.muteMicphone&&this.client.muteMicphone(t)}}]),a}();exports.default=a;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var _rollupPluginBabelHelpers=require("./_virtual/_rollupPluginBabelHelpers.js"),BrtcInstance=require("@bddh/starling-brtc"),starlingTimeoutController=require("@bddh/starling-timeout-controller"),CustomJSON=require("@bddh/starling-json"),isEmpty=require("lodash/isEmpty"),isFunction=require("lodash/isFunction"),_interface=require("./interface.js"),BrtcClient=function(){function BrtcClient(props){var _this=this;_rollupPluginBabelHelpers.classCallCheck(this,BrtcClient),_rollupPluginBabelHelpers.defineProperty(this,"client",void 0),_rollupPluginBabelHelpers.defineProperty(this,"isRtcVideoOn",!1),_rollupPluginBabelHelpers.defineProperty(this,"rtcConnection",void 0),_rollupPluginBabelHelpers.defineProperty(this,"rtcConfig",void 0),_rollupPluginBabelHelpers.defineProperty(this,"bizConfig",void 0),_rollupPluginBabelHelpers.defineProperty(this,"rtcCallback",void 0),_rollupPluginBabelHelpers.defineProperty(this,"restarting",!1),_rollupPluginBabelHelpers.defineProperty(this,"timeoutEvent",void 0),_rollupPluginBabelHelpers.defineProperty(this,"timeoutStarted",!1),_rollupPluginBabelHelpers.defineProperty(this,"reopenTimer",void 0),_rollupPluginBabelHelpers.defineProperty(this,"restartCount",0),_rollupPluginBabelHelpers.defineProperty(this,"closeLog",!0),_rollupPluginBabelHelpers.defineProperty(this,"stopped",!1),_rollupPluginBabelHelpers.defineProperty(this,"haveVideoOn",!1),_rollupPluginBabelHelpers.defineProperty(this,"rtcStateCallback",null),_rollupPluginBabelHelpers.defineProperty(this,"startRtcTimeout",(function(){_this.timeoutStarted||(_this.timeoutEvent.start(),_this.timeoutStarted=!0)})),_rollupPluginBabelHelpers.defineProperty(this,"clearRtcTimeout",(function(){_this.timeoutStarted&&(_this.timeoutEvent.clear(),_this.timeoutStarted=!1)})),_rollupPluginBabelHelpers.defineProperty(this,"mergeRtcConfig",(function(partial){_this.rtcConfig&&partial&&Object.keys(partial).length&&Object.assign(_this.rtcConfig,partial)})),_rollupPluginBabelHelpers.defineProperty(this,"openRtc",(function(rtcConnection){if(_this.stopped=!1,_this.restarting)!_this.closeLog&&console.warn("rtc restarting");else if(rtcConnection&&(_this.rtcConnection=rtcConnection),_this.rtcConnection&&!isEmpty(_this.rtcConnection)){var _this$client,_this$rtcConnection=_this.rtcConnection,server=_this$rtcConnection.server,appId=_this$rtcConnection.appId,token=_this$rtcConnection.token,roomName=_this$rtcConnection.roomName,userId=_this$rtcConnection.userId,_ref=_this.rtcCallback||{},_onRemotedata=_ref.onRemotedata,_onLocalStream=_ref.onLocalStream,_onRemoteVideoComing=_ref.onRemoteVideoComing,_onLocalVideoPublished=_ref.onLocalVideoPublished,_onLocalVideoPublishing=_ref.onLocalVideoPublishing,_onRemoteVideoOn=_ref.onRemoteVideoOn,_onRemoteVideoOff=_ref.onRemoteVideoOff,_onRemoteVideoLoading=_ref.onRemoteVideoLoading,_onSuccess=_ref.onSuccess,_onError=_ref.onError,_onLocalVideoConnected=_ref.onLocalVideoConnected,_onRemoteVideoConnected=_ref.onRemoteVideoConnected,_onRemoteMediaState=_ref.onRemoteMediaState,onPlayingError=_ref.onPlayingError,onDigitalHumanCallback=_ref.onDigitalHumanCallback;null===(_this$client=_this.client)||void 0===_this$client||_this$client.destroy(),_this.client=void 0,_this.startRtcTimeout(),_this.rtcStateCallback=function(data){var body=data.body,action=data.action;onDigitalHumanCallback&&onDigitalHumanCallback({status:_interface.statusEnum.DH_LIB_FULL_STATUS,content:{type:"rtcState",action:action,body:body}})},_this.client=new BrtcInstance({roomName:roomName,token:token,userId:userId,appId:appId,server:server,rtcConfig:_this.rtcConfig,callback:{onRemoteVideoConnected:function(id,connected){var _this$bizConfig;if(!connected&&!_this.haveVideoOn)var connectTimer=setTimeout((function(){_this.restartCount<3?(_this.restartCount=++_this.restartCount,_this.restartRtc&&_this.restartRtc(rtcConnection)):(_this.restartCount=0,_this.closeRtc()),clearTimeout(connectTimer)}),500);if(connected&&!1!==(null===(_this$bizConfig=_this.bizConfig)||void 0===_this$bizConfig?void 0:_this$bizConfig.remoteAutoPlay)){var videoElement=document.getElementById("remotevideo500");if(videoElement){videoElement.muted=!1;var promise=videoElement.play();void 0!==promise&&promise.catch((function(){videoElement.muted=!0,videoElement.play().catch((function(e){!_this.closeLog&&console.info("videoElement play error",e),onPlayingError&&onPlayingError(videoElement),onDigitalHumanCallback&&onDigitalHumanCallback({status:_interface.statusEnum.DH_LIB_ERROR,content:{type:_interface.errorTypeEnum.LOCAL_VIDEO_ERROR}}),_this.rtcStateCallback&&_this.rtcStateCallback({action:"localVideoError",body:!0})})),onDigitalHumanCallback&&onDigitalHumanCallback({status:_interface.statusEnum.DH_LIB_STATUS,content:{type:_interface.errorTypeEnum.LOCAL_VIDEO_MUTED}}),_this.rtcStateCallback&&_this.rtcStateCallback({action:"localVideoMuted",body:!0})}))}else!_this.closeLog&&console.error("videoElement is null!")}!_this.closeLog&&console.info("remoteVideoConnected",id,connected,_this.restartCount),_this.rtcStateCallback&&_this.rtcStateCallback({action:"remoteVideoConnected",body:{id:id,connected:connected,restartCount:_this.restartCount}}),isFunction(_onRemoteVideoConnected)&&_onRemoteVideoConnected(id,connected)},onRemoteVideoOn:function(id){_this.haveVideoOn=!0,!_this.closeLog&&console.info("remotevideoon by id: ",id),_this.clearRtcTimeout();var rtcContainer=document.querySelector("#starlingRtcContainer"),therevideo=rtcContainer&&rtcContainer.lastChild;therevideo&&(therevideo.style.display="none"),_this.rtcStateCallback&&_this.rtcStateCallback({action:"remotevideoon",body:id}),onDigitalHumanCallback&&onDigitalHumanCallback({status:_interface.statusEnum.DH_LIB_OPEN}),isFunction(_onRemoteVideoOn)&&_onRemoteVideoOn(id)},onRemoteMediaState:function(id,medium,connected){!_this.closeLog&&console.info("remoteMediaState",id,medium,connected),_this.rtcStateCallback&&_this.rtcStateCallback({action:"remoteMediaState",body:{id:id,medium:medium,connected:connected}}),isFunction(_onRemoteMediaState)&&_onRemoteMediaState(id,medium,connected)},onLocalVideoConnected:function(connected){!_this.closeLog&&console.info("localVideoConnected",connected),_this.rtcStateCallback&&_this.rtcStateCallback({action:"localVideoConnected",body:{connected:connected}}),isFunction(_onLocalVideoConnected)&&_onLocalVideoConnected(connected)},onRemotedata:function(data){if(_this.rtcConfig&&_this.rtcConfig.usingdatachannel){var msg=CustomJSON.parse(data);!_this.closeLog&&console.info("RTC - receive:",msg),isFunction(_onRemotedata)&&_onRemotedata(msg)}},onLocalStream:function(stream,name){!_this.closeLog&&console.info("rtc - onlocalstream by name: "+name),_this.rtcStateCallback&&_this.rtcStateCallback({action:"onlocalstream",body:{stream:stream,name:name}}),isFunction(_onLocalStream)&&_onLocalStream(stream,name)},onLocalVideoPublished:function(){!_this.closeLog&&console.info("LocalVideoPublished 本地视频发布成功"),_this.rtcStateCallback&&_this.rtcStateCallback({action:"localvideopublished_ok",body:!0}),isFunction(_onLocalVideoPublished)&&_onLocalVideoPublished()},onLocalVideoPublishing:function(){!_this.closeLog&&console.info("LocalVideoPublishing 本地视频发布成功"),_this.rtcStateCallback&&_this.rtcStateCallback({action:"localvideopublishing",body:!0}),isFunction(_onLocalVideoPublishing)&&_onLocalVideoPublishing()},onRemoteVideoComing:function(id){!_this.closeLog&&console.info("remotevideocoming",id),_this.rtcStateCallback&&_this.rtcStateCallback({action:"remotevideocoming",body:id}),isFunction(_onRemoteVideoComing)&&_onRemoteVideoComing(id)},onRemoteVideoLoading:function(id){!_this.closeLog&&console.info("remotevideoloading by id: ",id),_this.rtcStateCallback&&_this.rtcStateCallback({action:"remotevideoloading",body:id}),isFunction(_onRemoteVideoLoading)&&_onRemoteVideoLoading(id)},onRemoteVideoOff:function(id){if(!_this.stopped){var videoEle=document.getElementById("remotevideo500");videoEle&&videoEle.pause(),!_this.closeLog&&console.info("remotevideooff: ",id),_this.isRtcVideoOn=!1,_this.rtcStateCallback&&_this.rtcStateCallback({action:"remotevideooff",body:id}),onDigitalHumanCallback&&onDigitalHumanCallback({status:_interface.statusEnum.DH_LIB_CLOSE}),isFunction(_onRemoteVideoOff)&&_onRemoteVideoOff(id),_this.startRtcTimeout()}},onSuccess:function(){!_this.closeLog&&console.info("rtc - success"),_this.rtcStateCallback&&_this.rtcStateCallback({action:"success",body:!0}),isFunction(_onSuccess)&&_onSuccess()},onError:function(e){_this.stopped||(_this.isRtcVideoOn=!1,!_this.closeLog&&console.error("rtc - error:",e),_this.rtcStateCallback&&_this.rtcStateCallback({action:"error",body:e}),onDigitalHumanCallback&&onDigitalHumanCallback({status:_interface.statusEnum.DH_LIB_ERROR,content:{type:_interface.errorTypeEnum.RTC_ERROR}}),isFunction(_onError)&&_onError(e),(e.includes("Lost connection to the server")||e.includes("Is the server down"))&&_this.restartRtc&&_this.restartRtc(rtcConnection))}}})}})),_rollupPluginBabelHelpers.defineProperty(this,"closeRtc",(function(){var _this$client2;_this.stopped=!0,_this.clearRtcTimeout(),clearTimeout(_this.reopenTimer),null===(_this$client2=_this.client)||void 0===_this$client2||_this$client2.destroy(),_this.client=void 0,_this.restarting=!1})),_rollupPluginBabelHelpers.defineProperty(this,"restartRtc",(function(rtcConnection){_this.stopped||!_this.restarting&&_this.bizConfig&&_this.bizConfig.autoReConnect&&(_this.rtcStateCallback&&_this.rtcStateCallback({action:"restartRtc",body:rtcConnection}),_this.restarting=!0,_this.closeRtc(),_this.reopenTimer=setTimeout((function(){!_this.closeLog&&console.error("拉流失败,开始重启"),_this.restarting=!1,_this.openRtc(rtcConnection)}),2e3))}));var _rtcConnection=props.rtcConnection,rtcConfig=props.rtcConfig,_props$closeLog=props.closeLog,closeLog=void 0===_props$closeLog||_props$closeLog,rtcCallback=props.rtcCallback,bizConfig=props.bizConfig;this.rtcConnection=_rtcConnection,this.rtcConfig=rtcConfig,this.rtcCallback=rtcCallback,this.closeLog=closeLog,this.bizConfig=bizConfig,this.timeoutEvent=new starlingTimeoutController.TimeoutController(6e4,(function(){if(_this.timeoutStarted=!1,!_this.stopped)return _this.rtcConnection?void(_this.restartRtc&&_this.restartRtc(_this.rtcConnection)):!_this.closeLog&&console.warn("remotevideoon事件超时, rtcConnectionRef is null")}))}return _rollupPluginBabelHelpers.createClass(BrtcClient,[{key:"muteMicphone",value:function(mute){this.client&&this.client.muteMicphone&&this.client.muteMicphone(mute)}}]),BrtcClient}();exports.default=BrtcClient;
|
package/cjs/Client.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./_virtual/_rollupPluginBabelHelpers.js"),t=require("@bddh/starling-json"),r=require("lodash/isEmpty"),n=require("lodash/omit"),a=require("lodash/pick"),o=require("uuid"),i=require("./interface.js"),s=require("./Server.js"),c=require("./BrtcClient.js"),u=require("./DomControl.js"),l=require("./Cutout.js"),d=require("./RecordController.js"),m=function(m,h,p){function v(r){var c,l=this;e.classCallCheck(this,v),e.defineProperty(this,"token",void 0),e.defineProperty(this,"appKey",void 0),e.defineProperty(this,"appId",void 0),e.defineProperty(this,"connectParams",void 0),e.defineProperty(this,"onDigitalHumanCallback",void 0),e.defineProperty(this,"dhServer",void 0),e.defineProperty(this,"rtcServer",void 0),e.defineProperty(this,"rtcConnectParams",void 0),e.defineProperty(this,"cutoutInstance",void 0),e.defineProperty(this,"hasInitChromaEffects",!1),e.defineProperty(this,"isHuawei",u.checkIsHuawei()),e.defineProperty(this,"rtcServerUrl",void 0),e.defineProperty(this,"rtcInternalIp",void 0),e.defineProperty(this,"recordController",null),e.defineProperty(this,"wsReadyState",-1),e.defineProperty(this,"isPreOpenSession",!1),e.defineProperty(this,"openWsOnly",!1),e.defineProperty(this,"hasConnectUserFigureEffects",!1),e.defineProperty(this,"_isMicMuted",!1),e.defineProperty(this,"mergeConnectRtcExtras",!1),e.defineProperty(this,"emitRawStatusMessage",!1),e.defineProperty(this,"resolveMediaServerByDomain",void 0),e.defineProperty(this,"remoteAutoPlay",!0),e.defineProperty(this,"onDigitalHumanCallbackPlus",(function(e){var t,r,n=e.content;e.status===i.statusEnum.DH_LIB_FULL_STATUS&&"wsState"===(null==n?void 0:n.type)&&(l.wsReadyState=n.readyState,3===n.readyState&&(null===(t=l.cutoutInstance)||void 0===t||t.setPlaying(!1),null===(r=l.rtcServer)||void 0===r||r.closeRtc(),l.canShowStaticFrameCover()&&(u.setHumanPlayerWrapperVisible(!1),u.setLastFrameCoverVisible(!0))));l.onDigitalHumanCallback&&l.onDigitalHumanCallback(e)})),e.defineProperty(this,"onRemoteVideoComing",(function(e){l.rtcConnectParams&&l.rtcConnectParams.feedId&&e===+l.rtcConnectParams.feedId&&l.rtcServer&&l.rtcServer.client&&l.rtcServer.client.subscribeStreaming("remotevideo500",+l.rtcConnectParams.feedId)})),e.defineProperty(this,"onLocalStream",(function(){(l.connectParams||{}).pullAudioFromRtc&&l.rtcServer&&l.rtcServer.muteMicphone(l._isMicMuted)})),e.defineProperty(this,"onRemoteVideoOn",(function(){setTimeout(e.asyncToGenerator(e.regeneratorRuntime().mark((function t(){var r;return e.regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=document.getElementById(u.RTC_VIDEO_ID),!l.cutoutInstance||!r){e.next=5;break}return l.cutoutInstance.setPlaying(!0),e.next=5,l.cutoutInstance.updateSource(r);case 5:l.canShowStaticFrameCover()&&(u.captureLastFrameToCover(),u.setHumanPlayerWrapperVisible(!0),u.setLastFrameCoverVisible(!1));case 6:case"end":return e.stop()}}),t)}))),100)})),e.defineProperty(this,"onRemoteVideoConnected",(function(e,t){var r;if(t&&!l.remoteAutoPlay){var n=null===(r=l.rtcConnectParams)||void 0===r?void 0:r.feedId;null!=n&&e!==+n||l.onRemoteVideoOn()}})),e.defineProperty(this,"onRemoteVideoOffLastFrame",(function(){var e;null===(e=l.cutoutInstance)||void 0===e||e.setPlaying(!1),l.canShowStaticFrameCover()&&u.setLastFrameCoverVisible(!0)})),e.defineProperty(this,"connectListener",(function(e){l.handleConnectResponse(e).catch((function(e){console.warn("[DhRealtimeHuman] handleConnectResponse failed",e)}))})),e.defineProperty(this,"createServer",(function(t){var r,o=e.objectSpread2(e.objectSpread2(e.objectSpread2({token:l.token,appKey:l.appKey,appId:l.appId},t?{sessionId:t}:{}),a(l.connectParams,i.CONNECT_MAIN_KEY)),{},{parameters:n(l.connectParams,i.CONNECT_MAIN_KEY),onConnect:l.connectListener,onDigitalHumanCallback:l.onDigitalHumanCallbackPlus});null!==(r=l.dhServer)&&void 0!==r&&r.preConnectSuccess?(l.dhServer.connectParams=o,l.dhServer&&l.dhServer.sendPreConnect(o)):l.openWsOnly?l.dhServer&&l.dhServer.sendConnect(o):l.dhServer&&l.dhServer.createSocket(o)})),e.defineProperty(this,"checkHumanInstansce",(function(){return l.dhServer?!(l.isPreOpenSession&&!l.dhServer.preConnectSuccess)||(l.onDigitalHumanCallback&&l.onDigitalHumanCallback({status:i.statusEnum.DH_LIB_ERROR,content:{type:i.errorTypeEnum.CONNECT_ERROR,msg:{code:4001,errMsg:"webSocket连接中"}}}),!1):(l.onDigitalHumanCallback&&l.onDigitalHumanCallback({status:i.statusEnum.DH_LIB_ERROR,content:{type:i.errorTypeEnum.CONNECT_ERROR,msg:{code:4002,errMsg:"请先初始化数字人实例"}}}),!1)})),e.defineProperty(this,"sendMessage",(function(e,t){return l.dhServer&&l.dhServer.sendMessage(e,t)})),e.defineProperty(this,"interrupt",e.asyncToGenerator(e.regeneratorRuntime().mark((function t(){return e.regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",new Promise((function(e){l.dhServer&&l.dhServer.sendMessage({requestId:o.v4(),action:"TEXT_RENDER",body:"<interrupt></interrupt>",clientTs:(new Date).getTime()},(function(){return e()}))})));case 1:case"end":return e.stop()}}),t)})))),e.defineProperty(this,"textRender",(function(e){var t=e.requestId,r=e.body,n=e.onCallbackMsg;l.checkHumanInstansce()&&l.dhServer&&l.dhServer.sendMessage({requestId:t||o.v4(),action:"TEXT_RENDER",body:r,clientTs:(new Date).getTime()},n)})),e.defineProperty(this,"textStreamRender",(function(e){var r=e.requestId,n=e.body,a=e.onCallbackMsg,i=t.parse(n).first;l.checkHumanInstansce()&&l.dhServer&&l.dhServer.sendMessage({requestId:r||o.v4(),action:"TEXT_STREAM_RENDER",body:n,clientTs:(new Date).getTime()},i?a:null)})),e.defineProperty(this,"audioRender",(function(e){var t=e.body,r=e.onCallbackMsg;l.checkHumanInstansce()&&l.dhServer&&l.dhServer.sendMessage({requestId:o.v4(),action:"AUDIO_RENDER",body:t,clientTs:(new Date).getTime()},r)})),e.defineProperty(this,"audioStreamRender",(function(e){var t=e.requestId,r=e.body,n=e.onCallbackMsg;l.checkHumanInstansce()&&l.dhServer&&l.dhServer.sendMessage({requestId:t||o.v4(),action:"AUDIO_STREAM_RENDER",body:r,clientTs:(new Date).getTime()},n)})),e.defineProperty(this,"textQuery",(function(e){var t=e.requestId,r=e.body,n=e.onCallbackMsg;l.dhServer&&l.dhServer.sendMessage({requestId:t||o.v4(),action:"TEXT_QUERY",body:r,clientTs:(new Date).getTime()},n)})),e.defineProperty(this,"handleDestroyView",(function(e){var t,r;return e?l.canShowStaticFrameCover()?(u.playHumanVideo(!1),u.setHumanPlayerWrapperVisible(!1),void u.setLastFrameCoverVisible(!0)):void(null===(t=l.cutoutInstance)||void 0===t||t.setPlaying(!1)):(null===(r=l.cutoutInstance)||void 0===r||r.destroy(),l.cutoutInstance=void 0,u.removeHumanDom(),void u.removeLastFrameCoverWrapper())})),e.defineProperty(this,"destroy",(function(t){return(c=c||e.asyncToGenerator(e.regeneratorRuntime().mark((function t(r){var n,a,o;return e.regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a=(r||{}).keepLastFrame,o=void 0!==a&&a,l.handleDestroyView(o),e.next=4,l.dhServer&&l.dhServer.closeSocket();case 4:l.rtcServer&&l.rtcServer.closeRtc(),null===(n=l.recordController)||void 0===n||n.destroy(),l.dhServer=null,l.rtcServer=null;case 8:case"end":return e.stop()}}),t)})))).apply(this,arguments)})),e.defineProperty(this,"pauseHuman",(function(){return u.playHumanVideo(!1)})),e.defineProperty(this,"playHuman",(function(){return u.playHumanVideo(!0)})),e.defineProperty(this,"muteHuman",(function(){return u.muteHumanVideo(!0)})),e.defineProperty(this,"unMuteHuman",(function(){var e=u.muteHumanVideo(!1);try{return l.isHuawei?(e.pause(),e.play()):e.paused&&e.play()}catch(e){console.info(e)}}));var d=r.isPreOpenSession,m=void 0!==d&&d,h=r.isOpenWsOnly,p=void 0!==h&&h,f=r.wsUrl,y=r.renderParams,C=r.checkHeartbeatMismatch,S=r.emitRawStatusMessage,R=void 0!==S&&S,g=r.onDigitalHumanCallback;this.isPreOpenSession=m,this.openWsOnly=p,this.emitRawStatusMessage=R,this.dhServer=new s.default(f||"wss://open.xiling.baidu.com/cloud/digital-human-demonstration",{checkHeartbeatMismatch:C,emitRawStatusMessage:R}),this.onDigitalHumanCallback=function(e){e.status!==i.statusEnum.DH_LIB_FULL_STATUS?g&&g(e):(null==y?void 0:y.fullStatus)&&g&&g(e)},m||p?this.dhServer.createSocket({onDigitalHumanCallback:this.onDigitalHumanCallbackPlus},m):this.init(r)}return e.createClass(v,[{key:"canShowStaticFrameCover",value:function(){return!this.hasInitChromaEffects&&!this.hasConnectUserFigureEffects}},{key:"init",value:function(t){var n,a,o=this,s=t.wrapperId,m=t.token,h=t.appKey,p=t.appId,v=t.connectParams,f=t.renderParams,y=void 0===f?{}:f,C=t.rtcConnectParams,S=t.brtcParams,R=t.rtcServerUrl,g=t.rtcInternalIp,I=t.mergeConnectRtcExtras,b=void 0!==I&&I,P=t.emitRawStatusMessage,k=void 0!==P&&P,E=t.remoteAutoPlay,D=t.resolveMediaServerByDomain;if(this.mergeConnectRtcExtras=Boolean(b),this.emitRawStatusMessage=k,null===(n=this.dhServer)||void 0===n||n.setEmitRawStatusMessage(this.emitRawStatusMessage),this.resolveMediaServerByDomain=D,this.remoteAutoPlay=!1!==E,this.hasConnectUserFigureEffects=!1,this.token=m,this.appKey=h,this.appId=p,this.rtcServerUrl=R,this.rtcInternalIp=g,this.connectParams=e.objectSpread2({autoChromaKey:(null==y?void 0:y.autoChromaKey)||!1},v),!p&&!h&&!m)throw new Error("appId and appKey or token is required");var w=y.closeLog,H=y.audio3AConstraints;this.hasInitChromaEffects=!r(null==y?void 0:y.chromaEffects)||!(null==y||!y.autoChromaKey),u.removeLastFrameCoverWrapper(),u.removeHumanDom();var M=(u.createHumanDom({autoChromaKey:!!y.autoChromaKey||!r(y.chromaEffects),autoplay:!1!==E})||{}).playerWrapper,T=document.getElementById(s||"");T||console.error("dom with wrapperId is not find"),M&&T&&T.appendChild(M),this.canShowStaticFrameCover()&&T&&("static"===window.getComputedStyle(T).position&&(T.style.position="relative"),u.appendLastFrameCoverSibling(T)),u.appendRtcDomStyle();var _=e.objectSpread2({remotevideoviewid:s,showvideobps:!1,usingvideo:!1,usingaudio:!(null==v||!v.pullAudioFromRtc),aspublisher:!(null==v||!v.pullAudioFromRtc),autopublish:!(null==v||!v.pullAudioFromRtc),usingdatachannel:!0,autoplaymuted:!1},S);this.rtcServer=new c.default({closeLog:w,videoWrapperId:u.RTC_VIDEO_ID,rtcConfig:_,bizConfig:e.objectSpread2({autoReConnect:null===(a=null==v?void 0:v.reConnect)||void 0===a||a},void 0!==E?{remoteAutoPlay:E}:{}),rtcCallback:{onRemoteVideoComing:this.onRemoteVideoComing,onDigitalHumanCallback:this.onDigitalHumanCallback,onLocalStream:this.onLocalStream,onRemoteVideoOn:this.onRemoteVideoOn,onRemoteVideoOff:this.onRemoteVideoOffLastFrame,onRemoteVideoConnected:this.onRemoteVideoConnected}}),(!r(null==y?void 0:y.chromaEffects)||null!=y&&y.autoChromaKey)&&(this.cutoutInstance=new l.default({sourceId:u.RTC_VIDEO_ID,effects:null==y?void 0:y.chromaEffects})),r(C)||(this.rtcConnectParams=C,this.rtcServer.openRtc(C)),null!=v&&v.pullAudioFromRtc?this.recordController=null:this.recordController=new d.default({pickAudioMode:null==v?void 0:v.pickAudioMode,audio3AConstraints:H,asrSample:null==v?void 0:v.asrSample,onAudioData:function(e){1===o.wsReadyState&&o.sendMessage(e,null)},onError:function(e){o.onDigitalHumanCallback&&o.onDigitalHumanCallback({status:i.statusEnum.DH_LIB_ERROR,content:{type:i.errorTypeEnum.CONNECT_ERROR,msg:{code:-1,errMsg:e.message}}})}})}},{key:"handleConnectResponse",value:function(r){return(m=m||e.asyncToGenerator(e.regeneratorRuntime().mark((function r(n){var a,o,s,c,u,l,d,m,h,p,v;return e.regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(a=n.code,o=n.body,s=n.message,0===a&&this.onDigitalHumanCallback&&this.onDigitalHumanCallback({status:i.statusEnum.DH_LIB_WS_SUCCESS,content:n}),this.emitRawStatusMessage&&this.onDigitalHumanCallback&&this.onDigitalHumanCallback({status:i.statusEnum.DH_LIB_MESSAGE,content:n}),0!==a){e.next=18;break}if(c=t.parse(o),!this.mergeConnectRtcExtras||!this.rtcServer){e.next=14;break}return e.prev=6,e.next=9,this.mergeConnectRtcExtrasFromBody(c);case 9:e.next=14;break;case 11:e.prev=11,e.t0=e.catch(6),console.warn("[DhRealtimeHuman] mergeConnectRtcExtrasFromBody failed",e.t0);case 14:u=c.rtcServerUrl,l=c.appId,d=c.clientToken,m=c.roomName,h=c.clientId,p=c.feedId,v=c.chargeId,l&&m&&(this.rtcConnectParams={server:this.rtcServerUrl||u,appId:l,token:d,roomName:m,userId:h,feedId:p,chargeId:v},this.rtcServer&&this.rtcServer.openRtc(this.rtcConnectParams)),e.next=19;break;case 18:this.onDigitalHumanCallback&&this.onDigitalHumanCallback({status:i.statusEnum.DH_LIB_ERROR,content:{type:i.errorTypeEnum.CONNECT_ERROR,msg:{code:a,errMsg:s}}});case 19:case"end":return e.stop()}}),r,this,[[6,11]])})))).apply(this,arguments)}},{key:"mergeConnectRtcExtrasFromBody",value:function(r){return(h=h||e.asyncToGenerator(e.regeneratorRuntime().mark((function r(n){var a,o,i,s,c,u,l;return e.regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.rtcServer){e.next=2;break}return e.abrupt("return");case 2:if(a=n.userFigure,o=void 0===a?"":a,i=n.rtcExternalInfo,s=(void 0===i?{}:i).udpDomain||"",c={},this.rtcInternalIp&&(c.mediaserverip=this.rtcInternalIp),!o){e.next=19;break}if(!(u=t.parse(o)).effects){e.next=17;break}return e.prev=9,e.next=12,this.applyConnectChroma(u.effects);case 12:e.next=17;break;case 14:e.prev=14,e.t0=e.catch(9),console.warn("[DhRealtimeHuman] applyConnectChroma failed",e.t0);case 17:e.next=36;break;case 19:if(!s){e.next=36;break}if(l=this.resolveMediaServerByDomain){e.next=26;break}console.warn("[DhRealtimeHuman] udpDomain 解析需传入 resolveMediaServerByDomain"),c.mediaserverip="",e.next=36;break;case 26:return e.prev=26,e.next=29,l(s);case 29:c.mediaserverip=e.sent,e.next=36;break;case 32:e.prev=32,e.t1=e.catch(26),c.mediaserverip="",console.error("resolveMediaServerByDomain failed",e.t1);case 36:this.rtcServer.mergeRtcConfig(c);case 37:case"end":return e.stop()}}),r,this,[[9,14],[26,32]])})))).apply(this,arguments)}},{key:"applyConnectChroma",value:function(t){return(p=p||e.asyncToGenerator(e.regeneratorRuntime().mark((function t(r){var n,a,o,i;return e.regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.hasInitChromaEffects){e.next=2;break}return e.abrupt("return");case 2:if(a=r.chromaKey,o=r.version,null!=a){e.next=5;break}return e.abrupt("return");case 5:if(u.ensureCutoutDomMounted()){e.next=7;break}return e.abrupt("return");case 7:if(this.hasConnectUserFigureEffects=!0,u.removeLastFrameCoverWrapper(),u.setLastFrameCoverVisible(!1),u.setHumanPlayerWrapperVisible(!0),null===(n=this.cutoutInstance)||void 0===n||n.destroy(),this.cutoutInstance=new l.default({sourceId:u.RTC_VIDEO_ID,effects:{version:o,chromaKey:a}}),!(i=document.getElementById(u.RTC_VIDEO_ID))){e.next=17;break}return e.next=17,this.cutoutInstance.updateSource(i);case 17:case"end":return e.stop()}}),t,this)})))).apply(this,arguments)}},{key:"startRecord",value:function(){var e;null!==(e=this.connectParams)&&void 0!==e&&e.pullAudioFromRtc?this.rtcServer&&this.rtcServer.muteMicphone(!1):this.recordController&&this.recordController.start()}},{key:"stopRecord",value:function(){var e;if(null!==(e=this.connectParams)&&void 0!==e&&e.pullAudioFromRtc)return this.rtcServer&&this.rtcServer.muteMicphone(!0),void this.sendMessage({action:"AUDIO_QUERY_INTERRUPT",requestId:o.v4(),clientTs:Date.now(),body:""},null);this.recordController&&this.recordController.stop(),this.sendMessage({action:"AUDIO_QUERY_INTERRUPT",requestId:o.v4(),clientTs:Date.now(),body:""},null)}},{key:"muteMicrophone",value:function(e){var t,r;null!==(t=this.connectParams)&&void 0!==t&&t.pullAudioFromRtc&&(this._isMicMuted=e,null===(r=this.rtcServer)||void 0===r||r.muteMicphone(e))}}]),v}();exports.default=m;
|
|
1
|
+
"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;
|
package/cjs/Cutout.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var _rollupPluginBabelHelpers=require("./_virtual/_rollupPluginBabelHelpers.js"),Seriously=require("@bddh/starling-cutout/es/Seriously"),DEFAULT_EFFECTS={version:2,chromaKey:{screen:[53,186,123],similarity:90,edgeShrink:3,smoothness:80,spill:100,opacity:1,contrast:0,brightness:0,gamma:0}},Cutout=function(){function Cutout(props){_rollupPluginBabelHelpers.classCallCheck(this,Cutout),_rollupPluginBabelHelpers.defineProperty(this,"cutoutInstance",void 0),_rollupPluginBabelHelpers.defineProperty(this,"sourceId",void 0);var effects=props.effects,sourceId=props.sourceId;this.sourceId=sourceId||"starling-cutout-video",this.cutoutInstance=new Seriously("starling-cutout-canvas",this.sourceId,effects&&effects.chromaKey||DEFAULT_EFFECTS.chromaKey,effects&&effects.version||DEFAULT_EFFECTS.version),this.setPlaying(!0)}return _rollupPluginBabelHelpers.createClass(Cutout,[{key:"setOptions",value:function(options){options&&this.cutoutInstance&&this.cutoutInstance.setOptions(options)}},{key:"destroy",value:function(){return this.cutoutInstance.destroy()}},{key:"setPlaying",value:function(playing){var source=document.getElementById(this.sourceId);source?source.setAttribute("data-playing",playing?"true":"false"):console.warn("[Cutout] video element not found: #".concat(this.sourceId,", skip setPlaying(").concat(playing,")"))}},{key:"updateSource",value:function(video){return"string"==typeof video&&(this.sourceId=video),this.setPlaying(!0),this.cutoutInstance.updateSource(video)}}]),Cutout}();exports.DEFAULT_EFFECTS=DEFAULT_EFFECTS,exports.default=Cutout;
|
package/cjs/DomControl.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var HUMAN_WRAPPER_ID="cloud-brtc-player-wrapper",RTC_VIDEO_ID="remotevideo500";exports.DEFAULT_CANVAS_ID="starling-cutout-canvas",exports.HUMAN_WRAPPER_ID=HUMAN_WRAPPER_ID,exports.LAST_FRAME_COVER_CANVAS_CLASS="canvas-item",exports.LAST_FRAME_COVER_INNER_CANVAS_ID="starling-last-frame-cover-canvas",exports.RTC_VIDEO_ID=RTC_VIDEO_ID,exports.appendLastFrameCoverSibling=function(mountEl){if(mountEl&&!mountEl.querySelector("[".concat("data-dh-last-frame-cover",'="1"]'))){var wrap=document.createElement("div");wrap.className="".concat("canvas-item"," "),wrap.setAttribute("data-dh-last-frame-cover","1");var canvas=document.createElement("canvas");canvas.id="starling-last-frame-cover-canvas",Object.assign(canvas.style,{position:"absolute",top:"0",left:"0",width:"100%",height:"100%",objectFit:"cover",display:"block",zIndex:"0"}),wrap.appendChild(canvas),mountEl.appendChild(wrap)}},exports.appendRtcDomStyle=function(){var style=document.createElement("style");style.appendChild(document.createTextNode('\n [id^="videoremote1-"] {\n display: none !important;\n }\n \n video#remotevideo500 {\n width: auto !important;\n height: auto !important;\n max-width: 100% !important;\n max-height: 100% !important;\n width: 100% !important;\n height: 100% !important;\n object-fit: cover;\n }\n\n .cloud-brtc-player-wrapper {\n width: inherit !important;\n background-size: cover;\n height: inherit;\n display: flex;\n justify-content: center;\n }\n\n #starling-cutout-canvas {\n object-fit: cover;\n }\n\n [data-dh-last-frame-cover="1"] {\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n pointer-events: none;\n z-index: 1;\n visibility: hidden;\n }\n\n [data-dh-last-frame-cover="1"] canvas {\n width: 100%;\n height: 100%;\n object-fit: cover;\n display: block;\n }\n ')),document.head.appendChild(style)},exports.captureLastFrameToCover=function(){var cover=document.getElementById("starling-last-frame-cover-canvas");if(!cover)return!1;var ctx=cover.getContext("2d");if(!ctx)return!1;var chroma=document.getElementById("starling-cutout-canvas"),video=document.getElementById(RTC_VIDEO_ID);return chroma&&chroma.width>0&&chroma.height>0?(cover.width=chroma.width,cover.height=chroma.height,ctx.drawImage(chroma,0,0),!0):!!(video&&video.videoWidth>0&&video.videoHeight>0)&&(cover.width=video.videoWidth,cover.height=video.videoHeight,ctx.drawImage(video,0,0,video.videoWidth,video.videoHeight),!0)},exports.checkIsHuawei=function(){var ua=navigator.userAgent||navigator.vendor;return/huawei/i.test(ua)||/honor/i.test(ua)},exports.createHumanDom=function(options){var _options$autoChromaKe=options.autoChromaKey,autoChromaKey=void 0!==_options$autoChromaKe&&_options$autoChromaKe,_options$autoplay=options.autoplay,autoplay=void 0===_options$autoplay||_options$autoplay;if(document.getElementById(RTC_VIDEO_ID))return console.error('DOM with id "'.concat(RTC_VIDEO_ID,'" already exists.')),null;var playerWrapper=document.createElement("div");playerWrapper.className=HUMAN_WRAPPER_ID,playerWrapper.id=HUMAN_WRAPPER_ID,playerWrapper.style.position="relative";var video=document.createElement("video");if(video.id=RTC_VIDEO_ID,video.width=0,video.height=0,video.setAttribute("width","100%"),video.setAttribute("height","100%"),video.setAttribute("data-playing","true"),video.setAttribute("playsinline",""),autoplay&&video.setAttribute("autoplay",""),playerWrapper.appendChild(video),autoChromaKey){var canvas=document.createElement("canvas");canvas.id="starling-cutout-canvas",Object.assign(canvas.style,{position:"absolute",top:"0",left:"0",height:"100%",width:"100%",zIndex:"1",display:autoChromaKey?"block":"none"}),video.style.visibility="hidden",playerWrapper.appendChild(canvas)}return{playerWrapper:playerWrapper,video:video}},exports.ensureCutoutDomMounted=function(){if(document.getElementById("starling-cutout-canvas"))return!0;var wrapper=document.getElementById(HUMAN_WRAPPER_ID),video=document.getElementById(RTC_VIDEO_ID);if(!wrapper||!video)return!1;var canvas=document.createElement("canvas");return canvas.id="starling-cutout-canvas",Object.assign(canvas.style,{position:"absolute",top:"0",left:"0",height:"100%",width:"100%",zIndex:"1",display:"block"}),video.style.visibility="hidden",wrapper.appendChild(canvas),!0},exports.muteHumanVideo=function(muted){var humanVideoDom=document.getElementById(RTC_VIDEO_ID);return humanVideoDom&&(humanVideoDom.muted=muted),humanVideoDom},exports.playHumanVideo=function(play){var humanVideoDom=document.getElementById(RTC_VIDEO_ID);try{if(humanVideoDom)return play?humanVideoDom.play():humanVideoDom.pause()}catch(e){console.info(e)}},exports.removeHumanDom=function(){var humanDom=document.getElementById(HUMAN_WRAPPER_ID);humanDom&&humanDom.parentNode&&humanDom.parentNode.removeChild(humanDom)},exports.removeLastFrameCoverWrapper=function(){var wrap=document.querySelector("[".concat("data-dh-last-frame-cover",'="1"]'));null!=wrap&&wrap.parentNode&&wrap.parentNode.removeChild(wrap)},exports.setHumanPlayerWrapperVisible=function(visible){var el=document.getElementById(HUMAN_WRAPPER_ID);el&&(el.style.visibility=visible?"visible":"hidden",el.style.pointerEvents=visible?"":"none")},exports.setLastFrameCoverVisible=function(visible){var inner=document.getElementById("starling-last-frame-cover-canvas"),wrap=null==inner?void 0:inner.parentNode;wrap&&(wrap.style.visibility=visible?"visible":"hidden")};
|
package/cjs/RecordController.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var _rollupPluginBabelHelpers=require("./_virtual/_rollupPluginBabelHelpers.js");function sampleData(pcmDatas,pcmSampleRate,newSampleRate,prevChunkInfo){try{for(var index=(prevChunkInfo=prevChunkInfo||{})&&"number"==typeof prevChunkInfo.index?prevChunkInfo.index:0,offset=prevChunkInfo&&"number"==typeof prevChunkInfo.offset?prevChunkInfo.offset:0,size=0,i=index;i<pcmDatas.length;i++)size+=pcmDatas[i].length;size=Math.max(0,size-Math.floor(offset));var step=pcmSampleRate/newSampleRate;step>1?size=Math.floor(size/step):(step=1,newSampleRate=pcmSampleRate);for(var res=new Int16Array(size),idx=0,nl=pcmDatas.length;index<nl;index++){for(var o=pcmDatas[index],_i=offset,il=o.length;_i<il;){var before=Math.floor(_i),after=Math.ceil(_i),atPoint=_i-before;res[idx]=o[before]+(o[after]-o[before])*atPoint,idx++,_i+=step}offset=_i-il}return{index:index,offset:offset,sampleRate:newSampleRate,data:res}}catch(error){console.log("转音错误了",error)}}function convertBuffer(arrayBuffer){for(var data=arrayBuffer,out=new Int16Array(arrayBuffer.length),i=0;i<data.length;i++){var s=Math.max(-1,Math.min(1,data[i]));out[i]=s<0?32768*s:32767*s}return out}var RecordController=function(_preWarmStream,_start){function RecordController(options){_rollupPluginBabelHelpers.classCallCheck(this,RecordController),_rollupPluginBabelHelpers.defineProperty(this,"onAudioData",void 0),_rollupPluginBabelHelpers.defineProperty(this,"onError",void 0),_rollupPluginBabelHelpers.defineProperty(this,"audioContext",null),_rollupPluginBabelHelpers.defineProperty(this,"processor",null),_rollupPluginBabelHelpers.defineProperty(this,"mediaStream",null),_rollupPluginBabelHelpers.defineProperty(this,"recording",!1),_rollupPluginBabelHelpers.defineProperty(this,"audio3AConstraints",void 0),_rollupPluginBabelHelpers.defineProperty(this,"asrSample",void 0),this.onAudioData=options.onAudioData,this.onError=options.onError,this.audio3AConstraints=options.audio3AConstraints,this.asrSample=options.asrSample,this.preWarmStream()}return _rollupPluginBabelHelpers.createClass(RecordController,[{key:"preWarmStream",value:function(){return(_preWarmStream=_preWarmStream||_rollupPluginBabelHelpers.asyncToGenerator(_rollupPluginBabelHelpers.regeneratorRuntime().mark((function _callee(){var _navigator$mediaDevic,AudioCtx,source;return _rollupPluginBabelHelpers.regeneratorRuntime().wrap((function(_context){for(;;)switch(_context.prev=_context.next){case 0:if(_context.prev=0,AudioCtx=window.AudioContext||window.webkitAudioContext){_context.next=4;break}throw new Error("当前环境不支持web api: AudioContext");case 4:if(null!==(_navigator$mediaDevic=navigator.mediaDevices)&&void 0!==_navigator$mediaDevic&&_navigator$mediaDevic.getUserMedia){_context.next=6;break}throw new Error("当前环境不支持web api: getUserMedia");case 6:return this.audioContext=new AudioCtx({sampleRate:this.asrSample||16e3}),_context.next=9,navigator.mediaDevices.getUserMedia({audio:_rollupPluginBabelHelpers.objectSpread2({echoCancellation:!0,noiseSuppression:!0,autoGainControl:!0},this.audio3AConstraints),video:!1});case 9:this.mediaStream=_context.sent,source=this.audioContext.createMediaStreamSource(this.mediaStream),this.processor=this.audioContext.createScriptProcessor(1024,1,1),source.connect(this.processor),this.processor.connect(this.audioContext.destination),this.processor.onaudioprocess=function(){},_context.next=20;break;case 17:_context.prev=17,_context.t0=_context.catch(0),console.error("preWarmStream error",_context.t0);case 20:case"end":return _context.stop()}}),_callee,this,[[0,17]])})))).apply(this,arguments)}},{key:"start",value:function(){return(_start=_start||_rollupPluginBabelHelpers.asyncToGenerator(_rollupPluginBabelHelpers.regeneratorRuntime().mark((function _callee2(){var _this=this;return _rollupPluginBabelHelpers.regeneratorRuntime().wrap((function(_context2){for(;;)switch(_context2.prev=_context2.next){case 0:if(!this.recording){_context2.next=2;break}return _context2.abrupt("return");case 2:if(this.audioContext&&this.processor){_context2.next=4;break}return _context2.abrupt("return");case 4:try{this.processor.onaudioprocess=function(e){if(_this.recording){var resampled=sampleData([convertBuffer(e.inputBuffer.getChannelData(0))],_this.audioContext.sampleRate,_this.asrSample||16e3,null);resampled&&resampled.data&&_this.onAudioData(resampled.data.buffer)}},this.recording=!0}catch(err){this.onError&&this.onError(err)}case 5:case"end":return _context2.stop()}}),_callee2,this)})))).apply(this,arguments)}},{key:"stop",value:function(){this.recording=!1,this.processor.onaudioprocess=function(){}}},{key:"destroy",value:function(){this.recording=!1,this.processor&&(this.processor.disconnect(),this.processor.onaudioprocess=null),this.audioContext&&this.audioContext.close(),this.mediaStream&&this.mediaStream.getTracks().forEach((function(track){track.stop()}))}}]),RecordController}();exports.default=RecordController;
|
package/cjs/Server.d.ts
CHANGED
|
@@ -69,6 +69,7 @@ declare class Server {
|
|
|
69
69
|
createSocket: (props: createSocketParamsType, isPreOpenSession?: boolean) => Promise<WebSocketClient | null>;
|
|
70
70
|
sendConnect: (props: createSocketParamsType) => void;
|
|
71
71
|
closeSocket: () => Promise<void>;
|
|
72
|
+
destroySocket: () => Promise<void>;
|
|
72
73
|
handleConnect: () => Promise<void>;
|
|
73
74
|
sendMessage(message: DHServerInterface | ArrayBuffer, listener: RenderCallback | null): Promise<void>;
|
|
74
75
|
private startConnectingWatch;
|
package/cjs/Server.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./_virtual/_rollupPluginBabelHelpers.js"),t=require("uuid"),n=require("@bddh/starling-web-socket/es/create-web-socket"),r=require("lodash/pick"),o=require("lodash/omit"),s=require("lodash/get"),c=require("./interface.js"),a=function(a){function i(a,u){var d,l=this;e.classCallCheck(this,i),e.defineProperty(this,"dhServerSocket",null),e.defineProperty(this,"preConnectSuccess",!1),e.defineProperty(this,"connectParams",null),e.defineProperty(this,"socketClosingPromise",null),e.defineProperty(this,"url",void 0),e.defineProperty(this,"firstConnect",!0),e.defineProperty(this,"connectingTimer",null),e.defineProperty(this,"connectingMs",3e4),e.defineProperty(this,"lastPreOpen",!1),e.defineProperty(this,"reconnectingTimeout",!1),e.defineProperty(this,"lastReportedReadyState",-1),e.defineProperty(this,"lastHbAckTs",0),e.defineProperty(this,"checkHeartbeatMismatch",void 0),e.defineProperty(this,"emitRawStatusMessage",void 0),e.defineProperty(this,"sendPreConnect",(function(e,n){var r,o=e.token,s=e.sessionId,c=e.onConnect;null===(r=l.dhServerSocket)||void 0===r||r.request({action:"RE_CONNECT",requestId:t.v4(),body:JSON.stringify({token:o,sessionId:s})}).on((function(e,t){null==c||c(e),0!==e.code&&(t(),l.handleConnect()),null==n||n(l.dhServerSocket)})),l.firstConnect=!1})),e.defineProperty(this,"createSocket",(function(t,r){return(d=d||e.asyncToGenerator(e.regeneratorRuntime().mark((function t(r,o){var a,i;return e.regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(l.connectParams=r,l.lastPreOpen=!!o,a=r.sessionId,i=r.onDigitalHumanCallback,!l.socketClosingPromise){e.next=6;break}return e.next=6,l.socketClosingPromise;case 6:if(!l.dhServerSocket){e.next=9;break}return e.next=9,l.closeSocket();case 9:return e.abrupt("return",new Promise((function(e,t){var u=!1,d=function(t){u||(u=!0,e(t))},h={keepAlive:"heartbeat",checkHeartbeatMismatch:l.checkHeartbeatMismatch,reopen:s(l.connectParams,"reConnect",!0),getKeepAliveMessage:function(e){return{requestId:e,action:"HEART_BEAT",body:"".concat(l.lastHbAckTs),clientTs:Date.now()}},combine:function(e,t){return e&&t&&e.requestId===t.requestId},onOpen:function(){l.dhServerSocket=p,d(l.dhServerSocket),a&&l.firstConnect?l.sendPreConnect(r,d):o&&l.firstConnect||l.handleConnect()},onClose:function(){l.dhServerSocket=null,l.socketClosingPromise=null,d(null)},onError:function(e){t(e)}},p=n.createWebSocket(l.url,h);p.onReadyStateChange((function(e){l.lastReportedReadyState=e,0===e?(l.startConnectingWatch(),i&&i({status:c.statusEnum.DH_LIB_INIT})):(l.clearConnectingWatch(),l.reconnectingTimeout=!1),1===e&&o&&(l.preConnectSuccess=!0),3===e&&(l.preConnectSuccess=!1),i&&i({status:c.statusEnum.DH_LIB_FULL_STATUS,content:{type:"wsState",readyState:e,body:c.WS_STATUS_MAP[e]}})})),p.onMessage((function(e){var t=e.action;"HEART_BEAT"===t&&(l.lastHbAckTs=Date.now()),[c.errorTypeEnum.TIMEOUT_EXIT,c.errorTypeEnum.DISCONNECT_ALERT].includes(t)&&(i&&i({status:c.statusEnum.DH_LIB_STATUS,content:{type:t}}),l.emitRawStatusMessage&&i&&i({status:c.statusEnum.DH_LIB_MESSAGE,content:e})),[c.errorTypeEnum.TIMEOUT_EXIT,c.errorTypeEnum.DISCONNECT_ALERT,"HEART_BEAT","CONNECT"].includes(t)||i&&i({status:c.statusEnum.DH_LIB_MESSAGE,content:e})})),l.dhServerSocket=p,p.open()})));case 10:case"end":return e.stop()}}),t)})))).apply(this,arguments)})),e.defineProperty(this,"sendConnect",(function(e){l.connectParams=e,l.dhServerSocket&&l.handleConnect()})),e.defineProperty(this,"closeSocket",e.asyncToGenerator(e.regeneratorRuntime().mark((function t(){return e.regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(l.resetState(),l.dhServerSocket){e.next=3;break}return e.abrupt("return");case 3:return l.socketClosingPromise=l.dhServerSocket.close(),e.next=6,l.socketClosingPromise;case 6:l.dhServerSocket=null;case 7:case"end":return e.stop()}}),t)})))),e.defineProperty(this,"handleConnect",e.asyncToGenerator(e.regeneratorRuntime().mark((function n(){var s,a,i,u,d,h;return e.regeneratorRuntime().wrap((function(n){for(;;)switch(n.prev=n.next){case 0:if(l.connectParams){n.next=2;break}return n.abrupt("return");case 2:if(s=l.connectParams,a=s.appId,i=s.appKey,u=s.token,d=s.parameters,h=s.onConnect,a||i||u){n.next=5;break}return n.abrupt("return");case 5:l.dhServerSocket&&l.dhServerSocket.request({action:"CONNECT",clientTs:(new Date).getTime(),requestId:t.v4(),body:JSON.stringify(e.objectSpread2(e.objectSpread2({token:u,appId:a,appKey:i},r(l.connectParams,c.CONNECT_MAIN_KEY)),{},{parameters:e.objectSpread2(e.objectSpread2({},o(d,["parameters"])),d&&d.parameters?d.parameters:{})}))}).on((function(e,t){null==h||h(e),0!==e.code&&t()}));case 6:case"end":return n.stop()}}),n)}))));var h=u||{},p=h.checkHeartbeatMismatch,S=h.emitRawStatusMessage,m=void 0!==S&&S;this.url=a,this.checkHeartbeatMismatch=null!=p&&p,this.emitRawStatusMessage=m}return e.createClass(i,[{key:"setEmitRawStatusMessage",value:function(e){this.emitRawStatusMessage=e}},{key:"sendMessage",value:function(n,r){return(a=a||e.asyncToGenerator(e.regeneratorRuntime().mark((function n(r,o){var s;return e.regeneratorRuntime().wrap((function(n){for(;;)switch(n.prev=n.next){case 0:try{this.dhServerSocket&&this.dhServerSocket&&this.dhServerSocket.request(r).on((function(e){o&&o(e)}))}catch(n){s="object"===e.typeof(r)&&"requestId"in r?r.requestId:t.v4(),o&&o({code:-11,body:null,action:"RENDER_ERROR",requestId:s,message:JSON.stringify(n)})}case 1:case"end":return n.stop()}}),n,this)})))).apply(this,arguments)}},{key:"startConnectingWatch",value:function(){var t=this;this.connectingTimer||this.reconnectingTimeout||(this.connectingTimer=setTimeout(e.asyncToGenerator(e.regeneratorRuntime().mark((function n(){return e.regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t.connectingTimer=null,t.dhServerSocket&&0===t.lastReportedReadyState){e.next=3;break}return e.abrupt("return");case 3:if(console.warn("reconnect from CONNECTING timeout"),t.reconnectingTimeout=!0,e.prev=5,!t.connectParams){e.next=9;break}return e.next=9,t.createSocket(t.connectParams,t.lastPreOpen);case 9:e.next=14;break;case 11:e.prev=11,e.t0=e.catch(5),console.error("reconnect from CONNECTING timeout failed",e.t0);case 14:return e.prev=14,t.reconnectingTimeout=!1,e.finish(14);case 17:case"end":return e.stop()}}),n,null,[[5,11,14,17]])}))),this.connectingMs))}},{key:"clearConnectingWatch",value:function(){this.connectingTimer&&(clearTimeout(this.connectingTimer),this.connectingTimer=null)}},{key:"resetState",value:function(){this.clearConnectingWatch(),this.reconnectingTimeout=!1,this.lastReportedReadyState=-1,this.lastHbAckTs=0}}]),i}();exports.CONNECTING_STUCK_MS_DEFAULT=3e4,exports.default=a;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var _rollupPluginBabelHelpers=require("./_virtual/_rollupPluginBabelHelpers.js"),uuid=require("uuid"),createWebSocket=require("@bddh/starling-web-socket/es/create-web-socket"),_interface$1=require("@bddh/starling-web-socket/es/interface"),pick=require("lodash/pick"),omit=require("lodash/omit"),get=require("lodash/get"),_interface=require("./interface.js"),Server=function(_sendMessage){function Server(url,options){var _ref,_this=this;_rollupPluginBabelHelpers.classCallCheck(this,Server),_rollupPluginBabelHelpers.defineProperty(this,"dhServerSocket",null),_rollupPluginBabelHelpers.defineProperty(this,"preConnectSuccess",!1),_rollupPluginBabelHelpers.defineProperty(this,"connectParams",null),_rollupPluginBabelHelpers.defineProperty(this,"socketClosingPromise",null),_rollupPluginBabelHelpers.defineProperty(this,"url",void 0),_rollupPluginBabelHelpers.defineProperty(this,"firstConnect",!0),_rollupPluginBabelHelpers.defineProperty(this,"connectingTimer",null),_rollupPluginBabelHelpers.defineProperty(this,"connectingMs",3e4),_rollupPluginBabelHelpers.defineProperty(this,"lastPreOpen",!1),_rollupPluginBabelHelpers.defineProperty(this,"reconnectingTimeout",!1),_rollupPluginBabelHelpers.defineProperty(this,"lastReportedReadyState",-1),_rollupPluginBabelHelpers.defineProperty(this,"lastHbAckTs",0),_rollupPluginBabelHelpers.defineProperty(this,"checkHeartbeatMismatch",void 0),_rollupPluginBabelHelpers.defineProperty(this,"emitRawStatusMessage",void 0),_rollupPluginBabelHelpers.defineProperty(this,"sendPreConnect",(function(props,resolve){var _this$dhServerSocket,token=props.token,sessionId=props.sessionId,onConnect=props.onConnect;null===(_this$dhServerSocket=_this.dhServerSocket)||void 0===_this$dhServerSocket||_this$dhServerSocket.request({action:"RE_CONNECT",requestId:uuid.v4(),body:JSON.stringify({token:token,sessionId:sessionId})}).on((function(res,off){null==onConnect||onConnect(res),0!==res.code&&(off(),_this.handleConnect()),null==resolve||resolve(_this.dhServerSocket)})),_this.firstConnect=!1})),_rollupPluginBabelHelpers.defineProperty(this,"createSocket",(function(_x,_x2){return(_ref=_ref||_rollupPluginBabelHelpers.asyncToGenerator(_rollupPluginBabelHelpers.regeneratorRuntime().mark((function _callee(props,isPreOpenSession){var sessionId,onDigitalHumanCallback;return _rollupPluginBabelHelpers.regeneratorRuntime().wrap((function(_context){for(;;)switch(_context.prev=_context.next){case 0:if(_this.connectParams=props,_this.lastPreOpen=!!isPreOpenSession,sessionId=props.sessionId,onDigitalHumanCallback=props.onDigitalHumanCallback,!_this.socketClosingPromise){_context.next=6;break}return _context.next=6,_this.socketClosingPromise;case 6:if(!_this.dhServerSocket||_this.dhServerSocket.readyState===_interface$1.ReadyState.CLOSED){_context.next=9;break}return _context.next=9,_this.closeSocket();case 9:return _context.abrupt("return",new Promise((function(resolve,reject){var settled=!1,onceResolve=function(value){settled||(settled=!0,resolve(value))},createPamrams={keepAlive:"heartbeat",checkHeartbeatMismatch:_this.checkHeartbeatMismatch,reopen:get(_this.connectParams,"reConnect",!0),getKeepAliveMessage:function(requestId){return{requestId:requestId,action:"HEART_BEAT",body:"".concat(_this.lastHbAckTs),clientTs:Date.now()}},combine:function(req,res){return req&&res&&req.requestId===res.requestId},onOpen:function(){_this.dhServerSocket=socket,onceResolve(_this.dhServerSocket),sessionId&&_this.firstConnect?_this.sendPreConnect(props,onceResolve):isPreOpenSession&&_this.firstConnect||_this.handleConnect()},onClose:function(){_this.socketClosingPromise=null,onceResolve(null)},onError:function(error){reject(error)}},socket=createWebSocket.createWebSocket(_this.url,createPamrams);socket.onReadyStateChange((function(readyState){_this.lastReportedReadyState=readyState,0===readyState?(_this.startConnectingWatch(),onDigitalHumanCallback&&onDigitalHumanCallback({status:_interface.statusEnum.DH_LIB_INIT})):(_this.clearConnectingWatch(),_this.reconnectingTimeout=!1),1===readyState&&isPreOpenSession&&(_this.preConnectSuccess=!0),3===readyState&&(_this.preConnectSuccess=!1),onDigitalHumanCallback&&onDigitalHumanCallback({status:_interface.statusEnum.DH_LIB_FULL_STATUS,content:{type:"wsState",readyState:readyState,body:_interface.WS_STATUS_MAP[readyState]}})})),socket.onMessage((function(msgData){var action=msgData.action;"HEART_BEAT"===action&&(_this.lastHbAckTs=Date.now()),[_interface.errorTypeEnum.TIMEOUT_EXIT,_interface.errorTypeEnum.DISCONNECT_ALERT].includes(action)&&(onDigitalHumanCallback&&onDigitalHumanCallback({status:_interface.statusEnum.DH_LIB_STATUS,content:{type:action}}),_this.emitRawStatusMessage&&onDigitalHumanCallback&&onDigitalHumanCallback({status:_interface.statusEnum.DH_LIB_MESSAGE,content:msgData})),[_interface.errorTypeEnum.TIMEOUT_EXIT,_interface.errorTypeEnum.DISCONNECT_ALERT,"HEART_BEAT","CONNECT"].includes(action)||onDigitalHumanCallback&&onDigitalHumanCallback({status:_interface.statusEnum.DH_LIB_MESSAGE,content:msgData})})),_this.dhServerSocket=socket,socket.open()})));case 10:case"end":return _context.stop()}}),_callee)})))).apply(this,arguments)})),_rollupPluginBabelHelpers.defineProperty(this,"sendConnect",(function(props){_this.connectParams=props,_this.dhServerSocket&&_this.handleConnect()})),_rollupPluginBabelHelpers.defineProperty(this,"closeSocket",_rollupPluginBabelHelpers.asyncToGenerator(_rollupPluginBabelHelpers.regeneratorRuntime().mark((function _callee2(){return _rollupPluginBabelHelpers.regeneratorRuntime().wrap((function(_context2){for(;;)switch(_context2.prev=_context2.next){case 0:if(_this.resetState(),_this.dhServerSocket){_context2.next=3;break}return _context2.abrupt("return");case 3:return _this.socketClosingPromise=_this.dhServerSocket.close(),_context2.next=6,_this.socketClosingPromise;case 6:_this.dhServerSocket=null;case 7:case"end":return _context2.stop()}}),_callee2)})))),_rollupPluginBabelHelpers.defineProperty(this,"destroySocket",_rollupPluginBabelHelpers.asyncToGenerator(_rollupPluginBabelHelpers.regeneratorRuntime().mark((function _callee3(){var _this$dhServerSocket2;return _rollupPluginBabelHelpers.regeneratorRuntime().wrap((function(_context3){for(;;)switch(_context3.prev=_context3.next){case 0:_this.resetState(),_this.connectParams=null,null===(_this$dhServerSocket2=_this.dhServerSocket)||void 0===_this$dhServerSocket2||_this$dhServerSocket2.destroy(),_this.dhServerSocket=null;case 4:case"end":return _context3.stop()}}),_callee3)})))),_rollupPluginBabelHelpers.defineProperty(this,"handleConnect",_rollupPluginBabelHelpers.asyncToGenerator(_rollupPluginBabelHelpers.regeneratorRuntime().mark((function _callee4(){var _this$connectParams,appId,appKey,token,parameters,onConnect;return _rollupPluginBabelHelpers.regeneratorRuntime().wrap((function(_context4){for(;;)switch(_context4.prev=_context4.next){case 0:if(_this.dhServerSocket&&_this.connectParams){_context4.next=2;break}return _context4.abrupt("return");case 2:if(_this$connectParams=_this.connectParams,appId=_this$connectParams.appId,appKey=_this$connectParams.appKey,token=_this$connectParams.token,parameters=_this$connectParams.parameters,onConnect=_this$connectParams.onConnect,appId||appKey||token){_context4.next=5;break}return _context4.abrupt("return");case 5:_this.dhServerSocket&&_this.dhServerSocket.request({action:"CONNECT",clientTs:(new Date).getTime(),requestId:uuid.v4(),body:JSON.stringify(_rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({token:token,appId:appId,appKey:appKey},pick(_this.connectParams,_interface.CONNECT_MAIN_KEY)),{},{parameters:_rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({},omit(parameters,["parameters"])),parameters&¶meters.parameters?parameters.parameters:{})}))}).on((function(res,off){null==onConnect||onConnect(res),0!==res.code&&off()}));case 6:case"end":return _context4.stop()}}),_callee4)}))));var _ref5=options||{},checkHeartbeatMismatch=_ref5.checkHeartbeatMismatch,_ref5$emitRawStatusMe=_ref5.emitRawStatusMessage,emitRawStatusMessage=void 0!==_ref5$emitRawStatusMe&&_ref5$emitRawStatusMe;this.url=url,this.checkHeartbeatMismatch=null!=checkHeartbeatMismatch&&checkHeartbeatMismatch,this.emitRawStatusMessage=emitRawStatusMessage}return _rollupPluginBabelHelpers.createClass(Server,[{key:"setEmitRawStatusMessage",value:function(value){this.emitRawStatusMessage=value}},{key:"sendMessage",value:function(_x3,_x4){return(_sendMessage=_sendMessage||_rollupPluginBabelHelpers.asyncToGenerator(_rollupPluginBabelHelpers.regeneratorRuntime().mark((function _callee5(message,listener){var requestId;return _rollupPluginBabelHelpers.regeneratorRuntime().wrap((function(_context5){for(;;)switch(_context5.prev=_context5.next){case 0:try{this.dhServerSocket&&this.dhServerSocket&&this.dhServerSocket.request(message).on((function(response){listener&&listener(response)}))}catch(e){requestId="object"===_rollupPluginBabelHelpers.typeof(message)&&"requestId"in message?message.requestId:uuid.v4(),listener&&listener({code:-11,body:null,action:"RENDER_ERROR",requestId:requestId,message:JSON.stringify(e)})}case 1:case"end":return _context5.stop()}}),_callee5,this)})))).apply(this,arguments)}},{key:"startConnectingWatch",value:function(){var _this2=this;this.connectingTimer||this.reconnectingTimeout||(this.connectingTimer=setTimeout(_rollupPluginBabelHelpers.asyncToGenerator(_rollupPluginBabelHelpers.regeneratorRuntime().mark((function _callee6(){return _rollupPluginBabelHelpers.regeneratorRuntime().wrap((function(_context6){for(;;)switch(_context6.prev=_context6.next){case 0:if(_this2.connectingTimer=null,_this2.dhServerSocket&&0===_this2.lastReportedReadyState){_context6.next=3;break}return _context6.abrupt("return");case 3:if(console.warn("reconnect from CONNECTING timeout"),_this2.reconnectingTimeout=!0,_context6.prev=5,!_this2.connectParams){_context6.next=9;break}return _context6.next=9,_this2.createSocket(_this2.connectParams,_this2.lastPreOpen);case 9:_context6.next=14;break;case 11:_context6.prev=11,_context6.t0=_context6.catch(5),console.error("reconnect from CONNECTING timeout failed",_context6.t0);case 14:return _context6.prev=14,_this2.reconnectingTimeout=!1,_context6.finish(14);case 17:case"end":return _context6.stop()}}),_callee6,null,[[5,11,14,17]])}))),this.connectingMs))}},{key:"clearConnectingWatch",value:function(){this.connectingTimer&&(clearTimeout(this.connectingTimer),this.connectingTimer=null)}},{key:"resetState",value:function(){this.clearConnectingWatch(),this.reconnectingTimeout=!1,this.lastReportedReadyState=-1,this.lastHbAckTs=0}}]),Server}();exports.CONNECTING_STUCK_MS_DEFAULT=3e4,exports.default=Server;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";function t(t,r){var e=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(t,r).enumerable}))),e.push.apply(e,n)}return e}function r(){r=function(){return e};var t,e={},n=Object.prototype,o=n.hasOwnProperty,i=Object.defineProperty||function(t,r,e){t[r]=e.value},a="function"==typeof Symbol?Symbol:{},c=a.iterator||"@@iterator",u=a.asyncIterator||"@@asyncIterator",f=a.toStringTag||"@@toStringTag";function l(t,r,e){return Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}),t[r]}try{l({},"")}catch(t){l=function(t,r,e){return t[r]=e}}function s(t,r,e,n){var o=r&&r.prototype instanceof m?r:m,a=Object.create(o.prototype),c=new N(n||[]);return i(a,"_invoke",{value:S(t,e,c)}),a}function h(t,r,e){try{return{type:"normal",arg:t.call(r,e)}}catch(t){return{type:"throw",arg:t}}}e.wrap=s;var p="suspendedStart",y="suspendedYield",v="executing",g="completed",d={};function m(){}function b(){}function w(){}var x={};l(x,c,(function(){return this}));var O=Object.getPrototypeOf,j=O&&O(O(T([])));j&&j!==n&&o.call(j,c)&&(x=j);var L=w.prototype=m.prototype=Object.create(x);function E(t){["next","throw","return"].forEach((function(r){l(t,r,(function(t){return this._invoke(r,t)}))}))}function P(t,r){function e(n,i,a,c){var u=h(t[n],t,i);if("throw"!==u.type){var f=u.arg,l=f.value;return l&&"object"==typeof l&&o.call(l,"__await")?r.resolve(l.__await).then((function(t){e("next",t,a,c)}),(function(t){e("throw",t,a,c)})):r.resolve(l).then((function(t){f.value=t,a(f)}),(function(t){return e("throw",t,a,c)}))}c(u.arg)}var n;i(this,"_invoke",{value:function(t,o){function i(){return new r((function(r,n){e(t,o,r,n)}))}return n=n?n.then(i,i):i()}})}function S(r,e,n){var o=p;return function(i,a){if(o===v)throw new Error("Generator is already running");if(o===g){if("throw"===i)throw a;return{value:t,done:!0}}for(n.method=i,n.arg=a;;){var c=n.delegate;if(c){var u=_(c,n);if(u){if(u===d)continue;return u}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(o===p)throw o=g,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o=v;var f=h(r,e,n);if("normal"===f.type){if(o=n.done?g:y,f.arg===d)continue;return{value:f.arg,done:n.done}}"throw"===f.type&&(o=g,n.method="throw",n.arg=f.arg)}}}function _(r,e){var n=e.method,o=r.iterator[n];if(o===t)return e.delegate=null,"throw"===n&&r.iterator.return&&(e.method="return",e.arg=t,_(r,e),"throw"===e.method)||"return"!==n&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+n+"' method")),d;var i=h(o,r.iterator,e.arg);if("throw"===i.type)return e.method="throw",e.arg=i.arg,e.delegate=null,d;var a=i.arg;return a?a.done?(e[r.resultName]=a.value,e.next=r.nextLoc,"return"!==e.method&&(e.method="next",e.arg=t),e.delegate=null,d):a:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,d)}function k(t){var r={tryLoc:t[0]};1 in t&&(r.catchLoc=t[1]),2 in t&&(r.finallyLoc=t[2],r.afterLoc=t[3]),this.tryEntries.push(r)}function G(t){var r=t.completion||{};r.type="normal",delete r.arg,t.completion=r}function N(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(k,this),this.reset(!0)}function T(r){if(r||""===r){var e=r[c];if(e)return e.call(r);if("function"==typeof r.next)return r;if(!isNaN(r.length)){var n=-1,i=function e(){for(;++n<r.length;)if(o.call(r,n))return e.value=r[n],e.done=!1,e;return e.value=t,e.done=!0,e};return i.next=i}}throw new TypeError(typeof r+" is not iterable")}return b.prototype=w,i(L,"constructor",{value:w,configurable:!0}),i(w,"constructor",{value:b,configurable:!0}),b.displayName=l(w,f,"GeneratorFunction"),e.isGeneratorFunction=function(t){var r="function"==typeof t&&t.constructor;return!!r&&(r===b||"GeneratorFunction"===(r.displayName||r.name))},e.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,w):(t.__proto__=w,l(t,f,"GeneratorFunction")),t.prototype=Object.create(L),t},e.awrap=function(t){return{__await:t}},E(P.prototype),l(P.prototype,u,(function(){return this})),e.AsyncIterator=P,e.async=function(t,r,n,o,i){void 0===i&&(i=Promise);var a=new P(s(t,r,n,o),i);return e.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},E(L),l(L,f,"Generator"),l(L,c,(function(){return this})),l(L,"toString",(function(){return"[object Generator]"})),e.keys=function(t){var r=Object(t),e=[];for(var n in r)e.push(n);return e.reverse(),function t(){for(;e.length;){var n=e.pop();if(n in r)return t.value=n,t.done=!1,t}return t.done=!0,t}},e.values=T,N.prototype={constructor:N,reset:function(r){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(G),!r)for(var e in this)"t"===e.charAt(0)&&o.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(r){if(this.done)throw r;var e=this;function n(n,o){return c.type="throw",c.arg=r,e.next=n,o&&(e.method="next",e.arg=t),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],c=a.completion;if("root"===a.tryLoc)return n("end");if(a.tryLoc<=this.prev){var u=o.call(a,"catchLoc"),f=o.call(a,"finallyLoc");if(u&&f){if(this.prev<a.catchLoc)return n(a.catchLoc,!0);if(this.prev<a.finallyLoc)return n(a.finallyLoc)}else if(u){if(this.prev<a.catchLoc)return n(a.catchLoc,!0)}else{if(!f)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return n(a.finallyLoc)}}}},abrupt:function(t,r){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.tryLoc<=this.prev&&o.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var i=n;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=r&&r<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=r,i?(this.method="next",this.next=i.finallyLoc,d):this.complete(a)},complete:function(t,r){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&r&&(this.next=r),d},finish:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.finallyLoc===t)return this.complete(e.completion,e.afterLoc),G(e),d}},catch:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.tryLoc===t){var n=e.completion;if("throw"===n.type){var o=n.arg;G(e)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(r,e,n){return this.delegate={iterator:T(r),resultName:e,nextLoc:n},"next"===this.method&&(this.arg=t),d}},e}function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},e(t)}function n(t,r,e,n,o,i,a){try{var c=t[i](a),u=c.value}catch(t){return void e(t)}c.done?r(u):Promise.resolve(u).then(n,o)}function o(t,r){for(var e=0;e<r.length;e++){var n=r[e];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,c(n.key),n)}}function i(t,r,e){return(r=c(r))in t?Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[r]=e,t}function a(t,r){if("object"!=typeof t||null===t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,r||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(t)}function c(t){var r=a(t,"string");return"symbol"==typeof r?r:String(r)}exports.asyncToGenerator=function(t){return function(){var r=this,e=arguments;return new Promise((function(o,i){var a=t.apply(r,e);function c(t){n(a,o,i,c,u,"next",t)}function u(t){n(a,o,i,c,u,"throw",t)}c(void 0)}))}},exports.classCallCheck=function(t,r){if(!(t instanceof r))throw new TypeError("Cannot call a class as a function")},exports.createClass=function(t,r,e){return r&&o(t.prototype,r),e&&o(t,e),Object.defineProperty(t,"prototype",{writable:!1}),t},exports.defineProperty=i,exports.objectSpread2=function(r){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?t(Object(n),!0).forEach((function(t){i(r,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(n)):t(Object(n)).forEach((function(t){Object.defineProperty(r,t,Object.getOwnPropertyDescriptor(n,t))}))}return r},exports.regeneratorRuntime=r,exports.toPrimitive=a,exports.toPropertyKey=c,exports.typeof=e;
|
|
1
|
+
"use strict";function ownKeys(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);r&&(o=o.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,o)}return t}function _regeneratorRuntime(){_regeneratorRuntime=function(){return e};var t,e={},r=Object.prototype,n=r.hasOwnProperty,o=Object.defineProperty||function(t,e,r){t[e]=r.value},i="function"==typeof Symbol?Symbol:{},a=i.iterator||"@@iterator",c=i.asyncIterator||"@@asyncIterator",u=i.toStringTag||"@@toStringTag";function define(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{define({},"")}catch(t){define=function(t,e,r){return t[e]=r}}function wrap(t,e,r,n){var i=e&&e.prototype instanceof Generator?e:Generator,a=Object.create(i.prototype),c=new Context(n||[]);return o(a,"_invoke",{value:makeInvokeMethod(t,r,c)}),a}function tryCatch(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}e.wrap=wrap;var h="suspendedStart",l="suspendedYield",f="executing",s="completed",y={};function Generator(){}function GeneratorFunction(){}function GeneratorFunctionPrototype(){}var p={};define(p,a,(function(){return this}));var d=Object.getPrototypeOf,v=d&&d(d(values([])));v&&v!==r&&n.call(v,a)&&(p=v);var g=GeneratorFunctionPrototype.prototype=Generator.prototype=Object.create(p);function defineIteratorMethods(t){["next","throw","return"].forEach((function(e){define(t,e,(function(t){return this._invoke(e,t)}))}))}function AsyncIterator(t,e){function invoke(r,o,i,a){var c=tryCatch(t[r],t,o);if("throw"!==c.type){var u=c.arg,h=u.value;return h&&"object"==typeof h&&n.call(h,"__await")?e.resolve(h.__await).then((function(t){invoke("next",t,i,a)}),(function(t){invoke("throw",t,i,a)})):e.resolve(h).then((function(t){u.value=t,i(u)}),(function(t){return invoke("throw",t,i,a)}))}a(c.arg)}var r;o(this,"_invoke",{value:function(t,n){function callInvokeWithMethodAndArg(){return new e((function(e,r){invoke(t,n,e,r)}))}return r=r?r.then(callInvokeWithMethodAndArg,callInvokeWithMethodAndArg):callInvokeWithMethodAndArg()}})}function makeInvokeMethod(e,r,n){var o=h;return function(i,a){if(o===f)throw new Error("Generator is already running");if(o===s){if("throw"===i)throw a;return{value:t,done:!0}}for(n.method=i,n.arg=a;;){var c=n.delegate;if(c){var u=maybeInvokeDelegate(c,n);if(u){if(u===y)continue;return u}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(o===h)throw o=s,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o=f;var p=tryCatch(e,r,n);if("normal"===p.type){if(o=n.done?s:l,p.arg===y)continue;return{value:p.arg,done:n.done}}"throw"===p.type&&(o=s,n.method="throw",n.arg=p.arg)}}}function maybeInvokeDelegate(e,r){var n=r.method,o=e.iterator[n];if(o===t)return r.delegate=null,"throw"===n&&e.iterator.return&&(r.method="return",r.arg=t,maybeInvokeDelegate(e,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),y;var i=tryCatch(o,e.iterator,r.arg);if("throw"===i.type)return r.method="throw",r.arg=i.arg,r.delegate=null,y;var a=i.arg;return a?a.done?(r[e.resultName]=a.value,r.next=e.nextLoc,"return"!==r.method&&(r.method="next",r.arg=t),r.delegate=null,y):a:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,y)}function pushTryEntry(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function resetTryEntry(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function Context(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(pushTryEntry,this),this.reset(!0)}function values(e){if(e||""===e){var r=e[a];if(r)return r.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var o=-1,i=function next(){for(;++o<e.length;)if(n.call(e,o))return next.value=e[o],next.done=!1,next;return next.value=t,next.done=!0,next};return i.next=i}}throw new TypeError(typeof e+" is not iterable")}return GeneratorFunction.prototype=GeneratorFunctionPrototype,o(g,"constructor",{value:GeneratorFunctionPrototype,configurable:!0}),o(GeneratorFunctionPrototype,"constructor",{value:GeneratorFunction,configurable:!0}),GeneratorFunction.displayName=define(GeneratorFunctionPrototype,u,"GeneratorFunction"),e.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===GeneratorFunction||"GeneratorFunction"===(e.displayName||e.name))},e.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,GeneratorFunctionPrototype):(t.__proto__=GeneratorFunctionPrototype,define(t,u,"GeneratorFunction")),t.prototype=Object.create(g),t},e.awrap=function(t){return{__await:t}},defineIteratorMethods(AsyncIterator.prototype),define(AsyncIterator.prototype,c,(function(){return this})),e.AsyncIterator=AsyncIterator,e.async=function(t,r,n,o,i){void 0===i&&(i=Promise);var a=new AsyncIterator(wrap(t,r,n,o),i);return e.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},defineIteratorMethods(g),define(g,u,"Generator"),define(g,a,(function(){return this})),define(g,"toString",(function(){return"[object Generator]"})),e.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function next(){for(;r.length;){var t=r.pop();if(t in e)return next.value=t,next.done=!1,next}return next.done=!0,next}},e.values=values,Context.prototype={constructor:Context,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(resetTryEntry),!e)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var r=this;function handle(n,o){return a.type="throw",a.arg=e,r.next=n,o&&(r.method="next",r.arg=t),!!o}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return handle("end");if(i.tryLoc<=this.prev){var c=n.call(i,"catchLoc"),u=n.call(i,"finallyLoc");if(c&&u){if(this.prev<i.catchLoc)return handle(i.catchLoc,!0);if(this.prev<i.finallyLoc)return handle(i.finallyLoc)}else if(c){if(this.prev<i.catchLoc)return handle(i.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return handle(i.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,y):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),y},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),resetTryEntry(r),y}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;resetTryEntry(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,r,n){return this.delegate={iterator:values(e),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=t),y}},e}function _typeof(o){return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(o){return typeof o}:function(o){return o&&"function"==typeof Symbol&&o.constructor===Symbol&&o!==Symbol.prototype?"symbol":typeof o},_typeof(o)}function asyncGeneratorStep(gen,resolve,reject,_next,_throw,key,arg){try{var info=gen[key](arg),value=info.value}catch(error){return void reject(error)}info.done?resolve(value):Promise.resolve(value).then(_next,_throw)}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||!1,descriptor.configurable=!0,"value"in descriptor&&(descriptor.writable=!0),Object.defineProperty(target,_toPropertyKey(descriptor.key),descriptor)}}function _defineProperty(obj,key,value){return(key=_toPropertyKey(key))in obj?Object.defineProperty(obj,key,{value:value,enumerable:!0,configurable:!0,writable:!0}):obj[key]=value,obj}function _toPrimitive(input,hint){if("object"!=typeof input||null===input)return input;var prim=input[Symbol.toPrimitive];if(void 0!==prim){var res=prim.call(input,hint||"default");if("object"!=typeof res)return res;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===hint?String:Number)(input)}function _toPropertyKey(arg){var key=_toPrimitive(arg,"string");return"symbol"==typeof key?key:String(key)}exports.asyncToGenerator=function(fn){return function(){var self=this,args=arguments;return new Promise((function(resolve,reject){var gen=fn.apply(self,args);function _next(value){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"next",value)}function _throw(err){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"throw",err)}_next(void 0)}))}},exports.classCallCheck=function(instance,Constructor){if(!(instance instanceof Constructor))throw new TypeError("Cannot call a class as a function")},exports.createClass=function(Constructor,protoProps,staticProps){return protoProps&&_defineProperties(Constructor.prototype,protoProps),staticProps&&_defineProperties(Constructor,staticProps),Object.defineProperty(Constructor,"prototype",{writable:!1}),Constructor},exports.defineProperty=_defineProperty,exports.objectSpread2=function(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?ownKeys(Object(t),!0).forEach((function(r){_defineProperty(e,r,t[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):ownKeys(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))}))}return e},exports.regeneratorRuntime=_regeneratorRuntime,exports.toPrimitive=_toPrimitive,exports.toPropertyKey=_toPropertyKey,exports.typeof=_typeof;
|
package/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var Client=require("./Client.js"),_interface=require("./interface.js");exports.default=Client.default,exports.CONNECT_MAIN_KEY=_interface.CONNECT_MAIN_KEY,exports.WS_STATUS_MAP=_interface.WS_STATUS_MAP,Object.defineProperty(exports,"errorTypeEnum",{enumerable:!0,get:function(){return _interface.errorTypeEnum}}),Object.defineProperty(exports,"statusEnum",{enumerable:!0,get:function(){return _interface.statusEnum}});
|
package/cjs/interface.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var statusEnum,errorTypeEnum;exports.statusEnum=void 0,(statusEnum=exports.statusEnum||(exports.statusEnum={})).DH_LIB_INIT="DH_LIB_INIT",statusEnum.DH_LIB_WS_SUCCESS="DH_LIB_WS_SUCCESS",statusEnum.DH_LIB_OPEN="DH_LIB_OPEN",statusEnum.DH_LIB_STATUS="DH_LIB_STATUS",statusEnum.DH_LIB_CLOSE="DH_LIB_CLOSE",statusEnum.DH_LIB_ERROR="DH_LIB_ERROR",statusEnum.DH_LIB_WARNING="DH_LIB_WARNING",statusEnum.DH_LIB_FULL_STATUS="DH_LIB_FULL_STATUS",statusEnum.DH_LIB_MESSAGE="DH_LIB_MESSAGE",exports.errorTypeEnum=void 0,(errorTypeEnum=exports.errorTypeEnum||(exports.errorTypeEnum={})).CONNECT_ERROR="CONNECT_ERROR",errorTypeEnum.DISCONNECT_ALERT="DISCONNECT_ALERT",errorTypeEnum.TIMEOUT_EXIT="TIMEOUT_EXIT",errorTypeEnum.LOCAL_VIDEO_MUTED="LOCAL_VIDEO_MUTED",errorTypeEnum.LOCAL_VIDEO_ERROR="LOCAL_VIDEO_ERROR",errorTypeEnum.RTC_ERROR="RTC_ERROR";exports.CONNECT_MAIN_KEY=["projectId","characterConfigId","configVersion","selectors","figureName","reConnect"],exports.WS_STATUS_MAP={"-1":"UNINSTANTIATED",0:"CONNECTING",1:"OPEN",2:"CLOSING",3:"CLOSED"};
|
package/es/BrtcClient.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createClass as
|
|
1
|
+
import{createClass as _createClass,classCallCheck as _classCallCheck,defineProperty as _defineProperty}from"./_virtual/_rollupPluginBabelHelpers.js";import BrtcInstance from"@bddh/starling-brtc";import{TimeoutController}from"@bddh/starling-timeout-controller";import CustomJSON from"@bddh/starling-json";import isEmpty from"lodash/isEmpty";import isFunction from"lodash/isFunction";import{statusEnum,errorTypeEnum}from"./interface.js";var BrtcClient=function(){function BrtcClient(props){var _this=this;_classCallCheck(this,BrtcClient),_defineProperty(this,"client",void 0),_defineProperty(this,"isRtcVideoOn",!1),_defineProperty(this,"rtcConnection",void 0),_defineProperty(this,"rtcConfig",void 0),_defineProperty(this,"bizConfig",void 0),_defineProperty(this,"rtcCallback",void 0),_defineProperty(this,"restarting",!1),_defineProperty(this,"timeoutEvent",void 0),_defineProperty(this,"timeoutStarted",!1),_defineProperty(this,"reopenTimer",void 0),_defineProperty(this,"restartCount",0),_defineProperty(this,"closeLog",!0),_defineProperty(this,"stopped",!1),_defineProperty(this,"haveVideoOn",!1),_defineProperty(this,"rtcStateCallback",null),_defineProperty(this,"startRtcTimeout",(function(){_this.timeoutStarted||(_this.timeoutEvent.start(),_this.timeoutStarted=!0)})),_defineProperty(this,"clearRtcTimeout",(function(){_this.timeoutStarted&&(_this.timeoutEvent.clear(),_this.timeoutStarted=!1)})),_defineProperty(this,"mergeRtcConfig",(function(partial){_this.rtcConfig&&partial&&Object.keys(partial).length&&Object.assign(_this.rtcConfig,partial)})),_defineProperty(this,"openRtc",(function(rtcConnection){if(_this.stopped=!1,_this.restarting)!_this.closeLog&&console.warn("rtc restarting");else if(rtcConnection&&(_this.rtcConnection=rtcConnection),_this.rtcConnection&&!isEmpty(_this.rtcConnection)){var _this$client,_this$rtcConnection=_this.rtcConnection,server=_this$rtcConnection.server,appId=_this$rtcConnection.appId,token=_this$rtcConnection.token,roomName=_this$rtcConnection.roomName,userId=_this$rtcConnection.userId,_ref=_this.rtcCallback||{},_onRemotedata=_ref.onRemotedata,_onLocalStream=_ref.onLocalStream,_onRemoteVideoComing=_ref.onRemoteVideoComing,_onLocalVideoPublished=_ref.onLocalVideoPublished,_onLocalVideoPublishing=_ref.onLocalVideoPublishing,_onRemoteVideoOn=_ref.onRemoteVideoOn,_onRemoteVideoOff=_ref.onRemoteVideoOff,_onRemoteVideoLoading=_ref.onRemoteVideoLoading,_onSuccess=_ref.onSuccess,_onError=_ref.onError,_onLocalVideoConnected=_ref.onLocalVideoConnected,_onRemoteVideoConnected=_ref.onRemoteVideoConnected,_onRemoteMediaState=_ref.onRemoteMediaState,onPlayingError=_ref.onPlayingError,onDigitalHumanCallback=_ref.onDigitalHumanCallback;null===(_this$client=_this.client)||void 0===_this$client||_this$client.destroy(),_this.client=void 0,_this.startRtcTimeout(),_this.rtcStateCallback=function(data){var body=data.body,action=data.action;onDigitalHumanCallback&&onDigitalHumanCallback({status:statusEnum.DH_LIB_FULL_STATUS,content:{type:"rtcState",action:action,body:body}})},_this.client=new BrtcInstance({roomName:roomName,token:token,userId:userId,appId:appId,server:server,rtcConfig:_this.rtcConfig,callback:{onRemoteVideoConnected:function(id,connected){var _this$bizConfig;if(!connected&&!_this.haveVideoOn)var connectTimer=setTimeout((function(){_this.restartCount<3?(_this.restartCount=++_this.restartCount,_this.restartRtc&&_this.restartRtc(rtcConnection)):(_this.restartCount=0,_this.closeRtc()),clearTimeout(connectTimer)}),500);if(connected&&!1!==(null===(_this$bizConfig=_this.bizConfig)||void 0===_this$bizConfig?void 0:_this$bizConfig.remoteAutoPlay)){var videoElement=document.getElementById("remotevideo500");if(videoElement){videoElement.muted=!1;var promise=videoElement.play();void 0!==promise&&promise.catch((function(){videoElement.muted=!0,videoElement.play().catch((function(e){!_this.closeLog&&console.info("videoElement play error",e),onPlayingError&&onPlayingError(videoElement),onDigitalHumanCallback&&onDigitalHumanCallback({status:statusEnum.DH_LIB_ERROR,content:{type:errorTypeEnum.LOCAL_VIDEO_ERROR}}),_this.rtcStateCallback&&_this.rtcStateCallback({action:"localVideoError",body:!0})})),onDigitalHumanCallback&&onDigitalHumanCallback({status:statusEnum.DH_LIB_STATUS,content:{type:errorTypeEnum.LOCAL_VIDEO_MUTED}}),_this.rtcStateCallback&&_this.rtcStateCallback({action:"localVideoMuted",body:!0})}))}else!_this.closeLog&&console.error("videoElement is null!")}!_this.closeLog&&console.info("remoteVideoConnected",id,connected,_this.restartCount),_this.rtcStateCallback&&_this.rtcStateCallback({action:"remoteVideoConnected",body:{id:id,connected:connected,restartCount:_this.restartCount}}),isFunction(_onRemoteVideoConnected)&&_onRemoteVideoConnected(id,connected)},onRemoteVideoOn:function(id){_this.haveVideoOn=!0,!_this.closeLog&&console.info("remotevideoon by id: ",id),_this.clearRtcTimeout();var rtcContainer=document.querySelector("#starlingRtcContainer"),therevideo=rtcContainer&&rtcContainer.lastChild;therevideo&&(therevideo.style.display="none"),_this.rtcStateCallback&&_this.rtcStateCallback({action:"remotevideoon",body:id}),onDigitalHumanCallback&&onDigitalHumanCallback({status:statusEnum.DH_LIB_OPEN}),isFunction(_onRemoteVideoOn)&&_onRemoteVideoOn(id)},onRemoteMediaState:function(id,medium,connected){!_this.closeLog&&console.info("remoteMediaState",id,medium,connected),_this.rtcStateCallback&&_this.rtcStateCallback({action:"remoteMediaState",body:{id:id,medium:medium,connected:connected}}),isFunction(_onRemoteMediaState)&&_onRemoteMediaState(id,medium,connected)},onLocalVideoConnected:function(connected){!_this.closeLog&&console.info("localVideoConnected",connected),_this.rtcStateCallback&&_this.rtcStateCallback({action:"localVideoConnected",body:{connected:connected}}),isFunction(_onLocalVideoConnected)&&_onLocalVideoConnected(connected)},onRemotedata:function(data){if(_this.rtcConfig&&_this.rtcConfig.usingdatachannel){var msg=CustomJSON.parse(data);!_this.closeLog&&console.info("RTC - receive:",msg),isFunction(_onRemotedata)&&_onRemotedata(msg)}},onLocalStream:function(stream,name){!_this.closeLog&&console.info("rtc - onlocalstream by name: "+name),_this.rtcStateCallback&&_this.rtcStateCallback({action:"onlocalstream",body:{stream:stream,name:name}}),isFunction(_onLocalStream)&&_onLocalStream(stream,name)},onLocalVideoPublished:function(){!_this.closeLog&&console.info("LocalVideoPublished 本地视频发布成功"),_this.rtcStateCallback&&_this.rtcStateCallback({action:"localvideopublished_ok",body:!0}),isFunction(_onLocalVideoPublished)&&_onLocalVideoPublished()},onLocalVideoPublishing:function(){!_this.closeLog&&console.info("LocalVideoPublishing 本地视频发布成功"),_this.rtcStateCallback&&_this.rtcStateCallback({action:"localvideopublishing",body:!0}),isFunction(_onLocalVideoPublishing)&&_onLocalVideoPublishing()},onRemoteVideoComing:function(id){!_this.closeLog&&console.info("remotevideocoming",id),_this.rtcStateCallback&&_this.rtcStateCallback({action:"remotevideocoming",body:id}),isFunction(_onRemoteVideoComing)&&_onRemoteVideoComing(id)},onRemoteVideoLoading:function(id){!_this.closeLog&&console.info("remotevideoloading by id: ",id),_this.rtcStateCallback&&_this.rtcStateCallback({action:"remotevideoloading",body:id}),isFunction(_onRemoteVideoLoading)&&_onRemoteVideoLoading(id)},onRemoteVideoOff:function(id){if(!_this.stopped){var videoEle=document.getElementById("remotevideo500");videoEle&&videoEle.pause(),!_this.closeLog&&console.info("remotevideooff: ",id),_this.isRtcVideoOn=!1,_this.rtcStateCallback&&_this.rtcStateCallback({action:"remotevideooff",body:id}),onDigitalHumanCallback&&onDigitalHumanCallback({status:statusEnum.DH_LIB_CLOSE}),isFunction(_onRemoteVideoOff)&&_onRemoteVideoOff(id),_this.startRtcTimeout()}},onSuccess:function(){!_this.closeLog&&console.info("rtc - success"),_this.rtcStateCallback&&_this.rtcStateCallback({action:"success",body:!0}),isFunction(_onSuccess)&&_onSuccess()},onError:function(e){_this.stopped||(_this.isRtcVideoOn=!1,!_this.closeLog&&console.error("rtc - error:",e),_this.rtcStateCallback&&_this.rtcStateCallback({action:"error",body:e}),onDigitalHumanCallback&&onDigitalHumanCallback({status:statusEnum.DH_LIB_ERROR,content:{type:errorTypeEnum.RTC_ERROR}}),isFunction(_onError)&&_onError(e),(e.includes("Lost connection to the server")||e.includes("Is the server down"))&&_this.restartRtc&&_this.restartRtc(rtcConnection))}}})}})),_defineProperty(this,"closeRtc",(function(){var _this$client2;_this.stopped=!0,_this.clearRtcTimeout(),clearTimeout(_this.reopenTimer),null===(_this$client2=_this.client)||void 0===_this$client2||_this$client2.destroy(),_this.client=void 0,_this.restarting=!1})),_defineProperty(this,"restartRtc",(function(rtcConnection){_this.stopped||!_this.restarting&&_this.bizConfig&&_this.bizConfig.autoReConnect&&(_this.rtcStateCallback&&_this.rtcStateCallback({action:"restartRtc",body:rtcConnection}),_this.restarting=!0,_this.closeRtc(),_this.reopenTimer=setTimeout((function(){!_this.closeLog&&console.error("拉流失败,开始重启"),_this.restarting=!1,_this.openRtc(rtcConnection)}),2e3))}));var _rtcConnection=props.rtcConnection,rtcConfig=props.rtcConfig,_props$closeLog=props.closeLog,closeLog=void 0===_props$closeLog||_props$closeLog,rtcCallback=props.rtcCallback,bizConfig=props.bizConfig;this.rtcConnection=_rtcConnection,this.rtcConfig=rtcConfig,this.rtcCallback=rtcCallback,this.closeLog=closeLog,this.bizConfig=bizConfig,this.timeoutEvent=new TimeoutController(6e4,(function(){if(_this.timeoutStarted=!1,!_this.stopped)return _this.rtcConnection?void(_this.restartRtc&&_this.restartRtc(_this.rtcConnection)):!_this.closeLog&&console.warn("remotevideoon事件超时, rtcConnectionRef is null")}))}return _createClass(BrtcClient,[{key:"muteMicphone",value:function(mute){this.client&&this.client.muteMicphone&&this.client.muteMicphone(mute)}}]),BrtcClient}();export{BrtcClient as default};
|
package/es/Client.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createClass as e,classCallCheck as t,defineProperty as r,objectSpread2 as n,asyncToGenerator as a,regeneratorRuntime as o}from"./_virtual/_rollupPluginBabelHelpers.js";import s from"@bddh/starling-json";import i from"lodash/isEmpty";import c from"lodash/omit";import u from"lodash/pick";import{v4 as l}from"uuid";import{statusEnum as d,errorTypeEnum as h,CONNECT_MAIN_KEY as m}from"./interface.js";import v from"./Server.js";import p from"./BrtcClient.js";import{removeLastFrameCoverWrapper as f,removeHumanDom as S,createHumanDom as C,appendLastFrameCoverSibling as g,appendRtcDomStyle as R,RTC_VIDEO_ID as y,checkIsHuawei as k,setHumanPlayerWrapperVisible as I,setLastFrameCoverVisible as b,captureLastFrameToCover as w,playHumanVideo as D,muteHumanVideo as E,ensureCutoutDomMounted as M}from"./DomControl.js";import H from"./Cutout.js";import P from"./RecordController.js";var x=function(x,_,T){function O(e){var i,p=this;t(this,O),r(this,"token",void 0),r(this,"appKey",void 0),r(this,"appId",void 0),r(this,"connectParams",void 0),r(this,"onDigitalHumanCallback",void 0),r(this,"dhServer",void 0),r(this,"rtcServer",void 0),r(this,"rtcConnectParams",void 0),r(this,"cutoutInstance",void 0),r(this,"hasInitChromaEffects",!1),r(this,"isHuawei",k()),r(this,"rtcServerUrl",void 0),r(this,"rtcInternalIp",void 0),r(this,"recordController",null),r(this,"wsReadyState",-1),r(this,"isPreOpenSession",!1),r(this,"openWsOnly",!1),r(this,"hasConnectUserFigureEffects",!1),r(this,"_isMicMuted",!1),r(this,"mergeConnectRtcExtras",!1),r(this,"emitRawStatusMessage",!1),r(this,"resolveMediaServerByDomain",void 0),r(this,"remoteAutoPlay",!0),r(this,"onDigitalHumanCallbackPlus",(function(e){var t,r,n=e.content;e.status===d.DH_LIB_FULL_STATUS&&"wsState"===(null==n?void 0:n.type)&&(p.wsReadyState=n.readyState,3===n.readyState&&(null===(t=p.cutoutInstance)||void 0===t||t.setPlaying(!1),null===(r=p.rtcServer)||void 0===r||r.closeRtc(),p.canShowStaticFrameCover()&&(I(!1),b(!0))));p.onDigitalHumanCallback&&p.onDigitalHumanCallback(e)})),r(this,"onRemoteVideoComing",(function(e){p.rtcConnectParams&&p.rtcConnectParams.feedId&&e===+p.rtcConnectParams.feedId&&p.rtcServer&&p.rtcServer.client&&p.rtcServer.client.subscribeStreaming("remotevideo500",+p.rtcConnectParams.feedId)})),r(this,"onLocalStream",(function(){(p.connectParams||{}).pullAudioFromRtc&&p.rtcServer&&p.rtcServer.muteMicphone(p._isMicMuted)})),r(this,"onRemoteVideoOn",(function(){setTimeout(a(o().mark((function e(){var t;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t=document.getElementById(y),!p.cutoutInstance||!t){e.next=5;break}return p.cutoutInstance.setPlaying(!0),e.next=5,p.cutoutInstance.updateSource(t);case 5:p.canShowStaticFrameCover()&&(w(),I(!0),b(!1));case 6:case"end":return e.stop()}}),e)}))),100)})),r(this,"onRemoteVideoConnected",(function(e,t){var r;if(t&&!p.remoteAutoPlay){var n=null===(r=p.rtcConnectParams)||void 0===r?void 0:r.feedId;null!=n&&e!==+n||p.onRemoteVideoOn()}})),r(this,"onRemoteVideoOffLastFrame",(function(){var e;null===(e=p.cutoutInstance)||void 0===e||e.setPlaying(!1),p.canShowStaticFrameCover()&&b(!0)})),r(this,"connectListener",(function(e){p.handleConnectResponse(e).catch((function(e){console.warn("[DhRealtimeHuman] handleConnectResponse failed",e)}))})),r(this,"createServer",(function(e){var t,r=n(n(n({token:p.token,appKey:p.appKey,appId:p.appId},e?{sessionId:e}:{}),u(p.connectParams,m)),{},{parameters:c(p.connectParams,m),onConnect:p.connectListener,onDigitalHumanCallback:p.onDigitalHumanCallbackPlus});null!==(t=p.dhServer)&&void 0!==t&&t.preConnectSuccess?(p.dhServer.connectParams=r,p.dhServer&&p.dhServer.sendPreConnect(r)):p.openWsOnly?p.dhServer&&p.dhServer.sendConnect(r):p.dhServer&&p.dhServer.createSocket(r)})),r(this,"checkHumanInstansce",(function(){return p.dhServer?!(p.isPreOpenSession&&!p.dhServer.preConnectSuccess)||(p.onDigitalHumanCallback&&p.onDigitalHumanCallback({status:d.DH_LIB_ERROR,content:{type:h.CONNECT_ERROR,msg:{code:4001,errMsg:"webSocket连接中"}}}),!1):(p.onDigitalHumanCallback&&p.onDigitalHumanCallback({status:d.DH_LIB_ERROR,content:{type:h.CONNECT_ERROR,msg:{code:4002,errMsg:"请先初始化数字人实例"}}}),!1)})),r(this,"sendMessage",(function(e,t){return p.dhServer&&p.dhServer.sendMessage(e,t)})),r(this,"interrupt",a(o().mark((function e(){return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",new Promise((function(e){p.dhServer&&p.dhServer.sendMessage({requestId:l(),action:"TEXT_RENDER",body:"<interrupt></interrupt>",clientTs:(new Date).getTime()},(function(){return e()}))})));case 1:case"end":return e.stop()}}),e)})))),r(this,"textRender",(function(e){var t=e.requestId,r=e.body,n=e.onCallbackMsg;p.checkHumanInstansce()&&p.dhServer&&p.dhServer.sendMessage({requestId:t||l(),action:"TEXT_RENDER",body:r,clientTs:(new Date).getTime()},n)})),r(this,"textStreamRender",(function(e){var t=e.requestId,r=e.body,n=e.onCallbackMsg,a=s.parse(r).first;p.checkHumanInstansce()&&p.dhServer&&p.dhServer.sendMessage({requestId:t||l(),action:"TEXT_STREAM_RENDER",body:r,clientTs:(new Date).getTime()},a?n:null)})),r(this,"audioRender",(function(e){var t=e.body,r=e.onCallbackMsg;p.checkHumanInstansce()&&p.dhServer&&p.dhServer.sendMessage({requestId:l(),action:"AUDIO_RENDER",body:t,clientTs:(new Date).getTime()},r)})),r(this,"audioStreamRender",(function(e){var t=e.requestId,r=e.body,n=e.onCallbackMsg;p.checkHumanInstansce()&&p.dhServer&&p.dhServer.sendMessage({requestId:t||l(),action:"AUDIO_STREAM_RENDER",body:r,clientTs:(new Date).getTime()},n)})),r(this,"textQuery",(function(e){var t=e.requestId,r=e.body,n=e.onCallbackMsg;p.dhServer&&p.dhServer.sendMessage({requestId:t||l(),action:"TEXT_QUERY",body:r,clientTs:(new Date).getTime()},n)})),r(this,"handleDestroyView",(function(e){var t,r;return e?p.canShowStaticFrameCover()?(D(!1),I(!1),void b(!0)):void(null===(t=p.cutoutInstance)||void 0===t||t.setPlaying(!1)):(null===(r=p.cutoutInstance)||void 0===r||r.destroy(),p.cutoutInstance=void 0,S(),void f())})),r(this,"destroy",(function(e){return(i=i||a(o().mark((function e(t){var r,n,a;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=(t||{}).keepLastFrame,a=void 0!==n&&n,p.handleDestroyView(a),e.next=4,p.dhServer&&p.dhServer.closeSocket();case 4:p.rtcServer&&p.rtcServer.closeRtc(),null===(r=p.recordController)||void 0===r||r.destroy(),p.dhServer=null,p.rtcServer=null;case 8:case"end":return e.stop()}}),e)})))).apply(this,arguments)})),r(this,"pauseHuman",(function(){return D(!1)})),r(this,"playHuman",(function(){return D(!0)})),r(this,"muteHuman",(function(){return E(!0)})),r(this,"unMuteHuman",(function(){var e=E(!1);try{return p.isHuawei?(e.pause(),e.play()):e.paused&&e.play()}catch(e){console.info(e)}}));var C=e.isPreOpenSession,g=void 0!==C&&C,R=e.isOpenWsOnly,M=void 0!==R&&R,H=e.wsUrl,P=e.renderParams,x=e.checkHeartbeatMismatch,_=e.emitRawStatusMessage,T=void 0!==_&&_,A=e.onDigitalHumanCallback;this.isPreOpenSession=g,this.openWsOnly=M,this.emitRawStatusMessage=T,this.dhServer=new v(H||"wss://open.xiling.baidu.com/cloud/digital-human-demonstration",{checkHeartbeatMismatch:x,emitRawStatusMessage:T}),this.onDigitalHumanCallback=function(e){e.status!==d.DH_LIB_FULL_STATUS?A&&A(e):(null==P?void 0:P.fullStatus)&&A&&A(e)},g||M?this.dhServer.createSocket({onDigitalHumanCallback:this.onDigitalHumanCallbackPlus},g):this.init(e)}return e(O,[{key:"canShowStaticFrameCover",value:function(){return!this.hasInitChromaEffects&&!this.hasConnectUserFigureEffects}},{key:"init",value:function(e){var t,r,a=this,o=e.wrapperId,s=e.token,c=e.appKey,u=e.appId,l=e.connectParams,m=e.renderParams,v=void 0===m?{}:m,k=e.rtcConnectParams,I=e.brtcParams,b=e.rtcServerUrl,w=e.rtcInternalIp,D=e.mergeConnectRtcExtras,E=void 0!==D&&D,M=e.emitRawStatusMessage,x=void 0!==M&&M,_=e.remoteAutoPlay,T=e.resolveMediaServerByDomain;if(this.mergeConnectRtcExtras=Boolean(E),this.emitRawStatusMessage=x,null===(t=this.dhServer)||void 0===t||t.setEmitRawStatusMessage(this.emitRawStatusMessage),this.resolveMediaServerByDomain=T,this.remoteAutoPlay=!1!==_,this.hasConnectUserFigureEffects=!1,this.token=s,this.appKey=c,this.appId=u,this.rtcServerUrl=b,this.rtcInternalIp=w,this.connectParams=n({autoChromaKey:(null==v?void 0:v.autoChromaKey)||!1},l),!u&&!c&&!s)throw new Error("appId and appKey or token is required");var O=v.closeLog,A=v.audio3AConstraints;this.hasInitChromaEffects=!i(null==v?void 0:v.chromaEffects)||!(null==v||!v.autoChromaKey),f(),S();var F=(C({autoChromaKey:!!v.autoChromaKey||!i(v.chromaEffects),autoplay:!1!==_})||{}).playerWrapper,U=document.getElementById(o||"");U||console.error("dom with wrapperId is not find"),F&&U&&U.appendChild(F),this.canShowStaticFrameCover()&&U&&("static"===window.getComputedStyle(U).position&&(U.style.position="relative"),g(U)),R();var B=n({remotevideoviewid:o,showvideobps:!1,usingvideo:!1,usingaudio:!(null==l||!l.pullAudioFromRtc),aspublisher:!(null==l||!l.pullAudioFromRtc),autopublish:!(null==l||!l.pullAudioFromRtc),usingdatachannel:!0,autoplaymuted:!1},I);this.rtcServer=new p({closeLog:O,videoWrapperId:y,rtcConfig:B,bizConfig:n({autoReConnect:null===(r=null==l?void 0:l.reConnect)||void 0===r||r},void 0!==_?{remoteAutoPlay:_}:{}),rtcCallback:{onRemoteVideoComing:this.onRemoteVideoComing,onDigitalHumanCallback:this.onDigitalHumanCallback,onLocalStream:this.onLocalStream,onRemoteVideoOn:this.onRemoteVideoOn,onRemoteVideoOff:this.onRemoteVideoOffLastFrame,onRemoteVideoConnected:this.onRemoteVideoConnected}}),(!i(null==v?void 0:v.chromaEffects)||null!=v&&v.autoChromaKey)&&(this.cutoutInstance=new H({sourceId:y,effects:null==v?void 0:v.chromaEffects})),i(k)||(this.rtcConnectParams=k,this.rtcServer.openRtc(k)),null!=l&&l.pullAudioFromRtc?this.recordController=null:this.recordController=new P({pickAudioMode:null==l?void 0:l.pickAudioMode,audio3AConstraints:A,asrSample:null==l?void 0:l.asrSample,onAudioData:function(e){1===a.wsReadyState&&a.sendMessage(e,null)},onError:function(e){a.onDigitalHumanCallback&&a.onDigitalHumanCallback({status:d.DH_LIB_ERROR,content:{type:h.CONNECT_ERROR,msg:{code:-1,errMsg:e.message}}})}})}},{key:"handleConnectResponse",value:function(e){return(x=x||a(o().mark((function e(t){var r,n,a,i,c,u,l,m,v,p,f;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=t.code,n=t.body,a=t.message,0===r&&this.onDigitalHumanCallback&&this.onDigitalHumanCallback({status:d.DH_LIB_WS_SUCCESS,content:t}),this.emitRawStatusMessage&&this.onDigitalHumanCallback&&this.onDigitalHumanCallback({status:d.DH_LIB_MESSAGE,content:t}),0!==r){e.next=18;break}if(i=s.parse(n),!this.mergeConnectRtcExtras||!this.rtcServer){e.next=14;break}return e.prev=6,e.next=9,this.mergeConnectRtcExtrasFromBody(i);case 9:e.next=14;break;case 11:e.prev=11,e.t0=e.catch(6),console.warn("[DhRealtimeHuman] mergeConnectRtcExtrasFromBody failed",e.t0);case 14:c=i.rtcServerUrl,u=i.appId,l=i.clientToken,m=i.roomName,v=i.clientId,p=i.feedId,f=i.chargeId,u&&m&&(this.rtcConnectParams={server:this.rtcServerUrl||c,appId:u,token:l,roomName:m,userId:v,feedId:p,chargeId:f},this.rtcServer&&this.rtcServer.openRtc(this.rtcConnectParams)),e.next=19;break;case 18:this.onDigitalHumanCallback&&this.onDigitalHumanCallback({status:d.DH_LIB_ERROR,content:{type:h.CONNECT_ERROR,msg:{code:r,errMsg:a}}});case 19:case"end":return e.stop()}}),e,this,[[6,11]])})))).apply(this,arguments)}},{key:"mergeConnectRtcExtrasFromBody",value:function(e){return(_=_||a(o().mark((function e(t){var r,n,a,i,c,u,l;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.rtcServer){e.next=2;break}return e.abrupt("return");case 2:if(r=t.userFigure,n=void 0===r?"":r,a=t.rtcExternalInfo,i=(void 0===a?{}:a).udpDomain||"",c={},this.rtcInternalIp&&(c.mediaserverip=this.rtcInternalIp),!n){e.next=19;break}if(!(u=s.parse(n)).effects){e.next=17;break}return e.prev=9,e.next=12,this.applyConnectChroma(u.effects);case 12:e.next=17;break;case 14:e.prev=14,e.t0=e.catch(9),console.warn("[DhRealtimeHuman] applyConnectChroma failed",e.t0);case 17:e.next=36;break;case 19:if(!i){e.next=36;break}if(l=this.resolveMediaServerByDomain){e.next=26;break}console.warn("[DhRealtimeHuman] udpDomain 解析需传入 resolveMediaServerByDomain"),c.mediaserverip="",e.next=36;break;case 26:return e.prev=26,e.next=29,l(i);case 29:c.mediaserverip=e.sent,e.next=36;break;case 32:e.prev=32,e.t1=e.catch(26),c.mediaserverip="",console.error("resolveMediaServerByDomain failed",e.t1);case 36:this.rtcServer.mergeRtcConfig(c);case 37:case"end":return e.stop()}}),e,this,[[9,14],[26,32]])})))).apply(this,arguments)}},{key:"applyConnectChroma",value:function(e){return(T=T||a(o().mark((function e(t){var r,n,a,s;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.hasInitChromaEffects){e.next=2;break}return e.abrupt("return");case 2:if(n=t.chromaKey,a=t.version,null!=n){e.next=5;break}return e.abrupt("return");case 5:if(M()){e.next=7;break}return e.abrupt("return");case 7:if(this.hasConnectUserFigureEffects=!0,f(),b(!1),I(!0),null===(r=this.cutoutInstance)||void 0===r||r.destroy(),this.cutoutInstance=new H({sourceId:y,effects:{version:a,chromaKey:n}}),!(s=document.getElementById(y))){e.next=17;break}return e.next=17,this.cutoutInstance.updateSource(s);case 17:case"end":return e.stop()}}),e,this)})))).apply(this,arguments)}},{key:"startRecord",value:function(){var e;null!==(e=this.connectParams)&&void 0!==e&&e.pullAudioFromRtc?this.rtcServer&&this.rtcServer.muteMicphone(!1):this.recordController&&this.recordController.start()}},{key:"stopRecord",value:function(){var e;if(null!==(e=this.connectParams)&&void 0!==e&&e.pullAudioFromRtc)return this.rtcServer&&this.rtcServer.muteMicphone(!0),void this.sendMessage({action:"AUDIO_QUERY_INTERRUPT",requestId:l(),clientTs:Date.now(),body:""},null);this.recordController&&this.recordController.stop(),this.sendMessage({action:"AUDIO_QUERY_INTERRUPT",requestId:l(),clientTs:Date.now(),body:""},null)}},{key:"muteMicrophone",value:function(e){var t,r;null!==(t=this.connectParams)&&void 0!==t&&t.pullAudioFromRtc&&(this._isMicMuted=e,null===(r=this.rtcServer)||void 0===r||r.muteMicphone(e))}}]),O}();export{x as default};
|
|
1
|
+
import{createClass as _createClass,classCallCheck as _classCallCheck,defineProperty as _defineProperty,objectSpread2 as _objectSpread2,asyncToGenerator as _asyncToGenerator,regeneratorRuntime as _regeneratorRuntime}from"./_virtual/_rollupPluginBabelHelpers.js";import CustomJSON from"@bddh/starling-json";import isEmpty from"lodash/isEmpty";import omit from"lodash/omit";import pick from"lodash/pick";import{v4}from"uuid";import{statusEnum,errorTypeEnum,CONNECT_MAIN_KEY}from"./interface.js";import Server from"./Server.js";import BrtcClient from"./BrtcClient.js";import{removeLastFrameCoverWrapper,removeHumanDom,createHumanDom,appendLastFrameCoverSibling,appendRtcDomStyle,RTC_VIDEO_ID,checkIsHuawei,setHumanPlayerWrapperVisible,setLastFrameCoverVisible,captureLastFrameToCover,playHumanVideo,muteHumanVideo,ensureCutoutDomMounted}from"./DomControl.js";import Cutout from"./Cutout.js";import RecordController from"./RecordController.js";var DhRealtimeHuman=function(_handleConnectResponse,_mergeConnectRtcExtrasFromBody,_applyConnectChroma){function DhRealtimeHuman(props){var _ref4,_this=this;_classCallCheck(this,DhRealtimeHuman),_defineProperty(this,"token",void 0),_defineProperty(this,"appKey",void 0),_defineProperty(this,"appId",void 0),_defineProperty(this,"connectParams",void 0),_defineProperty(this,"onDigitalHumanCallback",void 0),_defineProperty(this,"dhServer",void 0),_defineProperty(this,"rtcServer",void 0),_defineProperty(this,"rtcConnectParams",void 0),_defineProperty(this,"cutoutInstance",void 0),_defineProperty(this,"hasInitChromaEffects",!1),_defineProperty(this,"isHuawei",checkIsHuawei()),_defineProperty(this,"rtcServerUrl",void 0),_defineProperty(this,"rtcInternalIp",void 0),_defineProperty(this,"recordController",null),_defineProperty(this,"wsReadyState",-1),_defineProperty(this,"isPreOpenSession",!1),_defineProperty(this,"openWsOnly",!1),_defineProperty(this,"hasConnectUserFigureEffects",!1),_defineProperty(this,"_isMicMuted",!1),_defineProperty(this,"mergeConnectRtcExtras",!1),_defineProperty(this,"emitRawStatusMessage",!1),_defineProperty(this,"resolveMediaServerByDomain",void 0),_defineProperty(this,"remoteAutoPlay",!0),_defineProperty(this,"onDigitalHumanCallbackPlus",(function(data){var _this$cutoutInstance,_this$rtcServer,content=data.content;data.status===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()&&(setHumanPlayerWrapperVisible(!1),setLastFrameCoverVisible(!0))));_this.onDigitalHumanCallback&&_this.onDigitalHumanCallback(data)})),_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)})),_defineProperty(this,"onLocalStream",(function(){(_this.connectParams||{}).pullAudioFromRtc&&_this.rtcServer&&_this.rtcServer.muteMicphone(_this._isMicMuted)})),_defineProperty(this,"onRemoteVideoOn",(function(){setTimeout(_asyncToGenerator(_regeneratorRuntime().mark((function _callee(){var video;return _regeneratorRuntime().wrap((function(_context){for(;;)switch(_context.prev=_context.next){case 0:if(video=document.getElementById(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()&&(captureLastFrameToCover(),setHumanPlayerWrapperVisible(!0),setLastFrameCoverVisible(!1));case 6:case"end":return _context.stop()}}),_callee)}))),100)})),_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()}})),_defineProperty(this,"onRemoteVideoOffLastFrame",(function(){var _this$cutoutInstance2;null===(_this$cutoutInstance2=_this.cutoutInstance)||void 0===_this$cutoutInstance2||_this$cutoutInstance2.setPlaying(!1),_this.canShowStaticFrameCover()&&setLastFrameCoverVisible(!0)})),_defineProperty(this,"connectListener",(function(data){_this.handleConnectResponse(data).catch((function(e){console.warn("[DhRealtimeHuman] handleConnectResponse failed",e)}))})),_defineProperty(this,"createServer",(function(sessionId){var _this$dhServer,params=_objectSpread2(_objectSpread2(_objectSpread2({token:_this.token,appKey:_this.appKey,appId:_this.appId},sessionId?{sessionId:sessionId}:{}),pick(_this.connectParams,CONNECT_MAIN_KEY)),{},{parameters:omit(_this.connectParams,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)})),_defineProperty(this,"checkHumanInstansce",(function(){return _this.dhServer?!(_this.isPreOpenSession&&!_this.dhServer.preConnectSuccess)||(_this.onDigitalHumanCallback&&_this.onDigitalHumanCallback({status:statusEnum.DH_LIB_ERROR,content:{type:errorTypeEnum.CONNECT_ERROR,msg:{code:4001,errMsg:"webSocket连接中"}}}),!1):(_this.onDigitalHumanCallback&&_this.onDigitalHumanCallback({status:statusEnum.DH_LIB_ERROR,content:{type:errorTypeEnum.CONNECT_ERROR,msg:{code:4002,errMsg:"请先初始化数字人实例"}}}),!1)})),_defineProperty(this,"sendMessage",(function(message,listener){return _this.dhServer&&_this.dhServer.sendMessage(message,listener)})),_defineProperty(this,"interrupt",_asyncToGenerator(_regeneratorRuntime().mark((function _callee2(){return _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:v4(),action:"TEXT_RENDER",body:"<interrupt></interrupt>",clientTs:(new Date).getTime()},(function(){return resolve()}))})));case 1:case"end":return _context2.stop()}}),_callee2)})))),_defineProperty(this,"textRender",(function(renderData){var requestId=renderData.requestId,body=renderData.body,onCallbackMsg=renderData.onCallbackMsg;_this.checkHumanInstansce()&&_this.dhServer&&_this.dhServer.sendMessage({requestId:requestId||v4(),action:"TEXT_RENDER",body:body,clientTs:(new Date).getTime()},onCallbackMsg)})),_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||v4(),action:"TEXT_STREAM_RENDER",body:body,clientTs:(new Date).getTime()},first?onCallbackMsg:null)})),_defineProperty(this,"audioRender",(function(renderData){var body=renderData.body,onCallbackMsg=renderData.onCallbackMsg;_this.checkHumanInstansce()&&_this.dhServer&&_this.dhServer.sendMessage({requestId:v4(),action:"AUDIO_RENDER",body:body,clientTs:(new Date).getTime()},onCallbackMsg)})),_defineProperty(this,"audioStreamRender",(function(renderData){var requestId=renderData.requestId,body=renderData.body,onCallbackMsg=renderData.onCallbackMsg;_this.checkHumanInstansce()&&_this.dhServer&&_this.dhServer.sendMessage({requestId:requestId||v4(),action:"AUDIO_STREAM_RENDER",body:body,clientTs:(new Date).getTime()},onCallbackMsg)})),_defineProperty(this,"textQuery",(function(queryData){var requestId=queryData.requestId,body=queryData.body,onCallbackMsg=queryData.onCallbackMsg;_this.dhServer&&_this.dhServer.sendMessage({requestId:requestId||v4(),action:"TEXT_QUERY",body:body,clientTs:(new Date).getTime()},onCallbackMsg)})),_defineProperty(this,"handleDestroyView",(function(keepLastFrame){var _this$cutoutInstance4,_this$cutoutInstance3;return keepLastFrame?_this.canShowStaticFrameCover()?(playHumanVideo(!1),setHumanPlayerWrapperVisible(!1),void 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,removeHumanDom(),void removeLastFrameCoverWrapper())})),_defineProperty(this,"destroy",(function(_x){return(_ref4=_ref4||_asyncToGenerator(_regeneratorRuntime().mark((function _callee3(options){var _this$recordControlle,_ref5$keepLastFrame,keepLastFrame;return _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)})),_defineProperty(this,"pauseHuman",(function(){return playHumanVideo(!1)})),_defineProperty(this,"playHuman",(function(){return playHumanVideo(!0)})),_defineProperty(this,"muteHuman",(function(){return muteHumanVideo(!0)})),_defineProperty(this,"unMuteHuman",(function(){var humanVideo=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(wsUrl||"wss://open.xiling.baidu.com/cloud/digital-human-demonstration",{checkHeartbeatMismatch:checkHeartbeatMismatch,emitRawStatusMessage:emitRawStatusMessage}),this.onDigitalHumanCallback=function(data){data.status!==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 _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=_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),removeLastFrameCoverWrapper(),removeHumanDom();var playerWrapper=(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"),appendLastFrameCoverSibling(wrapperEle)),appendRtcDomStyle();var rtcConfig=_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({closeLog:closeLog,videoWrapperId:RTC_VIDEO_ID,rtcConfig:rtcConfig,bizConfig:_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({sourceId: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({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:statusEnum.DH_LIB_ERROR,content:{type:errorTypeEnum.CONNECT_ERROR,msg:{code:-1,errMsg:err.message}}})}})}},{key:"handleConnectResponse",value:function(_x2){return(_handleConnectResponse=_handleConnectResponse||_asyncToGenerator(_regeneratorRuntime().mark((function _callee4(data){var code,body,message,_data,server,appId,token,roomName,userId,feedId,chargeId;return _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:statusEnum.DH_LIB_WS_SUCCESS,content:data}),this.emitRawStatusMessage&&this.onDigitalHumanCallback&&this.onDigitalHumanCallback({status: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:statusEnum.DH_LIB_ERROR,content:{type: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||_asyncToGenerator(_regeneratorRuntime().mark((function _callee5(body){var _body$userFigure,userFigure,_body$rtcExternalInfo,mediaServerDN,partial,userFigureParams,resolve;return _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||_asyncToGenerator(_regeneratorRuntime().mark((function _callee6(effects){var _this$cutoutInstance5,chromaKey,version,video;return _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(ensureCutoutDomMounted()){_context6.next=7;break}return _context6.abrupt("return");case 7:if(this.hasConnectUserFigureEffects=!0,removeLastFrameCoverWrapper(),setLastFrameCoverVisible(!1),setHumanPlayerWrapperVisible(!0),null===(_this$cutoutInstance5=this.cutoutInstance)||void 0===_this$cutoutInstance5||_this$cutoutInstance5.destroy(),this.cutoutInstance=new Cutout({sourceId:RTC_VIDEO_ID,effects:{version:version,chromaKey:chromaKey}}),!(video=document.getElementById(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:v4(),clientTs:Date.now(),body:""},null);this.recordController&&this.recordController.stop(),this.sendMessage({action:"AUDIO_QUERY_INTERRUPT",requestId: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}();export{DhRealtimeHuman as default};
|
package/es/Cutout.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createClass as
|
|
1
|
+
import{createClass as _createClass,classCallCheck as _classCallCheck,defineProperty as _defineProperty}from"./_virtual/_rollupPluginBabelHelpers.js";import Seriously from"@bddh/starling-cutout/es/Seriously";var DEFAULT_EFFECTS={version:2,chromaKey:{screen:[53,186,123],similarity:90,edgeShrink:3,smoothness:80,spill:100,opacity:1,contrast:0,brightness:0,gamma:0}},Cutout=function(){function Cutout(props){_classCallCheck(this,Cutout),_defineProperty(this,"cutoutInstance",void 0),_defineProperty(this,"sourceId",void 0);var effects=props.effects,sourceId=props.sourceId;this.sourceId=sourceId||"starling-cutout-video",this.cutoutInstance=new Seriously("starling-cutout-canvas",this.sourceId,effects&&effects.chromaKey||DEFAULT_EFFECTS.chromaKey,effects&&effects.version||DEFAULT_EFFECTS.version),this.setPlaying(!0)}return _createClass(Cutout,[{key:"setOptions",value:function(options){options&&this.cutoutInstance&&this.cutoutInstance.setOptions(options)}},{key:"destroy",value:function(){return this.cutoutInstance.destroy()}},{key:"setPlaying",value:function(playing){var source=document.getElementById(this.sourceId);source?source.setAttribute("data-playing",playing?"true":"false"):console.warn("[Cutout] video element not found: #".concat(this.sourceId,", skip setPlaying(").concat(playing,")"))}},{key:"updateSource",value:function(video){return"string"==typeof video&&(this.sourceId=video),this.setPlaying(!0),this.cutoutInstance.updateSource(video)}}]),Cutout}();export{DEFAULT_EFFECTS,Cutout as default};
|
package/es/DomControl.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var DEFAULT_CANVAS_ID="starling-cutout-canvas",HUMAN_WRAPPER_ID="cloud-brtc-player-wrapper",RTC_VIDEO_ID="remotevideo500",LAST_FRAME_COVER_CANVAS_CLASS="canvas-item",LAST_FRAME_COVER_INNER_CANVAS_ID="starling-last-frame-cover-canvas";function createHumanDom(options){var _options$autoChromaKe=options.autoChromaKey,autoChromaKey=void 0!==_options$autoChromaKe&&_options$autoChromaKe,_options$autoplay=options.autoplay,autoplay=void 0===_options$autoplay||_options$autoplay;if(document.getElementById(RTC_VIDEO_ID))return console.error('DOM with id "'.concat(RTC_VIDEO_ID,'" already exists.')),null;var playerWrapper=document.createElement("div");playerWrapper.className=HUMAN_WRAPPER_ID,playerWrapper.id=HUMAN_WRAPPER_ID,playerWrapper.style.position="relative";var video=document.createElement("video");if(video.id=RTC_VIDEO_ID,video.width=0,video.height=0,video.setAttribute("width","100%"),video.setAttribute("height","100%"),video.setAttribute("data-playing","true"),video.setAttribute("playsinline",""),autoplay&&video.setAttribute("autoplay",""),playerWrapper.appendChild(video),autoChromaKey){var canvas=document.createElement("canvas");canvas.id="starling-cutout-canvas",Object.assign(canvas.style,{position:"absolute",top:"0",left:"0",height:"100%",width:"100%",zIndex:"1",display:autoChromaKey?"block":"none"}),video.style.visibility="hidden",playerWrapper.appendChild(canvas)}return{playerWrapper:playerWrapper,video:video}}function ensureCutoutDomMounted(){if(document.getElementById("starling-cutout-canvas"))return!0;var wrapper=document.getElementById(HUMAN_WRAPPER_ID),video=document.getElementById(RTC_VIDEO_ID);if(!wrapper||!video)return!1;var canvas=document.createElement("canvas");return canvas.id="starling-cutout-canvas",Object.assign(canvas.style,{position:"absolute",top:"0",left:"0",height:"100%",width:"100%",zIndex:"1",display:"block"}),video.style.visibility="hidden",wrapper.appendChild(canvas),!0}function appendLastFrameCoverSibling(mountEl){if(mountEl&&!mountEl.querySelector("[".concat("data-dh-last-frame-cover",'="1"]'))){var wrap=document.createElement("div");wrap.className="".concat("canvas-item"," "),wrap.setAttribute("data-dh-last-frame-cover","1");var canvas=document.createElement("canvas");canvas.id="starling-last-frame-cover-canvas",Object.assign(canvas.style,{position:"absolute",top:"0",left:"0",width:"100%",height:"100%",objectFit:"cover",display:"block",zIndex:"0"}),wrap.appendChild(canvas),mountEl.appendChild(wrap)}}function captureLastFrameToCover(){var cover=document.getElementById("starling-last-frame-cover-canvas");if(!cover)return!1;var ctx=cover.getContext("2d");if(!ctx)return!1;var chroma=document.getElementById("starling-cutout-canvas"),video=document.getElementById(RTC_VIDEO_ID);return chroma&&chroma.width>0&&chroma.height>0?(cover.width=chroma.width,cover.height=chroma.height,ctx.drawImage(chroma,0,0),!0):!!(video&&video.videoWidth>0&&video.videoHeight>0)&&(cover.width=video.videoWidth,cover.height=video.videoHeight,ctx.drawImage(video,0,0,video.videoWidth,video.videoHeight),!0)}function setHumanPlayerWrapperVisible(visible){var el=document.getElementById(HUMAN_WRAPPER_ID);el&&(el.style.visibility=visible?"visible":"hidden",el.style.pointerEvents=visible?"":"none")}function setLastFrameCoverVisible(visible){var inner=document.getElementById("starling-last-frame-cover-canvas"),wrap=null==inner?void 0:inner.parentNode;wrap&&(wrap.style.visibility=visible?"visible":"hidden")}function removeLastFrameCoverWrapper(){var wrap=document.querySelector("[".concat("data-dh-last-frame-cover",'="1"]'));null!=wrap&&wrap.parentNode&&wrap.parentNode.removeChild(wrap)}function removeHumanDom(){var humanDom=document.getElementById(HUMAN_WRAPPER_ID);humanDom&&humanDom.parentNode&&humanDom.parentNode.removeChild(humanDom)}function muteHumanVideo(muted){var humanVideoDom=document.getElementById(RTC_VIDEO_ID);return humanVideoDom&&(humanVideoDom.muted=muted),humanVideoDom}function playHumanVideo(play){var humanVideoDom=document.getElementById(RTC_VIDEO_ID);try{if(humanVideoDom)return play?humanVideoDom.play():humanVideoDom.pause()}catch(e){console.info(e)}}function checkIsHuawei(){var ua=navigator.userAgent||navigator.vendor;return/huawei/i.test(ua)||/honor/i.test(ua)}function appendRtcDomStyle(){var style=document.createElement("style");style.appendChild(document.createTextNode('\n [id^="videoremote1-"] {\n display: none !important;\n }\n \n video#remotevideo500 {\n width: auto !important;\n height: auto !important;\n max-width: 100% !important;\n max-height: 100% !important;\n width: 100% !important;\n height: 100% !important;\n object-fit: cover;\n }\n\n .cloud-brtc-player-wrapper {\n width: inherit !important;\n background-size: cover;\n height: inherit;\n display: flex;\n justify-content: center;\n }\n\n #starling-cutout-canvas {\n object-fit: cover;\n }\n\n [data-dh-last-frame-cover="1"] {\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n pointer-events: none;\n z-index: 1;\n visibility: hidden;\n }\n\n [data-dh-last-frame-cover="1"] canvas {\n width: 100%;\n height: 100%;\n object-fit: cover;\n display: block;\n }\n ')),document.head.appendChild(style)}export{DEFAULT_CANVAS_ID,HUMAN_WRAPPER_ID,LAST_FRAME_COVER_CANVAS_CLASS,LAST_FRAME_COVER_INNER_CANVAS_ID,RTC_VIDEO_ID,appendLastFrameCoverSibling,appendRtcDomStyle,captureLastFrameToCover,checkIsHuawei,createHumanDom,ensureCutoutDomMounted,muteHumanVideo,playHumanVideo,removeHumanDom,removeLastFrameCoverWrapper,setHumanPlayerWrapperVisible,setLastFrameCoverVisible};
|
package/es/RecordController.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createClass as
|
|
1
|
+
import{createClass as _createClass,asyncToGenerator as _asyncToGenerator,regeneratorRuntime as _regeneratorRuntime,objectSpread2 as _objectSpread2,classCallCheck as _classCallCheck,defineProperty as _defineProperty}from"./_virtual/_rollupPluginBabelHelpers.js";function sampleData(pcmDatas,pcmSampleRate,newSampleRate,prevChunkInfo){try{for(var index=(prevChunkInfo=prevChunkInfo||{})&&"number"==typeof prevChunkInfo.index?prevChunkInfo.index:0,offset=prevChunkInfo&&"number"==typeof prevChunkInfo.offset?prevChunkInfo.offset:0,size=0,i=index;i<pcmDatas.length;i++)size+=pcmDatas[i].length;size=Math.max(0,size-Math.floor(offset));var step=pcmSampleRate/newSampleRate;step>1?size=Math.floor(size/step):(step=1,newSampleRate=pcmSampleRate);for(var res=new Int16Array(size),idx=0,nl=pcmDatas.length;index<nl;index++){for(var o=pcmDatas[index],_i=offset,il=o.length;_i<il;){var before=Math.floor(_i),after=Math.ceil(_i),atPoint=_i-before;res[idx]=o[before]+(o[after]-o[before])*atPoint,idx++,_i+=step}offset=_i-il}return{index:index,offset:offset,sampleRate:newSampleRate,data:res}}catch(error){console.log("转音错误了",error)}}function convertBuffer(arrayBuffer){for(var data=arrayBuffer,out=new Int16Array(arrayBuffer.length),i=0;i<data.length;i++){var s=Math.max(-1,Math.min(1,data[i]));out[i]=s<0?32768*s:32767*s}return out}var RecordController=function(_preWarmStream,_start){function RecordController(options){_classCallCheck(this,RecordController),_defineProperty(this,"onAudioData",void 0),_defineProperty(this,"onError",void 0),_defineProperty(this,"audioContext",null),_defineProperty(this,"processor",null),_defineProperty(this,"mediaStream",null),_defineProperty(this,"recording",!1),_defineProperty(this,"audio3AConstraints",void 0),_defineProperty(this,"asrSample",void 0),this.onAudioData=options.onAudioData,this.onError=options.onError,this.audio3AConstraints=options.audio3AConstraints,this.asrSample=options.asrSample,this.preWarmStream()}return _createClass(RecordController,[{key:"preWarmStream",value:function(){return(_preWarmStream=_preWarmStream||_asyncToGenerator(_regeneratorRuntime().mark((function _callee(){var _navigator$mediaDevic,AudioCtx,source;return _regeneratorRuntime().wrap((function(_context){for(;;)switch(_context.prev=_context.next){case 0:if(_context.prev=0,AudioCtx=window.AudioContext||window.webkitAudioContext){_context.next=4;break}throw new Error("当前环境不支持web api: AudioContext");case 4:if(null!==(_navigator$mediaDevic=navigator.mediaDevices)&&void 0!==_navigator$mediaDevic&&_navigator$mediaDevic.getUserMedia){_context.next=6;break}throw new Error("当前环境不支持web api: getUserMedia");case 6:return this.audioContext=new AudioCtx({sampleRate:this.asrSample||16e3}),_context.next=9,navigator.mediaDevices.getUserMedia({audio:_objectSpread2({echoCancellation:!0,noiseSuppression:!0,autoGainControl:!0},this.audio3AConstraints),video:!1});case 9:this.mediaStream=_context.sent,source=this.audioContext.createMediaStreamSource(this.mediaStream),this.processor=this.audioContext.createScriptProcessor(1024,1,1),source.connect(this.processor),this.processor.connect(this.audioContext.destination),this.processor.onaudioprocess=function(){},_context.next=20;break;case 17:_context.prev=17,_context.t0=_context.catch(0),console.error("preWarmStream error",_context.t0);case 20:case"end":return _context.stop()}}),_callee,this,[[0,17]])})))).apply(this,arguments)}},{key:"start",value:function(){return(_start=_start||_asyncToGenerator(_regeneratorRuntime().mark((function _callee2(){var _this=this;return _regeneratorRuntime().wrap((function(_context2){for(;;)switch(_context2.prev=_context2.next){case 0:if(!this.recording){_context2.next=2;break}return _context2.abrupt("return");case 2:if(this.audioContext&&this.processor){_context2.next=4;break}return _context2.abrupt("return");case 4:try{this.processor.onaudioprocess=function(e){if(_this.recording){var resampled=sampleData([convertBuffer(e.inputBuffer.getChannelData(0))],_this.audioContext.sampleRate,_this.asrSample||16e3,null);resampled&&resampled.data&&_this.onAudioData(resampled.data.buffer)}},this.recording=!0}catch(err){this.onError&&this.onError(err)}case 5:case"end":return _context2.stop()}}),_callee2,this)})))).apply(this,arguments)}},{key:"stop",value:function(){this.recording=!1,this.processor.onaudioprocess=function(){}}},{key:"destroy",value:function(){this.recording=!1,this.processor&&(this.processor.disconnect(),this.processor.onaudioprocess=null),this.audioContext&&this.audioContext.close(),this.mediaStream&&this.mediaStream.getTracks().forEach((function(track){track.stop()}))}}]),RecordController}();export{RecordController as default};
|
package/es/Server.d.ts
CHANGED
|
@@ -69,6 +69,7 @@ declare class Server {
|
|
|
69
69
|
createSocket: (props: createSocketParamsType, isPreOpenSession?: boolean) => Promise<WebSocketClient | null>;
|
|
70
70
|
sendConnect: (props: createSocketParamsType) => void;
|
|
71
71
|
closeSocket: () => Promise<void>;
|
|
72
|
+
destroySocket: () => Promise<void>;
|
|
72
73
|
handleConnect: () => Promise<void>;
|
|
73
74
|
sendMessage(message: DHServerInterface | ArrayBuffer, listener: RenderCallback | null): Promise<void>;
|
|
74
75
|
private startConnectingWatch;
|
package/es/Server.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createClass as
|
|
1
|
+
import{createClass as _createClass,asyncToGenerator as _asyncToGenerator,regeneratorRuntime as _regeneratorRuntime,typeof as _typeof,classCallCheck as _classCallCheck,defineProperty as _defineProperty,objectSpread2 as _objectSpread2}from"./_virtual/_rollupPluginBabelHelpers.js";import{v4}from"uuid";import{createWebSocket}from"@bddh/starling-web-socket/es/create-web-socket";import{ReadyState}from"@bddh/starling-web-socket/es/interface";import pick from"lodash/pick";import omit from"lodash/omit";import get from"lodash/get";import{errorTypeEnum,CONNECT_MAIN_KEY,statusEnum,WS_STATUS_MAP}from"./interface.js";var CONNECTING_STUCK_MS_DEFAULT=3e4,Server=function(_sendMessage){function Server(url,options){var _ref,_this=this;_classCallCheck(this,Server),_defineProperty(this,"dhServerSocket",null),_defineProperty(this,"preConnectSuccess",!1),_defineProperty(this,"connectParams",null),_defineProperty(this,"socketClosingPromise",null),_defineProperty(this,"url",void 0),_defineProperty(this,"firstConnect",!0),_defineProperty(this,"connectingTimer",null),_defineProperty(this,"connectingMs",3e4),_defineProperty(this,"lastPreOpen",!1),_defineProperty(this,"reconnectingTimeout",!1),_defineProperty(this,"lastReportedReadyState",-1),_defineProperty(this,"lastHbAckTs",0),_defineProperty(this,"checkHeartbeatMismatch",void 0),_defineProperty(this,"emitRawStatusMessage",void 0),_defineProperty(this,"sendPreConnect",(function(props,resolve){var _this$dhServerSocket,token=props.token,sessionId=props.sessionId,onConnect=props.onConnect;null===(_this$dhServerSocket=_this.dhServerSocket)||void 0===_this$dhServerSocket||_this$dhServerSocket.request({action:"RE_CONNECT",requestId:v4(),body:JSON.stringify({token:token,sessionId:sessionId})}).on((function(res,off){null==onConnect||onConnect(res),0!==res.code&&(off(),_this.handleConnect()),null==resolve||resolve(_this.dhServerSocket)})),_this.firstConnect=!1})),_defineProperty(this,"createSocket",(function(_x,_x2){return(_ref=_ref||_asyncToGenerator(_regeneratorRuntime().mark((function _callee(props,isPreOpenSession){var sessionId,onDigitalHumanCallback;return _regeneratorRuntime().wrap((function(_context){for(;;)switch(_context.prev=_context.next){case 0:if(_this.connectParams=props,_this.lastPreOpen=!!isPreOpenSession,sessionId=props.sessionId,onDigitalHumanCallback=props.onDigitalHumanCallback,!_this.socketClosingPromise){_context.next=6;break}return _context.next=6,_this.socketClosingPromise;case 6:if(!_this.dhServerSocket||_this.dhServerSocket.readyState===ReadyState.CLOSED){_context.next=9;break}return _context.next=9,_this.closeSocket();case 9:return _context.abrupt("return",new Promise((function(resolve,reject){var settled=!1,onceResolve=function(value){settled||(settled=!0,resolve(value))},createPamrams={keepAlive:"heartbeat",checkHeartbeatMismatch:_this.checkHeartbeatMismatch,reopen:get(_this.connectParams,"reConnect",!0),getKeepAliveMessage:function(requestId){return{requestId:requestId,action:"HEART_BEAT",body:"".concat(_this.lastHbAckTs),clientTs:Date.now()}},combine:function(req,res){return req&&res&&req.requestId===res.requestId},onOpen:function(){_this.dhServerSocket=socket,onceResolve(_this.dhServerSocket),sessionId&&_this.firstConnect?_this.sendPreConnect(props,onceResolve):isPreOpenSession&&_this.firstConnect||_this.handleConnect()},onClose:function(){_this.socketClosingPromise=null,onceResolve(null)},onError:function(error){reject(error)}},socket=createWebSocket(_this.url,createPamrams);socket.onReadyStateChange((function(readyState){_this.lastReportedReadyState=readyState,0===readyState?(_this.startConnectingWatch(),onDigitalHumanCallback&&onDigitalHumanCallback({status:statusEnum.DH_LIB_INIT})):(_this.clearConnectingWatch(),_this.reconnectingTimeout=!1),1===readyState&&isPreOpenSession&&(_this.preConnectSuccess=!0),3===readyState&&(_this.preConnectSuccess=!1),onDigitalHumanCallback&&onDigitalHumanCallback({status:statusEnum.DH_LIB_FULL_STATUS,content:{type:"wsState",readyState:readyState,body:WS_STATUS_MAP[readyState]}})})),socket.onMessage((function(msgData){var action=msgData.action;"HEART_BEAT"===action&&(_this.lastHbAckTs=Date.now()),[errorTypeEnum.TIMEOUT_EXIT,errorTypeEnum.DISCONNECT_ALERT].includes(action)&&(onDigitalHumanCallback&&onDigitalHumanCallback({status:statusEnum.DH_LIB_STATUS,content:{type:action}}),_this.emitRawStatusMessage&&onDigitalHumanCallback&&onDigitalHumanCallback({status:statusEnum.DH_LIB_MESSAGE,content:msgData})),[errorTypeEnum.TIMEOUT_EXIT,errorTypeEnum.DISCONNECT_ALERT,"HEART_BEAT","CONNECT"].includes(action)||onDigitalHumanCallback&&onDigitalHumanCallback({status:statusEnum.DH_LIB_MESSAGE,content:msgData})})),_this.dhServerSocket=socket,socket.open()})));case 10:case"end":return _context.stop()}}),_callee)})))).apply(this,arguments)})),_defineProperty(this,"sendConnect",(function(props){_this.connectParams=props,_this.dhServerSocket&&_this.handleConnect()})),_defineProperty(this,"closeSocket",_asyncToGenerator(_regeneratorRuntime().mark((function _callee2(){return _regeneratorRuntime().wrap((function(_context2){for(;;)switch(_context2.prev=_context2.next){case 0:if(_this.resetState(),_this.dhServerSocket){_context2.next=3;break}return _context2.abrupt("return");case 3:return _this.socketClosingPromise=_this.dhServerSocket.close(),_context2.next=6,_this.socketClosingPromise;case 6:_this.dhServerSocket=null;case 7:case"end":return _context2.stop()}}),_callee2)})))),_defineProperty(this,"destroySocket",_asyncToGenerator(_regeneratorRuntime().mark((function _callee3(){var _this$dhServerSocket2;return _regeneratorRuntime().wrap((function(_context3){for(;;)switch(_context3.prev=_context3.next){case 0:_this.resetState(),_this.connectParams=null,null===(_this$dhServerSocket2=_this.dhServerSocket)||void 0===_this$dhServerSocket2||_this$dhServerSocket2.destroy(),_this.dhServerSocket=null;case 4:case"end":return _context3.stop()}}),_callee3)})))),_defineProperty(this,"handleConnect",_asyncToGenerator(_regeneratorRuntime().mark((function _callee4(){var _this$connectParams,appId,appKey,token,parameters,onConnect;return _regeneratorRuntime().wrap((function(_context4){for(;;)switch(_context4.prev=_context4.next){case 0:if(_this.dhServerSocket&&_this.connectParams){_context4.next=2;break}return _context4.abrupt("return");case 2:if(_this$connectParams=_this.connectParams,appId=_this$connectParams.appId,appKey=_this$connectParams.appKey,token=_this$connectParams.token,parameters=_this$connectParams.parameters,onConnect=_this$connectParams.onConnect,appId||appKey||token){_context4.next=5;break}return _context4.abrupt("return");case 5:_this.dhServerSocket&&_this.dhServerSocket.request({action:"CONNECT",clientTs:(new Date).getTime(),requestId:v4(),body:JSON.stringify(_objectSpread2(_objectSpread2({token:token,appId:appId,appKey:appKey},pick(_this.connectParams,CONNECT_MAIN_KEY)),{},{parameters:_objectSpread2(_objectSpread2({},omit(parameters,["parameters"])),parameters&¶meters.parameters?parameters.parameters:{})}))}).on((function(res,off){null==onConnect||onConnect(res),0!==res.code&&off()}));case 6:case"end":return _context4.stop()}}),_callee4)}))));var _ref5=options||{},checkHeartbeatMismatch=_ref5.checkHeartbeatMismatch,_ref5$emitRawStatusMe=_ref5.emitRawStatusMessage,emitRawStatusMessage=void 0!==_ref5$emitRawStatusMe&&_ref5$emitRawStatusMe;this.url=url,this.checkHeartbeatMismatch=null!=checkHeartbeatMismatch&&checkHeartbeatMismatch,this.emitRawStatusMessage=emitRawStatusMessage}return _createClass(Server,[{key:"setEmitRawStatusMessage",value:function(value){this.emitRawStatusMessage=value}},{key:"sendMessage",value:function(_x3,_x4){return(_sendMessage=_sendMessage||_asyncToGenerator(_regeneratorRuntime().mark((function _callee5(message,listener){var requestId;return _regeneratorRuntime().wrap((function(_context5){for(;;)switch(_context5.prev=_context5.next){case 0:try{this.dhServerSocket&&this.dhServerSocket&&this.dhServerSocket.request(message).on((function(response){listener&&listener(response)}))}catch(e){requestId="object"===_typeof(message)&&"requestId"in message?message.requestId:v4(),listener&&listener({code:-11,body:null,action:"RENDER_ERROR",requestId:requestId,message:JSON.stringify(e)})}case 1:case"end":return _context5.stop()}}),_callee5,this)})))).apply(this,arguments)}},{key:"startConnectingWatch",value:function(){var _this2=this;this.connectingTimer||this.reconnectingTimeout||(this.connectingTimer=setTimeout(_asyncToGenerator(_regeneratorRuntime().mark((function _callee6(){return _regeneratorRuntime().wrap((function(_context6){for(;;)switch(_context6.prev=_context6.next){case 0:if(_this2.connectingTimer=null,_this2.dhServerSocket&&0===_this2.lastReportedReadyState){_context6.next=3;break}return _context6.abrupt("return");case 3:if(console.warn("reconnect from CONNECTING timeout"),_this2.reconnectingTimeout=!0,_context6.prev=5,!_this2.connectParams){_context6.next=9;break}return _context6.next=9,_this2.createSocket(_this2.connectParams,_this2.lastPreOpen);case 9:_context6.next=14;break;case 11:_context6.prev=11,_context6.t0=_context6.catch(5),console.error("reconnect from CONNECTING timeout failed",_context6.t0);case 14:return _context6.prev=14,_this2.reconnectingTimeout=!1,_context6.finish(14);case 17:case"end":return _context6.stop()}}),_callee6,null,[[5,11,14,17]])}))),this.connectingMs))}},{key:"clearConnectingWatch",value:function(){this.connectingTimer&&(clearTimeout(this.connectingTimer),this.connectingTimer=null)}},{key:"resetState",value:function(){this.clearConnectingWatch(),this.reconnectingTimeout=!1,this.lastReportedReadyState=-1,this.lastHbAckTs=0}}]),Server}();export{CONNECTING_STUCK_MS_DEFAULT,Server as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function t(t,r){var e=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(t,r).enumerable}))),e.push.apply(e,n)}return e}function r(r){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?t(Object(n),!0).forEach((function(t){f(r,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(n)):t(Object(n)).forEach((function(t){Object.defineProperty(r,t,Object.getOwnPropertyDescriptor(n,t))}))}return r}function e(){e=function(){return r};var t,r={},n=Object.prototype,o=n.hasOwnProperty,i=Object.defineProperty||function(t,r,e){t[r]=e.value},a="function"==typeof Symbol?Symbol:{},c=a.iterator||"@@iterator",u=a.asyncIterator||"@@asyncIterator",f=a.toStringTag||"@@toStringTag";function l(t,r,e){return Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}),t[r]}try{l({},"")}catch(t){l=function(t,r,e){return t[r]=e}}function s(t,r,e,n){var o=r&&r.prototype instanceof m?r:m,a=Object.create(o.prototype),c=new N(n||[]);return i(a,"_invoke",{value:S(t,e,c)}),a}function h(t,r,e){try{return{type:"normal",arg:t.call(r,e)}}catch(t){return{type:"throw",arg:t}}}r.wrap=s;var p="suspendedStart",y="suspendedYield",v="executing",g="completed",d={};function m(){}function b(){}function w(){}var O={};l(O,c,(function(){return this}));var j=Object.getPrototypeOf,L=j&&j(j(T([])));L&&L!==n&&o.call(L,c)&&(O=L);var E=w.prototype=m.prototype=Object.create(O);function x(t){["next","throw","return"].forEach((function(r){l(t,r,(function(t){return this._invoke(r,t)}))}))}function P(t,r){function e(n,i,a,c){var u=h(t[n],t,i);if("throw"!==u.type){var f=u.arg,l=f.value;return l&&"object"==typeof l&&o.call(l,"__await")?r.resolve(l.__await).then((function(t){e("next",t,a,c)}),(function(t){e("throw",t,a,c)})):r.resolve(l).then((function(t){f.value=t,a(f)}),(function(t){return e("throw",t,a,c)}))}c(u.arg)}var n;i(this,"_invoke",{value:function(t,o){function i(){return new r((function(r,n){e(t,o,r,n)}))}return n=n?n.then(i,i):i()}})}function S(r,e,n){var o=p;return function(i,a){if(o===v)throw new Error("Generator is already running");if(o===g){if("throw"===i)throw a;return{value:t,done:!0}}for(n.method=i,n.arg=a;;){var c=n.delegate;if(c){var u=_(c,n);if(u){if(u===d)continue;return u}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(o===p)throw o=g,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o=v;var f=h(r,e,n);if("normal"===f.type){if(o=n.done?g:y,f.arg===d)continue;return{value:f.arg,done:n.done}}"throw"===f.type&&(o=g,n.method="throw",n.arg=f.arg)}}}function _(r,e){var n=e.method,o=r.iterator[n];if(o===t)return e.delegate=null,"throw"===n&&r.iterator.return&&(e.method="return",e.arg=t,_(r,e),"throw"===e.method)||"return"!==n&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+n+"' method")),d;var i=h(o,r.iterator,e.arg);if("throw"===i.type)return e.method="throw",e.arg=i.arg,e.delegate=null,d;var a=i.arg;return a?a.done?(e[r.resultName]=a.value,e.next=r.nextLoc,"return"!==e.method&&(e.method="next",e.arg=t),e.delegate=null,d):a:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,d)}function k(t){var r={tryLoc:t[0]};1 in t&&(r.catchLoc=t[1]),2 in t&&(r.finallyLoc=t[2],r.afterLoc=t[3]),this.tryEntries.push(r)}function G(t){var r=t.completion||{};r.type="normal",delete r.arg,t.completion=r}function N(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(k,this),this.reset(!0)}function T(r){if(r||""===r){var e=r[c];if(e)return e.call(r);if("function"==typeof r.next)return r;if(!isNaN(r.length)){var n=-1,i=function e(){for(;++n<r.length;)if(o.call(r,n))return e.value=r[n],e.done=!1,e;return e.value=t,e.done=!0,e};return i.next=i}}throw new TypeError(typeof r+" is not iterable")}return b.prototype=w,i(E,"constructor",{value:w,configurable:!0}),i(w,"constructor",{value:b,configurable:!0}),b.displayName=l(w,f,"GeneratorFunction"),r.isGeneratorFunction=function(t){var r="function"==typeof t&&t.constructor;return!!r&&(r===b||"GeneratorFunction"===(r.displayName||r.name))},r.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,w):(t.__proto__=w,l(t,f,"GeneratorFunction")),t.prototype=Object.create(E),t},r.awrap=function(t){return{__await:t}},x(P.prototype),l(P.prototype,u,(function(){return this})),r.AsyncIterator=P,r.async=function(t,e,n,o,i){void 0===i&&(i=Promise);var a=new P(s(t,e,n,o),i);return r.isGeneratorFunction(e)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},x(E),l(E,f,"Generator"),l(E,c,(function(){return this})),l(E,"toString",(function(){return"[object Generator]"})),r.keys=function(t){var r=Object(t),e=[];for(var n in r)e.push(n);return e.reverse(),function t(){for(;e.length;){var n=e.pop();if(n in r)return t.value=n,t.done=!1,t}return t.done=!0,t}},r.values=T,N.prototype={constructor:N,reset:function(r){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(G),!r)for(var e in this)"t"===e.charAt(0)&&o.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(r){if(this.done)throw r;var e=this;function n(n,o){return c.type="throw",c.arg=r,e.next=n,o&&(e.method="next",e.arg=t),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],c=a.completion;if("root"===a.tryLoc)return n("end");if(a.tryLoc<=this.prev){var u=o.call(a,"catchLoc"),f=o.call(a,"finallyLoc");if(u&&f){if(this.prev<a.catchLoc)return n(a.catchLoc,!0);if(this.prev<a.finallyLoc)return n(a.finallyLoc)}else if(u){if(this.prev<a.catchLoc)return n(a.catchLoc,!0)}else{if(!f)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return n(a.finallyLoc)}}}},abrupt:function(t,r){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.tryLoc<=this.prev&&o.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var i=n;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=r&&r<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=r,i?(this.method="next",this.next=i.finallyLoc,d):this.complete(a)},complete:function(t,r){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&r&&(this.next=r),d},finish:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.finallyLoc===t)return this.complete(e.completion,e.afterLoc),G(e),d}},catch:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.tryLoc===t){var n=e.completion;if("throw"===n.type){var o=n.arg;G(e)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(r,e,n){return this.delegate={iterator:T(r),resultName:e,nextLoc:n},"next"===this.method&&(this.arg=t),d}},r}function n(t){return n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},n(t)}function o(t,r,e,n,o,i,a){try{var c=t[i](a),u=c.value}catch(t){return void e(t)}c.done?r(u):Promise.resolve(u).then(n,o)}function i(t){return function(){var r=this,e=arguments;return new Promise((function(n,i){var a=t.apply(r,e);function c(t){o(a,n,i,c,u,"next",t)}function u(t){o(a,n,i,c,u,"throw",t)}c(void 0)}))}}function a(t,r){if(!(t instanceof r))throw new TypeError("Cannot call a class as a function")}function c(t,r){for(var e=0;e<r.length;e++){var n=r[e];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,s(n.key),n)}}function u(t,r,e){return r&&c(t.prototype,r),e&&c(t,e),Object.defineProperty(t,"prototype",{writable:!1}),t}function f(t,r,e){return(r=s(r))in t?Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[r]=e,t}function l(t,r){if("object"!=typeof t||null===t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,r||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(t)}function s(t){var r=l(t,"string");return"symbol"==typeof r?r:String(r)}export{i as asyncToGenerator,a as classCallCheck,u as createClass,f as defineProperty,r as objectSpread2,e as regeneratorRuntime,l as toPrimitive,s as toPropertyKey,n as typeof};
|
|
1
|
+
function ownKeys(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);r&&(o=o.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,o)}return t}function _objectSpread2(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?ownKeys(Object(t),!0).forEach((function(r){_defineProperty(e,r,t[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):ownKeys(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))}))}return e}function _regeneratorRuntime(){_regeneratorRuntime=function(){return e};var t,e={},r=Object.prototype,n=r.hasOwnProperty,o=Object.defineProperty||function(t,e,r){t[e]=r.value},i="function"==typeof Symbol?Symbol:{},a=i.iterator||"@@iterator",c=i.asyncIterator||"@@asyncIterator",u=i.toStringTag||"@@toStringTag";function define(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{define({},"")}catch(t){define=function(t,e,r){return t[e]=r}}function wrap(t,e,r,n){var i=e&&e.prototype instanceof Generator?e:Generator,a=Object.create(i.prototype),c=new Context(n||[]);return o(a,"_invoke",{value:makeInvokeMethod(t,r,c)}),a}function tryCatch(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}e.wrap=wrap;var h="suspendedStart",l="suspendedYield",f="executing",s="completed",y={};function Generator(){}function GeneratorFunction(){}function GeneratorFunctionPrototype(){}var p={};define(p,a,(function(){return this}));var d=Object.getPrototypeOf,v=d&&d(d(values([])));v&&v!==r&&n.call(v,a)&&(p=v);var g=GeneratorFunctionPrototype.prototype=Generator.prototype=Object.create(p);function defineIteratorMethods(t){["next","throw","return"].forEach((function(e){define(t,e,(function(t){return this._invoke(e,t)}))}))}function AsyncIterator(t,e){function invoke(r,o,i,a){var c=tryCatch(t[r],t,o);if("throw"!==c.type){var u=c.arg,h=u.value;return h&&"object"==typeof h&&n.call(h,"__await")?e.resolve(h.__await).then((function(t){invoke("next",t,i,a)}),(function(t){invoke("throw",t,i,a)})):e.resolve(h).then((function(t){u.value=t,i(u)}),(function(t){return invoke("throw",t,i,a)}))}a(c.arg)}var r;o(this,"_invoke",{value:function(t,n){function callInvokeWithMethodAndArg(){return new e((function(e,r){invoke(t,n,e,r)}))}return r=r?r.then(callInvokeWithMethodAndArg,callInvokeWithMethodAndArg):callInvokeWithMethodAndArg()}})}function makeInvokeMethod(e,r,n){var o=h;return function(i,a){if(o===f)throw new Error("Generator is already running");if(o===s){if("throw"===i)throw a;return{value:t,done:!0}}for(n.method=i,n.arg=a;;){var c=n.delegate;if(c){var u=maybeInvokeDelegate(c,n);if(u){if(u===y)continue;return u}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(o===h)throw o=s,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o=f;var p=tryCatch(e,r,n);if("normal"===p.type){if(o=n.done?s:l,p.arg===y)continue;return{value:p.arg,done:n.done}}"throw"===p.type&&(o=s,n.method="throw",n.arg=p.arg)}}}function maybeInvokeDelegate(e,r){var n=r.method,o=e.iterator[n];if(o===t)return r.delegate=null,"throw"===n&&e.iterator.return&&(r.method="return",r.arg=t,maybeInvokeDelegate(e,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),y;var i=tryCatch(o,e.iterator,r.arg);if("throw"===i.type)return r.method="throw",r.arg=i.arg,r.delegate=null,y;var a=i.arg;return a?a.done?(r[e.resultName]=a.value,r.next=e.nextLoc,"return"!==r.method&&(r.method="next",r.arg=t),r.delegate=null,y):a:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,y)}function pushTryEntry(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function resetTryEntry(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function Context(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(pushTryEntry,this),this.reset(!0)}function values(e){if(e||""===e){var r=e[a];if(r)return r.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var o=-1,i=function next(){for(;++o<e.length;)if(n.call(e,o))return next.value=e[o],next.done=!1,next;return next.value=t,next.done=!0,next};return i.next=i}}throw new TypeError(typeof e+" is not iterable")}return GeneratorFunction.prototype=GeneratorFunctionPrototype,o(g,"constructor",{value:GeneratorFunctionPrototype,configurable:!0}),o(GeneratorFunctionPrototype,"constructor",{value:GeneratorFunction,configurable:!0}),GeneratorFunction.displayName=define(GeneratorFunctionPrototype,u,"GeneratorFunction"),e.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===GeneratorFunction||"GeneratorFunction"===(e.displayName||e.name))},e.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,GeneratorFunctionPrototype):(t.__proto__=GeneratorFunctionPrototype,define(t,u,"GeneratorFunction")),t.prototype=Object.create(g),t},e.awrap=function(t){return{__await:t}},defineIteratorMethods(AsyncIterator.prototype),define(AsyncIterator.prototype,c,(function(){return this})),e.AsyncIterator=AsyncIterator,e.async=function(t,r,n,o,i){void 0===i&&(i=Promise);var a=new AsyncIterator(wrap(t,r,n,o),i);return e.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},defineIteratorMethods(g),define(g,u,"Generator"),define(g,a,(function(){return this})),define(g,"toString",(function(){return"[object Generator]"})),e.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function next(){for(;r.length;){var t=r.pop();if(t in e)return next.value=t,next.done=!1,next}return next.done=!0,next}},e.values=values,Context.prototype={constructor:Context,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(resetTryEntry),!e)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var r=this;function handle(n,o){return a.type="throw",a.arg=e,r.next=n,o&&(r.method="next",r.arg=t),!!o}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return handle("end");if(i.tryLoc<=this.prev){var c=n.call(i,"catchLoc"),u=n.call(i,"finallyLoc");if(c&&u){if(this.prev<i.catchLoc)return handle(i.catchLoc,!0);if(this.prev<i.finallyLoc)return handle(i.finallyLoc)}else if(c){if(this.prev<i.catchLoc)return handle(i.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return handle(i.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,y):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),y},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),resetTryEntry(r),y}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;resetTryEntry(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,r,n){return this.delegate={iterator:values(e),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=t),y}},e}function _typeof(o){return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(o){return typeof o}:function(o){return o&&"function"==typeof Symbol&&o.constructor===Symbol&&o!==Symbol.prototype?"symbol":typeof o},_typeof(o)}function asyncGeneratorStep(gen,resolve,reject,_next,_throw,key,arg){try{var info=gen[key](arg),value=info.value}catch(error){return void reject(error)}info.done?resolve(value):Promise.resolve(value).then(_next,_throw)}function _asyncToGenerator(fn){return function(){var self=this,args=arguments;return new Promise((function(resolve,reject){var gen=fn.apply(self,args);function _next(value){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"next",value)}function _throw(err){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"throw",err)}_next(void 0)}))}}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor))throw new TypeError("Cannot call a class as a function")}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||!1,descriptor.configurable=!0,"value"in descriptor&&(descriptor.writable=!0),Object.defineProperty(target,_toPropertyKey(descriptor.key),descriptor)}}function _createClass(Constructor,protoProps,staticProps){return protoProps&&_defineProperties(Constructor.prototype,protoProps),staticProps&&_defineProperties(Constructor,staticProps),Object.defineProperty(Constructor,"prototype",{writable:!1}),Constructor}function _defineProperty(obj,key,value){return(key=_toPropertyKey(key))in obj?Object.defineProperty(obj,key,{value:value,enumerable:!0,configurable:!0,writable:!0}):obj[key]=value,obj}function _toPrimitive(input,hint){if("object"!=typeof input||null===input)return input;var prim=input[Symbol.toPrimitive];if(void 0!==prim){var res=prim.call(input,hint||"default");if("object"!=typeof res)return res;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===hint?String:Number)(input)}function _toPropertyKey(arg){var key=_toPrimitive(arg,"string");return"symbol"==typeof key?key:String(key)}export{_asyncToGenerator as asyncToGenerator,_classCallCheck as classCallCheck,_createClass as createClass,_defineProperty as defineProperty,_objectSpread2 as objectSpread2,_regeneratorRuntime as regeneratorRuntime,_toPrimitive as toPrimitive,_toPropertyKey as toPropertyKey,_typeof as typeof};
|
package/es/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import DhRealtimeHuman from"./Client.js";export{CONNECT_MAIN_KEY,WS_STATUS_MAP,errorTypeEnum,statusEnum}from"./interface.js";export{DhRealtimeHuman as default};
|
package/es/interface.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var statusEnum,errorTypeEnum,CONNECT_MAIN_KEY=["projectId","characterConfigId","configVersion","selectors","figureName","reConnect"];!function(statusEnum){statusEnum.DH_LIB_INIT="DH_LIB_INIT",statusEnum.DH_LIB_WS_SUCCESS="DH_LIB_WS_SUCCESS",statusEnum.DH_LIB_OPEN="DH_LIB_OPEN",statusEnum.DH_LIB_STATUS="DH_LIB_STATUS",statusEnum.DH_LIB_CLOSE="DH_LIB_CLOSE",statusEnum.DH_LIB_ERROR="DH_LIB_ERROR",statusEnum.DH_LIB_WARNING="DH_LIB_WARNING",statusEnum.DH_LIB_FULL_STATUS="DH_LIB_FULL_STATUS",statusEnum.DH_LIB_MESSAGE="DH_LIB_MESSAGE"}(statusEnum||(statusEnum={})),function(errorTypeEnum){errorTypeEnum.CONNECT_ERROR="CONNECT_ERROR",errorTypeEnum.DISCONNECT_ALERT="DISCONNECT_ALERT",errorTypeEnum.TIMEOUT_EXIT="TIMEOUT_EXIT",errorTypeEnum.LOCAL_VIDEO_MUTED="LOCAL_VIDEO_MUTED",errorTypeEnum.LOCAL_VIDEO_ERROR="LOCAL_VIDEO_ERROR",errorTypeEnum.RTC_ERROR="RTC_ERROR"}(errorTypeEnum||(errorTypeEnum={}));var WS_STATUS_MAP={"-1":"UNINSTANTIATED",0:"CONNECTING",1:"OPEN",2:"CLOSING",3:"CLOSED"};export{CONNECT_MAIN_KEY,WS_STATUS_MAP,errorTypeEnum,statusEnum};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bddh/starling-realtime-client",
|
|
3
|
-
"version": "2.0.11-beta.
|
|
3
|
+
"version": "2.0.11-beta.5",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"react",
|
|
6
6
|
"indexDB"
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"@bddh/starling-cutout": "^1.2.1",
|
|
32
32
|
"@bddh/starling-json": "^1.0.1",
|
|
33
33
|
"@bddh/starling-timeout-controller": "^1.0.3",
|
|
34
|
-
"@bddh/starling-web-socket": "1.0.13-beta.
|
|
34
|
+
"@bddh/starling-web-socket": "1.0.13-beta.3",
|
|
35
35
|
"lodash": "^4.17.21",
|
|
36
36
|
"uuid": "^9.0.0"
|
|
37
37
|
},
|
|
@@ -40,9 +40,9 @@
|
|
|
40
40
|
"@bddh/starling-cutout": "^1.2.1",
|
|
41
41
|
"@bddh/starling-json": "^1.0.1",
|
|
42
42
|
"@bddh/starling-timeout-controller": "^1.0.3",
|
|
43
|
-
"@bddh/starling-web-socket": "1.0.13-beta.
|
|
43
|
+
"@bddh/starling-web-socket": "1.0.13-beta.3",
|
|
44
44
|
"lodash": "^4.17.21",
|
|
45
45
|
"uuid": "^9.0.0"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "57047f3cb36e6d33c1143d5395bfbad02aa7bd74"
|
|
48
48
|
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) zhangyibo02@baidu.com
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|