@bddh/starling-realtime-client 2.0.11-beta.2 → 2.0.11-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/BrtcClient.d.ts +2 -2
- package/cjs/Client.d.ts +5 -2
- package/cjs/Client.js +1 -1
- package/cjs/Cutout.d.ts +2 -0
- package/cjs/Cutout.js +1 -1
- package/cjs/interface.d.ts +3 -0
- package/es/BrtcClient.d.ts +2 -2
- package/es/Client.d.ts +5 -2
- package/es/Client.js +1 -1
- package/es/Cutout.d.ts +2 -0
- package/es/Cutout.js +1 -1
- package/es/interface.d.ts +3 -0
- package/package.json +2 -2
package/cjs/BrtcClient.d.ts
CHANGED
|
@@ -92,8 +92,8 @@ declare class BrtcClient {
|
|
|
92
92
|
private haveVideoOn;
|
|
93
93
|
private rtcStateCallback;
|
|
94
94
|
constructor(props: BrtcClientType);
|
|
95
|
-
|
|
96
|
-
|
|
95
|
+
startRtcTimeout: () => void;
|
|
96
|
+
clearRtcTimeout: () => void;
|
|
97
97
|
mergeRtcConfig: (partial: Record<string, unknown>) => void;
|
|
98
98
|
openRtc: (rtcConnection: RtcConnectionType) => void;
|
|
99
99
|
closeRtc: () => void;
|
package/cjs/Client.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* @description 云渲染数字人sdk
|
|
4
4
|
* @author zhangyue49
|
|
5
5
|
*/
|
|
6
|
-
import { DhRealtimeHumanType, ConnectDataType, CallbackMsgType, EffectsType } from './interface';
|
|
6
|
+
import { DhRealtimeHumanType, ConnectDataType, CallbackMsgType, EffectsType, DestroyOptions } from './interface';
|
|
7
7
|
import { DHServerInterface, RenderCallback } from './Server';
|
|
8
8
|
export default class DhRealtimeHuman {
|
|
9
9
|
private token;
|
|
@@ -28,6 +28,7 @@ export default class DhRealtimeHuman {
|
|
|
28
28
|
private mergeConnectRtcExtras;
|
|
29
29
|
private emitRawStatusMessage;
|
|
30
30
|
private resolveMediaServerByDomain?;
|
|
31
|
+
private remoteAutoPlay;
|
|
31
32
|
constructor(props: DhRealtimeHumanType);
|
|
32
33
|
canShowStaticFrameCover(): boolean;
|
|
33
34
|
init(props: DhRealtimeHumanType): void;
|
|
@@ -35,6 +36,7 @@ export default class DhRealtimeHuman {
|
|
|
35
36
|
onRemoteVideoComing: (id: number) => void;
|
|
36
37
|
onLocalStream: () => void;
|
|
37
38
|
onRemoteVideoOn: () => void;
|
|
39
|
+
onRemoteVideoConnected: (id: number, connected: boolean) => void;
|
|
38
40
|
onRemoteVideoOffLastFrame: () => void;
|
|
39
41
|
connectListener: (data: ConnectDataType) => void;
|
|
40
42
|
handleConnectResponse(data: ConnectDataType): Promise<void>;
|
|
@@ -68,7 +70,8 @@ export default class DhRealtimeHuman {
|
|
|
68
70
|
body: string;
|
|
69
71
|
onCallbackMsg: RenderCallback;
|
|
70
72
|
}) => void;
|
|
71
|
-
|
|
73
|
+
handleDestroyView: (keepLastFrame: boolean) => void;
|
|
74
|
+
destroy: (options?: DestroyOptions) => Promise<void>;
|
|
72
75
|
pauseHuman: () => void | Promise<void>;
|
|
73
76
|
playHuman: () => void | Promise<void>;
|
|
74
77
|
muteHuman: () => HTMLVideoElement;
|
package/cjs/Client.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./_virtual/_rollupPluginBabelHelpers.js"),t=require("@bddh/starling-json"),r=require("lodash/isEmpty"),n=require("lodash/omit"),a=require("lodash/pick"),o=require("uuid"),i=require("./interface.js"),s=require("./Server.js"),c=require("./BrtcClient.js"),u=require("./DomControl.js"),l=require("./Cutout.js"),d=require("./RecordController.js"),m=function(m,h,p){function v(r){var c=this;e.classCallCheck(this,v),e.defineProperty(this,"token",void 0),e.defineProperty(this,"appKey",void 0),e.defineProperty(this,"appId",void 0),e.defineProperty(this,"connectParams",void 0),e.defineProperty(this,"onDigitalHumanCallback",void 0),e.defineProperty(this,"dhServer",void 0),e.defineProperty(this,"rtcServer",void 0),e.defineProperty(this,"rtcConnectParams",void 0),e.defineProperty(this,"cutoutInstance",void 0),e.defineProperty(this,"hasInitChromaEffects",!1),e.defineProperty(this,"isHuawei",u.checkIsHuawei()),e.defineProperty(this,"rtcServerUrl",void 0),e.defineProperty(this,"rtcInternalIp",void 0),e.defineProperty(this,"recordController",null),e.defineProperty(this,"wsReadyState",-1),e.defineProperty(this,"isPreOpenSession",!1),e.defineProperty(this,"openWsOnly",!1),e.defineProperty(this,"hasConnectUserFigureEffects",!1),e.defineProperty(this,"_isMicMuted",!1),e.defineProperty(this,"mergeConnectRtcExtras",!1),e.defineProperty(this,"emitRawStatusMessage",!1),e.defineProperty(this,"resolveMediaServerByDomain",void 0),e.defineProperty(this,"onDigitalHumanCallbackPlus",(function(e){var t,r=e.content;e.status===i.statusEnum.DH_LIB_FULL_STATUS&&"wsState"===(null==r?void 0:r.type)&&(c.wsReadyState=r.readyState,3===r.readyState&&(null===(t=c.rtcServer)||void 0===t||t.closeRtc(),c.canShowStaticFrameCover()&&(u.setHumanPlayerWrapperVisible(!1),u.setLastFrameCoverVisible(!0))));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(c._isMicMuted)})),e.defineProperty(this,"onRemoteVideoOn",(function(){setTimeout(e.asyncToGenerator(e.regeneratorRuntime().mark((function t(){var r;return e.regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=document.getElementById(u.RTC_VIDEO_ID),!c.cutoutInstance||!r){e.next=4;break}return e.next=4,c.cutoutInstance.updateSource(r);case 4:c.canShowStaticFrameCover()&&(u.captureLastFrameToCover(),u.setHumanPlayerWrapperVisible(!0),u.setLastFrameCoverVisible(!1));case 5:case"end":return e.stop()}}),t)}))),100)})),e.defineProperty(this,"onRemoteVideoOffLastFrame",(function(){c.canShowStaticFrameCover()&&u.setLastFrameCoverVisible(!0)})),e.defineProperty(this,"connectListener",(function(e){c.handleConnectResponse(e).catch((function(e){console.warn("[DhRealtimeHuman] handleConnectResponse failed",e)}))})),e.defineProperty(this,"createServer",(function(t){var r,o=e.objectSpread2(e.objectSpread2(e.objectSpread2({token:c.token,appKey:c.appKey,appId:c.appId},t?{sessionId:t}:{}),a(c.connectParams,i.CONNECT_MAIN_KEY)),{},{parameters:n(c.connectParams,i.CONNECT_MAIN_KEY),onConnect:c.connectListener,onDigitalHumanCallback:c.onDigitalHumanCallbackPlus});null!==(r=c.dhServer)&&void 0!==r&&r.preConnectSuccess?(c.dhServer.connectParams=o,c.dhServer&&c.dhServer.sendPreConnect(o)):c.openWsOnly?c.dhServer&&c.dhServer.sendConnect(o):c.dhServer&&c.dhServer.createSocket(o)})),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,t){return c.dhServer&&c.dhServer.sendMessage(e,t)})),e.defineProperty(this,"interrupt",e.asyncToGenerator(e.regeneratorRuntime().mark((function t(){return e.regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",new Promise((function(e){c.dhServer&&c.dhServer.sendMessage({requestId:o.v4(),action:"TEXT_RENDER",body:"<interrupt></interrupt>",clientTs:(new Date).getTime()},(function(){return e()}))})));case 1:case"end":return e.stop()}}),t)})))),e.defineProperty(this,"textRender",(function(e){var t=e.requestId,r=e.body,n=e.onCallbackMsg;c.checkHumanInstansce()&&c.dhServer&&c.dhServer.sendMessage({requestId:t||o.v4(),action:"TEXT_RENDER",body:r,clientTs:(new Date).getTime()},n)})),e.defineProperty(this,"textStreamRender",(function(e){var r=e.requestId,n=e.body,a=e.onCallbackMsg,i=t.parse(n).first;c.checkHumanInstansce()&&c.dhServer&&c.dhServer.sendMessage({requestId:r||o.v4(),action:"TEXT_STREAM_RENDER",body:n,clientTs:(new Date).getTime()},i?a:null)})),e.defineProperty(this,"audioRender",(function(e){var t=e.body,r=e.onCallbackMsg;c.checkHumanInstansce()&&c.dhServer&&c.dhServer.sendMessage({requestId:o.v4(),action:"AUDIO_RENDER",body:t,clientTs:(new Date).getTime()},r)})),e.defineProperty(this,"audioStreamRender",(function(e){var t=e.requestId,r=e.body,n=e.onCallbackMsg;c.checkHumanInstansce()&&c.dhServer&&c.dhServer.sendMessage({requestId:t||o.v4(),action:"AUDIO_STREAM_RENDER",body:r,clientTs:(new Date).getTime()},n)})),e.defineProperty(this,"textQuery",(function(e){var t=e.requestId,r=e.body,n=e.onCallbackMsg;c.dhServer&&c.dhServer.sendMessage({requestId:t||o.v4(),action:"TEXT_QUERY",body:r,clientTs:(new Date).getTime()},n)})),e.defineProperty(this,"destroy",e.asyncToGenerator(e.regeneratorRuntime().mark((function t(){var r,n;return e.regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return null===(r=c.cutoutInstance)||void 0===r||r.destroy(),c.cutoutInstance=void 0,c.canShowStaticFrameCover()?(u.playHumanVideo(!1),u.setHumanPlayerWrapperVisible(!1),u.setLastFrameCoverVisible(!0)):(u.removeHumanDom(),u.removeLastFrameCoverWrapper()),e.next=5,c.dhServer&&c.dhServer.closeSocket();case 5:c.rtcServer&&c.rtcServer.closeRtc(),null===(n=c.recordController)||void 0===n||n.destroy(),c.dhServer=null,c.rtcServer=null;case 9:case"end":return e.stop()}}),t)})))),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 l=r.isPreOpenSession,d=void 0!==l&&l,m=r.isOpenWsOnly,h=void 0!==m&&m,p=r.wsUrl,f=r.renderParams,y=r.checkHeartbeatMismatch,C=r.emitRawStatusMessage,S=void 0!==C&&C,R=r.onDigitalHumanCallback;this.isPreOpenSession=d,this.openWsOnly=h,this.emitRawStatusMessage=S,this.dhServer=new s.default(p||"wss://open.xiling.baidu.com/cloud/digital-human-demonstration",{checkHeartbeatMismatch:y,emitRawStatusMessage:S}),this.onDigitalHumanCallback=function(e){e.status!==i.statusEnum.DH_LIB_FULL_STATUS?R&&R(e):(null==f?void 0:f.fullStatus)&&R&&R(e)},d||h?this.dhServer.createSocket({onDigitalHumanCallback:this.onDigitalHumanCallbackPlus},d):this.init(r)}return e.createClass(v,[{key:"canShowStaticFrameCover",value:function(){return!this.hasInitChromaEffects&&!this.hasConnectUserFigureEffects}},{key:"init",value:function(t){var n,a,o=this,s=t.wrapperId,m=t.token,h=t.appKey,p=t.appId,v=t.connectParams,f=t.renderParams,y=void 0===f?{}:f,C=t.rtcConnectParams,S=t.brtcParams,R=t.rtcServerUrl,g=t.rtcInternalIp,b=t.mergeConnectRtcExtras,I=void 0!==b&&b,k=t.emitRawStatusMessage,E=void 0!==k&&k,P=t.remoteAutoPlay,D=t.resolveMediaServerByDomain;if(this.mergeConnectRtcExtras=Boolean(I),this.emitRawStatusMessage=E,null===(n=this.dhServer)||void 0===n||n.setEmitRawStatusMessage(this.emitRawStatusMessage),this.resolveMediaServerByDomain=D,this.hasConnectUserFigureEffects=!1,this.token=m,this.appKey=h,this.appId=p,this.rtcServerUrl=R,this.rtcInternalIp=g,this.connectParams=e.objectSpread2({autoChromaKey:(null==y?void 0:y.autoChromaKey)||!1},v),!p&&!h&&!m)throw new Error("appId and appKey or token is required");var w=y.closeLog,H=y.audio3AConstraints;this.hasInitChromaEffects=!r(null==y?void 0:y.chromaEffects)||!(null==y||!y.autoChromaKey),u.removeLastFrameCoverWrapper(),u.removeHumanDom();var M=(u.createHumanDom({autoChromaKey:!!y.autoChromaKey||!r(y.chromaEffects)})||{}).playerWrapper,T=document.getElementById(s||"");T||console.error("dom with wrapperId is not find"),M&&T&&T.appendChild(M),this.canShowStaticFrameCover()&&T&&("static"===window.getComputedStyle(T).position&&(T.style.position="relative"),u.appendLastFrameCoverSibling(T)),u.appendRtcDomStyle();var _=e.objectSpread2({remotevideoviewid:s,showvideobps:!1,usingvideo:!1,usingaudio:!(null==v||!v.pullAudioFromRtc),aspublisher:!(null==v||!v.pullAudioFromRtc),autopublish:!(null==v||!v.pullAudioFromRtc),usingdatachannel:!0,autoplaymuted:!1},S);this.rtcServer=new c.default({closeLog:w,videoWrapperId:u.RTC_VIDEO_ID,rtcConfig:_,bizConfig:e.objectSpread2({autoReConnect:null===(a=null==v?void 0:v.reConnect)||void 0===a||a},void 0!==P?{remoteAutoPlay:P}:{}),rtcCallback:{onRemoteVideoComing:this.onRemoteVideoComing,onDigitalHumanCallback:this.onDigitalHumanCallback,onLocalStream:this.onLocalStream,onRemoteVideoOn:this.onRemoteVideoOn,onRemoteVideoOff:this.onRemoteVideoOffLastFrame}}),(!r(null==y?void 0:y.chromaEffects)||null!=y&&y.autoChromaKey)&&(this.cutoutInstance=new l.default({sourceId:u.RTC_VIDEO_ID,effects:null==y?void 0:y.chromaEffects})),r(C)||(this.rtcConnectParams=C,this.rtcServer.openRtc(C)),null!=v&&v.pullAudioFromRtc?this.recordController=null:this.recordController=new d.default({pickAudioMode:null==v?void 0:v.pickAudioMode,audio3AConstraints:H,asrSample:null==v?void 0:v.asrSample,onAudioData:function(e){1===o.wsReadyState&&o.sendMessage(e,null)},onError:function(e){o.onDigitalHumanCallback&&o.onDigitalHumanCallback({status:i.statusEnum.DH_LIB_ERROR,content:{type:i.errorTypeEnum.CONNECT_ERROR,msg:{code:-1,errMsg:e.message}}})}})}},{key:"handleConnectResponse",value:function(r){return(m=m||e.asyncToGenerator(e.regeneratorRuntime().mark((function r(n){var a,o,s,c,u,l,d,m,h,p,v;return e.regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(a=n.code,o=n.body,s=n.message,0===a&&this.onDigitalHumanCallback&&this.onDigitalHumanCallback({status:i.statusEnum.DH_LIB_WS_SUCCESS,content:n}),this.emitRawStatusMessage&&this.onDigitalHumanCallback&&this.onDigitalHumanCallback({status:i.statusEnum.DH_LIB_MESSAGE,content:n}),0!==a){e.next=18;break}if(c=t.parse(o),!this.mergeConnectRtcExtras||!this.rtcServer){e.next=14;break}return e.prev=6,e.next=9,this.mergeConnectRtcExtrasFromBody(c);case 9:e.next=14;break;case 11:e.prev=11,e.t0=e.catch(6),console.warn("[DhRealtimeHuman] mergeConnectRtcExtrasFromBody failed",e.t0);case 14:u=c.rtcServerUrl,l=c.appId,d=c.clientToken,m=c.roomName,h=c.clientId,p=c.feedId,v=c.chargeId,l&&m&&(this.rtcConnectParams={server:this.rtcServerUrl||u,appId:l,token:d,roomName:m,userId:h,feedId:p,chargeId:v},this.rtcServer&&this.rtcServer.openRtc(this.rtcConnectParams)),e.next=19;break;case 18:this.onDigitalHumanCallback&&this.onDigitalHumanCallback({status:i.statusEnum.DH_LIB_ERROR,content:{type:i.errorTypeEnum.CONNECT_ERROR,msg:{code:a,errMsg:s}}});case 19:case"end":return e.stop()}}),r,this,[[6,11]])})))).apply(this,arguments)}},{key:"mergeConnectRtcExtrasFromBody",value:function(r){return(h=h||e.asyncToGenerator(e.regeneratorRuntime().mark((function r(n){var a,o,i,s,c,u,l;return e.regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.rtcServer){e.next=2;break}return e.abrupt("return");case 2:if(a=n.userFigure,o=void 0===a?"":a,i=n.rtcExternalInfo,s=(void 0===i?{}:i).udpDomain||"",c={},this.rtcInternalIp&&(c.mediaserverip=this.rtcInternalIp),!o){e.next=19;break}if(!(u=t.parse(o)).effects){e.next=17;break}return e.prev=9,e.next=12,this.applyConnectChroma(u.effects);case 12:e.next=17;break;case 14:e.prev=14,e.t0=e.catch(9),console.warn("[DhRealtimeHuman] applyConnectChroma failed",e.t0);case 17:e.next=36;break;case 19:if(!s){e.next=36;break}if(l=this.resolveMediaServerByDomain){e.next=26;break}console.warn("[DhRealtimeHuman] udpDomain 解析需传入 resolveMediaServerByDomain"),c.mediaserverip="",e.next=36;break;case 26:return e.prev=26,e.next=29,l(s);case 29:c.mediaserverip=e.sent,e.next=36;break;case 32:e.prev=32,e.t1=e.catch(26),c.mediaserverip="",console.error("resolveMediaServerByDomain failed",e.t1);case 36:this.rtcServer.mergeRtcConfig(c);case 37:case"end":return e.stop()}}),r,this,[[9,14],[26,32]])})))).apply(this,arguments)}},{key:"applyConnectChroma",value:function(t){return(p=p||e.asyncToGenerator(e.regeneratorRuntime().mark((function t(r){var n,a,o,i;return e.regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.hasInitChromaEffects){e.next=2;break}return e.abrupt("return");case 2:if(a=r.chromaKey,o=r.version,null!=a){e.next=5;break}return e.abrupt("return");case 5:if(u.ensureCutoutDomMounted()){e.next=7;break}return e.abrupt("return");case 7:if(this.hasConnectUserFigureEffects=!0,u.removeLastFrameCoverWrapper(),u.setLastFrameCoverVisible(!1),u.setHumanPlayerWrapperVisible(!0),null===(n=this.cutoutInstance)||void 0===n||n.destroy(),this.cutoutInstance=new l.default({sourceId:u.RTC_VIDEO_ID,effects:{version:o,chromaKey:a}}),!(i=document.getElementById(u.RTC_VIDEO_ID))){e.next=17;break}return e.next=17,this.cutoutInstance.updateSource(i);case 17:case"end":return e.stop()}}),t,this)})))).apply(this,arguments)}},{key:"startRecord",value:function(){var e;null!==(e=this.connectParams)&&void 0!==e&&e.pullAudioFromRtc?this.rtcServer&&this.rtcServer.muteMicphone(!1):this.recordController&&this.recordController.start()}},{key:"stopRecord",value:function(){var e;if(null!==(e=this.connectParams)&&void 0!==e&&e.pullAudioFromRtc)return this.rtcServer&&this.rtcServer.muteMicphone(!0),void this.sendMessage({action:"AUDIO_QUERY_INTERRUPT",requestId:o.v4(),clientTs:Date.now(),body:""},null);this.recordController&&this.recordController.stop(),this.sendMessage({action:"AUDIO_QUERY_INTERRUPT",requestId:o.v4(),clientTs:Date.now(),body:""},null)}},{key:"muteMicrophone",value:function(e){var t,r;null!==(t=this.connectParams)&&void 0!==t&&t.pullAudioFromRtc&&(this._isMicMuted=e,null===(r=this.rtcServer)||void 0===r||r.muteMicphone(e))}}]),v}();exports.default=m;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./_virtual/_rollupPluginBabelHelpers.js"),t=require("@bddh/starling-json"),r=require("lodash/isEmpty"),n=require("lodash/omit"),a=require("lodash/pick"),o=require("uuid"),i=require("./interface.js"),s=require("./Server.js"),c=require("./BrtcClient.js"),u=require("./DomControl.js"),l=require("./Cutout.js"),d=require("./RecordController.js"),m=function(m,h,p){function v(r){var c,l=this;e.classCallCheck(this,v),e.defineProperty(this,"token",void 0),e.defineProperty(this,"appKey",void 0),e.defineProperty(this,"appId",void 0),e.defineProperty(this,"connectParams",void 0),e.defineProperty(this,"onDigitalHumanCallback",void 0),e.defineProperty(this,"dhServer",void 0),e.defineProperty(this,"rtcServer",void 0),e.defineProperty(this,"rtcConnectParams",void 0),e.defineProperty(this,"cutoutInstance",void 0),e.defineProperty(this,"hasInitChromaEffects",!1),e.defineProperty(this,"isHuawei",u.checkIsHuawei()),e.defineProperty(this,"rtcServerUrl",void 0),e.defineProperty(this,"rtcInternalIp",void 0),e.defineProperty(this,"recordController",null),e.defineProperty(this,"wsReadyState",-1),e.defineProperty(this,"isPreOpenSession",!1),e.defineProperty(this,"openWsOnly",!1),e.defineProperty(this,"hasConnectUserFigureEffects",!1),e.defineProperty(this,"_isMicMuted",!1),e.defineProperty(this,"mergeConnectRtcExtras",!1),e.defineProperty(this,"emitRawStatusMessage",!1),e.defineProperty(this,"resolveMediaServerByDomain",void 0),e.defineProperty(this,"remoteAutoPlay",!0),e.defineProperty(this,"onDigitalHumanCallbackPlus",(function(e){var t,r,n=e.content;e.status===i.statusEnum.DH_LIB_FULL_STATUS&&"wsState"===(null==n?void 0:n.type)&&(l.wsReadyState=n.readyState,3===n.readyState&&(null===(t=l.cutoutInstance)||void 0===t||t.setPlaying(!1),null===(r=l.rtcServer)||void 0===r||r.closeRtc(),l.canShowStaticFrameCover()&&(u.setHumanPlayerWrapperVisible(!1),u.setLastFrameCoverVisible(!0))));l.onDigitalHumanCallback&&l.onDigitalHumanCallback(e)})),e.defineProperty(this,"onRemoteVideoComing",(function(e){l.rtcConnectParams&&l.rtcConnectParams.feedId&&e===+l.rtcConnectParams.feedId&&l.rtcServer&&l.rtcServer.client&&l.rtcServer.client.subscribeStreaming("remotevideo500",+l.rtcConnectParams.feedId)})),e.defineProperty(this,"onLocalStream",(function(){(l.connectParams||{}).pullAudioFromRtc&&l.rtcServer&&l.rtcServer.muteMicphone(l._isMicMuted)})),e.defineProperty(this,"onRemoteVideoOn",(function(){setTimeout(e.asyncToGenerator(e.regeneratorRuntime().mark((function t(){var r;return e.regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=document.getElementById(u.RTC_VIDEO_ID),!l.cutoutInstance||!r){e.next=5;break}return l.cutoutInstance.setPlaying(!0),e.next=5,l.cutoutInstance.updateSource(r);case 5:l.canShowStaticFrameCover()&&(u.captureLastFrameToCover(),u.setHumanPlayerWrapperVisible(!0),u.setLastFrameCoverVisible(!1));case 6:case"end":return e.stop()}}),t)}))),100)})),e.defineProperty(this,"onRemoteVideoConnected",(function(e,t){var r;if(t&&!l.remoteAutoPlay){var n=null===(r=l.rtcConnectParams)||void 0===r?void 0:r.feedId;null!=n&&e!==+n||l.onRemoteVideoOn()}})),e.defineProperty(this,"onRemoteVideoOffLastFrame",(function(){var e;null===(e=l.cutoutInstance)||void 0===e||e.setPlaying(!1),l.canShowStaticFrameCover()&&u.setLastFrameCoverVisible(!0)})),e.defineProperty(this,"connectListener",(function(e){l.handleConnectResponse(e).catch((function(e){console.warn("[DhRealtimeHuman] handleConnectResponse failed",e)}))})),e.defineProperty(this,"createServer",(function(t){var r,o=e.objectSpread2(e.objectSpread2(e.objectSpread2({token:l.token,appKey:l.appKey,appId:l.appId},t?{sessionId:t}:{}),a(l.connectParams,i.CONNECT_MAIN_KEY)),{},{parameters:n(l.connectParams,i.CONNECT_MAIN_KEY),onConnect:l.connectListener,onDigitalHumanCallback:l.onDigitalHumanCallbackPlus});null!==(r=l.dhServer)&&void 0!==r&&r.preConnectSuccess?(l.dhServer.connectParams=o,l.dhServer&&l.dhServer.sendPreConnect(o)):l.openWsOnly?l.dhServer&&l.dhServer.sendConnect(o):l.dhServer&&l.dhServer.createSocket(o)})),e.defineProperty(this,"checkHumanInstansce",(function(){return l.dhServer?!(l.isPreOpenSession&&!l.dhServer.preConnectSuccess)||(l.onDigitalHumanCallback&&l.onDigitalHumanCallback({status:i.statusEnum.DH_LIB_ERROR,content:{type:i.errorTypeEnum.CONNECT_ERROR,msg:{code:4001,errMsg:"webSocket连接中"}}}),!1):(l.onDigitalHumanCallback&&l.onDigitalHumanCallback({status:i.statusEnum.DH_LIB_ERROR,content:{type:i.errorTypeEnum.CONNECT_ERROR,msg:{code:4002,errMsg:"请先初始化数字人实例"}}}),!1)})),e.defineProperty(this,"sendMessage",(function(e,t){return l.dhServer&&l.dhServer.sendMessage(e,t)})),e.defineProperty(this,"interrupt",e.asyncToGenerator(e.regeneratorRuntime().mark((function t(){return e.regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",new Promise((function(e){l.dhServer&&l.dhServer.sendMessage({requestId:o.v4(),action:"TEXT_RENDER",body:"<interrupt></interrupt>",clientTs:(new Date).getTime()},(function(){return e()}))})));case 1:case"end":return e.stop()}}),t)})))),e.defineProperty(this,"textRender",(function(e){var t=e.requestId,r=e.body,n=e.onCallbackMsg;l.checkHumanInstansce()&&l.dhServer&&l.dhServer.sendMessage({requestId:t||o.v4(),action:"TEXT_RENDER",body:r,clientTs:(new Date).getTime()},n)})),e.defineProperty(this,"textStreamRender",(function(e){var r=e.requestId,n=e.body,a=e.onCallbackMsg,i=t.parse(n).first;l.checkHumanInstansce()&&l.dhServer&&l.dhServer.sendMessage({requestId:r||o.v4(),action:"TEXT_STREAM_RENDER",body:n,clientTs:(new Date).getTime()},i?a:null)})),e.defineProperty(this,"audioRender",(function(e){var t=e.body,r=e.onCallbackMsg;l.checkHumanInstansce()&&l.dhServer&&l.dhServer.sendMessage({requestId:o.v4(),action:"AUDIO_RENDER",body:t,clientTs:(new Date).getTime()},r)})),e.defineProperty(this,"audioStreamRender",(function(e){var t=e.requestId,r=e.body,n=e.onCallbackMsg;l.checkHumanInstansce()&&l.dhServer&&l.dhServer.sendMessage({requestId:t||o.v4(),action:"AUDIO_STREAM_RENDER",body:r,clientTs:(new Date).getTime()},n)})),e.defineProperty(this,"textQuery",(function(e){var t=e.requestId,r=e.body,n=e.onCallbackMsg;l.dhServer&&l.dhServer.sendMessage({requestId:t||o.v4(),action:"TEXT_QUERY",body:r,clientTs:(new Date).getTime()},n)})),e.defineProperty(this,"handleDestroyView",(function(e){var t,r;return e?l.canShowStaticFrameCover()?(u.playHumanVideo(!1),u.setHumanPlayerWrapperVisible(!1),void u.setLastFrameCoverVisible(!0)):void(null===(t=l.cutoutInstance)||void 0===t||t.setPlaying(!1)):(null===(r=l.cutoutInstance)||void 0===r||r.destroy(),l.cutoutInstance=void 0,u.removeHumanDom(),void u.removeLastFrameCoverWrapper())})),e.defineProperty(this,"destroy",(function(t){return(c=c||e.asyncToGenerator(e.regeneratorRuntime().mark((function t(r){var n,a,o;return e.regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a=(r||{}).keepLastFrame,o=void 0!==a&&a,l.handleDestroyView(o),e.next=4,l.dhServer&&l.dhServer.closeSocket();case 4:l.rtcServer&&l.rtcServer.closeRtc(),null===(n=l.recordController)||void 0===n||n.destroy(),l.dhServer=null,l.rtcServer=null;case 8:case"end":return e.stop()}}),t)})))).apply(this,arguments)})),e.defineProperty(this,"pauseHuman",(function(){return u.playHumanVideo(!1)})),e.defineProperty(this,"playHuman",(function(){return u.playHumanVideo(!0)})),e.defineProperty(this,"muteHuman",(function(){return u.muteHumanVideo(!0)})),e.defineProperty(this,"unMuteHuman",(function(){var e=u.muteHumanVideo(!1);try{return l.isHuawei?(e.pause(),e.play()):e.paused&&e.play()}catch(e){console.info(e)}}));var d=r.isPreOpenSession,m=void 0!==d&&d,h=r.isOpenWsOnly,p=void 0!==h&&h,f=r.wsUrl,y=r.renderParams,C=r.checkHeartbeatMismatch,S=r.emitRawStatusMessage,R=void 0!==S&&S,g=r.onDigitalHumanCallback;this.isPreOpenSession=m,this.openWsOnly=p,this.emitRawStatusMessage=R,this.dhServer=new s.default(f||"wss://open.xiling.baidu.com/cloud/digital-human-demonstration",{checkHeartbeatMismatch:C,emitRawStatusMessage:R}),this.onDigitalHumanCallback=function(e){e.status!==i.statusEnum.DH_LIB_FULL_STATUS?g&&g(e):(null==y?void 0:y.fullStatus)&&g&&g(e)},m||p?this.dhServer.createSocket({onDigitalHumanCallback:this.onDigitalHumanCallbackPlus},m):this.init(r)}return e.createClass(v,[{key:"canShowStaticFrameCover",value:function(){return!this.hasInitChromaEffects&&!this.hasConnectUserFigureEffects}},{key:"init",value:function(t){var n,a,o=this,s=t.wrapperId,m=t.token,h=t.appKey,p=t.appId,v=t.connectParams,f=t.renderParams,y=void 0===f?{}:f,C=t.rtcConnectParams,S=t.brtcParams,R=t.rtcServerUrl,g=t.rtcInternalIp,I=t.mergeConnectRtcExtras,b=void 0!==I&&I,P=t.emitRawStatusMessage,k=void 0!==P&&P,E=t.remoteAutoPlay,D=t.resolveMediaServerByDomain;if(this.mergeConnectRtcExtras=Boolean(b),this.emitRawStatusMessage=k,null===(n=this.dhServer)||void 0===n||n.setEmitRawStatusMessage(this.emitRawStatusMessage),this.resolveMediaServerByDomain=D,this.remoteAutoPlay=!1!==E,this.hasConnectUserFigureEffects=!1,this.token=m,this.appKey=h,this.appId=p,this.rtcServerUrl=R,this.rtcInternalIp=g,this.connectParams=e.objectSpread2({autoChromaKey:(null==y?void 0:y.autoChromaKey)||!1},v),!p&&!h&&!m)throw new Error("appId and appKey or token is required");var w=y.closeLog,H=y.audio3AConstraints;this.hasInitChromaEffects=!r(null==y?void 0:y.chromaEffects)||!(null==y||!y.autoChromaKey),u.removeLastFrameCoverWrapper(),u.removeHumanDom();var M=(u.createHumanDom({autoChromaKey:!!y.autoChromaKey||!r(y.chromaEffects),autoplay:!1!==E})||{}).playerWrapper,T=document.getElementById(s||"");T||console.error("dom with wrapperId is not find"),M&&T&&T.appendChild(M),this.canShowStaticFrameCover()&&T&&("static"===window.getComputedStyle(T).position&&(T.style.position="relative"),u.appendLastFrameCoverSibling(T)),u.appendRtcDomStyle();var _=e.objectSpread2({remotevideoviewid:s,showvideobps:!1,usingvideo:!1,usingaudio:!(null==v||!v.pullAudioFromRtc),aspublisher:!(null==v||!v.pullAudioFromRtc),autopublish:!(null==v||!v.pullAudioFromRtc),usingdatachannel:!0,autoplaymuted:!1},S);this.rtcServer=new c.default({closeLog:w,videoWrapperId:u.RTC_VIDEO_ID,rtcConfig:_,bizConfig:e.objectSpread2({autoReConnect:null===(a=null==v?void 0:v.reConnect)||void 0===a||a},void 0!==E?{remoteAutoPlay:E}:{}),rtcCallback:{onRemoteVideoComing:this.onRemoteVideoComing,onDigitalHumanCallback:this.onDigitalHumanCallback,onLocalStream:this.onLocalStream,onRemoteVideoOn:this.onRemoteVideoOn,onRemoteVideoOff:this.onRemoteVideoOffLastFrame,onRemoteVideoConnected:this.onRemoteVideoConnected}}),(!r(null==y?void 0:y.chromaEffects)||null!=y&&y.autoChromaKey)&&(this.cutoutInstance=new l.default({sourceId:u.RTC_VIDEO_ID,effects:null==y?void 0:y.chromaEffects})),r(C)||(this.rtcConnectParams=C,this.rtcServer.openRtc(C)),null!=v&&v.pullAudioFromRtc?this.recordController=null:this.recordController=new d.default({pickAudioMode:null==v?void 0:v.pickAudioMode,audio3AConstraints:H,asrSample:null==v?void 0:v.asrSample,onAudioData:function(e){1===o.wsReadyState&&o.sendMessage(e,null)},onError:function(e){o.onDigitalHumanCallback&&o.onDigitalHumanCallback({status:i.statusEnum.DH_LIB_ERROR,content:{type:i.errorTypeEnum.CONNECT_ERROR,msg:{code:-1,errMsg:e.message}}})}})}},{key:"handleConnectResponse",value:function(r){return(m=m||e.asyncToGenerator(e.regeneratorRuntime().mark((function r(n){var a,o,s,c,u,l,d,m,h,p,v;return e.regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(a=n.code,o=n.body,s=n.message,0===a&&this.onDigitalHumanCallback&&this.onDigitalHumanCallback({status:i.statusEnum.DH_LIB_WS_SUCCESS,content:n}),this.emitRawStatusMessage&&this.onDigitalHumanCallback&&this.onDigitalHumanCallback({status:i.statusEnum.DH_LIB_MESSAGE,content:n}),0!==a){e.next=18;break}if(c=t.parse(o),!this.mergeConnectRtcExtras||!this.rtcServer){e.next=14;break}return e.prev=6,e.next=9,this.mergeConnectRtcExtrasFromBody(c);case 9:e.next=14;break;case 11:e.prev=11,e.t0=e.catch(6),console.warn("[DhRealtimeHuman] mergeConnectRtcExtrasFromBody failed",e.t0);case 14:u=c.rtcServerUrl,l=c.appId,d=c.clientToken,m=c.roomName,h=c.clientId,p=c.feedId,v=c.chargeId,l&&m&&(this.rtcConnectParams={server:this.rtcServerUrl||u,appId:l,token:d,roomName:m,userId:h,feedId:p,chargeId:v},this.rtcServer&&this.rtcServer.openRtc(this.rtcConnectParams)),e.next=19;break;case 18:this.onDigitalHumanCallback&&this.onDigitalHumanCallback({status:i.statusEnum.DH_LIB_ERROR,content:{type:i.errorTypeEnum.CONNECT_ERROR,msg:{code:a,errMsg:s}}});case 19:case"end":return e.stop()}}),r,this,[[6,11]])})))).apply(this,arguments)}},{key:"mergeConnectRtcExtrasFromBody",value:function(r){return(h=h||e.asyncToGenerator(e.regeneratorRuntime().mark((function r(n){var a,o,i,s,c,u,l;return e.regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.rtcServer){e.next=2;break}return e.abrupt("return");case 2:if(a=n.userFigure,o=void 0===a?"":a,i=n.rtcExternalInfo,s=(void 0===i?{}:i).udpDomain||"",c={},this.rtcInternalIp&&(c.mediaserverip=this.rtcInternalIp),!o){e.next=19;break}if(!(u=t.parse(o)).effects){e.next=17;break}return e.prev=9,e.next=12,this.applyConnectChroma(u.effects);case 12:e.next=17;break;case 14:e.prev=14,e.t0=e.catch(9),console.warn("[DhRealtimeHuman] applyConnectChroma failed",e.t0);case 17:e.next=36;break;case 19:if(!s){e.next=36;break}if(l=this.resolveMediaServerByDomain){e.next=26;break}console.warn("[DhRealtimeHuman] udpDomain 解析需传入 resolveMediaServerByDomain"),c.mediaserverip="",e.next=36;break;case 26:return e.prev=26,e.next=29,l(s);case 29:c.mediaserverip=e.sent,e.next=36;break;case 32:e.prev=32,e.t1=e.catch(26),c.mediaserverip="",console.error("resolveMediaServerByDomain failed",e.t1);case 36:this.rtcServer.mergeRtcConfig(c);case 37:case"end":return e.stop()}}),r,this,[[9,14],[26,32]])})))).apply(this,arguments)}},{key:"applyConnectChroma",value:function(t){return(p=p||e.asyncToGenerator(e.regeneratorRuntime().mark((function t(r){var n,a,o,i;return e.regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.hasInitChromaEffects){e.next=2;break}return e.abrupt("return");case 2:if(a=r.chromaKey,o=r.version,null!=a){e.next=5;break}return e.abrupt("return");case 5:if(u.ensureCutoutDomMounted()){e.next=7;break}return e.abrupt("return");case 7:if(this.hasConnectUserFigureEffects=!0,u.removeLastFrameCoverWrapper(),u.setLastFrameCoverVisible(!1),u.setHumanPlayerWrapperVisible(!0),null===(n=this.cutoutInstance)||void 0===n||n.destroy(),this.cutoutInstance=new l.default({sourceId:u.RTC_VIDEO_ID,effects:{version:o,chromaKey:a}}),!(i=document.getElementById(u.RTC_VIDEO_ID))){e.next=17;break}return e.next=17,this.cutoutInstance.updateSource(i);case 17:case"end":return e.stop()}}),t,this)})))).apply(this,arguments)}},{key:"startRecord",value:function(){var e;null!==(e=this.connectParams)&&void 0!==e&&e.pullAudioFromRtc?this.rtcServer&&this.rtcServer.muteMicphone(!1):this.recordController&&this.recordController.start()}},{key:"stopRecord",value:function(){var e;if(null!==(e=this.connectParams)&&void 0!==e&&e.pullAudioFromRtc)return this.rtcServer&&this.rtcServer.muteMicphone(!0),void this.sendMessage({action:"AUDIO_QUERY_INTERRUPT",requestId:o.v4(),clientTs:Date.now(),body:""},null);this.recordController&&this.recordController.stop(),this.sendMessage({action:"AUDIO_QUERY_INTERRUPT",requestId:o.v4(),clientTs:Date.now(),body:""},null)}},{key:"muteMicrophone",value:function(e){var t,r;null!==(t=this.connectParams)&&void 0!==t&&t.pullAudioFromRtc&&(this._isMicMuted=e,null===(r=this.rtcServer)||void 0===r||r.muteMicphone(e))}}]),v}();exports.default=m;
|
package/cjs/Cutout.d.ts
CHANGED
|
@@ -28,9 +28,11 @@ export declare const DEFAULT_EFFECTS: {
|
|
|
28
28
|
};
|
|
29
29
|
declare class Cutout {
|
|
30
30
|
cutoutInstance: Seriously;
|
|
31
|
+
private sourceId;
|
|
31
32
|
constructor(props: CutoutType);
|
|
32
33
|
setOptions(options: Partial<ChromaEffectOptions>): void;
|
|
33
34
|
destroy(): void;
|
|
35
|
+
setPlaying(playing: boolean): void;
|
|
34
36
|
updateSource(video: HTMLVideoElement | string): Promise<void>;
|
|
35
37
|
}
|
|
36
38
|
export default Cutout;
|
package/cjs/Cutout.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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}},
|
|
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}},n=function(){function n(o){t.classCallCheck(this,n),t.defineProperty(this,"cutoutInstance",void 0),t.defineProperty(this,"sourceId",void 0);var u=o.effects,i=o.sourceId;this.sourceId=i||"starling-cutout-video",this.cutoutInstance=new e("starling-cutout-canvas",this.sourceId,u&&u.chromaKey||s.chromaKey,u&&u.version||s.version),this.setPlaying(!0)}return t.createClass(n,[{key:"setOptions",value:function(t){t&&this.cutoutInstance&&this.cutoutInstance.setOptions(t)}},{key:"destroy",value:function(){return this.cutoutInstance.destroy()}},{key:"setPlaying",value:function(t){var e=document.getElementById(this.sourceId);e?e.setAttribute("data-playing",t?"true":"false"):console.warn("[Cutout] video element not found: #".concat(this.sourceId,", skip setPlaying(").concat(t,")"))}},{key:"updateSource",value:function(t){return"string"==typeof t&&(this.sourceId=t),this.setPlaying(!0),this.cutoutInstance.updateSource(t)}}]),n}();exports.DEFAULT_EFFECTS=s,exports.default=n;
|
package/cjs/interface.d.ts
CHANGED
package/es/BrtcClient.d.ts
CHANGED
|
@@ -92,8 +92,8 @@ declare class BrtcClient {
|
|
|
92
92
|
private haveVideoOn;
|
|
93
93
|
private rtcStateCallback;
|
|
94
94
|
constructor(props: BrtcClientType);
|
|
95
|
-
|
|
96
|
-
|
|
95
|
+
startRtcTimeout: () => void;
|
|
96
|
+
clearRtcTimeout: () => void;
|
|
97
97
|
mergeRtcConfig: (partial: Record<string, unknown>) => void;
|
|
98
98
|
openRtc: (rtcConnection: RtcConnectionType) => void;
|
|
99
99
|
closeRtc: () => void;
|
package/es/Client.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* @description 云渲染数字人sdk
|
|
4
4
|
* @author zhangyue49
|
|
5
5
|
*/
|
|
6
|
-
import { DhRealtimeHumanType, ConnectDataType, CallbackMsgType, EffectsType } from './interface';
|
|
6
|
+
import { DhRealtimeHumanType, ConnectDataType, CallbackMsgType, EffectsType, DestroyOptions } from './interface';
|
|
7
7
|
import { DHServerInterface, RenderCallback } from './Server';
|
|
8
8
|
export default class DhRealtimeHuman {
|
|
9
9
|
private token;
|
|
@@ -28,6 +28,7 @@ export default class DhRealtimeHuman {
|
|
|
28
28
|
private mergeConnectRtcExtras;
|
|
29
29
|
private emitRawStatusMessage;
|
|
30
30
|
private resolveMediaServerByDomain?;
|
|
31
|
+
private remoteAutoPlay;
|
|
31
32
|
constructor(props: DhRealtimeHumanType);
|
|
32
33
|
canShowStaticFrameCover(): boolean;
|
|
33
34
|
init(props: DhRealtimeHumanType): void;
|
|
@@ -35,6 +36,7 @@ export default class DhRealtimeHuman {
|
|
|
35
36
|
onRemoteVideoComing: (id: number) => void;
|
|
36
37
|
onLocalStream: () => void;
|
|
37
38
|
onRemoteVideoOn: () => void;
|
|
39
|
+
onRemoteVideoConnected: (id: number, connected: boolean) => void;
|
|
38
40
|
onRemoteVideoOffLastFrame: () => void;
|
|
39
41
|
connectListener: (data: ConnectDataType) => void;
|
|
40
42
|
handleConnectResponse(data: ConnectDataType): Promise<void>;
|
|
@@ -68,7 +70,8 @@ export default class DhRealtimeHuman {
|
|
|
68
70
|
body: string;
|
|
69
71
|
onCallbackMsg: RenderCallback;
|
|
70
72
|
}) => void;
|
|
71
|
-
|
|
73
|
+
handleDestroyView: (keepLastFrame: boolean) => void;
|
|
74
|
+
destroy: (options?: DestroyOptions) => Promise<void>;
|
|
72
75
|
pauseHuman: () => void | Promise<void>;
|
|
73
76
|
playHuman: () => void | Promise<void>;
|
|
74
77
|
muteHuman: () => HTMLVideoElement;
|
package/es/Client.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createClass as e,classCallCheck as t,defineProperty as r,objectSpread2 as n,asyncToGenerator as a,regeneratorRuntime as o}from"./_virtual/_rollupPluginBabelHelpers.js";import s from"@bddh/starling-json";import i from"lodash/isEmpty";import c from"lodash/omit";import u from"lodash/pick";import{v4 as l}from"uuid";import{statusEnum as d,errorTypeEnum as h,CONNECT_MAIN_KEY as m}from"./interface.js";import v from"./Server.js";import p from"./BrtcClient.js";import{removeLastFrameCoverWrapper as f,removeHumanDom as S,createHumanDom as C,appendLastFrameCoverSibling as g,appendRtcDomStyle as R,RTC_VIDEO_ID as y,checkIsHuawei as k,setHumanPlayerWrapperVisible as b,setLastFrameCoverVisible as I,captureLastFrameToCover as w,playHumanVideo as D,muteHumanVideo as E,ensureCutoutDomMounted as M}from"./DomControl.js";import H from"./Cutout.js";import x from"./RecordController.js";var _=function(_,T,P){function O(e){var i=this;t(this,O),r(this,"token",void 0),r(this,"appKey",void 0),r(this,"appId",void 0),r(this,"connectParams",void 0),r(this,"onDigitalHumanCallback",void 0),r(this,"dhServer",void 0),r(this,"rtcServer",void 0),r(this,"rtcConnectParams",void 0),r(this,"cutoutInstance",void 0),r(this,"hasInitChromaEffects",!1),r(this,"isHuawei",k()),r(this,"rtcServerUrl",void 0),r(this,"rtcInternalIp",void 0),r(this,"recordController",null),r(this,"wsReadyState",-1),r(this,"isPreOpenSession",!1),r(this,"openWsOnly",!1),r(this,"hasConnectUserFigureEffects",!1),r(this,"_isMicMuted",!1),r(this,"mergeConnectRtcExtras",!1),r(this,"emitRawStatusMessage",!1),r(this,"resolveMediaServerByDomain",void 0),r(this,"onDigitalHumanCallbackPlus",(function(e){var t,r=e.content;e.status===d.DH_LIB_FULL_STATUS&&"wsState"===(null==r?void 0:r.type)&&(i.wsReadyState=r.readyState,3===r.readyState&&(null===(t=i.rtcServer)||void 0===t||t.closeRtc(),i.canShowStaticFrameCover()&&(b(!1),I(!0))));i.onDigitalHumanCallback&&i.onDigitalHumanCallback(e)})),r(this,"onRemoteVideoComing",(function(e){i.rtcConnectParams&&i.rtcConnectParams.feedId&&e===+i.rtcConnectParams.feedId&&i.rtcServer&&i.rtcServer.client&&i.rtcServer.client.subscribeStreaming("remotevideo500",+i.rtcConnectParams.feedId)})),r(this,"onLocalStream",(function(){(i.connectParams||{}).pullAudioFromRtc&&i.rtcServer&&i.rtcServer.muteMicphone(i._isMicMuted)})),r(this,"onRemoteVideoOn",(function(){setTimeout(a(o().mark((function e(){var t;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t=document.getElementById(y),!i.cutoutInstance||!t){e.next=4;break}return e.next=4,i.cutoutInstance.updateSource(t);case 4:i.canShowStaticFrameCover()&&(w(),b(!0),I(!1));case 5:case"end":return e.stop()}}),e)}))),100)})),r(this,"onRemoteVideoOffLastFrame",(function(){i.canShowStaticFrameCover()&&I(!0)})),r(this,"connectListener",(function(e){i.handleConnectResponse(e).catch((function(e){console.warn("[DhRealtimeHuman] handleConnectResponse failed",e)}))})),r(this,"createServer",(function(e){var t,r=n(n(n({token:i.token,appKey:i.appKey,appId:i.appId},e?{sessionId:e}:{}),u(i.connectParams,m)),{},{parameters:c(i.connectParams,m),onConnect:i.connectListener,onDigitalHumanCallback:i.onDigitalHumanCallbackPlus});null!==(t=i.dhServer)&&void 0!==t&&t.preConnectSuccess?(i.dhServer.connectParams=r,i.dhServer&&i.dhServer.sendPreConnect(r)):i.openWsOnly?i.dhServer&&i.dhServer.sendConnect(r):i.dhServer&&i.dhServer.createSocket(r)})),r(this,"checkHumanInstansce",(function(){return i.dhServer?!(i.isPreOpenSession&&!i.dhServer.preConnectSuccess)||(i.onDigitalHumanCallback&&i.onDigitalHumanCallback({status:d.DH_LIB_ERROR,content:{type:h.CONNECT_ERROR,msg:{code:4001,errMsg:"webSocket连接中"}}}),!1):(i.onDigitalHumanCallback&&i.onDigitalHumanCallback({status:d.DH_LIB_ERROR,content:{type:h.CONNECT_ERROR,msg:{code:4002,errMsg:"请先初始化数字人实例"}}}),!1)})),r(this,"sendMessage",(function(e,t){return i.dhServer&&i.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){i.dhServer&&i.dhServer.sendMessage({requestId:l(),action:"TEXT_RENDER",body:"<interrupt></interrupt>",clientTs:(new Date).getTime()},(function(){return e()}))})));case 1:case"end":return e.stop()}}),e)})))),r(this,"textRender",(function(e){var t=e.requestId,r=e.body,n=e.onCallbackMsg;i.checkHumanInstansce()&&i.dhServer&&i.dhServer.sendMessage({requestId:t||l(),action:"TEXT_RENDER",body:r,clientTs:(new Date).getTime()},n)})),r(this,"textStreamRender",(function(e){var t=e.requestId,r=e.body,n=e.onCallbackMsg,a=s.parse(r).first;i.checkHumanInstansce()&&i.dhServer&&i.dhServer.sendMessage({requestId:t||l(),action:"TEXT_STREAM_RENDER",body:r,clientTs:(new Date).getTime()},a?n:null)})),r(this,"audioRender",(function(e){var t=e.body,r=e.onCallbackMsg;i.checkHumanInstansce()&&i.dhServer&&i.dhServer.sendMessage({requestId:l(),action:"AUDIO_RENDER",body:t,clientTs:(new Date).getTime()},r)})),r(this,"audioStreamRender",(function(e){var t=e.requestId,r=e.body,n=e.onCallbackMsg;i.checkHumanInstansce()&&i.dhServer&&i.dhServer.sendMessage({requestId:t||l(),action:"AUDIO_STREAM_RENDER",body:r,clientTs:(new Date).getTime()},n)})),r(this,"textQuery",(function(e){var t=e.requestId,r=e.body,n=e.onCallbackMsg;i.dhServer&&i.dhServer.sendMessage({requestId:t||l(),action:"TEXT_QUERY",body:r,clientTs:(new Date).getTime()},n)})),r(this,"destroy",a(o().mark((function e(){var t,r;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return null===(t=i.cutoutInstance)||void 0===t||t.destroy(),i.cutoutInstance=void 0,i.canShowStaticFrameCover()?(D(!1),b(!1),I(!0)):(S(),f()),e.next=5,i.dhServer&&i.dhServer.closeSocket();case 5:i.rtcServer&&i.rtcServer.closeRtc(),null===(r=i.recordController)||void 0===r||r.destroy(),i.dhServer=null,i.rtcServer=null;case 9:case"end":return e.stop()}}),e)})))),r(this,"pauseHuman",(function(){return D(!1)})),r(this,"playHuman",(function(){return D(!0)})),r(this,"muteHuman",(function(){return E(!0)})),r(this,"unMuteHuman",(function(){var e=E(!1);try{return i.isHuawei?(e.pause(),e.play()):e.paused&&e.play()}catch(e){console.info(e)}}));var p=e.isPreOpenSession,C=void 0!==p&&p,g=e.isOpenWsOnly,R=void 0!==g&&g,M=e.wsUrl,H=e.renderParams,x=e.checkHeartbeatMismatch,_=e.emitRawStatusMessage,T=void 0!==_&&_,P=e.onDigitalHumanCallback;this.isPreOpenSession=C,this.openWsOnly=R,this.emitRawStatusMessage=T,this.dhServer=new v(M||"wss://open.xiling.baidu.com/cloud/digital-human-demonstration",{checkHeartbeatMismatch:x,emitRawStatusMessage:T}),this.onDigitalHumanCallback=function(e){e.status!==d.DH_LIB_FULL_STATUS?P&&P(e):(null==H?void 0:H.fullStatus)&&P&&P(e)},C||R?this.dhServer.createSocket({onDigitalHumanCallback:this.onDigitalHumanCallbackPlus},C):this.init(e)}return e(O,[{key:"canShowStaticFrameCover",value:function(){return!this.hasInitChromaEffects&&!this.hasConnectUserFigureEffects}},{key:"init",value:function(e){var t,r,a=this,o=e.wrapperId,s=e.token,c=e.appKey,u=e.appId,l=e.connectParams,m=e.renderParams,v=void 0===m?{}:m,k=e.rtcConnectParams,b=e.brtcParams,I=e.rtcServerUrl,w=e.rtcInternalIp,D=e.mergeConnectRtcExtras,E=void 0!==D&&D,M=e.emitRawStatusMessage,_=void 0!==M&&M,T=e.remoteAutoPlay,P=e.resolveMediaServerByDomain;if(this.mergeConnectRtcExtras=Boolean(E),this.emitRawStatusMessage=_,null===(t=this.dhServer)||void 0===t||t.setEmitRawStatusMessage(this.emitRawStatusMessage),this.resolveMediaServerByDomain=P,this.hasConnectUserFigureEffects=!1,this.token=s,this.appKey=c,this.appId=u,this.rtcServerUrl=I,this.rtcInternalIp=w,this.connectParams=n({autoChromaKey:(null==v?void 0:v.autoChromaKey)||!1},l),!u&&!c&&!s)throw new Error("appId and appKey or token is required");var O=v.closeLog,F=v.audio3AConstraints;this.hasInitChromaEffects=!i(null==v?void 0:v.chromaEffects)||!(null==v||!v.autoChromaKey),f(),S();var A=(C({autoChromaKey:!!v.autoChromaKey||!i(v.chromaEffects)})||{}).playerWrapper,U=document.getElementById(o||"");U||console.error("dom with wrapperId is not find"),A&&U&&U.appendChild(A),this.canShowStaticFrameCover()&&U&&("static"===window.getComputedStyle(U).position&&(U.style.position="relative"),g(U)),R();var B=n({remotevideoviewid:o,showvideobps:!1,usingvideo:!1,usingaudio:!(null==l||!l.pullAudioFromRtc),aspublisher:!(null==l||!l.pullAudioFromRtc),autopublish:!(null==l||!l.pullAudioFromRtc),usingdatachannel:!0,autoplaymuted:!1},b);this.rtcServer=new p({closeLog:O,videoWrapperId:y,rtcConfig:B,bizConfig:n({autoReConnect:null===(r=null==l?void 0:l.reConnect)||void 0===r||r},void 0!==T?{remoteAutoPlay:T}:{}),rtcCallback:{onRemoteVideoComing:this.onRemoteVideoComing,onDigitalHumanCallback:this.onDigitalHumanCallback,onLocalStream:this.onLocalStream,onRemoteVideoOn:this.onRemoteVideoOn,onRemoteVideoOff:this.onRemoteVideoOffLastFrame}}),(!i(null==v?void 0:v.chromaEffects)||null!=v&&v.autoChromaKey)&&(this.cutoutInstance=new H({sourceId:y,effects:null==v?void 0:v.chromaEffects})),i(k)||(this.rtcConnectParams=k,this.rtcServer.openRtc(k)),null!=l&&l.pullAudioFromRtc?this.recordController=null:this.recordController=new x({pickAudioMode:null==l?void 0:l.pickAudioMode,audio3AConstraints:F,asrSample:null==l?void 0:l.asrSample,onAudioData:function(e){1===a.wsReadyState&&a.sendMessage(e,null)},onError:function(e){a.onDigitalHumanCallback&&a.onDigitalHumanCallback({status:d.DH_LIB_ERROR,content:{type:h.CONNECT_ERROR,msg:{code:-1,errMsg:e.message}}})}})}},{key:"handleConnectResponse",value:function(e){return(_=_||a(o().mark((function e(t){var r,n,a,i,c,u,l,m,v,p,f;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=t.code,n=t.body,a=t.message,0===r&&this.onDigitalHumanCallback&&this.onDigitalHumanCallback({status:d.DH_LIB_WS_SUCCESS,content:t}),this.emitRawStatusMessage&&this.onDigitalHumanCallback&&this.onDigitalHumanCallback({status:d.DH_LIB_MESSAGE,content:t}),0!==r){e.next=18;break}if(i=s.parse(n),!this.mergeConnectRtcExtras||!this.rtcServer){e.next=14;break}return e.prev=6,e.next=9,this.mergeConnectRtcExtrasFromBody(i);case 9:e.next=14;break;case 11:e.prev=11,e.t0=e.catch(6),console.warn("[DhRealtimeHuman] mergeConnectRtcExtrasFromBody failed",e.t0);case 14:c=i.rtcServerUrl,u=i.appId,l=i.clientToken,m=i.roomName,v=i.clientId,p=i.feedId,f=i.chargeId,u&&m&&(this.rtcConnectParams={server:this.rtcServerUrl||c,appId:u,token:l,roomName:m,userId:v,feedId:p,chargeId:f},this.rtcServer&&this.rtcServer.openRtc(this.rtcConnectParams)),e.next=19;break;case 18:this.onDigitalHumanCallback&&this.onDigitalHumanCallback({status:d.DH_LIB_ERROR,content:{type:h.CONNECT_ERROR,msg:{code:r,errMsg:a}}});case 19:case"end":return e.stop()}}),e,this,[[6,11]])})))).apply(this,arguments)}},{key:"mergeConnectRtcExtrasFromBody",value:function(e){return(T=T||a(o().mark((function e(t){var r,n,a,i,c,u,l;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.rtcServer){e.next=2;break}return e.abrupt("return");case 2:if(r=t.userFigure,n=void 0===r?"":r,a=t.rtcExternalInfo,i=(void 0===a?{}:a).udpDomain||"",c={},this.rtcInternalIp&&(c.mediaserverip=this.rtcInternalIp),!n){e.next=19;break}if(!(u=s.parse(n)).effects){e.next=17;break}return e.prev=9,e.next=12,this.applyConnectChroma(u.effects);case 12:e.next=17;break;case 14:e.prev=14,e.t0=e.catch(9),console.warn("[DhRealtimeHuman] applyConnectChroma failed",e.t0);case 17:e.next=36;break;case 19:if(!i){e.next=36;break}if(l=this.resolveMediaServerByDomain){e.next=26;break}console.warn("[DhRealtimeHuman] udpDomain 解析需传入 resolveMediaServerByDomain"),c.mediaserverip="",e.next=36;break;case 26:return e.prev=26,e.next=29,l(i);case 29:c.mediaserverip=e.sent,e.next=36;break;case 32:e.prev=32,e.t1=e.catch(26),c.mediaserverip="",console.error("resolveMediaServerByDomain failed",e.t1);case 36:this.rtcServer.mergeRtcConfig(c);case 37:case"end":return e.stop()}}),e,this,[[9,14],[26,32]])})))).apply(this,arguments)}},{key:"applyConnectChroma",value:function(e){return(P=P||a(o().mark((function e(t){var r,n,a,s;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.hasInitChromaEffects){e.next=2;break}return e.abrupt("return");case 2:if(n=t.chromaKey,a=t.version,null!=n){e.next=5;break}return e.abrupt("return");case 5:if(M()){e.next=7;break}return e.abrupt("return");case 7:if(this.hasConnectUserFigureEffects=!0,f(),I(!1),b(!0),null===(r=this.cutoutInstance)||void 0===r||r.destroy(),this.cutoutInstance=new H({sourceId:y,effects:{version:a,chromaKey:n}}),!(s=document.getElementById(y))){e.next=17;break}return e.next=17,this.cutoutInstance.updateSource(s);case 17:case"end":return e.stop()}}),e,this)})))).apply(this,arguments)}},{key:"startRecord",value:function(){var e;null!==(e=this.connectParams)&&void 0!==e&&e.pullAudioFromRtc?this.rtcServer&&this.rtcServer.muteMicphone(!1):this.recordController&&this.recordController.start()}},{key:"stopRecord",value:function(){var e;if(null!==(e=this.connectParams)&&void 0!==e&&e.pullAudioFromRtc)return this.rtcServer&&this.rtcServer.muteMicphone(!0),void this.sendMessage({action:"AUDIO_QUERY_INTERRUPT",requestId:l(),clientTs:Date.now(),body:""},null);this.recordController&&this.recordController.stop(),this.sendMessage({action:"AUDIO_QUERY_INTERRUPT",requestId:l(),clientTs:Date.now(),body:""},null)}},{key:"muteMicrophone",value:function(e){var t,r;null!==(t=this.connectParams)&&void 0!==t&&t.pullAudioFromRtc&&(this._isMicMuted=e,null===(r=this.rtcServer)||void 0===r||r.muteMicphone(e))}}]),O}();export{_ 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 s from"@bddh/starling-json";import i from"lodash/isEmpty";import c from"lodash/omit";import u from"lodash/pick";import{v4 as l}from"uuid";import{statusEnum as d,errorTypeEnum as h,CONNECT_MAIN_KEY as m}from"./interface.js";import v from"./Server.js";import p from"./BrtcClient.js";import{removeLastFrameCoverWrapper as f,removeHumanDom as S,createHumanDom as C,appendLastFrameCoverSibling as g,appendRtcDomStyle as R,RTC_VIDEO_ID as y,checkIsHuawei as k,setHumanPlayerWrapperVisible as I,setLastFrameCoverVisible as b,captureLastFrameToCover as w,playHumanVideo as D,muteHumanVideo as E,ensureCutoutDomMounted as M}from"./DomControl.js";import H from"./Cutout.js";import P from"./RecordController.js";var x=function(x,_,T){function O(e){var i,p=this;t(this,O),r(this,"token",void 0),r(this,"appKey",void 0),r(this,"appId",void 0),r(this,"connectParams",void 0),r(this,"onDigitalHumanCallback",void 0),r(this,"dhServer",void 0),r(this,"rtcServer",void 0),r(this,"rtcConnectParams",void 0),r(this,"cutoutInstance",void 0),r(this,"hasInitChromaEffects",!1),r(this,"isHuawei",k()),r(this,"rtcServerUrl",void 0),r(this,"rtcInternalIp",void 0),r(this,"recordController",null),r(this,"wsReadyState",-1),r(this,"isPreOpenSession",!1),r(this,"openWsOnly",!1),r(this,"hasConnectUserFigureEffects",!1),r(this,"_isMicMuted",!1),r(this,"mergeConnectRtcExtras",!1),r(this,"emitRawStatusMessage",!1),r(this,"resolveMediaServerByDomain",void 0),r(this,"remoteAutoPlay",!0),r(this,"onDigitalHumanCallbackPlus",(function(e){var t,r,n=e.content;e.status===d.DH_LIB_FULL_STATUS&&"wsState"===(null==n?void 0:n.type)&&(p.wsReadyState=n.readyState,3===n.readyState&&(null===(t=p.cutoutInstance)||void 0===t||t.setPlaying(!1),null===(r=p.rtcServer)||void 0===r||r.closeRtc(),p.canShowStaticFrameCover()&&(I(!1),b(!0))));p.onDigitalHumanCallback&&p.onDigitalHumanCallback(e)})),r(this,"onRemoteVideoComing",(function(e){p.rtcConnectParams&&p.rtcConnectParams.feedId&&e===+p.rtcConnectParams.feedId&&p.rtcServer&&p.rtcServer.client&&p.rtcServer.client.subscribeStreaming("remotevideo500",+p.rtcConnectParams.feedId)})),r(this,"onLocalStream",(function(){(p.connectParams||{}).pullAudioFromRtc&&p.rtcServer&&p.rtcServer.muteMicphone(p._isMicMuted)})),r(this,"onRemoteVideoOn",(function(){setTimeout(a(o().mark((function e(){var t;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t=document.getElementById(y),!p.cutoutInstance||!t){e.next=5;break}return p.cutoutInstance.setPlaying(!0),e.next=5,p.cutoutInstance.updateSource(t);case 5:p.canShowStaticFrameCover()&&(w(),I(!0),b(!1));case 6:case"end":return e.stop()}}),e)}))),100)})),r(this,"onRemoteVideoConnected",(function(e,t){var r;if(t&&!p.remoteAutoPlay){var n=null===(r=p.rtcConnectParams)||void 0===r?void 0:r.feedId;null!=n&&e!==+n||p.onRemoteVideoOn()}})),r(this,"onRemoteVideoOffLastFrame",(function(){var e;null===(e=p.cutoutInstance)||void 0===e||e.setPlaying(!1),p.canShowStaticFrameCover()&&b(!0)})),r(this,"connectListener",(function(e){p.handleConnectResponse(e).catch((function(e){console.warn("[DhRealtimeHuman] handleConnectResponse failed",e)}))})),r(this,"createServer",(function(e){var t,r=n(n(n({token:p.token,appKey:p.appKey,appId:p.appId},e?{sessionId:e}:{}),u(p.connectParams,m)),{},{parameters:c(p.connectParams,m),onConnect:p.connectListener,onDigitalHumanCallback:p.onDigitalHumanCallbackPlus});null!==(t=p.dhServer)&&void 0!==t&&t.preConnectSuccess?(p.dhServer.connectParams=r,p.dhServer&&p.dhServer.sendPreConnect(r)):p.openWsOnly?p.dhServer&&p.dhServer.sendConnect(r):p.dhServer&&p.dhServer.createSocket(r)})),r(this,"checkHumanInstansce",(function(){return p.dhServer?!(p.isPreOpenSession&&!p.dhServer.preConnectSuccess)||(p.onDigitalHumanCallback&&p.onDigitalHumanCallback({status:d.DH_LIB_ERROR,content:{type:h.CONNECT_ERROR,msg:{code:4001,errMsg:"webSocket连接中"}}}),!1):(p.onDigitalHumanCallback&&p.onDigitalHumanCallback({status:d.DH_LIB_ERROR,content:{type:h.CONNECT_ERROR,msg:{code:4002,errMsg:"请先初始化数字人实例"}}}),!1)})),r(this,"sendMessage",(function(e,t){return p.dhServer&&p.dhServer.sendMessage(e,t)})),r(this,"interrupt",a(o().mark((function e(){return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",new Promise((function(e){p.dhServer&&p.dhServer.sendMessage({requestId:l(),action:"TEXT_RENDER",body:"<interrupt></interrupt>",clientTs:(new Date).getTime()},(function(){return e()}))})));case 1:case"end":return e.stop()}}),e)})))),r(this,"textRender",(function(e){var t=e.requestId,r=e.body,n=e.onCallbackMsg;p.checkHumanInstansce()&&p.dhServer&&p.dhServer.sendMessage({requestId:t||l(),action:"TEXT_RENDER",body:r,clientTs:(new Date).getTime()},n)})),r(this,"textStreamRender",(function(e){var t=e.requestId,r=e.body,n=e.onCallbackMsg,a=s.parse(r).first;p.checkHumanInstansce()&&p.dhServer&&p.dhServer.sendMessage({requestId:t||l(),action:"TEXT_STREAM_RENDER",body:r,clientTs:(new Date).getTime()},a?n:null)})),r(this,"audioRender",(function(e){var t=e.body,r=e.onCallbackMsg;p.checkHumanInstansce()&&p.dhServer&&p.dhServer.sendMessage({requestId:l(),action:"AUDIO_RENDER",body:t,clientTs:(new Date).getTime()},r)})),r(this,"audioStreamRender",(function(e){var t=e.requestId,r=e.body,n=e.onCallbackMsg;p.checkHumanInstansce()&&p.dhServer&&p.dhServer.sendMessage({requestId:t||l(),action:"AUDIO_STREAM_RENDER",body:r,clientTs:(new Date).getTime()},n)})),r(this,"textQuery",(function(e){var t=e.requestId,r=e.body,n=e.onCallbackMsg;p.dhServer&&p.dhServer.sendMessage({requestId:t||l(),action:"TEXT_QUERY",body:r,clientTs:(new Date).getTime()},n)})),r(this,"handleDestroyView",(function(e){var t,r;return e?p.canShowStaticFrameCover()?(D(!1),I(!1),void b(!0)):void(null===(t=p.cutoutInstance)||void 0===t||t.setPlaying(!1)):(null===(r=p.cutoutInstance)||void 0===r||r.destroy(),p.cutoutInstance=void 0,S(),void f())})),r(this,"destroy",(function(e){return(i=i||a(o().mark((function e(t){var r,n,a;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=(t||{}).keepLastFrame,a=void 0!==n&&n,p.handleDestroyView(a),e.next=4,p.dhServer&&p.dhServer.closeSocket();case 4:p.rtcServer&&p.rtcServer.closeRtc(),null===(r=p.recordController)||void 0===r||r.destroy(),p.dhServer=null,p.rtcServer=null;case 8:case"end":return e.stop()}}),e)})))).apply(this,arguments)})),r(this,"pauseHuman",(function(){return D(!1)})),r(this,"playHuman",(function(){return D(!0)})),r(this,"muteHuman",(function(){return E(!0)})),r(this,"unMuteHuman",(function(){var e=E(!1);try{return p.isHuawei?(e.pause(),e.play()):e.paused&&e.play()}catch(e){console.info(e)}}));var C=e.isPreOpenSession,g=void 0!==C&&C,R=e.isOpenWsOnly,M=void 0!==R&&R,H=e.wsUrl,P=e.renderParams,x=e.checkHeartbeatMismatch,_=e.emitRawStatusMessage,T=void 0!==_&&_,A=e.onDigitalHumanCallback;this.isPreOpenSession=g,this.openWsOnly=M,this.emitRawStatusMessage=T,this.dhServer=new v(H||"wss://open.xiling.baidu.com/cloud/digital-human-demonstration",{checkHeartbeatMismatch:x,emitRawStatusMessage:T}),this.onDigitalHumanCallback=function(e){e.status!==d.DH_LIB_FULL_STATUS?A&&A(e):(null==P?void 0:P.fullStatus)&&A&&A(e)},g||M?this.dhServer.createSocket({onDigitalHumanCallback:this.onDigitalHumanCallbackPlus},g):this.init(e)}return e(O,[{key:"canShowStaticFrameCover",value:function(){return!this.hasInitChromaEffects&&!this.hasConnectUserFigureEffects}},{key:"init",value:function(e){var t,r,a=this,o=e.wrapperId,s=e.token,c=e.appKey,u=e.appId,l=e.connectParams,m=e.renderParams,v=void 0===m?{}:m,k=e.rtcConnectParams,I=e.brtcParams,b=e.rtcServerUrl,w=e.rtcInternalIp,D=e.mergeConnectRtcExtras,E=void 0!==D&&D,M=e.emitRawStatusMessage,x=void 0!==M&&M,_=e.remoteAutoPlay,T=e.resolveMediaServerByDomain;if(this.mergeConnectRtcExtras=Boolean(E),this.emitRawStatusMessage=x,null===(t=this.dhServer)||void 0===t||t.setEmitRawStatusMessage(this.emitRawStatusMessage),this.resolveMediaServerByDomain=T,this.remoteAutoPlay=!1!==_,this.hasConnectUserFigureEffects=!1,this.token=s,this.appKey=c,this.appId=u,this.rtcServerUrl=b,this.rtcInternalIp=w,this.connectParams=n({autoChromaKey:(null==v?void 0:v.autoChromaKey)||!1},l),!u&&!c&&!s)throw new Error("appId and appKey or token is required");var O=v.closeLog,A=v.audio3AConstraints;this.hasInitChromaEffects=!i(null==v?void 0:v.chromaEffects)||!(null==v||!v.autoChromaKey),f(),S();var F=(C({autoChromaKey:!!v.autoChromaKey||!i(v.chromaEffects),autoplay:!1!==_})||{}).playerWrapper,U=document.getElementById(o||"");U||console.error("dom with wrapperId is not find"),F&&U&&U.appendChild(F),this.canShowStaticFrameCover()&&U&&("static"===window.getComputedStyle(U).position&&(U.style.position="relative"),g(U)),R();var B=n({remotevideoviewid:o,showvideobps:!1,usingvideo:!1,usingaudio:!(null==l||!l.pullAudioFromRtc),aspublisher:!(null==l||!l.pullAudioFromRtc),autopublish:!(null==l||!l.pullAudioFromRtc),usingdatachannel:!0,autoplaymuted:!1},I);this.rtcServer=new p({closeLog:O,videoWrapperId:y,rtcConfig:B,bizConfig:n({autoReConnect:null===(r=null==l?void 0:l.reConnect)||void 0===r||r},void 0!==_?{remoteAutoPlay:_}:{}),rtcCallback:{onRemoteVideoComing:this.onRemoteVideoComing,onDigitalHumanCallback:this.onDigitalHumanCallback,onLocalStream:this.onLocalStream,onRemoteVideoOn:this.onRemoteVideoOn,onRemoteVideoOff:this.onRemoteVideoOffLastFrame,onRemoteVideoConnected:this.onRemoteVideoConnected}}),(!i(null==v?void 0:v.chromaEffects)||null!=v&&v.autoChromaKey)&&(this.cutoutInstance=new H({sourceId:y,effects:null==v?void 0:v.chromaEffects})),i(k)||(this.rtcConnectParams=k,this.rtcServer.openRtc(k)),null!=l&&l.pullAudioFromRtc?this.recordController=null:this.recordController=new P({pickAudioMode:null==l?void 0:l.pickAudioMode,audio3AConstraints:A,asrSample:null==l?void 0:l.asrSample,onAudioData:function(e){1===a.wsReadyState&&a.sendMessage(e,null)},onError:function(e){a.onDigitalHumanCallback&&a.onDigitalHumanCallback({status:d.DH_LIB_ERROR,content:{type:h.CONNECT_ERROR,msg:{code:-1,errMsg:e.message}}})}})}},{key:"handleConnectResponse",value:function(e){return(x=x||a(o().mark((function e(t){var r,n,a,i,c,u,l,m,v,p,f;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=t.code,n=t.body,a=t.message,0===r&&this.onDigitalHumanCallback&&this.onDigitalHumanCallback({status:d.DH_LIB_WS_SUCCESS,content:t}),this.emitRawStatusMessage&&this.onDigitalHumanCallback&&this.onDigitalHumanCallback({status:d.DH_LIB_MESSAGE,content:t}),0!==r){e.next=18;break}if(i=s.parse(n),!this.mergeConnectRtcExtras||!this.rtcServer){e.next=14;break}return e.prev=6,e.next=9,this.mergeConnectRtcExtrasFromBody(i);case 9:e.next=14;break;case 11:e.prev=11,e.t0=e.catch(6),console.warn("[DhRealtimeHuman] mergeConnectRtcExtrasFromBody failed",e.t0);case 14:c=i.rtcServerUrl,u=i.appId,l=i.clientToken,m=i.roomName,v=i.clientId,p=i.feedId,f=i.chargeId,u&&m&&(this.rtcConnectParams={server:this.rtcServerUrl||c,appId:u,token:l,roomName:m,userId:v,feedId:p,chargeId:f},this.rtcServer&&this.rtcServer.openRtc(this.rtcConnectParams)),e.next=19;break;case 18:this.onDigitalHumanCallback&&this.onDigitalHumanCallback({status:d.DH_LIB_ERROR,content:{type:h.CONNECT_ERROR,msg:{code:r,errMsg:a}}});case 19:case"end":return e.stop()}}),e,this,[[6,11]])})))).apply(this,arguments)}},{key:"mergeConnectRtcExtrasFromBody",value:function(e){return(_=_||a(o().mark((function e(t){var r,n,a,i,c,u,l;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.rtcServer){e.next=2;break}return e.abrupt("return");case 2:if(r=t.userFigure,n=void 0===r?"":r,a=t.rtcExternalInfo,i=(void 0===a?{}:a).udpDomain||"",c={},this.rtcInternalIp&&(c.mediaserverip=this.rtcInternalIp),!n){e.next=19;break}if(!(u=s.parse(n)).effects){e.next=17;break}return e.prev=9,e.next=12,this.applyConnectChroma(u.effects);case 12:e.next=17;break;case 14:e.prev=14,e.t0=e.catch(9),console.warn("[DhRealtimeHuman] applyConnectChroma failed",e.t0);case 17:e.next=36;break;case 19:if(!i){e.next=36;break}if(l=this.resolveMediaServerByDomain){e.next=26;break}console.warn("[DhRealtimeHuman] udpDomain 解析需传入 resolveMediaServerByDomain"),c.mediaserverip="",e.next=36;break;case 26:return e.prev=26,e.next=29,l(i);case 29:c.mediaserverip=e.sent,e.next=36;break;case 32:e.prev=32,e.t1=e.catch(26),c.mediaserverip="",console.error("resolveMediaServerByDomain failed",e.t1);case 36:this.rtcServer.mergeRtcConfig(c);case 37:case"end":return e.stop()}}),e,this,[[9,14],[26,32]])})))).apply(this,arguments)}},{key:"applyConnectChroma",value:function(e){return(T=T||a(o().mark((function e(t){var r,n,a,s;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.hasInitChromaEffects){e.next=2;break}return e.abrupt("return");case 2:if(n=t.chromaKey,a=t.version,null!=n){e.next=5;break}return e.abrupt("return");case 5:if(M()){e.next=7;break}return e.abrupt("return");case 7:if(this.hasConnectUserFigureEffects=!0,f(),b(!1),I(!0),null===(r=this.cutoutInstance)||void 0===r||r.destroy(),this.cutoutInstance=new H({sourceId:y,effects:{version:a,chromaKey:n}}),!(s=document.getElementById(y))){e.next=17;break}return e.next=17,this.cutoutInstance.updateSource(s);case 17:case"end":return e.stop()}}),e,this)})))).apply(this,arguments)}},{key:"startRecord",value:function(){var e;null!==(e=this.connectParams)&&void 0!==e&&e.pullAudioFromRtc?this.rtcServer&&this.rtcServer.muteMicphone(!1):this.recordController&&this.recordController.start()}},{key:"stopRecord",value:function(){var e;if(null!==(e=this.connectParams)&&void 0!==e&&e.pullAudioFromRtc)return this.rtcServer&&this.rtcServer.muteMicphone(!0),void this.sendMessage({action:"AUDIO_QUERY_INTERRUPT",requestId:l(),clientTs:Date.now(),body:""},null);this.recordController&&this.recordController.stop(),this.sendMessage({action:"AUDIO_QUERY_INTERRUPT",requestId:l(),clientTs:Date.now(),body:""},null)}},{key:"muteMicrophone",value:function(e){var t,r;null!==(t=this.connectParams)&&void 0!==t&&t.pullAudioFromRtc&&(this._isMicMuted=e,null===(r=this.rtcServer)||void 0===r||r.muteMicphone(e))}}]),O}();export{x as default};
|
package/es/Cutout.d.ts
CHANGED
|
@@ -28,9 +28,11 @@ export declare const DEFAULT_EFFECTS: {
|
|
|
28
28
|
};
|
|
29
29
|
declare class Cutout {
|
|
30
30
|
cutoutInstance: Seriously;
|
|
31
|
+
private sourceId;
|
|
31
32
|
constructor(props: CutoutType);
|
|
32
33
|
setOptions(options: Partial<ChromaEffectOptions>): void;
|
|
33
34
|
destroy(): void;
|
|
35
|
+
setPlaying(playing: boolean): void;
|
|
34
36
|
updateSource(video: HTMLVideoElement | string): Promise<void>;
|
|
35
37
|
}
|
|
36
38
|
export default Cutout;
|
package/es/Cutout.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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}},
|
|
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}},i=function(){function i(t){e(this,i),s(this,"cutoutInstance",void 0),s(this,"sourceId",void 0);var u=t.effects,a=t.sourceId;this.sourceId=a||"starling-cutout-video",this.cutoutInstance=new n("starling-cutout-canvas",this.sourceId,u&&u.chromaKey||o.chromaKey,u&&u.version||o.version),this.setPlaying(!0)}return t(i,[{key:"setOptions",value:function(t){t&&this.cutoutInstance&&this.cutoutInstance.setOptions(t)}},{key:"destroy",value:function(){return this.cutoutInstance.destroy()}},{key:"setPlaying",value:function(t){var e=document.getElementById(this.sourceId);e?e.setAttribute("data-playing",t?"true":"false"):console.warn("[Cutout] video element not found: #".concat(this.sourceId,", skip setPlaying(").concat(t,")"))}},{key:"updateSource",value:function(t){return"string"==typeof t&&(this.sourceId=t),this.setPlaying(!0),this.cutoutInstance.updateSource(t)}}]),i}();export{o as DEFAULT_EFFECTS,i as default};
|
package/es/interface.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bddh/starling-realtime-client",
|
|
3
|
-
"version": "2.0.11-beta.
|
|
3
|
+
"version": "2.0.11-beta.3",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"react",
|
|
6
6
|
"indexDB"
|
|
@@ -44,5 +44,5 @@
|
|
|
44
44
|
"lodash": "^4.17.21",
|
|
45
45
|
"uuid": "^9.0.0"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "1b229a8fccde51e9ef816005ca67d99f44c29ee2"
|
|
48
48
|
}
|