@bddh/starling-realtime-client 2.0.10 → 2.0.11-beta.2

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.
@@ -46,6 +46,7 @@ export interface BizConfig {
46
46
  welcomeContent?: string;
47
47
  autoChromaKey?: boolean;
48
48
  chromaEffects?: ChromaEffectOptions;
49
+ remoteAutoPlay?: boolean;
49
50
  }
50
51
  export interface RtcCallback {
51
52
  [x: string]: any;
@@ -83,12 +84,17 @@ declare class BrtcClient {
83
84
  private readonly rtcCallback?;
84
85
  private restarting;
85
86
  private readonly timeoutEvent;
87
+ private timeoutStarted;
86
88
  private reopenTimer;
87
89
  private restartCount;
88
90
  private readonly closeLog;
91
+ private stopped;
89
92
  private haveVideoOn;
90
93
  private rtcStateCallback;
91
94
  constructor(props: BrtcClientType);
95
+ private startRtcTimeout;
96
+ private clearRtcTimeout;
97
+ mergeRtcConfig: (partial: Record<string, unknown>) => void;
92
98
  openRtc: (rtcConnection: RtcConnectionType) => void;
93
99
  closeRtc: () => void;
94
100
  restartRtc: (rtcConnection: RtcConnectionType) => void;
package/cjs/BrtcClient.js CHANGED
@@ -1 +1 @@
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,h=f.onLocalVideoPublishing,v=f.onRemoteVideoOn,p=f.onRemoteVideoOff,R=f.onRemoteVideoLoading,L=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}})}))}}!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(v)&&v(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(h)&&h()},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(R)&&R(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(L)&&L()},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;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("./_virtual/_rollupPluginBabelHelpers.js"),e=require("@bddh/starling-brtc"),o=require("@bddh/starling-timeout-controller"),n=require("@bddh/starling-json"),i=require("lodash/isEmpty"),c=require("lodash/isFunction"),r=require("./interface.js"),a=function(){function a(l){var s=this;t.classCallCheck(this,a),t.defineProperty(this,"client",void 0),t.defineProperty(this,"isRtcVideoOn",!1),t.defineProperty(this,"rtcConnection",void 0),t.defineProperty(this,"rtcConfig",void 0),t.defineProperty(this,"bizConfig",void 0),t.defineProperty(this,"rtcCallback",void 0),t.defineProperty(this,"restarting",!1),t.defineProperty(this,"timeoutEvent",void 0),t.defineProperty(this,"timeoutStarted",!1),t.defineProperty(this,"reopenTimer",void 0),t.defineProperty(this,"restartCount",0),t.defineProperty(this,"closeLog",!0),t.defineProperty(this,"stopped",!1),t.defineProperty(this,"haveVideoOn",!1),t.defineProperty(this,"rtcStateCallback",null),t.defineProperty(this,"startRtcTimeout",(function(){s.timeoutStarted||(s.timeoutEvent.start(),s.timeoutStarted=!0)})),t.defineProperty(this,"clearRtcTimeout",(function(){s.timeoutStarted&&(s.timeoutEvent.clear(),s.timeoutStarted=!1)})),t.defineProperty(this,"mergeRtcConfig",(function(t){s.rtcConfig&&t&&Object.keys(t).length&&Object.assign(s.rtcConfig,t)})),t.defineProperty(this,"openRtc",(function(t){if(s.stopped=!1,s.restarting)!s.closeLog&&console.warn("rtc restarting");else if(t&&(s.rtcConnection=t),s.rtcConnection&&!i(s.rtcConnection)){var o,a=s.rtcConnection,l=a.server,d=a.appId,u=a.token,f=a.roomName,m=a.userId,C=s.rtcCallback||{},b=C.onRemotedata,g=C.onLocalStream,p=C.onRemoteVideoComing,y=C.onLocalVideoPublished,h=C.onLocalVideoPublishing,v=C.onRemoteVideoOn,R=C.onRemoteVideoOff,S=C.onRemoteVideoLoading,L=C.onSuccess,k=C.onError,P=C.onLocalVideoConnected,E=C.onRemoteVideoConnected,V=C.onRemoteMediaState,T=C.onPlayingError,O=C.onDigitalHumanCallback;null===(o=s.client)||void 0===o||o.destroy(),s.client=void 0,s.startRtcTimeout(),s.rtcStateCallback=function(t){var e=t.body,o=t.action;O&&O({status:r.statusEnum.DH_LIB_FULL_STATUS,content:{type:"rtcState",action:o,body:e}})},s.client=new e({roomName:f,token:u,userId:m,appId:d,server:l,rtcConfig:s.rtcConfig,callback:{onRemoteVideoConnected:function(e,o){var n;if(!o&&!s.haveVideoOn)var i=setTimeout((function(){s.restartCount<3?(s.restartCount=++s.restartCount,s.restartRtc&&s.restartRtc(t)):(s.restartCount=0,s.closeRtc()),clearTimeout(i)}),500);if(o&&!1!==(null===(n=s.bizConfig)||void 0===n?void 0:n.remoteAutoPlay)){var a=document.getElementById("remotevideo500");if(a){a.muted=!1;var l=a.play();void 0!==l&&l.catch((function(){a.muted=!0,a.play().catch((function(t){!s.closeLog&&console.info("videoElement play error",t),T&&T(a),O&&O({status:r.statusEnum.DH_LIB_ERROR,content:{type:r.errorTypeEnum.LOCAL_VIDEO_ERROR}})})),O&&O({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",e,o,s.restartCount),s.rtcStateCallback&&s.rtcStateCallback({action:"remoteVideoConnected",body:{id:e,connected:o,restartCount:s.restartCount}}),c(E)&&E(e,o)},onRemoteVideoOn:function(t){s.haveVideoOn=!0,!s.closeLog&&console.info("remotevideoon by id: ",t),s.clearRtcTimeout();var e=document.querySelector("#starlingRtcContainer"),o=e&&e.lastChild;o&&(o.style.display="none"),s.rtcStateCallback&&s.rtcStateCallback({action:"remotevideoon",body:t}),O&&O({status:r.statusEnum.DH_LIB_OPEN}),c(v)&&v(t)},onRemoteMediaState:function(t,e,o){!s.closeLog&&console.info("remoteMediaState",t,e,o),s.rtcStateCallback&&s.rtcStateCallback({action:"remoteMediaState",body:{id:t,medium:e,connected:o}}),c(V)&&V(t,e,o)},onLocalVideoConnected:function(t){!s.closeLog&&console.info("localVideoConnected",t),s.rtcStateCallback&&s.rtcStateCallback({action:"localVideoConnected",body:{connected:t}}),c(P)&&P(t)},onRemotedata:function(t){if(s.rtcConfig&&s.rtcConfig.usingdatachannel){var e=n.parse(t);!s.closeLog&&console.info("RTC - receive:",e),c(b)&&b(e)}},onLocalStream:function(t,e){!s.closeLog&&console.info("rtc - onlocalstream by name: "+e),s.rtcStateCallback&&s.rtcStateCallback({action:"onlocalstream",body:{stream:t,name:e}}),c(g)&&g(t,e)},onLocalVideoPublished:function(){!s.closeLog&&console.info("LocalVideoPublished 本地视频发布成功"),s.rtcStateCallback&&s.rtcStateCallback({action:"localvideopublished_ok",body:!0}),c(y)&&y()},onLocalVideoPublishing:function(){!s.closeLog&&console.info("LocalVideoPublishing 本地视频发布成功"),s.rtcStateCallback&&s.rtcStateCallback({action:"localvideopublishing",body:!0}),c(h)&&h()},onRemoteVideoComing:function(t){!s.closeLog&&console.info("remotevideocoming",t),s.rtcStateCallback&&s.rtcStateCallback({action:"remotevideocoming",body:t}),c(p)&&p(t)},onRemoteVideoLoading:function(t){!s.closeLog&&console.info("remotevideoloading by id: ",t),s.rtcStateCallback&&s.rtcStateCallback({action:"remotevideoloading",body:t}),c(S)&&S(t)},onRemoteVideoOff:function(t){if(!s.stopped){var e=document.getElementById("remotevideo500");e&&e.pause(),!s.closeLog&&console.info("remotevideooff: ",t),s.isRtcVideoOn=!1,s.rtcStateCallback&&s.rtcStateCallback({action:"remotevideooff",body:t}),O&&O({status:r.statusEnum.DH_LIB_CLOSE}),c(R)&&R(t),s.startRtcTimeout()}},onSuccess:function(){!s.closeLog&&console.info("rtc - success"),s.rtcStateCallback&&s.rtcStateCallback({action:"success",body:!0}),c(L)&&L()},onError:function(e){s.stopped||(s.isRtcVideoOn=!1,!s.closeLog&&console.error("rtc - error:",e),s.rtcStateCallback&&s.rtcStateCallback({action:"error",body:e}),O&&O({status:r.statusEnum.DH_LIB_ERROR,content:{type:r.errorTypeEnum.RTC_ERROR}}),c(k)&&k(e),(e.includes("Lost connection to the server")||e.includes("Is the server down"))&&s.restartRtc&&s.restartRtc(t))}}})}})),t.defineProperty(this,"closeRtc",(function(){var t;s.stopped=!0,s.clearRtcTimeout(),clearTimeout(s.reopenTimer),null===(t=s.client)||void 0===t||t.destroy(),s.client=void 0,s.restarting=!1})),t.defineProperty(this,"restartRtc",(function(t){s.stopped||!s.restarting&&s.bizConfig&&s.bizConfig.autoReConnect&&(s.rtcStateCallback&&s.rtcStateCallback({action:"restartRtc",body:t}),s.restarting=!0,s.closeRtc(),s.reopenTimer=setTimeout((function(){!s.closeLog&&console.error("拉流失败,开始重启"),s.restarting=!1,s.openRtc(t)}),2e3))}));var d=l.rtcConnection,u=l.rtcConfig,f=l.closeLog,m=void 0===f||f,C=l.rtcCallback,b=l.bizConfig;this.rtcConnection=d,this.rtcConfig=u,this.rtcCallback=C,this.closeLog=m,this.bizConfig=b,this.timeoutEvent=new o.TimeoutController(6e4,(function(){if(s.timeoutStarted=!1,!s.stopped)return s.rtcConnection?void(s.restartRtc&&s.restartRtc(s.rtcConnection)):!s.closeLog&&console.warn("remotevideoon事件超时, rtcConnectionRef is null")}))}return t.createClass(a,[{key:"muteMicphone",value:function(t){this.client&&this.client.muteMicphone&&this.client.muteMicphone(t)}}]),a}();exports.default=a;
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 } from './interface';
6
+ import { DhRealtimeHumanType, ConnectDataType, CallbackMsgType, EffectsType } from './interface';
7
7
  import { DHServerInterface, RenderCallback } from './Server';
8
8
  export default class DhRealtimeHuman {
9
9
  private token;
@@ -15,18 +15,31 @@ export default class DhRealtimeHuman {
15
15
  private rtcServer?;
16
16
  private rtcConnectParams;
17
17
  private cutoutInstance?;
18
+ private hasInitChromaEffects;
18
19
  private readonly isHuawei;
19
20
  private rtcServerUrl;
21
+ private rtcInternalIp;
20
22
  private recordController;
21
23
  private wsReadyState;
22
24
  private readonly isPreOpenSession;
25
+ private readonly openWsOnly;
26
+ private hasConnectUserFigureEffects;
27
+ private _isMicMuted;
28
+ private mergeConnectRtcExtras;
29
+ private emitRawStatusMessage;
30
+ private resolveMediaServerByDomain?;
23
31
  constructor(props: DhRealtimeHumanType);
32
+ canShowStaticFrameCover(): boolean;
24
33
  init(props: DhRealtimeHumanType): void;
25
34
  onDigitalHumanCallbackPlus: (data: CallbackMsgType) => void;
26
35
  onRemoteVideoComing: (id: number) => void;
27
36
  onLocalStream: () => void;
28
37
  onRemoteVideoOn: () => void;
38
+ onRemoteVideoOffLastFrame: () => void;
29
39
  connectListener: (data: ConnectDataType) => void;
40
+ handleConnectResponse(data: ConnectDataType): Promise<void>;
41
+ mergeConnectRtcExtrasFromBody(body: Record<string, any>): Promise<void>;
42
+ applyConnectChroma(effects: EffectsType): Promise<void>;
30
43
  createServer: (sessionId?: string) => void;
31
44
  checkHumanInstansce: () => boolean;
32
45
  sendMessage: (message: DHServerInterface | ArrayBuffer, listener: RenderCallback | null) => Promise<void> | null;
package/cjs/Client.js CHANGED
@@ -1 +1 @@
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.closeSocket();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;
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;
package/cjs/Cutout.d.ts CHANGED
@@ -7,8 +7,8 @@ import { ChromaEffectOptions } from '@bddh/starling-cutout/es/interface';
7
7
  import Seriously from '@bddh/starling-cutout/es/Seriously';
8
8
  interface CutoutType {
9
9
  effects?: {
10
- version: number;
11
- chromaKey: Partial<ChromaEffectOptions>;
10
+ version?: number;
11
+ chromaKey?: Partial<ChromaEffectOptions>;
12
12
  };
13
13
  sourceId: string;
14
14
  }
@@ -14,7 +14,15 @@ 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";
17
19
  export declare function createHumanDom(options: CreateVideoDomOptions): CreateVideoDomResult | null;
20
+ export declare function ensureCutoutDomMounted(): boolean;
21
+ export declare function appendLastFrameCoverSibling(mountEl: HTMLElement | null): void;
22
+ export declare function captureLastFrameToCover(): boolean;
23
+ export declare function setHumanPlayerWrapperVisible(visible: boolean): void;
24
+ export declare function setLastFrameCoverVisible(visible: boolean): void;
25
+ export declare function removeLastFrameCoverWrapper(): void;
18
26
  export declare function removeHumanDom(): void;
19
27
  export declare function muteHumanVideo(muted: boolean): HTMLVideoElement;
20
28
  export declare function playHumanVideo(play: boolean): void | Promise<void>;
package/cjs/DomControl.js CHANGED
@@ -1 +1 @@
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)};
1
+ "use strict";var e="starling-cutout-canvas",t="cloud-brtc-player-wrapper",n="remotevideo500",i="canvas-item",o="starling-last-frame-cover-canvas",r="data-dh-last-frame-cover";exports.DEFAULT_CANVAS_ID=e,exports.HUMAN_WRAPPER_ID=t,exports.LAST_FRAME_COVER_CANVAS_CLASS=i,exports.LAST_FRAME_COVER_INNER_CANVAS_ID=o,exports.RTC_VIDEO_ID=n,exports.appendLastFrameCoverSibling=function(e){if(e&&!e.querySelector("[".concat(r,'="1"]'))){var t=document.createElement("div");t.className="".concat(i," "),t.setAttribute(r,"1");var n=document.createElement("canvas");n.id=o,Object.assign(n.style,{position:"absolute",top:"0",left:"0",width:"100%",height:"100%",objectFit:"cover",display:"block",zIndex:"0"}),t.appendChild(n),e.appendChild(t)}},exports.appendRtcDomStyle=function(){var e=document.createElement("style");e.appendChild(document.createTextNode('\n [id^="videoremote1-"] {\n display: none !important;\n }\n \n video#remotevideo500 {\n width: auto !important;\n height: auto !important;\n max-width: 100% !important;\n max-height: 100% !important;\n width: 100% !important;\n height: 100% !important;\n object-fit: cover;\n }\n\n .cloud-brtc-player-wrapper {\n width: inherit !important;\n background-size: cover;\n height: inherit;\n display: flex;\n justify-content: center;\n }\n\n #starling-cutout-canvas {\n object-fit: cover;\n }\n\n [data-dh-last-frame-cover="1"] {\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n pointer-events: none;\n z-index: 1;\n visibility: hidden;\n }\n\n [data-dh-last-frame-cover="1"] canvas {\n width: 100%;\n height: 100%;\n object-fit: cover;\n display: block;\n }\n ')),document.head.appendChild(e)},exports.captureLastFrameToCover=function(){var t=document.getElementById(o);if(!t)return!1;var i=t.getContext("2d");if(!i)return!1;var r=document.getElementById(e),a=document.getElementById(n);return r&&r.width>0&&r.height>0?(t.width=r.width,t.height=r.height,i.drawImage(r,0,0),!0):!!(a&&a.videoWidth>0&&a.videoHeight>0)&&(t.width=a.videoWidth,t.height=a.videoHeight,i.drawImage(a,0,0,a.videoWidth,a.videoHeight),!0)},exports.checkIsHuawei=function(){var e=navigator.userAgent||navigator.vendor;return/huawei/i.test(e)||/honor/i.test(e)},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 s=document.createElement("div");s.className=t,s.id=t,s.style.position="relative";var l=document.createElement("video");if(l.id=n,l.width=0,l.height=0,l.setAttribute("width","100%"),l.setAttribute("height","100%"),l.setAttribute("data-playing","true"),l.setAttribute("playsinline",""),d&&l.setAttribute("autoplay",""),s.appendChild(l),r){var c=document.createElement("canvas");c.id=e,Object.assign(c.style,{position:"absolute",top:"0",left:"0",height:"100%",width:"100%",zIndex:"1",display:r?"block":"none"}),l.style.visibility="hidden",s.appendChild(c)}return{playerWrapper:s,video:l}},exports.ensureCutoutDomMounted=function(){if(document.getElementById(e))return!0;var i=document.getElementById(t),o=document.getElementById(n);if(!i||!o)return!1;var r=document.createElement("canvas");return r.id=e,Object.assign(r.style,{position:"absolute",top:"0",left:"0",height:"100%",width:"100%",zIndex:"1",display:"block"}),o.style.visibility="hidden",i.appendChild(r),!0},exports.muteHumanVideo=function(e){var t=document.getElementById(n);return t&&(t.muted=e),t},exports.playHumanVideo=function(e){var t=document.getElementById(n);try{if(t)return e?t.play():t.pause()}catch(e){console.info(e)}},exports.removeHumanDom=function(){var e=document.getElementById(t);e&&e.parentNode&&e.parentNode.removeChild(e)},exports.removeLastFrameCoverWrapper=function(){var e=document.querySelector("[".concat(r,'="1"]'));null!=e&&e.parentNode&&e.parentNode.removeChild(e)},exports.setHumanPlayerWrapperVisible=function(e){var n=document.getElementById(t);n&&(n.style.visibility=e?"visible":"hidden",n.style.pointerEvents=e?"":"none")},exports.setLastFrameCoverVisible=function(e){var t=document.getElementById(o),n=null==t?void 0:t.parentNode;n&&(n.style.visibility=e?"visible":"hidden")};
package/cjs/Server.d.ts CHANGED
@@ -42,7 +42,12 @@ export interface RenderCallbackRes {
42
42
  body: string | null;
43
43
  message: string;
44
44
  }
45
+ interface ServerOptions {
46
+ checkHeartbeatMismatch?: boolean;
47
+ emitRawStatusMessage?: boolean;
48
+ }
45
49
  export type RenderCallback = (res: RenderCallbackRes) => void;
50
+ export declare const CONNECTING_STUCK_MS_DEFAULT: number;
46
51
  declare class Server {
47
52
  dhServerSocket: WebSocketClient | null;
48
53
  preConnectSuccess: boolean;
@@ -50,11 +55,24 @@ declare class Server {
50
55
  private socketClosingPromise;
51
56
  private readonly url;
52
57
  private firstConnect;
53
- constructor(url: string);
58
+ private connectingTimer;
59
+ private readonly connectingMs;
60
+ private lastPreOpen;
61
+ private reconnectingTimeout;
62
+ private lastReportedReadyState;
63
+ private lastHbAckTs;
64
+ private readonly checkHeartbeatMismatch;
65
+ private emitRawStatusMessage;
66
+ constructor(url: string, options?: ServerOptions);
67
+ setEmitRawStatusMessage(value: boolean): void;
54
68
  sendPreConnect: (props: createSocketParamsType, resolve?: ((value: any) => void) | undefined) => void;
55
69
  createSocket: (props: createSocketParamsType, isPreOpenSession?: boolean) => Promise<WebSocketClient | null>;
70
+ sendConnect: (props: createSocketParamsType) => void;
56
71
  closeSocket: () => Promise<void>;
57
72
  handleConnect: () => Promise<void>;
58
73
  sendMessage(message: DHServerInterface | ArrayBuffer, listener: RenderCallback | null): Promise<void>;
74
+ private startConnectingWatch;
75
+ private clearConnectingWatch;
76
+ private resetState;
59
77
  }
60
78
  export default Server;
package/cjs/Server.js CHANGED
@@ -1 +1 @@
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("lodash/pick"),o=require("lodash/omit"),s=require("lodash/get"),c=require("./interface.js"),a=function(a){function i(a){var u,d=this;e.classCallCheck(this,i),e.defineProperty(this,"dhServerSocket",null),e.defineProperty(this,"preConnectSuccess",!1),e.defineProperty(this,"connectParams",null),e.defineProperty(this,"socketClosingPromise",null),e.defineProperty(this,"url",void 0),e.defineProperty(this,"firstConnect",!0),e.defineProperty(this,"sendPreConnect",(function(e,t){var n,o=e.token,s=e.sessionId,c=e.onConnect;null===(n=d.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(),d.handleConnect()),null==t||t(d.dhServerSocket)})),d.firstConnect=!1})),e.defineProperty(this,"createSocket",(function(r,n){return(u=u||e.asyncToGenerator(e.regeneratorRuntime().mark((function r(n,o){var a,i;return e.regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(d.connectParams=n,a=n.sessionId,i=n.onDigitalHumanCallback,!d.socketClosingPromise){e.next=5;break}return e.next=5,d.socketClosingPromise;case 5:if(!d.dhServerSocket){e.next=8;break}return e.next=8,d.closeSocket();case 8:return e.abrupt("return",new Promise((function(e,r){var u={keepAlive:"heartbeat",reopen:s(d.connectParams,"reConnect",!0),combine:function(e,r){return e&&r&&e.requestId===r.requestId},onOpen:function(){d.dhServerSocket=p,a&&d.firstConnect?d.sendPreConnect(n,e):o&&d.firstConnect||d.handleConnect()},onClose:function(){d.dhServerSocket=null,d.socketClosingPromise=null},onError:function(e){r(e)}},p=t.createWebSocket(d.url,u);p.onReadyStateChange((function(e){0===e&&i&&i({status:c.statusEnum.DH_LIB_INIT}),1===e&&o&&(d.preConnectSuccess=!0),3===e&&(d.preConnectSuccess=!1),i&&i({status:c.statusEnum.DH_LIB_FULL_STATUS,content:{type:"wsState",readyState:e,body:c.WS_STATUS_MAP[e]}})})),p.onMessage((function(e){var r=e.action;[c.errorTypeEnum.TIMEOUT_EXIT,c.errorTypeEnum.DISCONNECT_ALERT].includes(r)&&i&&i({status:c.statusEnum.DH_LIB_STATUS,content:{type:r}}),[c.errorTypeEnum.TIMEOUT_EXIT,c.errorTypeEnum.DISCONNECT_ALERT,"HEART_BEAT","CONNECT"].includes(r)||i&&i({status:c.statusEnum.DH_LIB_MESSAGE,content:e})})),o&&(d.dhServerSocket=p),p.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(d.dhServerSocket){e.next=2;break}return e.abrupt("return");case 2:return d.socketClosingPromise=d.dhServerSocket.close(),e.next=5,d.socketClosingPromise;case 5:d.dhServerSocket=null;case 6:case"end":return e.stop()}}),r)})))),e.defineProperty(this,"handleConnect",e.asyncToGenerator(e.regeneratorRuntime().mark((function t(){var s,a,i,u,p,l;return e.regeneratorRuntime().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(d.connectParams){t.next=2;break}return t.abrupt("return");case 2:if(s=d.connectParams,a=s.appId,i=s.appKey,u=s.token,p=s.parameters,l=s.onConnect,a||i||u){t.next=5;break}return t.abrupt("return");case 5:d.dhServerSocket&&d.dhServerSocket.request({action:"CONNECT",clientTs:(new Date).getTime(),requestId:r.v4(),body:JSON.stringify(e.objectSpread2(e.objectSpread2({token:u,appId:a,appKey:i},n(d.connectParams,c.CONNECT_MAIN_KEY)),{},{parameters:e.objectSpread2(e.objectSpread2({},o(p,["parameters"])),p&&p.parameters?p.parameters:{})}))}).on((function(e,r){null==l||l(e),0!==e.code&&r()}));case 6:case"end":return t.stop()}}),t)})))),this.url=a}return e.createClass(i,[{key:"sendMessage",value:function(t,n){return(a=a||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)}}]),i}();exports.default=a;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./_virtual/_rollupPluginBabelHelpers.js"),t=require("uuid"),n=require("@bddh/starling-web-socket/es/create-web-socket"),r=require("lodash/pick"),o=require("lodash/omit"),s=require("lodash/get"),c=require("./interface.js"),a=function(a){function i(a,u){var d,l=this;e.classCallCheck(this,i),e.defineProperty(this,"dhServerSocket",null),e.defineProperty(this,"preConnectSuccess",!1),e.defineProperty(this,"connectParams",null),e.defineProperty(this,"socketClosingPromise",null),e.defineProperty(this,"url",void 0),e.defineProperty(this,"firstConnect",!0),e.defineProperty(this,"connectingTimer",null),e.defineProperty(this,"connectingMs",3e4),e.defineProperty(this,"lastPreOpen",!1),e.defineProperty(this,"reconnectingTimeout",!1),e.defineProperty(this,"lastReportedReadyState",-1),e.defineProperty(this,"lastHbAckTs",0),e.defineProperty(this,"checkHeartbeatMismatch",void 0),e.defineProperty(this,"emitRawStatusMessage",void 0),e.defineProperty(this,"sendPreConnect",(function(e,n){var r,o=e.token,s=e.sessionId,c=e.onConnect;null===(r=l.dhServerSocket)||void 0===r||r.request({action:"RE_CONNECT",requestId:t.v4(),body:JSON.stringify({token:o,sessionId:s})}).on((function(e,t){null==c||c(e),0!==e.code&&(t(),l.handleConnect()),null==n||n(l.dhServerSocket)})),l.firstConnect=!1})),e.defineProperty(this,"createSocket",(function(t,r){return(d=d||e.asyncToGenerator(e.regeneratorRuntime().mark((function t(r,o){var a,i;return e.regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(l.connectParams=r,l.lastPreOpen=!!o,a=r.sessionId,i=r.onDigitalHumanCallback,!l.socketClosingPromise){e.next=6;break}return e.next=6,l.socketClosingPromise;case 6:if(!l.dhServerSocket){e.next=9;break}return e.next=9,l.closeSocket();case 9:return e.abrupt("return",new Promise((function(e,t){var u=!1,d=function(t){u||(u=!0,e(t))},h={keepAlive:"heartbeat",checkHeartbeatMismatch:l.checkHeartbeatMismatch,reopen:s(l.connectParams,"reConnect",!0),getKeepAliveMessage:function(e){return{requestId:e,action:"HEART_BEAT",body:"".concat(l.lastHbAckTs),clientTs:Date.now()}},combine:function(e,t){return e&&t&&e.requestId===t.requestId},onOpen:function(){l.dhServerSocket=p,d(l.dhServerSocket),a&&l.firstConnect?l.sendPreConnect(r,d):o&&l.firstConnect||l.handleConnect()},onClose:function(){l.dhServerSocket=null,l.socketClosingPromise=null,d(null)},onError:function(e){t(e)}},p=n.createWebSocket(l.url,h);p.onReadyStateChange((function(e){l.lastReportedReadyState=e,0===e?(l.startConnectingWatch(),i&&i({status:c.statusEnum.DH_LIB_INIT})):(l.clearConnectingWatch(),l.reconnectingTimeout=!1),1===e&&o&&(l.preConnectSuccess=!0),3===e&&(l.preConnectSuccess=!1),i&&i({status:c.statusEnum.DH_LIB_FULL_STATUS,content:{type:"wsState",readyState:e,body:c.WS_STATUS_MAP[e]}})})),p.onMessage((function(e){var t=e.action;"HEART_BEAT"===t&&(l.lastHbAckTs=Date.now()),[c.errorTypeEnum.TIMEOUT_EXIT,c.errorTypeEnum.DISCONNECT_ALERT].includes(t)&&(i&&i({status:c.statusEnum.DH_LIB_STATUS,content:{type:t}}),l.emitRawStatusMessage&&i&&i({status:c.statusEnum.DH_LIB_MESSAGE,content:e})),[c.errorTypeEnum.TIMEOUT_EXIT,c.errorTypeEnum.DISCONNECT_ALERT,"HEART_BEAT","CONNECT"].includes(t)||i&&i({status:c.statusEnum.DH_LIB_MESSAGE,content:e})})),l.dhServerSocket=p,p.open()})));case 10:case"end":return e.stop()}}),t)})))).apply(this,arguments)})),e.defineProperty(this,"sendConnect",(function(e){l.connectParams=e,l.dhServerSocket&&l.handleConnect()})),e.defineProperty(this,"closeSocket",e.asyncToGenerator(e.regeneratorRuntime().mark((function t(){return e.regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(l.resetState(),l.dhServerSocket){e.next=3;break}return e.abrupt("return");case 3:return l.socketClosingPromise=l.dhServerSocket.close(),e.next=6,l.socketClosingPromise;case 6:l.dhServerSocket=null;case 7:case"end":return e.stop()}}),t)})))),e.defineProperty(this,"handleConnect",e.asyncToGenerator(e.regeneratorRuntime().mark((function n(){var s,a,i,u,d,h;return e.regeneratorRuntime().wrap((function(n){for(;;)switch(n.prev=n.next){case 0:if(l.connectParams){n.next=2;break}return n.abrupt("return");case 2:if(s=l.connectParams,a=s.appId,i=s.appKey,u=s.token,d=s.parameters,h=s.onConnect,a||i||u){n.next=5;break}return n.abrupt("return");case 5:l.dhServerSocket&&l.dhServerSocket.request({action:"CONNECT",clientTs:(new Date).getTime(),requestId:t.v4(),body:JSON.stringify(e.objectSpread2(e.objectSpread2({token:u,appId:a,appKey:i},r(l.connectParams,c.CONNECT_MAIN_KEY)),{},{parameters:e.objectSpread2(e.objectSpread2({},o(d,["parameters"])),d&&d.parameters?d.parameters:{})}))}).on((function(e,t){null==h||h(e),0!==e.code&&t()}));case 6:case"end":return n.stop()}}),n)}))));var h=u||{},p=h.checkHeartbeatMismatch,S=h.emitRawStatusMessage,m=void 0!==S&&S;this.url=a,this.checkHeartbeatMismatch=null!=p&&p,this.emitRawStatusMessage=m}return e.createClass(i,[{key:"setEmitRawStatusMessage",value:function(e){this.emitRawStatusMessage=e}},{key:"sendMessage",value:function(n,r){return(a=a||e.asyncToGenerator(e.regeneratorRuntime().mark((function n(r,o){var s;return e.regeneratorRuntime().wrap((function(n){for(;;)switch(n.prev=n.next){case 0:try{this.dhServerSocket&&this.dhServerSocket&&this.dhServerSocket.request(r).on((function(e){o&&o(e)}))}catch(n){s="object"===e.typeof(r)&&"requestId"in r?r.requestId:t.v4(),o&&o({code:-11,body:null,action:"RENDER_ERROR",requestId:s,message:JSON.stringify(n)})}case 1:case"end":return n.stop()}}),n,this)})))).apply(this,arguments)}},{key:"startConnectingWatch",value:function(){var t=this;this.connectingTimer||this.reconnectingTimeout||(this.connectingTimer=setTimeout(e.asyncToGenerator(e.regeneratorRuntime().mark((function n(){return e.regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t.connectingTimer=null,t.dhServerSocket&&0===t.lastReportedReadyState){e.next=3;break}return e.abrupt("return");case 3:if(console.warn("reconnect from CONNECTING timeout"),t.reconnectingTimeout=!0,e.prev=5,!t.connectParams){e.next=9;break}return e.next=9,t.createSocket(t.connectParams,t.lastPreOpen);case 9:e.next=14;break;case 11:e.prev=11,e.t0=e.catch(5),console.error("reconnect from CONNECTING timeout failed",e.t0);case 14:return e.prev=14,t.reconnectingTimeout=!1,e.finish(14);case 17:case"end":return e.stop()}}),n,null,[[5,11,14,17]])}))),this.connectingMs))}},{key:"clearConnectingWatch",value:function(){this.connectingTimer&&(clearTimeout(this.connectingTimer),this.connectingTimer=null)}},{key:"resetState",value:function(){this.clearConnectingWatch(),this.reconnectingTimeout=!1,this.lastReportedReadyState=-1,this.lastHbAckTs=0}}]),i}();exports.CONNECTING_STUCK_MS_DEFAULT=3e4,exports.default=a;
@@ -1,3 +1,4 @@
1
+ import { ChromaEffectOptions } from '@bddh/starling-cutout/es/interface';
1
2
  import { RtcConnectionType } from './BrtcClient';
2
3
  export interface ConnectDataType {
3
4
  action: string;
@@ -56,7 +57,10 @@ export interface ConnectParamsType {
56
57
  enabled: boolean;
57
58
  };
58
59
  enableInterrupt?: boolean;
59
- asrVadPauseTime?: Number;
60
+ asrVadPauseTime?: number;
61
+ positionV2?: string;
62
+ ttsModel?: string;
63
+ autoAnimoji?: boolean;
60
64
  }
61
65
  export declare const CONNECT_MAIN_KEY: string[];
62
66
  export interface RenderParamsType {
@@ -116,7 +120,9 @@ export interface CallbackMsgType {
116
120
  export interface DhRealtimeHumanType {
117
121
  token?: string;
118
122
  wsUrl?: string;
123
+ checkHeartbeatMismatch?: boolean;
119
124
  rtcServerUrl?: string;
125
+ rtcInternalIp?: string;
120
126
  appKey?: string;
121
127
  appId?: string;
122
128
  wrapperId?: string;
@@ -124,7 +130,16 @@ export interface DhRealtimeHumanType {
124
130
  renderParams?: RenderParamsType;
125
131
  rtcConnectParams?: RtcConnectionType;
126
132
  brtcParams?: any;
133
+ remoteAutoPlay?: boolean;
134
+ mergeConnectRtcExtras?: boolean;
135
+ emitRawStatusMessage?: boolean;
136
+ resolveMediaServerByDomain?: (domain: string) => Promise<string>;
127
137
  isPreOpenSession?: boolean;
138
+ isOpenWsOnly?: boolean;
128
139
  onDigitalHumanCallback: (data: CallbackMsgType) => void;
129
140
  }
141
+ export interface EffectsType {
142
+ chromaKey?: Partial<ChromaEffectOptions>;
143
+ version?: number;
144
+ }
130
145
  export {};
@@ -46,6 +46,7 @@ export interface BizConfig {
46
46
  welcomeContent?: string;
47
47
  autoChromaKey?: boolean;
48
48
  chromaEffects?: ChromaEffectOptions;
49
+ remoteAutoPlay?: boolean;
49
50
  }
50
51
  export interface RtcCallback {
51
52
  [x: string]: any;
@@ -83,12 +84,17 @@ declare class BrtcClient {
83
84
  private readonly rtcCallback?;
84
85
  private restarting;
85
86
  private readonly timeoutEvent;
87
+ private timeoutStarted;
86
88
  private reopenTimer;
87
89
  private restartCount;
88
90
  private readonly closeLog;
91
+ private stopped;
89
92
  private haveVideoOn;
90
93
  private rtcStateCallback;
91
94
  constructor(props: BrtcClientType);
95
+ private startRtcTimeout;
96
+ private clearRtcTimeout;
97
+ mergeRtcConfig: (partial: Record<string, unknown>) => void;
92
98
  openRtc: (rtcConnection: RtcConnectionType) => void;
93
99
  closeRtc: () => void;
94
100
  restartRtc: (rtcConnection: RtcConnectionType) => void;
package/es/BrtcClient.js CHANGED
@@ -1 +1 @@
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,R=f.onLocalVideoPublishing,L=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}})}))}}!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(L)&&L(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(R)&&R()},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};
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,"timeoutStarted",!1),e(this,"reopenTimer",void 0),e(this,"restartCount",0),e(this,"closeLog",!0),e(this,"stopped",!1),e(this,"haveVideoOn",!1),e(this,"rtcStateCallback",null),e(this,"startRtcTimeout",(function(){u.timeoutStarted||(u.timeoutEvent.start(),u.timeoutStarted=!0)})),e(this,"clearRtcTimeout",(function(){u.timeoutStarted&&(u.timeoutEvent.clear(),u.timeoutStarted=!1)})),e(this,"mergeRtcConfig",(function(t){u.rtcConfig&&t&&Object.keys(t).length&&Object.assign(u.rtcConfig,t)})),e(this,"openRtc",(function(t){if(u.stopped=!1,u.restarting)!u.closeLog&&console.warn("rtc restarting");else if(t&&(u.rtcConnection=t),u.rtcConnection&&!a(u.rtcConnection)){var o,e=u.rtcConnection,c=e.server,d=e.appId,m=e.token,C=e.roomName,f=e.userId,b=u.rtcCallback||{},g=b.onRemotedata,h=b.onLocalStream,v=b.onRemoteVideoComing,R=b.onLocalVideoPublished,p=b.onLocalVideoPublishing,S=b.onRemoteVideoOn,L=b.onRemoteVideoOff,k=b.onRemoteVideoLoading,y=b.onSuccess,V=b.onError,O=b.onLocalVideoConnected,E=b.onRemoteVideoConnected,_=b.onRemoteMediaState,T=b.onPlayingError,I=b.onDigitalHumanCallback;null===(o=u.client)||void 0===o||o.destroy(),u.client=void 0,u.startRtcTimeout(),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:C,token:m,userId:f,appId:d,server:c,rtcConfig:u.rtcConfig,callback:{onRemoteVideoConnected:function(o,e){var n;if(!e&&!u.haveVideoOn)var c=setTimeout((function(){u.restartCount<3?(u.restartCount=++u.restartCount,u.restartRtc&&u.restartRtc(t)):(u.restartCount=0,u.closeRtc()),clearTimeout(c)}),500);if(e&&!1!==(null===(n=u.bizConfig)||void 0===n?void 0:n.remoteAutoPlay)){var i=document.getElementById("remotevideo500");if(i){i.muted=!1;var a=i.play();void 0!==a&&a.catch((function(){i.muted=!0,i.play().catch((function(t){!u.closeLog&&console.info("videoElement play error",t),T&&T(i),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.clearRtcTimeout();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(S)&&S(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(O)&&O(t)},onRemotedata:function(t){if(u.rtcConfig&&u.rtcConfig.usingdatachannel){var o=i.parse(t);!u.closeLog&&console.info("RTC - receive:",o),r(g)&&g(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(h)&&h(t,o)},onLocalVideoPublished:function(){!u.closeLog&&console.info("LocalVideoPublished 本地视频发布成功"),u.rtcStateCallback&&u.rtcStateCallback({action:"localvideopublished_ok",body:!0}),r(R)&&R()},onLocalVideoPublishing:function(){!u.closeLog&&console.info("LocalVideoPublishing 本地视频发布成功"),u.rtcStateCallback&&u.rtcStateCallback({action:"localvideopublishing",body:!0}),r(p)&&p()},onRemoteVideoComing:function(t){!u.closeLog&&console.info("remotevideocoming",t),u.rtcStateCallback&&u.rtcStateCallback({action:"remotevideocoming",body:t}),r(v)&&v(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){if(!u.stopped){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(L)&&L(t),u.startRtcTimeout()}},onSuccess:function(){!u.closeLog&&console.info("rtc - success"),u.rtcStateCallback&&u.rtcStateCallback({action:"success",body:!0}),r(y)&&y()},onError:function(o){u.stopped||(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(V)&&V(o),(o.includes("Lost connection to the server")||o.includes("Is the server down"))&&u.restartRtc&&u.restartRtc(t))}}})}})),e(this,"closeRtc",(function(){var t;u.stopped=!0,u.clearRtcTimeout(),clearTimeout(u.reopenTimer),null===(t=u.client)||void 0===t||t.destroy(),u.client=void 0,u.restarting=!1})),e(this,"restartRtc",(function(t){u.stopped||!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,h=t.bizConfig;this.rtcConnection=m,this.rtcConfig=C,this.rtcCallback=g,this.closeLog=b,this.bizConfig=h,this.timeoutEvent=new c(6e4,(function(){if(u.timeoutStarted=!1,!u.stopped)return u.rtcConnection?void(u.restartRtc&&u.restartRtc(u.rtcConnection)):!u.closeLog&&console.warn("remotevideoon事件超时, rtcConnectionRef is null")}))}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
@@ -3,7 +3,7 @@
3
3
  * @description 云渲染数字人sdk
4
4
  * @author zhangyue49
5
5
  */
6
- import { DhRealtimeHumanType, ConnectDataType, CallbackMsgType } from './interface';
6
+ import { DhRealtimeHumanType, ConnectDataType, CallbackMsgType, EffectsType } from './interface';
7
7
  import { DHServerInterface, RenderCallback } from './Server';
8
8
  export default class DhRealtimeHuman {
9
9
  private token;
@@ -15,18 +15,31 @@ export default class DhRealtimeHuman {
15
15
  private rtcServer?;
16
16
  private rtcConnectParams;
17
17
  private cutoutInstance?;
18
+ private hasInitChromaEffects;
18
19
  private readonly isHuawei;
19
20
  private rtcServerUrl;
21
+ private rtcInternalIp;
20
22
  private recordController;
21
23
  private wsReadyState;
22
24
  private readonly isPreOpenSession;
25
+ private readonly openWsOnly;
26
+ private hasConnectUserFigureEffects;
27
+ private _isMicMuted;
28
+ private mergeConnectRtcExtras;
29
+ private emitRawStatusMessage;
30
+ private resolveMediaServerByDomain?;
23
31
  constructor(props: DhRealtimeHumanType);
32
+ canShowStaticFrameCover(): boolean;
24
33
  init(props: DhRealtimeHumanType): void;
25
34
  onDigitalHumanCallbackPlus: (data: CallbackMsgType) => void;
26
35
  onRemoteVideoComing: (id: number) => void;
27
36
  onLocalStream: () => void;
28
37
  onRemoteVideoOn: () => void;
38
+ onRemoteVideoOffLastFrame: () => void;
29
39
  connectListener: (data: ConnectDataType) => void;
40
+ handleConnectResponse(data: ConnectDataType): Promise<void>;
41
+ mergeConnectRtcExtrasFromBody(body: Record<string, any>): Promise<void>;
42
+ applyConnectChroma(effects: EffectsType): Promise<void>;
30
43
  createServer: (sessionId?: string) => void;
31
44
  checkHumanInstansce: () => boolean;
32
45
  sendMessage: (message: DHServerInterface | ArrayBuffer, listener: RenderCallback | null) => Promise<void> | null;
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 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.closeSocket();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};
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};
package/es/Cutout.d.ts CHANGED
@@ -7,8 +7,8 @@ import { ChromaEffectOptions } from '@bddh/starling-cutout/es/interface';
7
7
  import Seriously from '@bddh/starling-cutout/es/Seriously';
8
8
  interface CutoutType {
9
9
  effects?: {
10
- version: number;
11
- chromaKey: Partial<ChromaEffectOptions>;
10
+ version?: number;
11
+ chromaKey?: Partial<ChromaEffectOptions>;
12
12
  };
13
13
  sourceId: string;
14
14
  }
@@ -14,7 +14,15 @@ 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";
17
19
  export declare function createHumanDom(options: CreateVideoDomOptions): CreateVideoDomResult | null;
20
+ export declare function ensureCutoutDomMounted(): boolean;
21
+ export declare function appendLastFrameCoverSibling(mountEl: HTMLElement | null): void;
22
+ export declare function captureLastFrameToCover(): boolean;
23
+ export declare function setHumanPlayerWrapperVisible(visible: boolean): void;
24
+ export declare function setLastFrameCoverVisible(visible: boolean): void;
25
+ export declare function removeLastFrameCoverWrapper(): void;
18
26
  export declare function removeHumanDom(): void;
19
27
  export declare function muteHumanVideo(muted: boolean): HTMLVideoElement;
20
28
  export declare function playHumanVideo(play: boolean): void | Promise<void>;
package/es/DomControl.js CHANGED
@@ -1 +1 @@
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};
1
+ var e="starling-cutout-canvas",t="cloud-brtc-player-wrapper",n="remotevideo500",i="canvas-item",o="starling-last-frame-cover-canvas",a="data-dh-last-frame-cover";function d(i){var o=i.autoChromaKey,a=void 0!==o&&o,d=i.autoplay,r=void 0===d||d;if(document.getElementById(n))return console.error('DOM with id "'.concat(n,'" already exists.')),null;var l=document.createElement("div");l.className=t,l.id=t,l.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",""),r&&c.setAttribute("autoplay",""),l.appendChild(c),a){var u=document.createElement("canvas");u.id=e,Object.assign(u.style,{position:"absolute",top:"0",left:"0",height:"100%",width:"100%",zIndex:"1",display:a?"block":"none"}),c.style.visibility="hidden",l.appendChild(u)}return{playerWrapper:l,video:c}}function r(){if(document.getElementById(e))return!0;var i=document.getElementById(t),o=document.getElementById(n);if(!i||!o)return!1;var a=document.createElement("canvas");return a.id=e,Object.assign(a.style,{position:"absolute",top:"0",left:"0",height:"100%",width:"100%",zIndex:"1",display:"block"}),o.style.visibility="hidden",i.appendChild(a),!0}function l(e){if(e&&!e.querySelector("[".concat(a,'="1"]'))){var t=document.createElement("div");t.className="".concat(i," "),t.setAttribute(a,"1");var n=document.createElement("canvas");n.id=o,Object.assign(n.style,{position:"absolute",top:"0",left:"0",width:"100%",height:"100%",objectFit:"cover",display:"block",zIndex:"0"}),t.appendChild(n),e.appendChild(t)}}function c(){var t=document.getElementById(o);if(!t)return!1;var i=t.getContext("2d");if(!i)return!1;var a=document.getElementById(e),d=document.getElementById(n);return a&&a.width>0&&a.height>0?(t.width=a.width,t.height=a.height,i.drawImage(a,0,0),!0):!!(d&&d.videoWidth>0&&d.videoHeight>0)&&(t.width=d.videoWidth,t.height=d.videoHeight,i.drawImage(d,0,0,d.videoWidth,d.videoHeight),!0)}function u(e){var n=document.getElementById(t);n&&(n.style.visibility=e?"visible":"hidden",n.style.pointerEvents=e?"":"none")}function h(e){var t=document.getElementById(o),n=null==t?void 0:t.parentNode;n&&(n.style.visibility=e?"visible":"hidden")}function s(){var e=document.querySelector("[".concat(a,'="1"]'));null!=e&&e.parentNode&&e.parentNode.removeChild(e)}function v(){var e=document.getElementById(t);e&&e.parentNode&&e.parentNode.removeChild(e)}function m(e){var t=document.getElementById(n);return t&&(t.muted=e),t}function p(e){var t=document.getElementById(n);try{if(t)return e?t.play():t.pause()}catch(e){console.info(e)}}function y(){var e=navigator.userAgent||navigator.vendor;return/huawei/i.test(e)||/honor/i.test(e)}function g(){var e=document.createElement("style");e.appendChild(document.createTextNode('\n [id^="videoremote1-"] {\n display: none !important;\n }\n \n video#remotevideo500 {\n width: auto !important;\n height: auto !important;\n max-width: 100% !important;\n max-height: 100% !important;\n width: 100% !important;\n height: 100% !important;\n object-fit: cover;\n }\n\n .cloud-brtc-player-wrapper {\n width: inherit !important;\n background-size: cover;\n height: inherit;\n display: flex;\n justify-content: center;\n }\n\n #starling-cutout-canvas {\n object-fit: cover;\n }\n\n [data-dh-last-frame-cover="1"] {\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n pointer-events: none;\n z-index: 1;\n visibility: hidden;\n }\n\n [data-dh-last-frame-cover="1"] canvas {\n width: 100%;\n height: 100%;\n object-fit: cover;\n display: block;\n }\n ')),document.head.appendChild(e)}export{e as DEFAULT_CANVAS_ID,t as HUMAN_WRAPPER_ID,i as LAST_FRAME_COVER_CANVAS_CLASS,o as LAST_FRAME_COVER_INNER_CANVAS_ID,n as RTC_VIDEO_ID,l as appendLastFrameCoverSibling,g as appendRtcDomStyle,c as captureLastFrameToCover,y as checkIsHuawei,d as createHumanDom,r as ensureCutoutDomMounted,m as muteHumanVideo,p as playHumanVideo,v as removeHumanDom,s as removeLastFrameCoverWrapper,u as setHumanPlayerWrapperVisible,h as setLastFrameCoverVisible};
@@ -1 +1 @@
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};
1
+ import{createClass as t,asyncToGenerator as e,regeneratorRuntime as r,objectSpread2 as o,classCallCheck as a,defineProperty 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){a(this,h),i(this,"onAudioData",void 0),i(this,"onError",void 0),i(this,"audioContext",null),i(this,"processor",null),i(this,"mediaStream",null),i(this,"recording",!1),i(this,"audio3AConstraints",void 0),i(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(r().mark((function t(){var e,a,i;return r().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(t.prev=0,a=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 a({sampleRate:this.asrSample||16e3}),t.next=9,navigator.mediaDevices.getUserMedia({audio:o({echoCancellation:!0,noiseSuppression:!0,autoGainControl:!0},this.audio3AConstraints),video:!1});case 9:this.mediaStream=t.sent,i=this.audioContext.createMediaStreamSource(this.mediaStream),this.processor=this.audioContext.createScriptProcessor(1024,1,1),i.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(r().mark((function t(){var e=this;return r().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,7 +42,12 @@ export interface RenderCallbackRes {
42
42
  body: string | null;
43
43
  message: string;
44
44
  }
45
+ interface ServerOptions {
46
+ checkHeartbeatMismatch?: boolean;
47
+ emitRawStatusMessage?: boolean;
48
+ }
45
49
  export type RenderCallback = (res: RenderCallbackRes) => void;
50
+ export declare const CONNECTING_STUCK_MS_DEFAULT: number;
46
51
  declare class Server {
47
52
  dhServerSocket: WebSocketClient | null;
48
53
  preConnectSuccess: boolean;
@@ -50,11 +55,24 @@ declare class Server {
50
55
  private socketClosingPromise;
51
56
  private readonly url;
52
57
  private firstConnect;
53
- constructor(url: string);
58
+ private connectingTimer;
59
+ private readonly connectingMs;
60
+ private lastPreOpen;
61
+ private reconnectingTimeout;
62
+ private lastReportedReadyState;
63
+ private lastHbAckTs;
64
+ private readonly checkHeartbeatMismatch;
65
+ private emitRawStatusMessage;
66
+ constructor(url: string, options?: ServerOptions);
67
+ setEmitRawStatusMessage(value: boolean): void;
54
68
  sendPreConnect: (props: createSocketParamsType, resolve?: ((value: any) => void) | undefined) => void;
55
69
  createSocket: (props: createSocketParamsType, isPreOpenSession?: boolean) => Promise<WebSocketClient | null>;
70
+ sendConnect: (props: createSocketParamsType) => void;
56
71
  closeSocket: () => Promise<void>;
57
72
  handleConnect: () => Promise<void>;
58
73
  sendMessage(message: DHServerInterface | ArrayBuffer, listener: RenderCallback | null): Promise<void>;
74
+ private startConnectingWatch;
75
+ private clearConnectingWatch;
76
+ private resetState;
59
77
  }
60
78
  export default Server;
package/es/Server.js CHANGED
@@ -1 +1 @@
1
- import{createClass as e,asyncToGenerator as t,classCallCheck as n,defineProperty as r,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 u from"lodash/pick";import l from"lodash/omit";import d from"lodash/get";import{errorTypeEnum as p,CONNECT_MAIN_KEY as S,statusEnum as f,WS_STATUS_MAP as h}from"./interface.js";var k=function(k){function m(e){var c,k=this;n(this,m),r(this,"dhServerSocket",null),r(this,"preConnectSuccess",!1),r(this,"connectParams",null),r(this,"socketClosingPromise",null),r(this,"url",void 0),r(this,"firstConnect",!0),r(this,"sendPreConnect",(function(e,t){var n,r=e.token,o=e.sessionId,s=e.onConnect;null===(n=k.dhServerSocket)||void 0===n||n.request({action:"RE_CONNECT",requestId:a(),body:JSON.stringify({token:r,sessionId:o})}).on((function(e,n){null==s||s(e),0!==e.code&&(n(),k.handleConnect()),null==t||t(k.dhServerSocket)})),k.firstConnect=!1})),r(this,"createSocket",(function(e,n){return(c=c||t(o().mark((function e(t,n){var r,s;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(k.connectParams=t,r=t.sessionId,s=t.onDigitalHumanCallback,!k.socketClosingPromise){e.next=5;break}return e.next=5,k.socketClosingPromise;case 5:if(!k.dhServerSocket){e.next=8;break}return e.next=8,k.closeSocket();case 8:return e.abrupt("return",new Promise((function(e,o){var c={keepAlive:"heartbeat",reopen:d(k.connectParams,"reConnect",!0),combine:function(e,t){return e&&t&&e.requestId===t.requestId},onOpen:function(){k.dhServerSocket=a,r&&k.firstConnect?k.sendPreConnect(t,e):n&&k.firstConnect||k.handleConnect()},onClose:function(){k.dhServerSocket=null,k.socketClosingPromise=null},onError:function(e){o(e)}},a=i(k.url,c);a.onReadyStateChange((function(e){0===e&&s&&s({status:f.DH_LIB_INIT}),1===e&&n&&(k.preConnectSuccess=!0),3===e&&(k.preConnectSuccess=!1),s&&s({status:f.DH_LIB_FULL_STATUS,content:{type:"wsState",readyState:e,body:h[e]}})})),a.onMessage((function(e){var t=e.action;[p.TIMEOUT_EXIT,p.DISCONNECT_ALERT].includes(t)&&s&&s({status:f.DH_LIB_STATUS,content:{type:t}}),[p.TIMEOUT_EXIT,p.DISCONNECT_ALERT,"HEART_BEAT","CONNECT"].includes(t)||s&&s({status:f.DH_LIB_MESSAGE,content:e})})),n&&(k.dhServerSocket=a),a.open()})));case 9:case"end":return e.stop()}}),e)})))).apply(this,arguments)})),r(this,"closeSocket",t(o().mark((function e(){return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(k.dhServerSocket){e.next=2;break}return e.abrupt("return");case 2:return k.socketClosingPromise=k.dhServerSocket.close(),e.next=5,k.socketClosingPromise;case 5:k.dhServerSocket=null;case 6:case"end":return e.stop()}}),e)})))),r(this,"handleConnect",t(o().mark((function e(){var t,n,r,c,i,d;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(k.connectParams){e.next=2;break}return e.abrupt("return");case 2:if(t=k.connectParams,n=t.appId,r=t.appKey,c=t.token,i=t.parameters,d=t.onConnect,n||r||c){e.next=5;break}return e.abrupt("return");case 5:k.dhServerSocket&&k.dhServerSocket.request({action:"CONNECT",clientTs:(new Date).getTime(),requestId:a(),body:JSON.stringify(s(s({token:c,appId:n,appKey:r},u(k.connectParams,S)),{},{parameters:s(s({},l(i,["parameters"])),i&&i.parameters?i.parameters:{})}))}).on((function(e,t){null==d||d(e),0!==e.code&&t()}));case 6:case"end":return e.stop()}}),e)})))),this.url=e}return e(m,[{key:"sendMessage",value:function(e,n){return(k=k||t(o().mark((function e(t,n){var r;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){n&&n(e)}))}catch(e){r="object"===c(t)&&"requestId"in t?t.requestId:a(),n&&n({code:-11,body:null,action:"RENDER_ERROR",requestId:r,message:JSON.stringify(e)})}case 1:case"end":return e.stop()}}),e,this)})))).apply(this,arguments)}}]),m}();export{k as default};
1
+ import{createClass as e,asyncToGenerator as t,regeneratorRuntime as n,typeof as r,classCallCheck as s,defineProperty as c,objectSpread2 as o}from"./_virtual/_rollupPluginBabelHelpers.js";import{v4 as a}from"uuid";import{createWebSocket as i}from"@bddh/starling-web-socket/es/create-web-socket";import u from"lodash/pick";import l from"lodash/omit";import h from"lodash/get";import{errorTypeEnum as d,CONNECT_MAIN_KEY as m,statusEnum as S,WS_STATUS_MAP as p}from"./interface.js";var f=3e4,k=function(f){function k(e,r){var f,v=this;s(this,k),c(this,"dhServerSocket",null),c(this,"preConnectSuccess",!1),c(this,"connectParams",null),c(this,"socketClosingPromise",null),c(this,"url",void 0),c(this,"firstConnect",!0),c(this,"connectingTimer",null),c(this,"connectingMs",3e4),c(this,"lastPreOpen",!1),c(this,"reconnectingTimeout",!1),c(this,"lastReportedReadyState",-1),c(this,"lastHbAckTs",0),c(this,"checkHeartbeatMismatch",void 0),c(this,"emitRawStatusMessage",void 0),c(this,"sendPreConnect",(function(e,t){var n,r=e.token,s=e.sessionId,c=e.onConnect;null===(n=v.dhServerSocket)||void 0===n||n.request({action:"RE_CONNECT",requestId:a(),body:JSON.stringify({token:r,sessionId:s})}).on((function(e,n){null==c||c(e),0!==e.code&&(n(),v.handleConnect()),null==t||t(v.dhServerSocket)})),v.firstConnect=!1})),c(this,"createSocket",(function(e,r){return(f=f||t(n().mark((function e(t,r){var s,c;return n().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(v.connectParams=t,v.lastPreOpen=!!r,s=t.sessionId,c=t.onDigitalHumanCallback,!v.socketClosingPromise){e.next=6;break}return e.next=6,v.socketClosingPromise;case 6:if(!v.dhServerSocket){e.next=9;break}return e.next=9,v.closeSocket();case 9:return e.abrupt("return",new Promise((function(e,n){var o=!1,a=function(t){o||(o=!0,e(t))},u={keepAlive:"heartbeat",checkHeartbeatMismatch:v.checkHeartbeatMismatch,reopen:h(v.connectParams,"reConnect",!0),getKeepAliveMessage:function(e){return{requestId:e,action:"HEART_BEAT",body:"".concat(v.lastHbAckTs),clientTs:Date.now()}},combine:function(e,t){return e&&t&&e.requestId===t.requestId},onOpen:function(){v.dhServerSocket=l,a(v.dhServerSocket),s&&v.firstConnect?v.sendPreConnect(t,a):r&&v.firstConnect||v.handleConnect()},onClose:function(){v.dhServerSocket=null,v.socketClosingPromise=null,a(null)},onError:function(e){n(e)}},l=i(v.url,u);l.onReadyStateChange((function(e){v.lastReportedReadyState=e,0===e?(v.startConnectingWatch(),c&&c({status:S.DH_LIB_INIT})):(v.clearConnectingWatch(),v.reconnectingTimeout=!1),1===e&&r&&(v.preConnectSuccess=!0),3===e&&(v.preConnectSuccess=!1),c&&c({status:S.DH_LIB_FULL_STATUS,content:{type:"wsState",readyState:e,body:p[e]}})})),l.onMessage((function(e){var t=e.action;"HEART_BEAT"===t&&(v.lastHbAckTs=Date.now()),[d.TIMEOUT_EXIT,d.DISCONNECT_ALERT].includes(t)&&(c&&c({status:S.DH_LIB_STATUS,content:{type:t}}),v.emitRawStatusMessage&&c&&c({status:S.DH_LIB_MESSAGE,content:e})),[d.TIMEOUT_EXIT,d.DISCONNECT_ALERT,"HEART_BEAT","CONNECT"].includes(t)||c&&c({status:S.DH_LIB_MESSAGE,content:e})})),v.dhServerSocket=l,l.open()})));case 10:case"end":return e.stop()}}),e)})))).apply(this,arguments)})),c(this,"sendConnect",(function(e){v.connectParams=e,v.dhServerSocket&&v.handleConnect()})),c(this,"closeSocket",t(n().mark((function e(){return n().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(v.resetState(),v.dhServerSocket){e.next=3;break}return e.abrupt("return");case 3:return v.socketClosingPromise=v.dhServerSocket.close(),e.next=6,v.socketClosingPromise;case 6:v.dhServerSocket=null;case 7:case"end":return e.stop()}}),e)})))),c(this,"handleConnect",t(n().mark((function e(){var t,r,s,c,i,h;return n().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(v.connectParams){e.next=2;break}return e.abrupt("return");case 2:if(t=v.connectParams,r=t.appId,s=t.appKey,c=t.token,i=t.parameters,h=t.onConnect,r||s||c){e.next=5;break}return e.abrupt("return");case 5:v.dhServerSocket&&v.dhServerSocket.request({action:"CONNECT",clientTs:(new Date).getTime(),requestId:a(),body:JSON.stringify(o(o({token:c,appId:r,appKey:s},u(v.connectParams,m)),{},{parameters:o(o({},l(i,["parameters"])),i&&i.parameters?i.parameters:{})}))}).on((function(e,t){null==h||h(e),0!==e.code&&t()}));case 6:case"end":return e.stop()}}),e)}))));var T=r||{},C=T.checkHeartbeatMismatch,g=T.emitRawStatusMessage,b=void 0!==g&&g;this.url=e,this.checkHeartbeatMismatch=null!=C&&C,this.emitRawStatusMessage=b}return e(k,[{key:"setEmitRawStatusMessage",value:function(e){this.emitRawStatusMessage=e}},{key:"sendMessage",value:function(e,s){return(f=f||t(n().mark((function e(t,s){var c;return n().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:try{this.dhServerSocket&&this.dhServerSocket&&this.dhServerSocket.request(t).on((function(e){s&&s(e)}))}catch(e){c="object"===r(t)&&"requestId"in t?t.requestId:a(),s&&s({code:-11,body:null,action:"RENDER_ERROR",requestId:c,message:JSON.stringify(e)})}case 1:case"end":return e.stop()}}),e,this)})))).apply(this,arguments)}},{key:"startConnectingWatch",value:function(){var e=this;this.connectingTimer||this.reconnectingTimeout||(this.connectingTimer=setTimeout(t(n().mark((function t(){return n().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(e.connectingTimer=null,e.dhServerSocket&&0===e.lastReportedReadyState){t.next=3;break}return t.abrupt("return");case 3:if(console.warn("reconnect from CONNECTING timeout"),e.reconnectingTimeout=!0,t.prev=5,!e.connectParams){t.next=9;break}return t.next=9,e.createSocket(e.connectParams,e.lastPreOpen);case 9:t.next=14;break;case 11:t.prev=11,t.t0=t.catch(5),console.error("reconnect from CONNECTING timeout failed",t.t0);case 14:return t.prev=14,e.reconnectingTimeout=!1,t.finish(14);case 17:case"end":return t.stop()}}),t,null,[[5,11,14,17]])}))),this.connectingMs))}},{key:"clearConnectingWatch",value:function(){this.connectingTimer&&(clearTimeout(this.connectingTimer),this.connectingTimer=null)}},{key:"resetState",value:function(){this.clearConnectingWatch(),this.reconnectingTimeout=!1,this.lastReportedReadyState=-1,this.lastHbAckTs=0}}]),k}();export{f as CONNECTING_STUCK_MS_DEFAULT,k as default};
package/es/interface.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { ChromaEffectOptions } from '@bddh/starling-cutout/es/interface';
1
2
  import { RtcConnectionType } from './BrtcClient';
2
3
  export interface ConnectDataType {
3
4
  action: string;
@@ -56,7 +57,10 @@ export interface ConnectParamsType {
56
57
  enabled: boolean;
57
58
  };
58
59
  enableInterrupt?: boolean;
59
- asrVadPauseTime?: Number;
60
+ asrVadPauseTime?: number;
61
+ positionV2?: string;
62
+ ttsModel?: string;
63
+ autoAnimoji?: boolean;
60
64
  }
61
65
  export declare const CONNECT_MAIN_KEY: string[];
62
66
  export interface RenderParamsType {
@@ -116,7 +120,9 @@ export interface CallbackMsgType {
116
120
  export interface DhRealtimeHumanType {
117
121
  token?: string;
118
122
  wsUrl?: string;
123
+ checkHeartbeatMismatch?: boolean;
119
124
  rtcServerUrl?: string;
125
+ rtcInternalIp?: string;
120
126
  appKey?: string;
121
127
  appId?: string;
122
128
  wrapperId?: string;
@@ -124,7 +130,16 @@ export interface DhRealtimeHumanType {
124
130
  renderParams?: RenderParamsType;
125
131
  rtcConnectParams?: RtcConnectionType;
126
132
  brtcParams?: any;
133
+ remoteAutoPlay?: boolean;
134
+ mergeConnectRtcExtras?: boolean;
135
+ emitRawStatusMessage?: boolean;
136
+ resolveMediaServerByDomain?: (domain: string) => Promise<string>;
127
137
  isPreOpenSession?: boolean;
138
+ isOpenWsOnly?: boolean;
128
139
  onDigitalHumanCallback: (data: CallbackMsgType) => void;
129
140
  }
141
+ export interface EffectsType {
142
+ chromaKey?: Partial<ChromaEffectOptions>;
143
+ version?: number;
144
+ }
130
145
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bddh/starling-realtime-client",
3
- "version": "2.0.10",
3
+ "version": "2.0.11-beta.2",
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.10",
34
+ "@bddh/starling-web-socket": "1.0.13-beta.1",
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.10",
43
+ "@bddh/starling-web-socket": "1.0.13-beta.1",
44
44
  "lodash": "^4.17.21",
45
45
  "uuid": "^9.0.0"
46
46
  },
47
- "gitHead": "b779c623fa778ef1ebca2e6b70c18fc8209b56c5"
47
+ "gitHead": "6953cbfa8a7f561bf97e664c310a8610b0a860ad"
48
48
  }