@bddh/starling-realtime-client 2.0.11-beta.1 → 2.0.12
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/LICENSE +21 -0
- package/cjs/BrtcClient.js +1 -1
- package/cjs/Client.d.ts +0 -4
- package/cjs/Client.js +1 -1
- package/cjs/Cutout.js +1 -1
- package/cjs/DomControl.d.ts +0 -7
- package/cjs/DomControl.js +1 -1
- package/cjs/RecordController.js +1 -1
- package/cjs/Server.d.ts +2 -16
- package/cjs/Server.js +1 -1
- package/cjs/_virtual/_rollupPluginBabelHelpers.js +1 -1
- package/cjs/index.js +1 -1
- package/cjs/interface.d.ts +0 -3
- package/cjs/interface.js +1 -1
- package/es/BrtcClient.js +1 -1
- package/es/Client.d.ts +0 -4
- package/es/Client.js +1 -1
- package/es/Cutout.js +1 -1
- package/es/DomControl.d.ts +0 -7
- package/es/DomControl.js +1 -1
- package/es/RecordController.js +1 -1
- package/es/Server.d.ts +2 -16
- package/es/Server.js +1 -1
- package/es/_virtual/_rollupPluginBabelHelpers.js +1 -1
- package/es/index.js +1 -1
- package/es/interface.d.ts +0 -3
- package/es/interface.js +1 -1
- package/package.json +4 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
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.
|
package/cjs/BrtcClient.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./_virtual/_rollupPluginBabelHelpers.js"),t=require("@bddh/starling-brtc"),o=require("@bddh/starling-timeout-controller"),n=require("@bddh/starling-json"),c=require("lodash/isEmpty"),i=require("lodash/isFunction"),r=require("./interface.js"),a=function(){function a(l){var s=this;e.classCallCheck(this,a),e.defineProperty(this,"client",void 0),e.defineProperty(this,"isRtcVideoOn",!1),e.defineProperty(this,"rtcConnection",void 0),e.defineProperty(this,"rtcConfig",void 0),e.defineProperty(this,"bizConfig",void 0),e.defineProperty(this,"rtcCallback",void 0),e.defineProperty(this,"restarting",!1),e.defineProperty(this,"timeoutEvent",void 0),e.defineProperty(this,"reopenTimer",void 0),e.defineProperty(this,"restartCount",0),e.defineProperty(this,"closeLog",!0),e.defineProperty(this,"haveVideoOn",!1),e.defineProperty(this,"rtcStateCallback",null),e.defineProperty(this,"openRtc",(function(e){if(s.restarting)!s.closeLog&&console.warn("rtc restarting");else if(e&&(s.rtcConnection=e),s.rtcConnection&&!c(s.rtcConnection)){var o=s.rtcConnection,a=o.server,l=o.appId,d=o.token,u=o.roomName,m=o.userId,f=s.rtcCallback||{},C=f.onRemotedata,b=f.onLocalStream,g=f.onRemoteVideoComing,y=f.onLocalVideoPublished,v=f.onLocalVideoPublishing,h=f.onRemoteVideoOn,p=f.onRemoteVideoOff,L=f.onRemoteVideoLoading,R=f.onSuccess,S=f.onError,k=f.onLocalVideoConnected,E=f.onRemoteVideoConnected,V=f.onRemoteMediaState,P=f.onPlayingError,_=f.onDigitalHumanCallback;s.timeoutEvent.start(),s.rtcStateCallback=function(e){var t=e.body,o=e.action;_&&_({status:r.statusEnum.DH_LIB_FULL_STATUS,content:{type:"rtcState",action:o,body:t}})},s.client=new t({roomName:u,token:d,userId:m,appId:l,server:a,rtcConfig:s.rtcConfig,callback:{onRemoteVideoConnected:function(t,o){if(!o&&!s.haveVideoOn)var n=setTimeout((function(){s.restartCount<3?(s.restartCount=++s.restartCount,s.restartRtc&&s.restartRtc(e)):(s.restartCount=0,s.closeRtc()),clearTimeout(n)}),500);if(o){var c=document.getElementById("remotevideo500");if(c){c.muted=!1;var a=c.play();void 0!==a&&a.catch((function(){c.muted=!0,c.play().catch((function(e){!s.closeLog&&console.info("videoElement play error",e),P&&P(c),_&&_({status:r.statusEnum.DH_LIB_ERROR,content:{type:r.errorTypeEnum.LOCAL_VIDEO_ERROR}})})),_&&_({status:r.statusEnum.DH_LIB_STATUS,content:{type:r.errorTypeEnum.LOCAL_VIDEO_MUTED}})}))}else!s.closeLog&&console.error("videoElement is null!")}!s.closeLog&&console.info("remoteVideoConnected",t,o,s.restartCount),s.rtcStateCallback&&s.rtcStateCallback({action:"remoteVideoConnected",body:{id:t,connected:o,restartCount:s.restartCount}}),i(E)&&E(t,o)},onRemoteVideoOn:function(e){s.haveVideoOn=!0,!s.closeLog&&console.info("remotevideoon by id: ",e),s.timeoutEvent.clear();var t=document.querySelector("#starlingRtcContainer"),o=t&&t.lastChild;o&&(o.style.display="none"),s.rtcStateCallback&&s.rtcStateCallback({action:"remotevideoon",body:e}),_&&_({status:r.statusEnum.DH_LIB_OPEN}),i(h)&&h(e)},onRemoteMediaState:function(e,t,o){!s.closeLog&&console.info("remoteMediaState",e,t,o),s.rtcStateCallback&&s.rtcStateCallback({action:"remoteMediaState",body:{id:e,medium:t,connected:o}}),i(V)&&V(e,t,o)},onLocalVideoConnected:function(e){!s.closeLog&&console.info("localVideoConnected",e),s.rtcStateCallback&&s.rtcStateCallback({action:"localVideoConnected",body:{connected:e}}),i(k)&&k(e)},onRemotedata:function(e){if(s.rtcConfig&&s.rtcConfig.usingdatachannel){var t=n.parse(e);!s.closeLog&&console.info("RTC - receive:",t),i(C)&&C(t)}},onLocalStream:function(e,t){!s.closeLog&&console.info("rtc - onlocalstream by name: "+t),s.rtcStateCallback&&s.rtcStateCallback({action:"onlocalstream",body:{stream:e,name:t}}),i(b)&&b(e,t)},onLocalVideoPublished:function(){!s.closeLog&&console.info("LocalVideoPublished 本地视频发布成功"),s.rtcStateCallback&&s.rtcStateCallback({action:"localvideopublished_ok",body:!0}),i(y)&&y()},onLocalVideoPublishing:function(){!s.closeLog&&console.info("LocalVideoPublishing 本地视频发布成功"),s.rtcStateCallback&&s.rtcStateCallback({action:"localvideopublishing",body:!0}),i(v)&&v()},onRemoteVideoComing:function(e){!s.closeLog&&console.info("remotevideocoming",e),s.rtcStateCallback&&s.rtcStateCallback({action:"remotevideocoming",body:e}),i(g)&&g(e)},onRemoteVideoLoading:function(e){!s.closeLog&&console.info("remotevideoloading by id: ",e),s.rtcStateCallback&&s.rtcStateCallback({action:"remotevideoloading",body:e}),i(L)&&L(e)},onRemoteVideoOff:function(e){var t=document.getElementById("remotevideo500");t&&t.pause(),!s.closeLog&&console.info("remotevideooff: ",e),s.isRtcVideoOn=!1,s.rtcStateCallback&&s.rtcStateCallback({action:"remotevideooff",body:e}),_&&_({status:r.statusEnum.DH_LIB_CLOSE}),i(p)&&p(e),s.timeoutEvent.start()},onSuccess:function(){!s.closeLog&&console.info("rtc - success"),s.rtcStateCallback&&s.rtcStateCallback({action:"success",body:!0}),i(R)&&R()},onError:function(t){s.isRtcVideoOn=!1,!s.closeLog&&console.error("rtc - error:",t),s.rtcStateCallback&&s.rtcStateCallback({action:"error",body:t}),_&&_({status:r.statusEnum.DH_LIB_ERROR,content:{type:r.errorTypeEnum.RTC_ERROR}}),i(S)&&S(t),(t.includes("Lost connection to the server")||t.includes("Is the server down"))&&s.restartRtc&&s.restartRtc(e)}}})}})),e.defineProperty(this,"closeRtc",(function(){s.timeoutEvent.clear(),clearTimeout(s.reopenTimer),s.client&&s.client.destroy(),s.restarting=!1})),e.defineProperty(this,"restartRtc",(function(e){!s.restarting&&s.bizConfig&&s.bizConfig.autoReConnect&&(s.rtcStateCallback&&s.rtcStateCallback({action:"restartRtc",body:e}),s.restarting=!0,s.closeRtc(),s.reopenTimer=setTimeout((function(){!s.closeLog&&console.error("拉流失败,开始重启"),s.restarting=!1,s.openRtc(e)}),2e3))}));var d=l.rtcConnection,u=l.rtcConfig,m=l.closeLog,f=void 0===m||m,C=l.rtcCallback;this.rtcConnection=d,this.rtcConfig=u,this.rtcCallback=C,this.closeLog=f,this.timeoutEvent=new o.TimeoutController(6e4,(function(){if(!s.rtcConnection)return!s.closeLog&&console.warn("remotevideoon事件超时, rtcConnectionRef is null");s.timeoutEvent.clear(),s.restartRtc&&s.restartRtc(s.rtcConnection)}))}return e.createClass(a,[{key:"muteMicphone",value:function(e){this.client&&this.client.muteMicphone&&this.client.muteMicphone(e)}}]),a}();exports.default=a;
|
package/cjs/Client.d.ts
CHANGED
|
@@ -20,16 +20,12 @@ export default class DhRealtimeHuman {
|
|
|
20
20
|
private recordController;
|
|
21
21
|
private wsReadyState;
|
|
22
22
|
private readonly isPreOpenSession;
|
|
23
|
-
private readonly openWsOnly;
|
|
24
|
-
private enableLastFrameCover;
|
|
25
|
-
private _isMicMuted;
|
|
26
23
|
constructor(props: DhRealtimeHumanType);
|
|
27
24
|
init(props: DhRealtimeHumanType): void;
|
|
28
25
|
onDigitalHumanCallbackPlus: (data: CallbackMsgType) => void;
|
|
29
26
|
onRemoteVideoComing: (id: number) => void;
|
|
30
27
|
onLocalStream: () => void;
|
|
31
28
|
onRemoteVideoOn: () => void;
|
|
32
|
-
onRemoteVideoOffLastFrame: () => void;
|
|
33
29
|
connectListener: (data: ConnectDataType) => void;
|
|
34
30
|
createServer: (sessionId?: string) => void;
|
|
35
31
|
checkHumanInstansce: () => boolean;
|
package/cjs/Client.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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(){function DhRealtimeHuman(props){var _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,"isHuawei",DomControl.checkIsHuawei()),_rollupPluginBabelHelpers.defineProperty(this,"rtcServerUrl",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,"enableLastFrameCover",!1),_rollupPluginBabelHelpers.defineProperty(this,"_isMicMuted",!1),_rollupPluginBabelHelpers.defineProperty(this,"onDigitalHumanCallbackPlus",(function(data){var _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$rtcServer=_this.rtcServer)||void 0===_this$rtcServer||_this$rtcServer.closeRtc(),_this.enableLastFrameCover&&(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(!_this.enableLastFrameCover){_context.next=8;break}if(video=document.getElementById(DomControl.RTC_VIDEO_ID),!_this.cutoutInstance||!video){_context.next=5;break}return _context.next=5,_this.cutoutInstance.updateSource(video);case 5:DomControl.captureLastFrameToCover(),DomControl.setHumanPlayerWrapperVisible(!0),DomControl.setLastFrameCoverVisible(!1);case 8:case"end":return _context.stop()}}),_callee)}))),100)})),_rollupPluginBabelHelpers.defineProperty(this,"onRemoteVideoOffLastFrame",(function(){DomControl.setLastFrameCoverVisible(!0)})),_rollupPluginBabelHelpers.defineProperty(this,"connectListener",(function(data){var code=data.code,body=data.body,message=data.message;if(0===code&&_this.onDigitalHumanCallback&&_this.onDigitalHumanCallback({status:_interface.statusEnum.DH_LIB_WS_SUCCESS,content:data}),0===code){var _data=CustomJSON.parse(body),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))}else _this.onDigitalHumanCallback&&_this.onDigitalHumanCallback({status:_interface.statusEnum.DH_LIB_ERROR,content:{type:_interface.errorTypeEnum.CONNECT_ERROR,msg:{code:code,errMsg:message}}})})),_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,"destroy",_rollupPluginBabelHelpers.asyncToGenerator(_rollupPluginBabelHelpers.regeneratorRuntime().mark((function _callee3(){var _this$recordControlle;return _rollupPluginBabelHelpers.regeneratorRuntime().wrap((function(_context3){for(;;)switch(_context3.prev=_context3.next){case 0:return _this.enableLastFrameCover?(DomControl.playHumanVideo(!1),DomControl.setHumanPlayerWrapperVisible(!1),DomControl.setLastFrameCoverVisible(!0)):(DomControl.removeHumanDom(),DomControl.removeLastFrameCoverWrapper()),_context3.next=3,_this.dhServer&&_this.dhServer.closeSocket();case 3:_this.rtcServer&&_this.rtcServer.closeRtc(),null===(_this$recordControlle=_this.recordController)||void 0===_this$recordControlle||_this$recordControlle.destroy(),_this.dhServer=null,_this.rtcServer=null;case 7:case"end":return _context3.stop()}}),_callee3)})))),_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,onDigitalHumanCallback=props.onDigitalHumanCallback;this.isPreOpenSession=isPreOpenSession,this.openWsOnly=isOpenWsOnly,this.dhServer=new Server.default(wsUrl||"wss://open.xiling.baidu.com/cloud/digital-human-demonstration",{checkHeartbeatMismatch:checkHeartbeatMismatch}),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:"init",value:function(props){var _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;if(this.token=token,this.appKey=appKey,this.appId=appId,this.rtcServerUrl=rtcServerUrl,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.enableLastFrameCover=!!renderParams.enableLastFrameCover,DomControl.removeLastFrameCoverWrapper(),DomControl.removeHumanDom();var playerWrapper=(DomControl.createHumanDom({autoChromaKey:!!renderParams.autoChromaKey||!isEmpty(renderParams.chromaEffects)})||{}).playerWrapper,wrapperEle=document.getElementById(wrapperId||"");wrapperEle||console.error("dom with wrapperId is not find"),playerWrapper&&wrapperEle&&wrapperEle.appendChild(playerWrapper),this.enableLastFrameCover&&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:{autoReConnect:null===(_connectParams$reConn=null==connectParams?void 0:connectParams.reConnect)||void 0===_connectParams$reConn||_connectParams$reConn},rtcCallback:_rollupPluginBabelHelpers.objectSpread2({onRemoteVideoComing:this.onRemoteVideoComing,onDigitalHumanCallback:this.onDigitalHumanCallback,onLocalStream:this.onLocalStream,onRemoteVideoOn:this.onRemoteVideoOn},this.enableLastFrameCover?{onRemoteVideoOff:this.onRemoteVideoOffLastFrame}:{})}),(!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:"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;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./_virtual/_rollupPluginBabelHelpers.js"),r=require("@bddh/starling-json"),t=require("lodash/isEmpty"),n=require("lodash/omit"),o=require("lodash/pick"),a=require("uuid"),i=require("./interface.js"),s=require("./Server.js"),c=require("./BrtcClient.js"),u=require("./DomControl.js"),d=require("./Cutout.js"),l=require("./RecordController.js"),m=function(){function m(t){var c=this;e.classCallCheck(this,m),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,"isHuawei",u.checkIsHuawei()),e.defineProperty(this,"rtcServerUrl",void 0),e.defineProperty(this,"recordController",null),e.defineProperty(this,"wsReadyState",-1),e.defineProperty(this,"isPreOpenSession",!1),e.defineProperty(this,"onDigitalHumanCallbackPlus",(function(e){var r;e.status===i.statusEnum.DH_LIB_FULL_STATUS&&"wsState"===(null===(r=e.content)||void 0===r?void 0:r.type)&&(c.wsReadyState=e.content.readyState),c.onDigitalHumanCallback&&c.onDigitalHumanCallback(e)})),e.defineProperty(this,"onRemoteVideoComing",(function(e){c.rtcConnectParams&&c.rtcConnectParams.feedId&&e===+c.rtcConnectParams.feedId&&c.rtcServer&&c.rtcServer.client&&c.rtcServer.client.subscribeStreaming("remotevideo500",+c.rtcConnectParams.feedId)})),e.defineProperty(this,"onLocalStream",(function(){(c.connectParams||{}).pullAudioFromRtc&&c.rtcServer&&c.rtcServer.muteMicphone(!1)})),e.defineProperty(this,"onRemoteVideoOn",(function(){setTimeout(e.asyncToGenerator(e.regeneratorRuntime().mark((function r(){var t,n,o,a,i;return e.regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=document.getElementById(u.RTC_VIDEO_ID),e.next=3,c.cutoutInstance&&c.cutoutInstance.updateSource(u.RTC_VIDEO_ID);case 3:t&&(t.setAttribute("data-playing","true"),n=t.videoWidth,o=t.videoHeight,a=document.getElementById(u.DEFAULT_CANVAS_ID),i=a&&a.getContext("2d"),a&&i&&(a.width=n,a.height=o,i.drawImage(t,0,0,n,o)));case 4:case"end":return e.stop()}}),r)}))),100)})),e.defineProperty(this,"connectListener",(function(e){var t=e.code,n=e.body,o=e.message;if(0===t&&c.onDigitalHumanCallback&&c.onDigitalHumanCallback({status:i.statusEnum.DH_LIB_WS_SUCCESS,content:e}),0===t){var a=r.parse(n),s=a.rtcServerUrl,u=a.appId,d=a.clientToken,l=a.roomName,m=a.clientId,p=a.feedId,h=a.chargeId;u&&l&&(c.rtcConnectParams={server:c.rtcServerUrl||s,appId:u,token:d,roomName:l,userId:m,feedId:p,chargeId:h},c.rtcServer&&c.rtcServer.openRtc(c.rtcConnectParams))}else c.onDigitalHumanCallback&&c.onDigitalHumanCallback({status:i.statusEnum.DH_LIB_ERROR,content:{type:i.errorTypeEnum.CONNECT_ERROR,msg:{code:t,errMsg:o}}})})),e.defineProperty(this,"createServer",(function(r){var t,a=e.objectSpread2(e.objectSpread2(e.objectSpread2({token:c.token,appKey:c.appKey,appId:c.appId},r?{sessionId:r}:{}),o(c.connectParams,i.CONNECT_MAIN_KEY)),{},{parameters:n(c.connectParams,i.CONNECT_MAIN_KEY),onConnect:c.connectListener,onDigitalHumanCallback:c.onDigitalHumanCallbackPlus});null!==(t=c.dhServer)&&void 0!==t&&t.preConnectSuccess?(c.dhServer.connectParams=a,c.dhServer&&c.dhServer.sendPreConnect(a)):c.dhServer&&c.dhServer.createSocket(a)})),e.defineProperty(this,"checkHumanInstansce",(function(){return c.dhServer?!(c.isPreOpenSession&&!c.dhServer.preConnectSuccess)||(c.onDigitalHumanCallback&&c.onDigitalHumanCallback({status:i.statusEnum.DH_LIB_ERROR,content:{type:i.errorTypeEnum.CONNECT_ERROR,msg:{code:4001,errMsg:"webSocket连接中"}}}),!1):(c.onDigitalHumanCallback&&c.onDigitalHumanCallback({status:i.statusEnum.DH_LIB_ERROR,content:{type:i.errorTypeEnum.CONNECT_ERROR,msg:{code:4002,errMsg:"请先初始化数字人实例"}}}),!1)})),e.defineProperty(this,"sendMessage",(function(e,r){return c.dhServer&&c.dhServer.sendMessage(e,r)})),e.defineProperty(this,"interrupt",e.asyncToGenerator(e.regeneratorRuntime().mark((function r(){return e.regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",new Promise((function(e){c.dhServer&&c.dhServer.sendMessage({requestId:a.v4(),action:"TEXT_RENDER",body:"<interrupt></interrupt>",clientTs:(new Date).getTime()},(function(){return e()}))})));case 1:case"end":return e.stop()}}),r)})))),e.defineProperty(this,"textRender",(function(e){var r=e.requestId,t=e.body,n=e.onCallbackMsg;c.checkHumanInstansce()&&c.dhServer&&c.dhServer.sendMessage({requestId:r||a.v4(),action:"TEXT_RENDER",body:t,clientTs:(new Date).getTime()},n)})),e.defineProperty(this,"textStreamRender",(function(e){var t=e.requestId,n=e.body,o=e.onCallbackMsg,i=r.parse(n).first;c.checkHumanInstansce()&&c.dhServer&&c.dhServer.sendMessage({requestId:t||a.v4(),action:"TEXT_STREAM_RENDER",body:n,clientTs:(new Date).getTime()},i?o:null)})),e.defineProperty(this,"audioRender",(function(e){var r=e.body,t=e.onCallbackMsg;c.checkHumanInstansce()&&c.dhServer&&c.dhServer.sendMessage({requestId:a.v4(),action:"AUDIO_RENDER",body:r,clientTs:(new Date).getTime()},t)})),e.defineProperty(this,"audioStreamRender",(function(e){var r=e.requestId,t=e.body,n=e.onCallbackMsg;c.checkHumanInstansce()&&c.dhServer&&c.dhServer.sendMessage({requestId:r||a.v4(),action:"AUDIO_STREAM_RENDER",body:t,clientTs:(new Date).getTime()},n)})),e.defineProperty(this,"textQuery",(function(e){var r=e.requestId,t=e.body,n=e.onCallbackMsg;c.dhServer&&c.dhServer.sendMessage({requestId:r||a.v4(),action:"TEXT_QUERY",body:t,clientTs:(new Date).getTime()},n)})),e.defineProperty(this,"destroy",e.asyncToGenerator(e.regeneratorRuntime().mark((function r(){var t;return e.regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,c.dhServer&&c.dhServer.destroySocket();case 2:c.rtcServer&&c.rtcServer.closeRtc(),u.removeHumanDom(),null===(t=c.recordController)||void 0===t||t.destroy(),c.dhServer=null,c.rtcServer=null;case 7:case"end":return e.stop()}}),r)})))),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 c.isHuawei?(e.pause(),e.play()):e.paused&&e.play()}catch(e){console.info(e)}}));var d=t.isPreOpenSession,l=void 0!==d&&d,p=t.wsUrl,h=t.renderParams,v=t.onDigitalHumanCallback;this.isPreOpenSession=l,this.dhServer=new s.default(p||"wss://open.xiling.baidu.com/cloud/digital-human-demonstration"),this.onDigitalHumanCallback=function(e){e.status!==i.statusEnum.DH_LIB_FULL_STATUS?v&&v(e):(null==h?void 0:h.fullStatus)&&v&&v(e)},l?this.dhServer.createSocket({onDigitalHumanCallback:this.onDigitalHumanCallbackPlus},l):this.init(t)}return e.createClass(m,[{key:"init",value:function(r){var n=this,o=r.wrapperId,a=r.token,s=r.appKey,m=r.appId,p=r.connectParams,h=r.renderParams,v=void 0===h?{}:h,f=r.rtcConnectParams,y=r.brtcParams,S=r.rtcServerUrl;if(this.token=a,this.appKey=s,this.appId=m,this.rtcServerUrl=S,this.connectParams=e.objectSpread2({autoChromaKey:(null==v?void 0:v.autoChromaKey)||!1},p),!m&&!s&&!a)throw new Error("appId and appKey or token is required");var C=v.closeLog,g=v.audio3AConstraints,R=(u.createHumanDom({autoChromaKey:!!v.autoChromaKey||!t(v.chromaEffects)})||{}).playerWrapper,I=document.getElementById(o||"");I||console.error("dom with wrapperId is not find"),R&&I&&I.appendChild(R),u.appendRtcDomStyle();var P=e.objectSpread2({remotevideoviewid:o,showvideobps:!1,usingvideo:!1,usingaudio:!(null==p||!p.pullAudioFromRtc),aspublisher:!(null==p||!p.pullAudioFromRtc),autopublish:!(null==p||!p.pullAudioFromRtc),usingdatachannel:!0,autoplaymuted:!1},y);this.rtcServer=new c.default({closeLog:C,videoWrapperId:u.RTC_VIDEO_ID,rtcConfig:P,bizConfig:{},rtcCallback:{onRemoteVideoComing:this.onRemoteVideoComing,onDigitalHumanCallback:this.onDigitalHumanCallback,onLocalStream:this.onLocalStream}}),(!t(null==v?void 0:v.chromaEffects)||null!=v&&v.autoChromaKey)&&(this.cutoutInstance=new d.default({sourceId:u.RTC_VIDEO_ID,effects:null==v?void 0:v.chromaEffects})),t(f)||(this.rtcConnectParams=f,this.rtcServer.openRtc(f)),null!=p&&p.pullAudioFromRtc?this.recordController=null:this.recordController=new l.default({pickAudioMode:null==p?void 0:p.pickAudioMode,audio3AConstraints:g,asrSample:null==p?void 0:p.asrSample,onAudioData:function(e){1===n.wsReadyState&&n.sendMessage(e,null)},onError:function(e){n.onDigitalHumanCallback&&n.onDigitalHumanCallback({status:i.statusEnum.DH_LIB_ERROR,content:{type:i.errorTypeEnum.CONNECT_ERROR,msg:{code:-1,errMsg:e.message}}})}})}},{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:a.v4(),clientTs:Date.now(),body:""},null);this.recordController&&this.recordController.stop(),this.sendMessage({action:"AUDIO_QUERY_INTERRUPT",requestId:a.v4(),clientTs:Date.now(),body:""},null)}},{key:"muteMicrophone",value:function(e){var r;null===(r=this.rtcServer)||void 0===r||r.muteMicphone(e)}}]),m}();exports.default=m;
|
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 t=require("./_virtual/_rollupPluginBabelHelpers.js"),e=require("@bddh/starling-cutout/es/Seriously"),s={version:2,chromaKey:{screen:[53,186,123],similarity:90,edgeShrink:3,smoothness:80,spill:100,opacity:1,contrast:0,brightness:0,gamma:0}},r=function(){function r(u){t.classCallCheck(this,r),t.defineProperty(this,"cutoutInstance",void 0);var n=u.effects,o=u.sourceId;this.cutoutInstance=new e("starling-cutout-canvas",o||"starling-cutout-video",n&&n.chromaKey||s.chromaKey,n&&n.version||s.version)}return t.createClass(r,[{key:"setOptions",value:function(t){t&&this.cutoutInstance&&this.cutoutInstance.setOptions(t)}},{key:"destroy",value:function(){return this.cutoutInstance.destroy()}},{key:"updateSource",value:function(t){return this.cutoutInstance.updateSource(t)}}]),r}();exports.DEFAULT_EFFECTS=s,exports.default=r;
|
package/cjs/DomControl.d.ts
CHANGED
|
@@ -14,14 +14,7 @@ interface CreateVideoDomResult {
|
|
|
14
14
|
export declare const DEFAULT_CANVAS_ID = "starling-cutout-canvas";
|
|
15
15
|
export declare const HUMAN_WRAPPER_ID = "cloud-brtc-player-wrapper";
|
|
16
16
|
export declare const RTC_VIDEO_ID = "remotevideo500";
|
|
17
|
-
export declare const LAST_FRAME_COVER_CANVAS_CLASS = "canvas-item";
|
|
18
|
-
export declare const LAST_FRAME_COVER_INNER_CANVAS_ID = "starling-last-frame-cover-canvas";
|
|
19
17
|
export declare function createHumanDom(options: CreateVideoDomOptions): CreateVideoDomResult | null;
|
|
20
|
-
export declare function appendLastFrameCoverSibling(mountEl: HTMLElement | null): void;
|
|
21
|
-
export declare function captureLastFrameToCover(): boolean;
|
|
22
|
-
export declare function setHumanPlayerWrapperVisible(visible: boolean): void;
|
|
23
|
-
export declare function setLastFrameCoverVisible(visible: boolean): void;
|
|
24
|
-
export declare function removeLastFrameCoverWrapper(): void;
|
|
25
18
|
export declare function removeHumanDom(): void;
|
|
26
19
|
export declare function muteHumanVideo(muted: boolean): HTMLVideoElement;
|
|
27
20
|
export declare function playHumanVideo(play: boolean): void | Promise<void>;
|
package/cjs/DomControl.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var t="starling-cutout-canvas",e="cloud-brtc-player-wrapper",n="remotevideo500";exports.DEFAULT_CANVAS_ID=t,exports.HUMAN_WRAPPER_ID=e,exports.RTC_VIDEO_ID=n,exports.appendRtcDomStyle=function(){var t=document.createElement("style");t.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 ')),document.head.appendChild(t)},exports.checkIsHuawei=function(){var t=navigator.userAgent||navigator.vendor;return/huawei/i.test(t)||/honor/i.test(t)},exports.createHumanDom=function(i){var o=i.autoChromaKey,r=void 0!==o&&o,a=i.autoplay,d=void 0===a||a;if(document.getElementById(n))return console.error('DOM with id "'.concat(n,'" already exists.')),null;var u=document.createElement("div");u.className=e,u.id=e,u.style.position="relative";var c=document.createElement("video");if(c.id=n,c.width=0,c.height=0,c.setAttribute("width","100%"),c.setAttribute("height","100%"),c.setAttribute("data-playing","true"),c.setAttribute("playsinline",""),d&&c.setAttribute("autoplay",""),u.appendChild(c),r){var p=document.createElement("canvas");p.id=t,Object.assign(p.style,{position:"absolute",top:"0",left:"0",height:"100%",width:"100%",zIndex:"1",display:r?"block":"none"}),c.style.visibility="hidden",u.appendChild(p)}return{playerWrapper:u,video:c}},exports.muteHumanVideo=function(t){var e=document.getElementById(n);return e&&(e.muted=t),e},exports.playHumanVideo=function(t){var e=document.getElementById(n);try{if(e)return t?e.play():e.pause()}catch(t){console.info(t)}},exports.removeHumanDom=function(){var t=document.getElementById(e);t&&t.parentNode&&t.parentNode.removeChild(t)};
|
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 e=require("./_virtual/_rollupPluginBabelHelpers.js");function t(e,t,r,o){try{for(var a=(o=o||{})&&"number"==typeof o.index?o.index:0,n=o&&"number"==typeof o.offset?o.offset:0,i=0,s=a;s<e.length;s++)i+=e[s].length;i=Math.max(0,i-Math.floor(n));var u=t/r;u>1?i=Math.floor(i/u):(u=1,r=t);for(var c=new Int16Array(i),d=0,h=e.length;a<h;a++){for(var p=e[a],l=n,f=p.length;l<f;){var m=Math.floor(l),v=Math.ceil(l),x=l-m;c[d]=p[m]+(p[v]-p[m])*x,d++,l+=u}n=l-f}return{index:a,offset:n,sampleRate:r,data:c}}catch(e){console.log("转音错误了",e)}}function r(e){for(var t=e,r=new Int16Array(e.length),o=0;o<t.length;o++){var a=Math.max(-1,Math.min(1,t[o]));r[o]=a<0?32768*a:32767*a}return r}var o=function(o,a){function n(t){e.classCallCheck(this,n),e.defineProperty(this,"onAudioData",void 0),e.defineProperty(this,"onError",void 0),e.defineProperty(this,"audioContext",null),e.defineProperty(this,"processor",null),e.defineProperty(this,"mediaStream",null),e.defineProperty(this,"recording",!1),e.defineProperty(this,"audio3AConstraints",void 0),e.defineProperty(this,"asrSample",void 0),this.onAudioData=t.onAudioData,this.onError=t.onError,this.audio3AConstraints=t.audio3AConstraints,this.asrSample=t.asrSample,this.preWarmStream()}return e.createClass(n,[{key:"preWarmStream",value:function(){return(o=o||e.asyncToGenerator(e.regeneratorRuntime().mark((function t(){var r,o,a;return e.regeneratorRuntime().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(t.prev=0,o=window.AudioContext||window.webkitAudioContext){t.next=4;break}throw new Error("当前环境不支持web api: AudioContext");case 4:if(null!==(r=navigator.mediaDevices)&&void 0!==r&&r.getUserMedia){t.next=6;break}throw new Error("当前环境不支持web api: getUserMedia");case 6:return this.audioContext=new o({sampleRate:this.asrSample||16e3}),t.next=9,navigator.mediaDevices.getUserMedia({audio:e.objectSpread2({echoCancellation:!0,noiseSuppression:!0,autoGainControl:!0},this.audio3AConstraints),video:!1});case 9:this.mediaStream=t.sent,a=this.audioContext.createMediaStreamSource(this.mediaStream),this.processor=this.audioContext.createScriptProcessor(1024,1,1),a.connect(this.processor),this.processor.connect(this.audioContext.destination),this.processor.onaudioprocess=function(){},t.next=20;break;case 17:t.prev=17,t.t0=t.catch(0),console.error("preWarmStream error",t.t0);case 20:case"end":return t.stop()}}),t,this,[[0,17]])})))).apply(this,arguments)}},{key:"start",value:function(){return(a=a||e.asyncToGenerator(e.regeneratorRuntime().mark((function o(){var a=this;return e.regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.recording){e.next=2;break}return e.abrupt("return");case 2:if(this.audioContext&&this.processor){e.next=4;break}return e.abrupt("return");case 4:try{this.processor.onaudioprocess=function(e){if(a.recording){var o=t([r(e.inputBuffer.getChannelData(0))],a.audioContext.sampleRate,a.asrSample||16e3,null);o&&o.data&&a.onAudioData(o.data.buffer)}},this.recording=!0}catch(e){this.onError&&this.onError(e)}case 5:case"end":return e.stop()}}),o,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(e){e.stop()}))}}]),n}();exports.default=o;
|
package/cjs/Server.d.ts
CHANGED
|
@@ -42,11 +42,7 @@ export interface RenderCallbackRes {
|
|
|
42
42
|
body: string | null;
|
|
43
43
|
message: string;
|
|
44
44
|
}
|
|
45
|
-
interface ServerOptions {
|
|
46
|
-
checkHeartbeatMismatch?: boolean;
|
|
47
|
-
}
|
|
48
45
|
export type RenderCallback = (res: RenderCallbackRes) => void;
|
|
49
|
-
export declare const CONNECTING_STUCK_MS_DEFAULT: number;
|
|
50
46
|
declare class Server {
|
|
51
47
|
dhServerSocket: WebSocketClient | null;
|
|
52
48
|
preConnectSuccess: boolean;
|
|
@@ -54,22 +50,12 @@ declare class Server {
|
|
|
54
50
|
private socketClosingPromise;
|
|
55
51
|
private readonly url;
|
|
56
52
|
private firstConnect;
|
|
57
|
-
|
|
58
|
-
private readonly connectingMs;
|
|
59
|
-
private lastPreOpen;
|
|
60
|
-
private reconnectingTimeout;
|
|
61
|
-
private lastReportedReadyState;
|
|
62
|
-
private lastHbAckTs;
|
|
63
|
-
private readonly checkHeartbeatMismatch;
|
|
64
|
-
constructor(url: string, options?: ServerOptions);
|
|
53
|
+
constructor(url: string);
|
|
65
54
|
sendPreConnect: (props: createSocketParamsType, resolve?: ((value: any) => void) | undefined) => void;
|
|
66
55
|
createSocket: (props: createSocketParamsType, isPreOpenSession?: boolean) => Promise<WebSocketClient | null>;
|
|
67
|
-
sendConnect: (props: createSocketParamsType) => void;
|
|
68
56
|
closeSocket: () => Promise<void>;
|
|
57
|
+
destroySocket: () => Promise<void>;
|
|
69
58
|
handleConnect: () => Promise<void>;
|
|
70
59
|
sendMessage(message: DHServerInterface | ArrayBuffer, listener: RenderCallback | null): Promise<void>;
|
|
71
|
-
private startConnectingWatch;
|
|
72
|
-
private clearConnectingWatch;
|
|
73
|
-
private resetState;
|
|
74
60
|
}
|
|
75
61
|
export default Server;
|
package/cjs/Server.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./_virtual/_rollupPluginBabelHelpers.js"),r=require("uuid"),t=require("@bddh/starling-web-socket/es/create-web-socket"),n=require("@bddh/starling-web-socket/es/interface"),o=require("lodash/pick"),s=require("lodash/omit"),c=require("lodash/get"),a=require("./interface.js"),i=function(i){function u(i){var d,p=this;e.classCallCheck(this,u),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,"sendPreConnect",(function(e,t){var n,o=e.token,s=e.sessionId,c=e.onConnect;null===(n=p.dhServerSocket)||void 0===n||n.request({action:"RE_CONNECT",requestId:r.v4(),body:JSON.stringify({token:o,sessionId:s})}).on((function(e,r){null==c||c(e),0!==e.code&&(r(),p.handleConnect()),null==t||t(p.dhServerSocket)})),p.firstConnect=!1})),e.defineProperty(this,"createSocket",(function(r,o){return(d=d||e.asyncToGenerator(e.regeneratorRuntime().mark((function r(o,s){var i,u;return e.regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(p.connectParams=o,i=o.sessionId,u=o.onDigitalHumanCallback,!p.socketClosingPromise){e.next=5;break}return e.next=5,p.socketClosingPromise;case 5:if(!p.dhServerSocket||p.dhServerSocket.readyState===n.ReadyState.CLOSED){e.next=8;break}return e.next=8,p.closeSocket();case 8:return e.abrupt("return",new Promise((function(e,r){var n={keepAlive:"heartbeat",reopen:c(p.connectParams,"reConnect",!0),combine:function(e,r){return e&&r&&e.requestId===r.requestId},onOpen:function(){p.dhServerSocket=d,i&&p.firstConnect?p.sendPreConnect(o,e):s&&p.firstConnect||p.handleConnect()},onClose:function(){p.socketClosingPromise=null},onError:function(e){r(e)}},d=t.createWebSocket(p.url,n);d.onReadyStateChange((function(e){0===e&&u&&u({status:a.statusEnum.DH_LIB_INIT}),1===e&&s&&(p.preConnectSuccess=!0),3===e&&(p.preConnectSuccess=!1),u&&u({status:a.statusEnum.DH_LIB_FULL_STATUS,content:{type:"wsState",readyState:e,body:a.WS_STATUS_MAP[e]}})})),d.onMessage((function(e){var r=e.action;[a.errorTypeEnum.TIMEOUT_EXIT,a.errorTypeEnum.DISCONNECT_ALERT].includes(r)&&u&&u({status:a.statusEnum.DH_LIB_STATUS,content:{type:r}}),[a.errorTypeEnum.TIMEOUT_EXIT,a.errorTypeEnum.DISCONNECT_ALERT,"HEART_BEAT","CONNECT"].includes(r)||u&&u({status:a.statusEnum.DH_LIB_MESSAGE,content:e})})),s&&(p.dhServerSocket=d),d.open()})));case 9:case"end":return e.stop()}}),r)})))).apply(this,arguments)})),e.defineProperty(this,"closeSocket",e.asyncToGenerator(e.regeneratorRuntime().mark((function r(){return e.regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(p.dhServerSocket){e.next=2;break}return e.abrupt("return");case 2:return p.socketClosingPromise=p.dhServerSocket.close(),e.next=5,p.socketClosingPromise;case 5:p.dhServerSocket=null;case 6:case"end":return e.stop()}}),r)})))),e.defineProperty(this,"destroySocket",e.asyncToGenerator(e.regeneratorRuntime().mark((function r(){var t;return e.regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:p.connectParams=null,null===(t=p.dhServerSocket)||void 0===t||t.destroy(),p.dhServerSocket=null;case 3:case"end":return e.stop()}}),r)})))),e.defineProperty(this,"handleConnect",e.asyncToGenerator(e.regeneratorRuntime().mark((function t(){var n,c,i,u,d,l;return e.regeneratorRuntime().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(p.dhServerSocket&&p.connectParams){t.next=2;break}return t.abrupt("return");case 2:if(n=p.connectParams,c=n.appId,i=n.appKey,u=n.token,d=n.parameters,l=n.onConnect,c||i||u){t.next=5;break}return t.abrupt("return");case 5:p.dhServerSocket&&p.dhServerSocket.request({action:"CONNECT",clientTs:(new Date).getTime(),requestId:r.v4(),body:JSON.stringify(e.objectSpread2(e.objectSpread2({token:u,appId:c,appKey:i},o(p.connectParams,a.CONNECT_MAIN_KEY)),{},{parameters:e.objectSpread2(e.objectSpread2({},s(d,["parameters"])),d&&d.parameters?d.parameters:{})}))}).on((function(e,r){null==l||l(e),0!==e.code&&r()}));case 6:case"end":return t.stop()}}),t)})))),this.url=i}return e.createClass(u,[{key:"sendMessage",value:function(t,n){return(i=i||e.asyncToGenerator(e.regeneratorRuntime().mark((function t(n,o){var s;return e.regeneratorRuntime().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:try{this.dhServerSocket&&this.dhServerSocket&&this.dhServerSocket.request(n).on((function(e){o&&o(e)}))}catch(t){s="object"===e.typeof(n)&&"requestId"in n?n.requestId:r.v4(),o&&o({code:-11,body:null,action:"RENDER_ERROR",requestId:s,message:JSON.stringify(t)})}case 1:case"end":return t.stop()}}),t,this)})))).apply(this,arguments)}}]),u}();exports.default=i;
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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;
|
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 e=require("./Client.js"),r=require("./interface.js");exports.default=e.default,exports.CONNECT_MAIN_KEY=r.CONNECT_MAIN_KEY,exports.WS_STATUS_MAP=r.WS_STATUS_MAP,Object.defineProperty(exports,"errorTypeEnum",{enumerable:!0,get:function(){return r.errorTypeEnum}}),Object.defineProperty(exports,"statusEnum",{enumerable:!0,get:function(){return r.statusEnum}});
|
package/cjs/interface.d.ts
CHANGED
|
@@ -68,7 +68,6 @@ export interface RenderParamsType {
|
|
|
68
68
|
closeLog?: boolean;
|
|
69
69
|
fullStatus?: boolean;
|
|
70
70
|
audio3AConstraints?: Mic3AType;
|
|
71
|
-
enableLastFrameCover?: boolean;
|
|
72
71
|
}
|
|
73
72
|
export declare enum statusEnum {
|
|
74
73
|
DH_LIB_INIT = "DH_LIB_INIT",
|
|
@@ -120,7 +119,6 @@ export interface CallbackMsgType {
|
|
|
120
119
|
export interface DhRealtimeHumanType {
|
|
121
120
|
token?: string;
|
|
122
121
|
wsUrl?: string;
|
|
123
|
-
checkHeartbeatMismatch?: boolean;
|
|
124
122
|
rtcServerUrl?: string;
|
|
125
123
|
appKey?: string;
|
|
126
124
|
appId?: string;
|
|
@@ -130,7 +128,6 @@ export interface DhRealtimeHumanType {
|
|
|
130
128
|
rtcConnectParams?: RtcConnectionType;
|
|
131
129
|
brtcParams?: any;
|
|
132
130
|
isPreOpenSession?: boolean;
|
|
133
|
-
isOpenWsOnly?: boolean;
|
|
134
131
|
onDigitalHumanCallback: (data: CallbackMsgType) => void;
|
|
135
132
|
}
|
|
136
133
|
export {};
|
package/cjs/interface.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var _,E;exports.statusEnum=void 0,(_=exports.statusEnum||(exports.statusEnum={})).DH_LIB_INIT="DH_LIB_INIT",_.DH_LIB_WS_SUCCESS="DH_LIB_WS_SUCCESS",_.DH_LIB_OPEN="DH_LIB_OPEN",_.DH_LIB_STATUS="DH_LIB_STATUS",_.DH_LIB_CLOSE="DH_LIB_CLOSE",_.DH_LIB_ERROR="DH_LIB_ERROR",_.DH_LIB_WARNING="DH_LIB_WARNING",_.DH_LIB_FULL_STATUS="DH_LIB_FULL_STATUS",_.DH_LIB_MESSAGE="DH_LIB_MESSAGE",exports.errorTypeEnum=void 0,(E=exports.errorTypeEnum||(exports.errorTypeEnum={})).CONNECT_ERROR="CONNECT_ERROR",E.DISCONNECT_ALERT="DISCONNECT_ALERT",E.TIMEOUT_EXIT="TIMEOUT_EXIT",E.LOCAL_VIDEO_MUTED="LOCAL_VIDEO_MUTED",E.LOCAL_VIDEO_ERROR="LOCAL_VIDEO_ERROR",E.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 t,classCallCheck as o,defineProperty as e}from"./_virtual/_rollupPluginBabelHelpers.js";import n from"@bddh/starling-brtc";import{TimeoutController as c}from"@bddh/starling-timeout-controller";import i from"@bddh/starling-json";import a from"lodash/isEmpty";import r from"lodash/isFunction";import{statusEnum as l,errorTypeEnum as s}from"./interface.js";var d=function(){function d(t){var u=this;o(this,d),e(this,"client",void 0),e(this,"isRtcVideoOn",!1),e(this,"rtcConnection",void 0),e(this,"rtcConfig",void 0),e(this,"bizConfig",void 0),e(this,"rtcCallback",void 0),e(this,"restarting",!1),e(this,"timeoutEvent",void 0),e(this,"reopenTimer",void 0),e(this,"restartCount",0),e(this,"closeLog",!0),e(this,"haveVideoOn",!1),e(this,"rtcStateCallback",null),e(this,"openRtc",(function(t){if(u.restarting)!u.closeLog&&console.warn("rtc restarting");else if(t&&(u.rtcConnection=t),u.rtcConnection&&!a(u.rtcConnection)){var o=u.rtcConnection,e=o.server,c=o.appId,d=o.token,m=o.roomName,C=o.userId,f=u.rtcCallback||{},b=f.onRemotedata,g=f.onLocalStream,h=f.onRemoteVideoComing,v=f.onLocalVideoPublished,L=f.onLocalVideoPublishing,R=f.onRemoteVideoOn,S=f.onRemoteVideoOff,k=f.onRemoteVideoLoading,p=f.onSuccess,y=f.onError,V=f.onLocalVideoConnected,E=f.onRemoteVideoConnected,_=f.onRemoteMediaState,O=f.onPlayingError,I=f.onDigitalHumanCallback;u.timeoutEvent.start(),u.rtcStateCallback=function(t){var o=t.body,e=t.action;I&&I({status:l.DH_LIB_FULL_STATUS,content:{type:"rtcState",action:e,body:o}})},u.client=new n({roomName:m,token:d,userId:C,appId:c,server:e,rtcConfig:u.rtcConfig,callback:{onRemoteVideoConnected:function(o,e){if(!e&&!u.haveVideoOn)var n=setTimeout((function(){u.restartCount<3?(u.restartCount=++u.restartCount,u.restartRtc&&u.restartRtc(t)):(u.restartCount=0,u.closeRtc()),clearTimeout(n)}),500);if(e){var c=document.getElementById("remotevideo500");if(c){c.muted=!1;var i=c.play();void 0!==i&&i.catch((function(){c.muted=!0,c.play().catch((function(t){!u.closeLog&&console.info("videoElement play error",t),O&&O(c),I&&I({status:l.DH_LIB_ERROR,content:{type:s.LOCAL_VIDEO_ERROR}})})),I&&I({status:l.DH_LIB_STATUS,content:{type:s.LOCAL_VIDEO_MUTED}})}))}else!u.closeLog&&console.error("videoElement is null!")}!u.closeLog&&console.info("remoteVideoConnected",o,e,u.restartCount),u.rtcStateCallback&&u.rtcStateCallback({action:"remoteVideoConnected",body:{id:o,connected:e,restartCount:u.restartCount}}),r(E)&&E(o,e)},onRemoteVideoOn:function(t){u.haveVideoOn=!0,!u.closeLog&&console.info("remotevideoon by id: ",t),u.timeoutEvent.clear();var o=document.querySelector("#starlingRtcContainer"),e=o&&o.lastChild;e&&(e.style.display="none"),u.rtcStateCallback&&u.rtcStateCallback({action:"remotevideoon",body:t}),I&&I({status:l.DH_LIB_OPEN}),r(R)&&R(t)},onRemoteMediaState:function(t,o,e){!u.closeLog&&console.info("remoteMediaState",t,o,e),u.rtcStateCallback&&u.rtcStateCallback({action:"remoteMediaState",body:{id:t,medium:o,connected:e}}),r(_)&&_(t,o,e)},onLocalVideoConnected:function(t){!u.closeLog&&console.info("localVideoConnected",t),u.rtcStateCallback&&u.rtcStateCallback({action:"localVideoConnected",body:{connected:t}}),r(V)&&V(t)},onRemotedata:function(t){if(u.rtcConfig&&u.rtcConfig.usingdatachannel){var o=i.parse(t);!u.closeLog&&console.info("RTC - receive:",o),r(b)&&b(o)}},onLocalStream:function(t,o){!u.closeLog&&console.info("rtc - onlocalstream by name: "+o),u.rtcStateCallback&&u.rtcStateCallback({action:"onlocalstream",body:{stream:t,name:o}}),r(g)&&g(t,o)},onLocalVideoPublished:function(){!u.closeLog&&console.info("LocalVideoPublished 本地视频发布成功"),u.rtcStateCallback&&u.rtcStateCallback({action:"localvideopublished_ok",body:!0}),r(v)&&v()},onLocalVideoPublishing:function(){!u.closeLog&&console.info("LocalVideoPublishing 本地视频发布成功"),u.rtcStateCallback&&u.rtcStateCallback({action:"localvideopublishing",body:!0}),r(L)&&L()},onRemoteVideoComing:function(t){!u.closeLog&&console.info("remotevideocoming",t),u.rtcStateCallback&&u.rtcStateCallback({action:"remotevideocoming",body:t}),r(h)&&h(t)},onRemoteVideoLoading:function(t){!u.closeLog&&console.info("remotevideoloading by id: ",t),u.rtcStateCallback&&u.rtcStateCallback({action:"remotevideoloading",body:t}),r(k)&&k(t)},onRemoteVideoOff:function(t){var o=document.getElementById("remotevideo500");o&&o.pause(),!u.closeLog&&console.info("remotevideooff: ",t),u.isRtcVideoOn=!1,u.rtcStateCallback&&u.rtcStateCallback({action:"remotevideooff",body:t}),I&&I({status:l.DH_LIB_CLOSE}),r(S)&&S(t),u.timeoutEvent.start()},onSuccess:function(){!u.closeLog&&console.info("rtc - success"),u.rtcStateCallback&&u.rtcStateCallback({action:"success",body:!0}),r(p)&&p()},onError:function(o){u.isRtcVideoOn=!1,!u.closeLog&&console.error("rtc - error:",o),u.rtcStateCallback&&u.rtcStateCallback({action:"error",body:o}),I&&I({status:l.DH_LIB_ERROR,content:{type:s.RTC_ERROR}}),r(y)&&y(o),(o.includes("Lost connection to the server")||o.includes("Is the server down"))&&u.restartRtc&&u.restartRtc(t)}}})}})),e(this,"closeRtc",(function(){u.timeoutEvent.clear(),clearTimeout(u.reopenTimer),u.client&&u.client.destroy(),u.restarting=!1})),e(this,"restartRtc",(function(t){!u.restarting&&u.bizConfig&&u.bizConfig.autoReConnect&&(u.rtcStateCallback&&u.rtcStateCallback({action:"restartRtc",body:t}),u.restarting=!0,u.closeRtc(),u.reopenTimer=setTimeout((function(){!u.closeLog&&console.error("拉流失败,开始重启"),u.restarting=!1,u.openRtc(t)}),2e3))}));var m=t.rtcConnection,C=t.rtcConfig,f=t.closeLog,b=void 0===f||f,g=t.rtcCallback;this.rtcConnection=m,this.rtcConfig=C,this.rtcCallback=g,this.closeLog=b,this.timeoutEvent=new c(6e4,(function(){if(!u.rtcConnection)return!u.closeLog&&console.warn("remotevideoon事件超时, rtcConnectionRef is null");u.timeoutEvent.clear(),u.restartRtc&&u.restartRtc(u.rtcConnection)}))}return t(d,[{key:"muteMicphone",value:function(t){this.client&&this.client.muteMicphone&&this.client.muteMicphone(t)}}]),d}();export{d as default};
|
package/es/Client.d.ts
CHANGED
|
@@ -20,16 +20,12 @@ export default class DhRealtimeHuman {
|
|
|
20
20
|
private recordController;
|
|
21
21
|
private wsReadyState;
|
|
22
22
|
private readonly isPreOpenSession;
|
|
23
|
-
private readonly openWsOnly;
|
|
24
|
-
private enableLastFrameCover;
|
|
25
|
-
private _isMicMuted;
|
|
26
23
|
constructor(props: DhRealtimeHumanType);
|
|
27
24
|
init(props: DhRealtimeHumanType): void;
|
|
28
25
|
onDigitalHumanCallbackPlus: (data: CallbackMsgType) => void;
|
|
29
26
|
onRemoteVideoComing: (id: number) => void;
|
|
30
27
|
onLocalStream: () => void;
|
|
31
28
|
onRemoteVideoOn: () => void;
|
|
32
|
-
onRemoteVideoOffLastFrame: () => void;
|
|
33
29
|
connectListener: (data: ConnectDataType) => void;
|
|
34
30
|
createServer: (sessionId?: string) => void;
|
|
35
31
|
checkHumanInstansce: () => boolean;
|
package/es/Client.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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,playHumanVideo,muteHumanVideo,captureLastFrameToCover}from"./DomControl.js";import Cutout from"./Cutout.js";import RecordController from"./RecordController.js";var DhRealtimeHuman=function(){function DhRealtimeHuman(props){var _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,"isHuawei",checkIsHuawei()),_defineProperty(this,"rtcServerUrl",void 0),_defineProperty(this,"recordController",null),_defineProperty(this,"wsReadyState",-1),_defineProperty(this,"isPreOpenSession",!1),_defineProperty(this,"openWsOnly",!1),_defineProperty(this,"enableLastFrameCover",!1),_defineProperty(this,"_isMicMuted",!1),_defineProperty(this,"onDigitalHumanCallbackPlus",(function(data){var _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$rtcServer=_this.rtcServer)||void 0===_this$rtcServer||_this$rtcServer.closeRtc(),_this.enableLastFrameCover&&(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(!_this.enableLastFrameCover){_context.next=8;break}if(video=document.getElementById(RTC_VIDEO_ID),!_this.cutoutInstance||!video){_context.next=5;break}return _context.next=5,_this.cutoutInstance.updateSource(video);case 5:captureLastFrameToCover(),setHumanPlayerWrapperVisible(!0),setLastFrameCoverVisible(!1);case 8:case"end":return _context.stop()}}),_callee)}))),100)})),_defineProperty(this,"onRemoteVideoOffLastFrame",(function(){setLastFrameCoverVisible(!0)})),_defineProperty(this,"connectListener",(function(data){var code=data.code,body=data.body,message=data.message;if(0===code&&_this.onDigitalHumanCallback&&_this.onDigitalHumanCallback({status:statusEnum.DH_LIB_WS_SUCCESS,content:data}),0===code){var _data=CustomJSON.parse(body),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))}else _this.onDigitalHumanCallback&&_this.onDigitalHumanCallback({status:statusEnum.DH_LIB_ERROR,content:{type:errorTypeEnum.CONNECT_ERROR,msg:{code:code,errMsg:message}}})})),_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,"destroy",_asyncToGenerator(_regeneratorRuntime().mark((function _callee3(){var _this$recordControlle;return _regeneratorRuntime().wrap((function(_context3){for(;;)switch(_context3.prev=_context3.next){case 0:return _this.enableLastFrameCover?(playHumanVideo(!1),setHumanPlayerWrapperVisible(!1),setLastFrameCoverVisible(!0)):(removeHumanDom(),removeLastFrameCoverWrapper()),_context3.next=3,_this.dhServer&&_this.dhServer.closeSocket();case 3:_this.rtcServer&&_this.rtcServer.closeRtc(),null===(_this$recordControlle=_this.recordController)||void 0===_this$recordControlle||_this$recordControlle.destroy(),_this.dhServer=null,_this.rtcServer=null;case 7:case"end":return _context3.stop()}}),_callee3)})))),_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,onDigitalHumanCallback=props.onDigitalHumanCallback;this.isPreOpenSession=isPreOpenSession,this.openWsOnly=isOpenWsOnly,this.dhServer=new Server(wsUrl||"wss://open.xiling.baidu.com/cloud/digital-human-demonstration",{checkHeartbeatMismatch:checkHeartbeatMismatch}),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:"init",value:function(props){var _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;if(this.token=token,this.appKey=appKey,this.appId=appId,this.rtcServerUrl=rtcServerUrl,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.enableLastFrameCover=!!renderParams.enableLastFrameCover,removeLastFrameCoverWrapper(),removeHumanDom();var playerWrapper=(createHumanDom({autoChromaKey:!!renderParams.autoChromaKey||!isEmpty(renderParams.chromaEffects)})||{}).playerWrapper,wrapperEle=document.getElementById(wrapperId||"");wrapperEle||console.error("dom with wrapperId is not find"),playerWrapper&&wrapperEle&&wrapperEle.appendChild(playerWrapper),this.enableLastFrameCover&&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:{autoReConnect:null===(_connectParams$reConn=null==connectParams?void 0:connectParams.reConnect)||void 0===_connectParams$reConn||_connectParams$reConn},rtcCallback:_objectSpread2({onRemoteVideoComing:this.onRemoteVideoComing,onDigitalHumanCallback:this.onDigitalHumanCallback,onLocalStream:this.onLocalStream,onRemoteVideoOn:this.onRemoteVideoOn},this.enableLastFrameCover?{onRemoteVideoOff:this.onRemoteVideoOffLastFrame}:{})}),(!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:"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};
|
|
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 i from"@bddh/starling-json";import s from"lodash/isEmpty";import c from"lodash/omit";import l from"lodash/pick";import{v4 as u}from"uuid";import{statusEnum as d,errorTypeEnum as m,CONNECT_MAIN_KEY as h}from"./interface.js";import p from"./Server.js";import v from"./BrtcClient.js";import{createHumanDom as S,appendRtcDomStyle as g,RTC_VIDEO_ID as C,checkIsHuawei as f,playHumanVideo as R,muteHumanVideo as I,removeHumanDom as b,DEFAULT_CANVAS_ID as k}from"./DomControl.js";import y from"./Cutout.js";import D from"./RecordController.js";var E=function(){function E(e){var s=this;t(this,E),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,"isHuawei",f()),r(this,"rtcServerUrl",void 0),r(this,"recordController",null),r(this,"wsReadyState",-1),r(this,"isPreOpenSession",!1),r(this,"onDigitalHumanCallbackPlus",(function(e){var t;e.status===d.DH_LIB_FULL_STATUS&&"wsState"===(null===(t=e.content)||void 0===t?void 0:t.type)&&(s.wsReadyState=e.content.readyState),s.onDigitalHumanCallback&&s.onDigitalHumanCallback(e)})),r(this,"onRemoteVideoComing",(function(e){s.rtcConnectParams&&s.rtcConnectParams.feedId&&e===+s.rtcConnectParams.feedId&&s.rtcServer&&s.rtcServer.client&&s.rtcServer.client.subscribeStreaming("remotevideo500",+s.rtcConnectParams.feedId)})),r(this,"onLocalStream",(function(){(s.connectParams||{}).pullAudioFromRtc&&s.rtcServer&&s.rtcServer.muteMicphone(!1)})),r(this,"onRemoteVideoOn",(function(){setTimeout(a(o().mark((function e(){var t,r,n,a,i;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=document.getElementById(C),e.next=3,s.cutoutInstance&&s.cutoutInstance.updateSource(C);case 3:t&&(t.setAttribute("data-playing","true"),r=t.videoWidth,n=t.videoHeight,a=document.getElementById(k),i=a&&a.getContext("2d"),a&&i&&(a.width=r,a.height=n,i.drawImage(t,0,0,r,n)));case 4:case"end":return e.stop()}}),e)}))),100)})),r(this,"connectListener",(function(e){var t=e.code,r=e.body,n=e.message;if(0===t&&s.onDigitalHumanCallback&&s.onDigitalHumanCallback({status:d.DH_LIB_WS_SUCCESS,content:e}),0===t){var a=i.parse(r),o=a.rtcServerUrl,c=a.appId,l=a.clientToken,u=a.roomName,h=a.clientId,p=a.feedId,v=a.chargeId;c&&u&&(s.rtcConnectParams={server:s.rtcServerUrl||o,appId:c,token:l,roomName:u,userId:h,feedId:p,chargeId:v},s.rtcServer&&s.rtcServer.openRtc(s.rtcConnectParams))}else s.onDigitalHumanCallback&&s.onDigitalHumanCallback({status:d.DH_LIB_ERROR,content:{type:m.CONNECT_ERROR,msg:{code:t,errMsg:n}}})})),r(this,"createServer",(function(e){var t,r=n(n(n({token:s.token,appKey:s.appKey,appId:s.appId},e?{sessionId:e}:{}),l(s.connectParams,h)),{},{parameters:c(s.connectParams,h),onConnect:s.connectListener,onDigitalHumanCallback:s.onDigitalHumanCallbackPlus});null!==(t=s.dhServer)&&void 0!==t&&t.preConnectSuccess?(s.dhServer.connectParams=r,s.dhServer&&s.dhServer.sendPreConnect(r)):s.dhServer&&s.dhServer.createSocket(r)})),r(this,"checkHumanInstansce",(function(){return s.dhServer?!(s.isPreOpenSession&&!s.dhServer.preConnectSuccess)||(s.onDigitalHumanCallback&&s.onDigitalHumanCallback({status:d.DH_LIB_ERROR,content:{type:m.CONNECT_ERROR,msg:{code:4001,errMsg:"webSocket连接中"}}}),!1):(s.onDigitalHumanCallback&&s.onDigitalHumanCallback({status:d.DH_LIB_ERROR,content:{type:m.CONNECT_ERROR,msg:{code:4002,errMsg:"请先初始化数字人实例"}}}),!1)})),r(this,"sendMessage",(function(e,t){return s.dhServer&&s.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){s.dhServer&&s.dhServer.sendMessage({requestId:u(),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;s.checkHumanInstansce()&&s.dhServer&&s.dhServer.sendMessage({requestId:t||u(),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=i.parse(r).first;s.checkHumanInstansce()&&s.dhServer&&s.dhServer.sendMessage({requestId:t||u(),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;s.checkHumanInstansce()&&s.dhServer&&s.dhServer.sendMessage({requestId:u(),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;s.checkHumanInstansce()&&s.dhServer&&s.dhServer.sendMessage({requestId:t||u(),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;s.dhServer&&s.dhServer.sendMessage({requestId:t||u(),action:"TEXT_QUERY",body:r,clientTs:(new Date).getTime()},n)})),r(this,"destroy",a(o().mark((function e(){var t;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,s.dhServer&&s.dhServer.destroySocket();case 2:s.rtcServer&&s.rtcServer.closeRtc(),b(),null===(t=s.recordController)||void 0===t||t.destroy(),s.dhServer=null,s.rtcServer=null;case 7:case"end":return e.stop()}}),e)})))),r(this,"pauseHuman",(function(){return R(!1)})),r(this,"playHuman",(function(){return R(!0)})),r(this,"muteHuman",(function(){return I(!0)})),r(this,"unMuteHuman",(function(){var e=I(!1);try{return s.isHuawei?(e.pause(),e.play()):e.paused&&e.play()}catch(e){console.info(e)}}));var v=e.isPreOpenSession,S=void 0!==v&&v,g=e.wsUrl,y=e.renderParams,D=e.onDigitalHumanCallback;this.isPreOpenSession=S,this.dhServer=new p(g||"wss://open.xiling.baidu.com/cloud/digital-human-demonstration"),this.onDigitalHumanCallback=function(e){e.status!==d.DH_LIB_FULL_STATUS?D&&D(e):(null==y?void 0:y.fullStatus)&&D&&D(e)},S?this.dhServer.createSocket({onDigitalHumanCallback:this.onDigitalHumanCallbackPlus},S):this.init(e)}return e(E,[{key:"init",value:function(e){var t=this,r=e.wrapperId,a=e.token,o=e.appKey,i=e.appId,c=e.connectParams,l=e.renderParams,u=void 0===l?{}:l,h=e.rtcConnectParams,p=e.brtcParams,f=e.rtcServerUrl;if(this.token=a,this.appKey=o,this.appId=i,this.rtcServerUrl=f,this.connectParams=n({autoChromaKey:(null==u?void 0:u.autoChromaKey)||!1},c),!i&&!o&&!a)throw new Error("appId and appKey or token is required");var R=u.closeLog,I=u.audio3AConstraints,b=(S({autoChromaKey:!!u.autoChromaKey||!s(u.chromaEffects)})||{}).playerWrapper,k=document.getElementById(r||"");k||console.error("dom with wrapperId is not find"),b&&k&&k.appendChild(b),g();var E=n({remotevideoviewid:r,showvideobps:!1,usingvideo:!1,usingaudio:!(null==c||!c.pullAudioFromRtc),aspublisher:!(null==c||!c.pullAudioFromRtc),autopublish:!(null==c||!c.pullAudioFromRtc),usingdatachannel:!0,autoplaymuted:!1},p);this.rtcServer=new v({closeLog:R,videoWrapperId:C,rtcConfig:E,bizConfig:{},rtcCallback:{onRemoteVideoComing:this.onRemoteVideoComing,onDigitalHumanCallback:this.onDigitalHumanCallback,onLocalStream:this.onLocalStream}}),(!s(null==u?void 0:u.chromaEffects)||null!=u&&u.autoChromaKey)&&(this.cutoutInstance=new y({sourceId:C,effects:null==u?void 0:u.chromaEffects})),s(h)||(this.rtcConnectParams=h,this.rtcServer.openRtc(h)),null!=c&&c.pullAudioFromRtc?this.recordController=null:this.recordController=new D({pickAudioMode:null==c?void 0:c.pickAudioMode,audio3AConstraints:I,asrSample:null==c?void 0:c.asrSample,onAudioData:function(e){1===t.wsReadyState&&t.sendMessage(e,null)},onError:function(e){t.onDigitalHumanCallback&&t.onDigitalHumanCallback({status:d.DH_LIB_ERROR,content:{type:m.CONNECT_ERROR,msg:{code:-1,errMsg:e.message}}})}})}},{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:u(),clientTs:Date.now(),body:""},null);this.recordController&&this.recordController.stop(),this.sendMessage({action:"AUDIO_QUERY_INTERRUPT",requestId:u(),clientTs:Date.now(),body:""},null)}},{key:"muteMicrophone",value:function(e){var t;null===(t=this.rtcServer)||void 0===t||t.muteMicphone(e)}}]),E}();export{E as default};
|
package/es/Cutout.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createClass as
|
|
1
|
+
import{createClass as t,classCallCheck as e,defineProperty as s}from"./_virtual/_rollupPluginBabelHelpers.js";import n from"@bddh/starling-cutout/es/Seriously";var o={version:2,chromaKey:{screen:[53,186,123],similarity:90,edgeShrink:3,smoothness:80,spill:100,opacity:1,contrast:0,brightness:0,gamma:0}},r=function(){function r(t){e(this,r),s(this,"cutoutInstance",void 0);var u=t.effects,a=t.sourceId;this.cutoutInstance=new n("starling-cutout-canvas",a||"starling-cutout-video",u&&u.chromaKey||o.chromaKey,u&&u.version||o.version)}return t(r,[{key:"setOptions",value:function(t){t&&this.cutoutInstance&&this.cutoutInstance.setOptions(t)}},{key:"destroy",value:function(){return this.cutoutInstance.destroy()}},{key:"updateSource",value:function(t){return this.cutoutInstance.updateSource(t)}}]),r}();export{o as DEFAULT_EFFECTS,r as default};
|
package/es/DomControl.d.ts
CHANGED
|
@@ -14,14 +14,7 @@ interface CreateVideoDomResult {
|
|
|
14
14
|
export declare const DEFAULT_CANVAS_ID = "starling-cutout-canvas";
|
|
15
15
|
export declare const HUMAN_WRAPPER_ID = "cloud-brtc-player-wrapper";
|
|
16
16
|
export declare const RTC_VIDEO_ID = "remotevideo500";
|
|
17
|
-
export declare const LAST_FRAME_COVER_CANVAS_CLASS = "canvas-item";
|
|
18
|
-
export declare const LAST_FRAME_COVER_INNER_CANVAS_ID = "starling-last-frame-cover-canvas";
|
|
19
17
|
export declare function createHumanDom(options: CreateVideoDomOptions): CreateVideoDomResult | null;
|
|
20
|
-
export declare function appendLastFrameCoverSibling(mountEl: HTMLElement | null): void;
|
|
21
|
-
export declare function captureLastFrameToCover(): boolean;
|
|
22
|
-
export declare function setHumanPlayerWrapperVisible(visible: boolean): void;
|
|
23
|
-
export declare function setLastFrameCoverVisible(visible: boolean): void;
|
|
24
|
-
export declare function removeLastFrameCoverWrapper(): void;
|
|
25
18
|
export declare function removeHumanDom(): void;
|
|
26
19
|
export declare function muteHumanVideo(muted: boolean): HTMLVideoElement;
|
|
27
20
|
export declare function playHumanVideo(play: boolean): void | Promise<void>;
|
package/es/DomControl.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var t="starling-cutout-canvas",e="cloud-brtc-player-wrapper",n="remotevideo500";function i(i){var a=i.autoChromaKey,o=void 0!==a&&a,r=i.autoplay,d=void 0===r||r;if(document.getElementById(n))return console.error('DOM with id "'.concat(n,'" already exists.')),null;var c=document.createElement("div");c.className=e,c.id=e,c.style.position="relative";var u=document.createElement("video");if(u.id=n,u.width=0,u.height=0,u.setAttribute("width","100%"),u.setAttribute("height","100%"),u.setAttribute("data-playing","true"),u.setAttribute("playsinline",""),d&&u.setAttribute("autoplay",""),c.appendChild(u),o){var l=document.createElement("canvas");l.id=t,Object.assign(l.style,{position:"absolute",top:"0",left:"0",height:"100%",width:"100%",zIndex:"1",display:o?"block":"none"}),u.style.visibility="hidden",c.appendChild(l)}return{playerWrapper:c,video:u}}function a(){var t=document.getElementById(e);t&&t.parentNode&&t.parentNode.removeChild(t)}function o(t){var e=document.getElementById(n);return e&&(e.muted=t),e}function r(t){var e=document.getElementById(n);try{if(e)return t?e.play():e.pause()}catch(t){console.info(t)}}function d(){var t=navigator.userAgent||navigator.vendor;return/huawei/i.test(t)||/honor/i.test(t)}function c(){var t=document.createElement("style");t.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 ')),document.head.appendChild(t)}export{t as DEFAULT_CANVAS_ID,e as HUMAN_WRAPPER_ID,n as RTC_VIDEO_ID,c as appendRtcDomStyle,d as checkIsHuawei,i as createHumanDom,o as muteHumanVideo,r as playHumanVideo,a as removeHumanDom};
|
package/es/RecordController.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createClass as
|
|
1
|
+
import{createClass as t,asyncToGenerator as e,classCallCheck as r,defineProperty as o,regeneratorRuntime as a,objectSpread2 as i}from"./_virtual/_rollupPluginBabelHelpers.js";function n(t,e,r,o){try{for(var a=(o=o||{})&&"number"==typeof o.index?o.index:0,i=o&&"number"==typeof o.offset?o.offset:0,n=0,s=a;s<t.length;s++)n+=t[s].length;n=Math.max(0,n-Math.floor(i));var c=e/r;c>1?n=Math.floor(n/c):(c=1,r=e);for(var u=new Int16Array(n),h=0,d=t.length;a<d;a++){for(var p=t[a],l=i,f=p.length;l<f;){var m=Math.floor(l),v=Math.ceil(l),x=l-m;u[h]=p[m]+(p[v]-p[m])*x,h++,l+=c}i=l-f}return{index:a,offset:i,sampleRate:r,data:u}}catch(t){console.log("转音错误了",t)}}function s(t){for(var e=t,r=new Int16Array(t.length),o=0;o<e.length;o++){var a=Math.max(-1,Math.min(1,e[o]));r[o]=a<0?32768*a:32767*a}return r}var c=function(c,u){function h(t){r(this,h),o(this,"onAudioData",void 0),o(this,"onError",void 0),o(this,"audioContext",null),o(this,"processor",null),o(this,"mediaStream",null),o(this,"recording",!1),o(this,"audio3AConstraints",void 0),o(this,"asrSample",void 0),this.onAudioData=t.onAudioData,this.onError=t.onError,this.audio3AConstraints=t.audio3AConstraints,this.asrSample=t.asrSample,this.preWarmStream()}return t(h,[{key:"preWarmStream",value:function(){return(c=c||e(a().mark((function t(){var e,r,o;return a().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(t.prev=0,r=window.AudioContext||window.webkitAudioContext){t.next=4;break}throw new Error("当前环境不支持web api: AudioContext");case 4:if(null!==(e=navigator.mediaDevices)&&void 0!==e&&e.getUserMedia){t.next=6;break}throw new Error("当前环境不支持web api: getUserMedia");case 6:return this.audioContext=new r({sampleRate:this.asrSample||16e3}),t.next=9,navigator.mediaDevices.getUserMedia({audio:i({echoCancellation:!0,noiseSuppression:!0,autoGainControl:!0},this.audio3AConstraints),video:!1});case 9:this.mediaStream=t.sent,o=this.audioContext.createMediaStreamSource(this.mediaStream),this.processor=this.audioContext.createScriptProcessor(1024,1,1),o.connect(this.processor),this.processor.connect(this.audioContext.destination),this.processor.onaudioprocess=function(){},t.next=20;break;case 17:t.prev=17,t.t0=t.catch(0),console.error("preWarmStream error",t.t0);case 20:case"end":return t.stop()}}),t,this,[[0,17]])})))).apply(this,arguments)}},{key:"start",value:function(){return(u=u||e(a().mark((function t(){var e=this;return a().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!this.recording){t.next=2;break}return t.abrupt("return");case 2:if(this.audioContext&&this.processor){t.next=4;break}return t.abrupt("return");case 4:try{this.processor.onaudioprocess=function(t){if(e.recording){var r=n([s(t.inputBuffer.getChannelData(0))],e.audioContext.sampleRate,e.asrSample||16e3,null);r&&r.data&&e.onAudioData(r.data.buffer)}},this.recording=!0}catch(t){this.onError&&this.onError(t)}case 5:case"end":return t.stop()}}),t,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(t){t.stop()}))}}]),h}();export{c as default};
|
package/es/Server.d.ts
CHANGED
|
@@ -42,11 +42,7 @@ export interface RenderCallbackRes {
|
|
|
42
42
|
body: string | null;
|
|
43
43
|
message: string;
|
|
44
44
|
}
|
|
45
|
-
interface ServerOptions {
|
|
46
|
-
checkHeartbeatMismatch?: boolean;
|
|
47
|
-
}
|
|
48
45
|
export type RenderCallback = (res: RenderCallbackRes) => void;
|
|
49
|
-
export declare const CONNECTING_STUCK_MS_DEFAULT: number;
|
|
50
46
|
declare class Server {
|
|
51
47
|
dhServerSocket: WebSocketClient | null;
|
|
52
48
|
preConnectSuccess: boolean;
|
|
@@ -54,22 +50,12 @@ declare class Server {
|
|
|
54
50
|
private socketClosingPromise;
|
|
55
51
|
private readonly url;
|
|
56
52
|
private firstConnect;
|
|
57
|
-
|
|
58
|
-
private readonly connectingMs;
|
|
59
|
-
private lastPreOpen;
|
|
60
|
-
private reconnectingTimeout;
|
|
61
|
-
private lastReportedReadyState;
|
|
62
|
-
private lastHbAckTs;
|
|
63
|
-
private readonly checkHeartbeatMismatch;
|
|
64
|
-
constructor(url: string, options?: ServerOptions);
|
|
53
|
+
constructor(url: string);
|
|
65
54
|
sendPreConnect: (props: createSocketParamsType, resolve?: ((value: any) => void) | undefined) => void;
|
|
66
55
|
createSocket: (props: createSocketParamsType, isPreOpenSession?: boolean) => Promise<WebSocketClient | null>;
|
|
67
|
-
sendConnect: (props: createSocketParamsType) => void;
|
|
68
56
|
closeSocket: () => Promise<void>;
|
|
57
|
+
destroySocket: () => Promise<void>;
|
|
69
58
|
handleConnect: () => Promise<void>;
|
|
70
59
|
sendMessage(message: DHServerInterface | ArrayBuffer, listener: RenderCallback | null): Promise<void>;
|
|
71
|
-
private startConnectingWatch;
|
|
72
|
-
private clearConnectingWatch;
|
|
73
|
-
private resetState;
|
|
74
60
|
}
|
|
75
61
|
export default Server;
|
package/es/Server.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createClass as
|
|
1
|
+
import{createClass as e,asyncToGenerator as t,classCallCheck as r,defineProperty as n,regeneratorRuntime as o,objectSpread2 as s,typeof as c}from"./_virtual/_rollupPluginBabelHelpers.js";import{v4 as a}from"uuid";import{createWebSocket as i}from"@bddh/starling-web-socket/es/create-web-socket";import{ReadyState as u}from"@bddh/starling-web-socket/es/interface";import d from"lodash/pick";import l from"lodash/omit";import p from"lodash/get";import{errorTypeEnum as S,CONNECT_MAIN_KEY as f,statusEnum as h,WS_STATUS_MAP as k}from"./interface.js";var m=function(m){function v(e){var c,m=this;r(this,v),n(this,"dhServerSocket",null),n(this,"preConnectSuccess",!1),n(this,"connectParams",null),n(this,"socketClosingPromise",null),n(this,"url",void 0),n(this,"firstConnect",!0),n(this,"sendPreConnect",(function(e,t){var r,n=e.token,o=e.sessionId,s=e.onConnect;null===(r=m.dhServerSocket)||void 0===r||r.request({action:"RE_CONNECT",requestId:a(),body:JSON.stringify({token:n,sessionId:o})}).on((function(e,r){null==s||s(e),0!==e.code&&(r(),m.handleConnect()),null==t||t(m.dhServerSocket)})),m.firstConnect=!1})),n(this,"createSocket",(function(e,r){return(c=c||t(o().mark((function e(t,r){var n,s;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(m.connectParams=t,n=t.sessionId,s=t.onDigitalHumanCallback,!m.socketClosingPromise){e.next=5;break}return e.next=5,m.socketClosingPromise;case 5:if(!m.dhServerSocket||m.dhServerSocket.readyState===u.CLOSED){e.next=8;break}return e.next=8,m.closeSocket();case 8:return e.abrupt("return",new Promise((function(e,o){var c={keepAlive:"heartbeat",reopen:p(m.connectParams,"reConnect",!0),combine:function(e,t){return e&&t&&e.requestId===t.requestId},onOpen:function(){m.dhServerSocket=a,n&&m.firstConnect?m.sendPreConnect(t,e):r&&m.firstConnect||m.handleConnect()},onClose:function(){m.socketClosingPromise=null},onError:function(e){o(e)}},a=i(m.url,c);a.onReadyStateChange((function(e){0===e&&s&&s({status:h.DH_LIB_INIT}),1===e&&r&&(m.preConnectSuccess=!0),3===e&&(m.preConnectSuccess=!1),s&&s({status:h.DH_LIB_FULL_STATUS,content:{type:"wsState",readyState:e,body:k[e]}})})),a.onMessage((function(e){var t=e.action;[S.TIMEOUT_EXIT,S.DISCONNECT_ALERT].includes(t)&&s&&s({status:h.DH_LIB_STATUS,content:{type:t}}),[S.TIMEOUT_EXIT,S.DISCONNECT_ALERT,"HEART_BEAT","CONNECT"].includes(t)||s&&s({status:h.DH_LIB_MESSAGE,content:e})})),r&&(m.dhServerSocket=a),a.open()})));case 9:case"end":return e.stop()}}),e)})))).apply(this,arguments)})),n(this,"closeSocket",t(o().mark((function e(){return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(m.dhServerSocket){e.next=2;break}return e.abrupt("return");case 2:return m.socketClosingPromise=m.dhServerSocket.close(),e.next=5,m.socketClosingPromise;case 5:m.dhServerSocket=null;case 6:case"end":return e.stop()}}),e)})))),n(this,"destroySocket",t(o().mark((function e(){var t;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:m.connectParams=null,null===(t=m.dhServerSocket)||void 0===t||t.destroy(),m.dhServerSocket=null;case 3:case"end":return e.stop()}}),e)})))),n(this,"handleConnect",t(o().mark((function e(){var t,r,n,c,i,u;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(m.dhServerSocket&&m.connectParams){e.next=2;break}return e.abrupt("return");case 2:if(t=m.connectParams,r=t.appId,n=t.appKey,c=t.token,i=t.parameters,u=t.onConnect,r||n||c){e.next=5;break}return e.abrupt("return");case 5:m.dhServerSocket&&m.dhServerSocket.request({action:"CONNECT",clientTs:(new Date).getTime(),requestId:a(),body:JSON.stringify(s(s({token:c,appId:r,appKey:n},d(m.connectParams,f)),{},{parameters:s(s({},l(i,["parameters"])),i&&i.parameters?i.parameters:{})}))}).on((function(e,t){null==u||u(e),0!==e.code&&t()}));case 6:case"end":return e.stop()}}),e)})))),this.url=e}return e(v,[{key:"sendMessage",value:function(e,r){return(m=m||t(o().mark((function e(t,r){var n;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:try{this.dhServerSocket&&this.dhServerSocket&&this.dhServerSocket.request(t).on((function(e){r&&r(e)}))}catch(e){n="object"===c(t)&&"requestId"in t?t.requestId:a(),r&&r({code:-11,body:null,action:"RENDER_ERROR",requestId:n,message:JSON.stringify(e)})}case 1:case"end":return e.stop()}}),e,this)})))).apply(this,arguments)}}]),v}();export{m as default};
|
|
@@ -1 +1 @@
|
|
|
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};
|
|
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};
|
package/es/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import r from"./Client.js";export{CONNECT_MAIN_KEY,WS_STATUS_MAP,errorTypeEnum,statusEnum}from"./interface.js";export{r as default};
|
package/es/interface.d.ts
CHANGED
|
@@ -68,7 +68,6 @@ export interface RenderParamsType {
|
|
|
68
68
|
closeLog?: boolean;
|
|
69
69
|
fullStatus?: boolean;
|
|
70
70
|
audio3AConstraints?: Mic3AType;
|
|
71
|
-
enableLastFrameCover?: boolean;
|
|
72
71
|
}
|
|
73
72
|
export declare enum statusEnum {
|
|
74
73
|
DH_LIB_INIT = "DH_LIB_INIT",
|
|
@@ -120,7 +119,6 @@ export interface CallbackMsgType {
|
|
|
120
119
|
export interface DhRealtimeHumanType {
|
|
121
120
|
token?: string;
|
|
122
121
|
wsUrl?: string;
|
|
123
|
-
checkHeartbeatMismatch?: boolean;
|
|
124
122
|
rtcServerUrl?: string;
|
|
125
123
|
appKey?: string;
|
|
126
124
|
appId?: string;
|
|
@@ -130,7 +128,6 @@ export interface DhRealtimeHumanType {
|
|
|
130
128
|
rtcConnectParams?: RtcConnectionType;
|
|
131
129
|
brtcParams?: any;
|
|
132
130
|
isPreOpenSession?: boolean;
|
|
133
|
-
isOpenWsOnly?: boolean;
|
|
134
131
|
onDigitalHumanCallback: (data: CallbackMsgType) => void;
|
|
135
132
|
}
|
|
136
133
|
export {};
|
package/es/interface.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var _,I,E=["projectId","characterConfigId","configVersion","selectors","figureName","reConnect"];!function(_){_.DH_LIB_INIT="DH_LIB_INIT",_.DH_LIB_WS_SUCCESS="DH_LIB_WS_SUCCESS",_.DH_LIB_OPEN="DH_LIB_OPEN",_.DH_LIB_STATUS="DH_LIB_STATUS",_.DH_LIB_CLOSE="DH_LIB_CLOSE",_.DH_LIB_ERROR="DH_LIB_ERROR",_.DH_LIB_WARNING="DH_LIB_WARNING",_.DH_LIB_FULL_STATUS="DH_LIB_FULL_STATUS",_.DH_LIB_MESSAGE="DH_LIB_MESSAGE"}(_||(_={})),function(_){_.CONNECT_ERROR="CONNECT_ERROR",_.DISCONNECT_ALERT="DISCONNECT_ALERT",_.TIMEOUT_EXIT="TIMEOUT_EXIT",_.LOCAL_VIDEO_MUTED="LOCAL_VIDEO_MUTED",_.LOCAL_VIDEO_ERROR="LOCAL_VIDEO_ERROR",_.RTC_ERROR="RTC_ERROR"}(I||(I={}));var L={"-1":"UNINSTANTIATED",0:"CONNECTING",1:"OPEN",2:"CLOSING",3:"CLOSED"};export{E as CONNECT_MAIN_KEY,L as WS_STATUS_MAP,I as errorTypeEnum,_ as statusEnum};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bddh/starling-realtime-client",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.12",
|
|
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.
|
|
34
|
+
"@bddh/starling-web-socket": "^1.0.14",
|
|
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.
|
|
43
|
+
"@bddh/starling-web-socket": "^1.0.14",
|
|
44
44
|
"lodash": "^4.17.21",
|
|
45
45
|
"uuid": "^9.0.0"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "b15a148355674019064e942fa219839a12d09304"
|
|
48
48
|
}
|