@bddh/starling-realtime-client 2.0.0-beta.1 → 2.0.0-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/cjs/Client.d.ts CHANGED
@@ -21,6 +21,7 @@ export default class DhRealtimeHuman {
21
21
  private wsReadyState;
22
22
  constructor(props: DhRealtimeHumanType);
23
23
  onRemoteVideoComing: (id: number) => void;
24
+ onLocalStream: () => void;
24
25
  onRemoteVideoOn: () => void;
25
26
  connectListener: (data: ConnectDataType) => void;
26
27
  createServer: (sessionId?: string) => void;
package/cjs/Client.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./_virtual/_rollupPluginBabelHelpers.js"),t=require("@bddh/starling-json"),r=require("lodash/isEmpty"),n=require("lodash/omit"),o=require("lodash/pick"),a=require("uuid"),i=require("./interface.js"),s=require("./Server.js"),c=require("./BrtcClient.js"),d=require("./DomControl.js"),u=require("./Cutout.js"),l=require("./RecordController.js"),p=function(){function p(m){var h=this;e.classCallCheck(this,p),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",d.checkIsHuawei()),e.defineProperty(this,"rtcServerUrl",void 0),e.defineProperty(this,"recordController",null),e.defineProperty(this,"wsReadyState",-1),e.defineProperty(this,"onRemoteVideoComing",(function(e){h.rtcConnectParams&&h.rtcConnectParams.feedId&&e===+h.rtcConnectParams.feedId&&h.rtcServer&&h.rtcServer.client&&h.rtcServer.client.subscribeStreaming("remotevideo500",+h.rtcConnectParams.feedId)})),e.defineProperty(this,"onRemoteVideoOn",(function(){setTimeout(e.asyncToGenerator(e.regeneratorRuntime().mark((function t(){var r,n,o,a,i;return e.regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=document.getElementById(d.RTC_VIDEO_ID),e.next=3,h.cutoutInstance&&h.cutoutInstance.updateSource(d.RTC_VIDEO_ID);case 3:r&&(r.setAttribute("data-playing","true"),n=r.videoWidth,o=r.videoHeight,a=document.getElementById(d.DEFAULT_CANVAS_ID),i=a.getContext("2d"),a&&i&&(a.width=n,a.height=o,i.drawImage(r,0,0,n,o)));case 4:case"end":return e.stop()}}),t)}))),100)})),e.defineProperty(this,"connectListener",(function(e){var r=e.code,n=e.body,o=e.message;if(0===r&&h.onDigitalHumanCallback&&h.onDigitalHumanCallback({status:i.statusEnum.DH_LIB_WS_SUCCESS,content:e}),0===r){var a=t.parse(n),s=a.rtcServerUrl,c=a.appId,d=a.clientToken,u=a.roomName,l=a.clientId,p=a.feedId,m=a.chargeId;c&&u&&(h.rtcConnectParams={server:h.rtcServerUrl||s,appId:c,token:d,roomName:u,userId:l,feedId:p,chargeId:m},h.rtcServer&&h.rtcServer.openRtc(h.rtcConnectParams))}else h.onDigitalHumanCallback&&h.onDigitalHumanCallback({status:i.statusEnum.DH_LIB_ERROR,content:{type:i.errorTypeEnum.CONNECT_ERROR,msg:{code:r,errMsg:o}}})})),e.defineProperty(this,"createServer",(function(t){h.dhServer&&h.dhServer.createSocket(e.objectSpread2(e.objectSpread2(e.objectSpread2({token:h.token,appKey:h.appKey,appId:h.appId},t?{sessionId:t}:{}),o(h.connectParams,i.CONNECT_MAIN_KEY)),{},{parameters:n(h.connectParams,i.CONNECT_MAIN_KEY),onConnect:h.connectListener,onDigitalHumanCallback:function(e){var t;e.status===i.statusEnum.DH_LIB_FULL_STATUS&&"wsState"===(null===(t=e.content)||void 0===t?void 0:t.type)&&(h.wsReadyState=e.content.readyState),h.onDigitalHumanCallback&&h.onDigitalHumanCallback(e)}}))})),e.defineProperty(this,"checkHumanInstansce",(function(){h.dhServer||console.warn("请先初始化数字人示例")})),e.defineProperty(this,"sendMessage",(function(e,t){return h.dhServer&&h.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){h.dhServer&&h.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()}}),t)})))),e.defineProperty(this,"textRender",(function(e){var t=e.requestId,r=e.body,n=e.onCallbackMsg;h.checkHumanInstansce(),h.dhServer&&h.dhServer.sendMessage({requestId:t||a.v4(),action:"TEXT_RENDER",body:r,clientTs:(new Date).getTime()},n)})),e.defineProperty(this,"textStreamRender",(function(e){var r=e.requestId,n=e.body,o=e.onCallbackMsg,i=t.parse(n).first;h.checkHumanInstansce(),h.dhServer&&h.dhServer.sendMessage({requestId:r||a.v4(),action:"TEXT_STREAM_RENDER",body:n,clientTs:(new Date).getTime()},i?o:null)})),e.defineProperty(this,"audioRender",(function(e){var t=e.body,r=e.onCallbackMsg;h.checkHumanInstansce(),h.dhServer&&h.dhServer.sendMessage({requestId:a.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;h.checkHumanInstansce(),h.dhServer&&h.dhServer.sendMessage({requestId:t||a.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;h.dhServer&&h.dhServer.sendMessage({requestId:t||a.v4(),action:"TEXT_QUERY",body:r,clientTs:(new Date).getTime()},n)})),e.defineProperty(this,"destory",e.asyncToGenerator(e.regeneratorRuntime().mark((function t(){return e.regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,h.dhServer&&h.dhServer.closeSocket();case 2:h.rtcServer&&h.rtcServer.closeRtc(),d.removeHumanDom(),h.dhServer=null,h.rtcServer=null;case 6:case"end":return e.stop()}}),t)})))),e.defineProperty(this,"pauseHuman",(function(){return d.playHumanVideo(!1)})),e.defineProperty(this,"playHuman",(function(){return d.playHumanVideo(!0)})),e.defineProperty(this,"muteHuman",(function(){return d.muteHumanVideo(!0)})),e.defineProperty(this,"unMuteHuman",(function(){var e=d.muteHumanVideo(!1);try{return h.isHuawei?(e.pause(),e.play()):e.paused&&e.play()}catch(e){console.info(e)}}));var v=m.wrapperId,f=m.token,y=m.appKey,g=m.appId,S=m.connectParams,C=m.renderParams,I=m.rtcConnectParams,R=m.brtcParams,P=m.wsUrl,b=m.rtcServerUrl,D=m.onDigitalHumanCallback;this.token=f,this.appKey=y,this.appId=g,this.rtcServerUrl=b,this.connectParams=e.objectSpread2({autoChromaKey:C.autoChromaKey},S);var E=C.fullStatus,T=C.closeLog;this.onDigitalHumanCallback=function(e){e.status!==i.statusEnum.DH_LIB_FULL_STATUS?D&&D(e):E&&D&&D(e)},this.dhServer=new s.default(P||"wss://open.xiling.baidu.com/cloud/digital-human-demonstration");var _=(d.createHumanDom({autoChromaKey:!!C.autoChromaKey})||{}).playerWrapper,k=document.getElementById(v);k||console.error("dom with wrapperId is not find"),_&&k&&k.appendChild(_),d.appendRtcDomStyle();var H=e.objectSpread2({remotevideoviewid:v,showvideobps:!1,usingvideo:!1,usingaudio:!!S.pullAudioFromRtc,aspublisher:!!S.pullAudioFromRtc,autopublish:!!S.pullAudioFromRtc,usingdatachannel:!0,autoplaymuted:!1},R);this.rtcServer=new c.default({closeLog:T,videoWrapperId:d.RTC_VIDEO_ID,rtcConfig:H,bizConfig:{},rtcCallback:{onRemoteVideoComing:this.onRemoteVideoComing,onDigitalHumanCallback:this.onDigitalHumanCallback}}),this.cutoutInstance=new u.default({sourceId:d.RTC_VIDEO_ID}),r(I)||(this.rtcConnectParams=I,this.rtcServer.openRtc(I)),S.pullAudioFromRtc?this.recordController=null:this.recordController=new l.default({pickAudioMode:S.pickAudioMode,onAudioData:function(e){1===h.wsReadyState&&h.sendMessage(e,null)},onError:function(e){h.onDigitalHumanCallback&&h.onDigitalHumanCallback({status:i.statusEnum.DH_LIB_ERROR,content:{type:i.errorTypeEnum.CONNECT_ERROR,msg:{code:-1,errMsg:e.message}}})}})}return e.createClass(p,[{key:"startRecord",value:function(){this.connectParams.pullAudioFromRtc?this.rtcServer&&this.rtcServer.muteMicphone(!1):this.recordController&&this.recordController.start()}},{key:"stopRecord",value:function(){if(this.connectParams.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)}}]),p}();exports.default=p;
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"),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"),p=function(){function p(m){var h=this;e.classCallCheck(this,p),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,"onRemoteVideoComing",(function(e){h.rtcConnectParams&&h.rtcConnectParams.feedId&&e===+h.rtcConnectParams.feedId&&h.rtcServer&&h.rtcServer.client&&h.rtcServer.client.subscribeStreaming("remotevideo500",+h.rtcConnectParams.feedId)})),e.defineProperty(this,"onLocalStream",(function(){var e=h.connectParams,t=e.pullAudioFromRtc,r=e.pickAudioMode;t&&"pressButton"===r&&h.rtcServer&&h.rtcServer.muteMicphone(!0)})),e.defineProperty(this,"onRemoteVideoOn",(function(){setTimeout(e.asyncToGenerator(e.regeneratorRuntime().mark((function t(){var r,n,o,a,i;return e.regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=document.getElementById(u.RTC_VIDEO_ID),e.next=3,h.cutoutInstance&&h.cutoutInstance.updateSource(u.RTC_VIDEO_ID);case 3:r&&(r.setAttribute("data-playing","true"),n=r.videoWidth,o=r.videoHeight,a=document.getElementById(u.DEFAULT_CANVAS_ID),i=a.getContext("2d"),a&&i&&(a.width=n,a.height=o,i.drawImage(r,0,0,n,o)));case 4:case"end":return e.stop()}}),t)}))),100)})),e.defineProperty(this,"connectListener",(function(e){var r=e.code,n=e.body,o=e.message;if(0===r&&h.onDigitalHumanCallback&&h.onDigitalHumanCallback({status:i.statusEnum.DH_LIB_WS_SUCCESS,content:e}),0===r){var a=t.parse(n),s=a.rtcServerUrl,c=a.appId,u=a.clientToken,d=a.roomName,l=a.clientId,p=a.feedId,m=a.chargeId;c&&d&&(h.rtcConnectParams={server:h.rtcServerUrl||s,appId:c,token:u,roomName:d,userId:l,feedId:p,chargeId:m},h.rtcServer&&h.rtcServer.openRtc(h.rtcConnectParams))}else h.onDigitalHumanCallback&&h.onDigitalHumanCallback({status:i.statusEnum.DH_LIB_ERROR,content:{type:i.errorTypeEnum.CONNECT_ERROR,msg:{code:r,errMsg:o}}})})),e.defineProperty(this,"createServer",(function(t){h.dhServer&&h.dhServer.createSocket(e.objectSpread2(e.objectSpread2(e.objectSpread2({token:h.token,appKey:h.appKey,appId:h.appId},t?{sessionId:t}:{}),o(h.connectParams,i.CONNECT_MAIN_KEY)),{},{parameters:n(h.connectParams,i.CONNECT_MAIN_KEY),onConnect:h.connectListener,onDigitalHumanCallback:function(e){var t;e.status===i.statusEnum.DH_LIB_FULL_STATUS&&"wsState"===(null===(t=e.content)||void 0===t?void 0:t.type)&&(h.wsReadyState=e.content.readyState),h.onDigitalHumanCallback&&h.onDigitalHumanCallback(e)}}))})),e.defineProperty(this,"checkHumanInstansce",(function(){h.dhServer||console.warn("请先初始化数字人示例")})),e.defineProperty(this,"sendMessage",(function(e,t){return h.dhServer&&h.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){h.dhServer&&h.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()}}),t)})))),e.defineProperty(this,"textRender",(function(e){var t=e.requestId,r=e.body,n=e.onCallbackMsg;h.checkHumanInstansce(),h.dhServer&&h.dhServer.sendMessage({requestId:t||a.v4(),action:"TEXT_RENDER",body:r,clientTs:(new Date).getTime()},n)})),e.defineProperty(this,"textStreamRender",(function(e){var r=e.requestId,n=e.body,o=e.onCallbackMsg,i=t.parse(n).first;h.checkHumanInstansce(),h.dhServer&&h.dhServer.sendMessage({requestId:r||a.v4(),action:"TEXT_STREAM_RENDER",body:n,clientTs:(new Date).getTime()},i?o:null)})),e.defineProperty(this,"audioRender",(function(e){var t=e.body,r=e.onCallbackMsg;h.checkHumanInstansce(),h.dhServer&&h.dhServer.sendMessage({requestId:a.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;h.checkHumanInstansce(),h.dhServer&&h.dhServer.sendMessage({requestId:t||a.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;h.dhServer&&h.dhServer.sendMessage({requestId:t||a.v4(),action:"TEXT_QUERY",body:r,clientTs:(new Date).getTime()},n)})),e.defineProperty(this,"destory",e.asyncToGenerator(e.regeneratorRuntime().mark((function t(){return e.regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,h.dhServer&&h.dhServer.closeSocket();case 2:h.rtcServer&&h.rtcServer.closeRtc(),u.removeHumanDom(),h.dhServer=null,h.rtcServer=null;case 6: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 h.isHuawei?(e.pause(),e.play()):e.paused&&e.play()}catch(e){console.info(e)}}));var v=m.wrapperId,f=m.token,y=m.appKey,S=m.appId,g=m.connectParams,C=m.renderParams,I=void 0===C?{}:C,R=m.rtcConnectParams,P=m.brtcParams,D=m.wsUrl,b=m.rtcServerUrl,E=m.onDigitalHumanCallback;if(this.token=f,this.appKey=y,this.appId=S,this.rtcServerUrl=b,this.connectParams=e.objectSpread2(e.objectSpread2({autoChromaKey:(null==I?void 0:I.autoChromaKey)||!1},g),{},{pickAudioMode:null!=g&&g.fullDuplex?"free":"pressButton"}),this.connectParams.fullDuplex&&delete this.connectParams.fullDuplex,!S&&!y&&!f)throw new Error("appId and appKey or token is required");var T=I.fullStatus,k=I.closeLog;this.onDigitalHumanCallback=function(e){e.status!==i.statusEnum.DH_LIB_FULL_STATUS?E&&E(e):T&&E&&E(e)},this.dhServer=new s.default(D||"wss://open.xiling.baidu.com/cloud/digital-human-demonstration");var _=(u.createHumanDom({autoChromaKey:!!I.autoChromaKey||!r(I.chromaEffects)})||{}).playerWrapper,H=document.getElementById(v);H||console.error("dom with wrapperId is not find"),_&&H&&H.appendChild(_),u.appendRtcDomStyle();var w=e.objectSpread2({remotevideoviewid:v,showvideobps:!1,usingvideo:!1,usingaudio:!(null==g||!g.pullAudioFromRtc),aspublisher:!(null==g||!g.pullAudioFromRtc),autopublish:!(null==g||!g.pullAudioFromRtc),usingdatachannel:!0,autoplaymuted:!1},P);this.rtcServer=new c.default({closeLog:k,videoWrapperId:u.RTC_VIDEO_ID,rtcConfig:w,bizConfig:{},rtcCallback:{onRemoteVideoComing:this.onRemoteVideoComing,onDigitalHumanCallback:this.onDigitalHumanCallback,onLocalStream:this.onLocalStream}}),this.cutoutInstance=new d.default({sourceId:u.RTC_VIDEO_ID,effects:null==I?void 0:I.chromaEffects}),r(R)||(this.rtcConnectParams=R,this.rtcServer.openRtc(R)),null!=g&&g.pullAudioFromRtc?this.recordController=null:this.recordController=new l.default({pickAudioMode:null==g?void 0:g.pickAudioMode,onAudioData:function(e){1===h.wsReadyState&&h.sendMessage(e,null)},onError:function(e){h.onDigitalHumanCallback&&h.onDigitalHumanCallback({status:i.statusEnum.DH_LIB_ERROR,content:{type:i.errorTypeEnum.CONNECT_ERROR,msg:{code:-1,errMsg:e.message}}})}})}return e.createClass(p,[{key:"startRecord",value:function(){this.connectParams.pullAudioFromRtc?this.rtcServer&&this.rtcServer.muteMicphone(!1):this.recordController&&this.recordController.start()}},{key:"stopRecord",value:function(){if(this.connectParams.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)}}]),p}();exports.default=p;
@@ -7,24 +7,14 @@ interface RecordControllerOptions {
7
7
  brtcClient?: any;
8
8
  }
9
9
  declare class RecordController {
10
- private pickAudioMode;
11
10
  private readonly onAudioData;
12
11
  private readonly onError?;
13
12
  private audioContext;
14
13
  private processor;
15
14
  private mediaStream;
16
15
  private recording;
17
- private keydownHandler;
18
- private keyupHandler;
19
- private readonly pullAudioFromRtc;
20
- private readonly brtcClient;
21
16
  constructor(options: RecordControllerOptions);
22
- setPickAudioMode(mode: PickAudioMode): void;
23
17
  start(): Promise<void>;
24
18
  stop(): void;
25
- private _bindKeyEvents;
26
- private _unbindKeyEvents;
27
- private _onPressStart;
28
- private _onPressStop;
29
19
  }
30
20
  export default RecordController;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./_virtual/_rollupPluginBabelHelpers.js");function t(e,t,r,i){try{for(var o=(i=i||{})&&"number"==typeof i.index?i.index:0,n=i&&"number"==typeof i.offset?i.offset:0,s=0,a=o;a<e.length;a++)s+=e[a].length;s=Math.max(0,s-Math.floor(n));var d=t/r;d>1?s=Math.floor(s/d):(d=1,r=t);for(var u=new Int16Array(s),c=0,h=e.length;o<h;o++){for(var l=e[o],p=n,f=l.length;p<f;){var y=Math.floor(p),v=Math.ceil(p),k=p-y;u[c]=l[y]+(l[v]-l[y])*k,c++,p+=d}n=p-f}return{index:o,offset:n,sampleRate:r,data:u}}catch(e){console.log("转音错误了",e)}}function r(e){for(var t=e,r=new Int16Array(e.length),i=0;i<t.length;i++){var o=Math.max(-1,Math.min(1,t[i]));r[i]=o<0?32768*o:32767*o}return r}var i=function(i){function o(t){e.classCallCheck(this,o),e.defineProperty(this,"pickAudioMode",void 0),e.defineProperty(this,"onAudioData",void 0),e.defineProperty(this,"onError",void 0),e.defineProperty(this,"audioContext",null),e.defineProperty(this,"processor",null),e.defineProperty(this,"mediaStream",null),e.defineProperty(this,"recording",!1),e.defineProperty(this,"keydownHandler",null),e.defineProperty(this,"keyupHandler",null),e.defineProperty(this,"pullAudioFromRtc",void 0),e.defineProperty(this,"brtcClient",void 0),this.pickAudioMode=t.pickAudioMode||"free",this.onAudioData=t.onAudioData,this.onError=t.onError,this.pullAudioFromRtc=!!t.pullAudioFromRtc,this.brtcClient=t.brtcClient}return e.createClass(o,[{key:"setPickAudioMode",value:function(e){this.pickAudioMode=e}},{key:"start",value:function(){return(i=i||e.asyncToGenerator(e.regeneratorRuntime().mark((function i(){var o,n=this;return e.regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.recording){e.next=2;break}return e.abrupt("return");case 2:return e.prev=2,this.audioContext=new(window.AudioContext||window.webkitAudioContext)({sampleRate:16e3}),e.next=6,navigator.mediaDevices.getUserMedia({audio:!0,video:!1});case 6:this.mediaStream=e.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(e){if(n.recording){var i=t([r(e.inputBuffer.getChannelData(0))],n.audioContext.sampleRate,16e3,null);i&&i.data&&n.onAudioData(i.data.buffer)}},this.recording=!0,"pressButton"===this.pickAudioMode&&this._bindKeyEvents(),e.next=19;break;case 16:e.prev=16,e.t0=e.catch(2),this.onError&&this.onError(e.t0);case 19:case"end":return e.stop()}}),i,this,[[2,16]])})))).apply(this,arguments)}},{key:"stop",value:function(){this.recording=!1,this.processor&&(this.processor.disconnect(),this.processor.onaudioprocess=null),this.audioContext&&this.audioContext.close(),this.mediaStream&&this.mediaStream.getTracks().forEach((function(e){e.stop()})),this._unbindKeyEvents()}},{key:"_bindKeyEvents",value:function(){var e=this;this.keydownHandler=function(t){"Space"===t.code&&e._onPressStart()},this.keyupHandler=function(t){"Space"===t.code&&e._onPressStop()},window.addEventListener("keydown",this.keydownHandler),window.addEventListener("keyup",this.keyupHandler)}},{key:"_unbindKeyEvents",value:function(){this.keydownHandler&&window.removeEventListener("keydown",this.keydownHandler),this.keyupHandler&&window.removeEventListener("keyup",this.keyupHandler)}},{key:"_onPressStart",value:function(){this.recording=!0,this.pullAudioFromRtc&&this.brtcClient&&this.brtcClient.muteMicphone(!1)}},{key:"_onPressStop",value:function(){this.recording=!1,this.pullAudioFromRtc&&this.brtcClient&&this.brtcClient.muteMicphone(!0)}}]),o}();exports.default=i;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./_virtual/_rollupPluginBabelHelpers.js");function t(e,t,r,o){try{for(var n=(o=o||{})&&"number"==typeof o.index?o.index:0,i=o&&"number"==typeof o.offset?o.offset:0,a=0,s=n;s<e.length;s++)a+=e[s].length;a=Math.max(0,a-Math.floor(i));var u=t/r;u>1?a=Math.floor(a/u):(u=1,r=t);for(var c=new Int16Array(a),d=0,h=e.length;n<h;n++){for(var l=e[n],f=i,p=l.length;f<p;){var m=Math.floor(f),v=Math.ceil(f),x=f-m;c[d]=l[m]+(l[v]-l[m])*x,d++,f+=u}i=f-p}return{index:n,offset:i,sampleRate:r,data:c}}catch(e){console.log("转音错误了",e)}}function r(e){for(var t=e,r=new Int16Array(e.length),o=0;o<t.length;o++){var n=Math.max(-1,Math.min(1,t[o]));r[o]=n<0?32768*n:32767*n}return r}var o=function(o){function n(t){e.classCallCheck(this,n),e.defineProperty(this,"onAudioData",void 0),e.defineProperty(this,"onError",void 0),e.defineProperty(this,"audioContext",null),e.defineProperty(this,"processor",null),e.defineProperty(this,"mediaStream",null),e.defineProperty(this,"recording",!1),this.onAudioData=t.onAudioData,this.onError=t.onError}return e.createClass(n,[{key:"start",value:function(){return(o=o||e.asyncToGenerator(e.regeneratorRuntime().mark((function o(){var n,i=this;return e.regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.recording){e.next=2;break}return e.abrupt("return");case 2:return e.prev=2,this.audioContext=new(window.AudioContext||window.webkitAudioContext)({sampleRate:16e3}),e.next=6,navigator.mediaDevices.getUserMedia({audio:!0,video:!1});case 6:this.mediaStream=e.sent,n=this.audioContext.createMediaStreamSource(this.mediaStream),this.processor=this.audioContext.createScriptProcessor(1024,1,1),n.connect(this.processor),this.processor.connect(this.audioContext.destination),this.processor.onaudioprocess=function(e){if(i.recording){var o=t([r(e.inputBuffer.getChannelData(0))],i.audioContext.sampleRate,16e3,null);o&&o.data&&i.onAudioData(o.data.buffer)}},this.recording=!0,e.next=18;break;case 15:e.prev=15,e.t0=e.catch(2),this.onError&&this.onError(e.t0);case 18:case"end":return e.stop()}}),o,this,[[2,15]])})))).apply(this,arguments)}},{key:"stop",value:function(){this.recording=!1,this.processor&&(this.processor.disconnect(),this.processor.onaudioprocess=null),this.audioContext&&this.audioContext.close(),this.mediaStream&&this.mediaStream.getTracks().forEach((function(e){e.stop()}))}}]),n}();exports.default=o;
package/cjs/Server.d.ts CHANGED
@@ -31,6 +31,7 @@ export interface createSocketParamsType {
31
31
  appId?: string;
32
32
  sessionId?: string;
33
33
  parameters?: ConnectParamsType;
34
+ reConnect?: boolean;
34
35
  onConnect: ConnectListener;
35
36
  onDigitalHumanCallback?: (data: CallbackMsgType) => void;
36
37
  }
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("./interface.js"),a=function(a){function c(a){var i,u=this;e.classCallCheck(this,c),e.defineProperty(this,"dhServerSocket",null),e.defineProperty(this,"socketClosingPromise",null),e.defineProperty(this,"url",void 0),e.defineProperty(this,"firstConnect",!0),e.defineProperty(this,"connectParams",null),e.defineProperty(this,"createSocket",(function(n){return(i=i||e.asyncToGenerator(e.regeneratorRuntime().mark((function n(o){var a,c,i,d;return e.regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(u.connectParams=o,a=o.token,c=o.sessionId,i=o.onConnect,d=o.onDigitalHumanCallback,!u.socketClosingPromise){e.next=5;break}return e.next=5,u.socketClosingPromise;case 5:if(!u.dhServerSocket){e.next=8;break}return e.next=8,u.closeSocket();case 8:return e.abrupt("return",new Promise((function(e,n){var o=t.createWebSocket(u.url,{reopen:!0,keepAlive:"heartbeat",combine:function(e,r){return e&&r&&e.requestId===r.requestId},onOpen:function(){if(u.dhServerSocket=o,c&&u.firstConnect)return o.request({action:"RE_CONNECT",requestId:r.v4(),body:JSON.stringify({token:a,sessionId:c})}).on((function(r,t){i(r),0!==r.code&&(t(),u.handleConnect()),e(o)})),void(u.firstConnect=!1);u.handleConnect()},onClose:function(){u.dhServerSocket=null,u.socketClosingPromise=null},onError:function(e){n(e)}});o.onReadyStateChange((function(e){0===e&&d&&d({status:s.statusEnum.DH_LIB_INIT}),d&&d({status:s.statusEnum.DH_LIB_FULL_STATUS,content:{type:"wsState",readyState:e,body:s.WS_STATUS_MAP[e]}})})),o.onMessage((function(e){var r=e.action;[s.errorTypeEnum.TIMEOUT_EXIT,s.errorTypeEnum.DISCONNECT_ALERT].includes(r)&&d&&d({status:s.statusEnum.DH_LIB_STATUS,content:{type:r}})})),o.open()})));case 9:case"end":return e.stop()}}),n)})))).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(u.dhServerSocket){e.next=2;break}return e.abrupt("return");case 2:return u.socketClosingPromise=u.dhServerSocket.close(),e.next=5,u.socketClosingPromise;case 5:u.dhServerSocket=null;case 6:case"end":return e.stop()}}),r)})))),e.defineProperty(this,"handleConnect",e.asyncToGenerator(e.regeneratorRuntime().mark((function t(){var a,c,i,d,p,l;return e.regeneratorRuntime().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(u.connectParams){t.next=2;break}return t.abrupt("return");case 2:if(a=u.connectParams,c=a.appId,i=a.appKey,d=a.token,p=a.parameters,l=a.onConnect,c||i||d){t.next=5;break}return t.abrupt("return");case 5:u.dhServerSocket&&u.dhServerSocket.request({action:"CONNECT",clientTs:(new Date).getTime(),requestId:r.v4(),body:JSON.stringify(e.objectSpread2(e.objectSpread2({token:d,appId:c,appKey:i},n(u.connectParams,s.CONNECT_MAIN_KEY)),{},{parameters:e.objectSpread2(e.objectSpread2({},o(p,["parameters"])),p&&p.parameters?p.parameters:{})}))}).on((function(e,r){l(e),0!==e.code&&r()}));case 6:case"end":return t.stop()}}),t)})))),this.url=a}return e.createClass(c,[{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)}}]),c}();exports.default=a;
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"),a=require("./interface.js"),c=function(c){function i(c){var u,d=this;e.classCallCheck(this,i),e.defineProperty(this,"dhServerSocket",null),e.defineProperty(this,"socketClosingPromise",null),e.defineProperty(this,"url",void 0),e.defineProperty(this,"firstConnect",!0),e.defineProperty(this,"connectParams",null),e.defineProperty(this,"createSocket",(function(n){return(u=u||e.asyncToGenerator(e.regeneratorRuntime().mark((function n(o){var c,i,u,p;return e.regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(d.connectParams=o,c=o.token,i=o.sessionId,u=o.onConnect,p=o.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,n){var o=t.createWebSocket(d.url,{reopen:s(d.connectParams,"reConnect",!0),keepAlive:"heartbeat",combine:function(e,r){return e&&r&&e.requestId===r.requestId},onOpen:function(){if(d.dhServerSocket=o,i&&d.firstConnect)return o.request({action:"RE_CONNECT",requestId:r.v4(),body:JSON.stringify({token:c,sessionId:i})}).on((function(r,t){u(r),0!==r.code&&(t(),d.handleConnect()),e(o)})),void(d.firstConnect=!1);d.handleConnect()},onClose:function(){d.dhServerSocket=null,d.socketClosingPromise=null},onError:function(e){n(e)}});o.onReadyStateChange((function(e){0===e&&p&&p({status:a.statusEnum.DH_LIB_INIT}),p&&p({status:a.statusEnum.DH_LIB_FULL_STATUS,content:{type:"wsState",readyState:e,body:a.WS_STATUS_MAP[e]}})})),o.onMessage((function(e){var r=e.action;[a.errorTypeEnum.TIMEOUT_EXIT,a.errorTypeEnum.DISCONNECT_ALERT].includes(r)&&p&&p({status:a.statusEnum.DH_LIB_STATUS,content:{type:r}})})),o.open()})));case 9:case"end":return e.stop()}}),n)})))).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,c,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,c=s.appId,i=s.appKey,u=s.token,p=s.parameters,l=s.onConnect,c||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:c,appKey:i},n(d.connectParams,a.CONNECT_MAIN_KEY)),{},{parameters:e.objectSpread2(e.objectSpread2({},o(p,["parameters"])),p&&p.parameters?p.parameters:{})}))}).on((function(e,r){l(e),0!==e.code&&r()}));case 6:case"end":return t.stop()}}),t)})))),this.url=c}return e.createClass(i,[{key:"sendMessage",value:function(t,n){return(c=c||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=c;
@@ -6,12 +6,14 @@ export interface ConnectDataType {
6
6
  message: string;
7
7
  }
8
8
  export interface ConnectParamsType {
9
- figureId: string | number;
9
+ figureId?: string | number;
10
10
  resolutionHeight: number;
11
11
  resolutionWidth: number;
12
+ x264BitRate?: number;
12
13
  cameraId?: string | number;
13
14
  characterOffset?: string;
14
15
  pickAudioMode?: 'pressButton' | 'free';
16
+ fullDuplex: boolean;
15
17
  autoChromaKey?: boolean;
16
18
  usingVideo?: boolean;
17
19
  ttsPer?: string | number;
@@ -22,7 +24,6 @@ export interface ConnectParamsType {
22
24
  pullAudioFromRtc?: boolean;
23
25
  inactiveDisconnectSec?: number;
24
26
  preAlertSec?: number;
25
- x264BitRate?: number;
26
27
  backgroundImageUrl?: string;
27
28
  projectId?: string;
28
29
  characterConfigId?: string;
@@ -36,6 +37,7 @@ export interface ConnectParamsType {
36
37
  paintWidgetOnPicture?: boolean;
37
38
  extraParameters?: any;
38
39
  parameters?: any;
40
+ reConnect?: boolean;
39
41
  }
40
42
  export declare const CONNECT_MAIN_KEY: string[];
41
43
  export interface RenderParamsType {
@@ -91,18 +93,14 @@ export interface CallbackMsgType {
91
93
  content?: ErrorType | WsStateType | RtcStateType | ConnectDataType;
92
94
  }
93
95
  export interface DhRealtimeHumanType {
94
- token: string;
96
+ token?: string;
95
97
  wsUrl?: string;
96
98
  rtcServerUrl?: string;
97
99
  appKey?: string;
98
100
  appId?: string;
99
101
  wrapperId: string;
100
- /**
101
- * connectParams.pickAudioMode: 'pressButton' | 'free',拾音模式
102
- * connectParams.pullAudioFromRtc: boolean,是否用rtc拾音
103
- */
104
- connectParams: ConnectParamsType;
105
- renderParams: RenderParamsType;
102
+ connectParams?: ConnectParamsType;
103
+ renderParams?: RenderParamsType;
106
104
  rtcConnectParams?: RtcConnectionType;
107
105
  brtcParams?: any;
108
106
  onDigitalHumanCallback: (data: CallbackMsgType) => void;
package/cjs/interface.js CHANGED
@@ -1 +1 @@
1
- "use strict";var _,E;exports.statusEnum=void 0,(_=exports.statusEnum||(exports.statusEnum={})).DH_LIB_INIT="DH_LIB_INIT",_.DH_LIB_WS_SUCCESS="DH_LIB_WS_SUCCESS",_.DH_LIB_OPEN="DH_LIB_OPEN",_.DH_LIB_STATUS="DH_LIB_STATUS",_.DH_LIB_CLOSE="DH_LIB_CLOSE",_.DH_LIB_ERROR="DH_LIB_ERROR",_.DH_LIB_WARNING="DH_LIB_WARNING",_.DH_LIB_FULL_STATUS="DH_LIB_FULL_STATUS",exports.errorTypeEnum=void 0,(E=exports.errorTypeEnum||(exports.errorTypeEnum={})).CONNECT_ERROR="CONNECT_ERROR",E.DISCONNECT_ALERT="DISCONNECT_ALERT",E.TIMEOUT_EXIT="TIMEOUT_EXIT",E.LOCAL_VIDEO_MUTED="LOCAL_VIDEO_MUTED",E.LOCAL_VIDEO_ERROR="LOCAL_VIDEO_ERROR",E.RTC_ERROR="RTC_ERROR";exports.CONNECT_MAIN_KEY=["projectId","characterConfigId","configVersion","selectors","figureName"],exports.WS_STATUS_MAP={"-1":"UNINSTANTIATED",0:"CONNECTING",1:"OPEN",2:"CLOSING",3:"CLOSED"};
1
+ "use strict";var _,E;exports.statusEnum=void 0,(_=exports.statusEnum||(exports.statusEnum={})).DH_LIB_INIT="DH_LIB_INIT",_.DH_LIB_WS_SUCCESS="DH_LIB_WS_SUCCESS",_.DH_LIB_OPEN="DH_LIB_OPEN",_.DH_LIB_STATUS="DH_LIB_STATUS",_.DH_LIB_CLOSE="DH_LIB_CLOSE",_.DH_LIB_ERROR="DH_LIB_ERROR",_.DH_LIB_WARNING="DH_LIB_WARNING",_.DH_LIB_FULL_STATUS="DH_LIB_FULL_STATUS",exports.errorTypeEnum=void 0,(E=exports.errorTypeEnum||(exports.errorTypeEnum={})).CONNECT_ERROR="CONNECT_ERROR",E.DISCONNECT_ALERT="DISCONNECT_ALERT",E.TIMEOUT_EXIT="TIMEOUT_EXIT",E.LOCAL_VIDEO_MUTED="LOCAL_VIDEO_MUTED",E.LOCAL_VIDEO_ERROR="LOCAL_VIDEO_ERROR",E.RTC_ERROR="RTC_ERROR";exports.CONNECT_MAIN_KEY=["projectId","characterConfigId","configVersion","selectors","figureName","reConnect"],exports.WS_STATUS_MAP={"-1":"UNINSTANTIATED",0:"CONNECTING",1:"OPEN",2:"CLOSING",3:"CLOSED"};
package/es/Client.d.ts CHANGED
@@ -21,6 +21,7 @@ export default class DhRealtimeHuman {
21
21
  private wsReadyState;
22
22
  constructor(props: DhRealtimeHumanType);
23
23
  onRemoteVideoComing: (id: number) => void;
24
+ onLocalStream: () => void;
24
25
  onRemoteVideoOn: () => void;
25
26
  connectListener: (data: ConnectDataType) => void;
26
27
  createServer: (sessionId?: string) => void;
package/es/Client.js CHANGED
@@ -1 +1 @@
1
- import{createClass as e,classCallCheck as t,defineProperty as r,objectSpread2 as n,asyncToGenerator as o,regeneratorRuntime as a}from"./_virtual/_rollupPluginBabelHelpers.js";import s from"@bddh/starling-json";import i from"lodash/isEmpty";import c from"lodash/omit";import d from"lodash/pick";import{v4 as u}from"uuid";import{statusEnum as l,errorTypeEnum as m,CONNECT_MAIN_KEY as h}from"./interface.js";import p from"./Server.js";import v from"./BrtcClient.js";import{createHumanDom as g,appendRtcDomStyle as S,RTC_VIDEO_ID as f,checkIsHuawei as C,playHumanVideo as I,muteHumanVideo as R,removeHumanDom as b,DEFAULT_CANVAS_ID as y}from"./DomControl.js";import k from"./Cutout.js";import D from"./RecordController.js";var T=function(){function T(e){var w=this;t(this,T),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",C()),r(this,"rtcServerUrl",void 0),r(this,"recordController",null),r(this,"wsReadyState",-1),r(this,"onRemoteVideoComing",(function(e){w.rtcConnectParams&&w.rtcConnectParams.feedId&&e===+w.rtcConnectParams.feedId&&w.rtcServer&&w.rtcServer.client&&w.rtcServer.client.subscribeStreaming("remotevideo500",+w.rtcConnectParams.feedId)})),r(this,"onRemoteVideoOn",(function(){setTimeout(o(a().mark((function e(){var t,r,n,o,s;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=document.getElementById(f),e.next=3,w.cutoutInstance&&w.cutoutInstance.updateSource(f);case 3:t&&(t.setAttribute("data-playing","true"),r=t.videoWidth,n=t.videoHeight,o=document.getElementById(y),s=o.getContext("2d"),o&&s&&(o.width=r,o.height=n,s.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&&w.onDigitalHumanCallback&&w.onDigitalHumanCallback({status:l.DH_LIB_WS_SUCCESS,content:e}),0===t){var o=s.parse(r),a=o.rtcServerUrl,i=o.appId,c=o.clientToken,d=o.roomName,u=o.clientId,h=o.feedId,p=o.chargeId;i&&d&&(w.rtcConnectParams={server:w.rtcServerUrl||a,appId:i,token:c,roomName:d,userId:u,feedId:h,chargeId:p},w.rtcServer&&w.rtcServer.openRtc(w.rtcConnectParams))}else w.onDigitalHumanCallback&&w.onDigitalHumanCallback({status:l.DH_LIB_ERROR,content:{type:m.CONNECT_ERROR,msg:{code:t,errMsg:n}}})})),r(this,"createServer",(function(e){w.dhServer&&w.dhServer.createSocket(n(n(n({token:w.token,appKey:w.appKey,appId:w.appId},e?{sessionId:e}:{}),d(w.connectParams,h)),{},{parameters:c(w.connectParams,h),onConnect:w.connectListener,onDigitalHumanCallback:function(e){var t;e.status===l.DH_LIB_FULL_STATUS&&"wsState"===(null===(t=e.content)||void 0===t?void 0:t.type)&&(w.wsReadyState=e.content.readyState),w.onDigitalHumanCallback&&w.onDigitalHumanCallback(e)}}))})),r(this,"checkHumanInstansce",(function(){w.dhServer||console.warn("请先初始化数字人示例")})),r(this,"sendMessage",(function(e,t){return w.dhServer&&w.dhServer.sendMessage(e,t)})),r(this,"interrupt",o(a().mark((function e(){return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",new Promise((function(e){w.dhServer&&w.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;w.checkHumanInstansce(),w.dhServer&&w.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,o=s.parse(r).first;w.checkHumanInstansce(),w.dhServer&&w.dhServer.sendMessage({requestId:t||u(),action:"TEXT_STREAM_RENDER",body:r,clientTs:(new Date).getTime()},o?n:null)})),r(this,"audioRender",(function(e){var t=e.body,r=e.onCallbackMsg;w.checkHumanInstansce(),w.dhServer&&w.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;w.checkHumanInstansce(),w.dhServer&&w.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;w.dhServer&&w.dhServer.sendMessage({requestId:t||u(),action:"TEXT_QUERY",body:r,clientTs:(new Date).getTime()},n)})),r(this,"destory",o(a().mark((function e(){return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,w.dhServer&&w.dhServer.closeSocket();case 2:w.rtcServer&&w.rtcServer.closeRtc(),b(),w.dhServer=null,w.rtcServer=null;case 6:case"end":return e.stop()}}),e)})))),r(this,"pauseHuman",(function(){return I(!1)})),r(this,"playHuman",(function(){return I(!0)})),r(this,"muteHuman",(function(){return R(!0)})),r(this,"unMuteHuman",(function(){var e=R(!1);try{return w.isHuawei?(e.pause(),e.play()):e.paused&&e.play()}catch(e){console.info(e)}}));var E=e.wrapperId,H=e.token,_=e.appKey,M=e.appId,P=e.connectParams,U=e.renderParams,A=e.rtcConnectParams,L=e.brtcParams,N=e.wsUrl,q=e.rtcServerUrl,x=e.onDigitalHumanCallback;this.token=H,this.appKey=_,this.appId=M,this.rtcServerUrl=q,this.connectParams=n({autoChromaKey:U.autoChromaKey},P);var O=U.fullStatus,B=U.closeLog;this.onDigitalHumanCallback=function(e){e.status!==l.DH_LIB_FULL_STATUS?x&&x(e):O&&x&&x(e)},this.dhServer=new p(N||"wss://open.xiling.baidu.com/cloud/digital-human-demonstration");var j=(g({autoChromaKey:!!U.autoChromaKey})||{}).playerWrapper,K=document.getElementById(E);K||console.error("dom with wrapperId is not find"),j&&K&&K.appendChild(j),S();var F=n({remotevideoviewid:E,showvideobps:!1,usingvideo:!1,usingaudio:!!P.pullAudioFromRtc,aspublisher:!!P.pullAudioFromRtc,autopublish:!!P.pullAudioFromRtc,usingdatachannel:!0,autoplaymuted:!1},L);this.rtcServer=new v({closeLog:B,videoWrapperId:f,rtcConfig:F,bizConfig:{},rtcCallback:{onRemoteVideoComing:this.onRemoteVideoComing,onDigitalHumanCallback:this.onDigitalHumanCallback}}),this.cutoutInstance=new k({sourceId:f}),i(A)||(this.rtcConnectParams=A,this.rtcServer.openRtc(A)),P.pullAudioFromRtc?this.recordController=null:this.recordController=new D({pickAudioMode:P.pickAudioMode,onAudioData:function(e){1===w.wsReadyState&&w.sendMessage(e,null)},onError:function(e){w.onDigitalHumanCallback&&w.onDigitalHumanCallback({status:l.DH_LIB_ERROR,content:{type:m.CONNECT_ERROR,msg:{code:-1,errMsg:e.message}}})}})}return e(T,[{key:"startRecord",value:function(){this.connectParams.pullAudioFromRtc?this.rtcServer&&this.rtcServer.muteMicphone(!1):this.recordController&&this.recordController.start()}},{key:"stopRecord",value:function(){if(this.connectParams.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)}}]),T}();export{T as default};
1
+ import{createClass as e,classCallCheck as t,defineProperty as r,objectSpread2 as n,asyncToGenerator as o,regeneratorRuntime as a}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 d}from"uuid";import{statusEnum as l,errorTypeEnum as m,CONNECT_MAIN_KEY as h}from"./interface.js";import p from"./Server.js";import v from"./BrtcClient.js";import{createHumanDom as f,appendRtcDomStyle as S,RTC_VIDEO_ID as g,checkIsHuawei as C,playHumanVideo as I,muteHumanVideo as R,removeHumanDom as y,DEFAULT_CANVAS_ID as b}from"./DomControl.js";import k from"./Cutout.js";import D from"./RecordController.js";var w=function(){function w(e){var T=this;t(this,w),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",C()),r(this,"rtcServerUrl",void 0),r(this,"recordController",null),r(this,"wsReadyState",-1),r(this,"onRemoteVideoComing",(function(e){T.rtcConnectParams&&T.rtcConnectParams.feedId&&e===+T.rtcConnectParams.feedId&&T.rtcServer&&T.rtcServer.client&&T.rtcServer.client.subscribeStreaming("remotevideo500",+T.rtcConnectParams.feedId)})),r(this,"onLocalStream",(function(){var e=T.connectParams,t=e.pullAudioFromRtc,r=e.pickAudioMode;t&&"pressButton"===r&&T.rtcServer&&T.rtcServer.muteMicphone(!0)})),r(this,"onRemoteVideoOn",(function(){setTimeout(o(a().mark((function e(){var t,r,n,o,s;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=document.getElementById(g),e.next=3,T.cutoutInstance&&T.cutoutInstance.updateSource(g);case 3:t&&(t.setAttribute("data-playing","true"),r=t.videoWidth,n=t.videoHeight,o=document.getElementById(b),s=o.getContext("2d"),o&&s&&(o.width=r,o.height=n,s.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&&T.onDigitalHumanCallback&&T.onDigitalHumanCallback({status:l.DH_LIB_WS_SUCCESS,content:e}),0===t){var o=s.parse(r),a=o.rtcServerUrl,i=o.appId,c=o.clientToken,u=o.roomName,d=o.clientId,h=o.feedId,p=o.chargeId;i&&u&&(T.rtcConnectParams={server:T.rtcServerUrl||a,appId:i,token:c,roomName:u,userId:d,feedId:h,chargeId:p},T.rtcServer&&T.rtcServer.openRtc(T.rtcConnectParams))}else T.onDigitalHumanCallback&&T.onDigitalHumanCallback({status:l.DH_LIB_ERROR,content:{type:m.CONNECT_ERROR,msg:{code:t,errMsg:n}}})})),r(this,"createServer",(function(e){T.dhServer&&T.dhServer.createSocket(n(n(n({token:T.token,appKey:T.appKey,appId:T.appId},e?{sessionId:e}:{}),u(T.connectParams,h)),{},{parameters:c(T.connectParams,h),onConnect:T.connectListener,onDigitalHumanCallback:function(e){var t;e.status===l.DH_LIB_FULL_STATUS&&"wsState"===(null===(t=e.content)||void 0===t?void 0:t.type)&&(T.wsReadyState=e.content.readyState),T.onDigitalHumanCallback&&T.onDigitalHumanCallback(e)}}))})),r(this,"checkHumanInstansce",(function(){T.dhServer||console.warn("请先初始化数字人示例")})),r(this,"sendMessage",(function(e,t){return T.dhServer&&T.dhServer.sendMessage(e,t)})),r(this,"interrupt",o(a().mark((function e(){return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",new Promise((function(e){T.dhServer&&T.dhServer.sendMessage({requestId:d(),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;T.checkHumanInstansce(),T.dhServer&&T.dhServer.sendMessage({requestId:t||d(),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,o=s.parse(r).first;T.checkHumanInstansce(),T.dhServer&&T.dhServer.sendMessage({requestId:t||d(),action:"TEXT_STREAM_RENDER",body:r,clientTs:(new Date).getTime()},o?n:null)})),r(this,"audioRender",(function(e){var t=e.body,r=e.onCallbackMsg;T.checkHumanInstansce(),T.dhServer&&T.dhServer.sendMessage({requestId:d(),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;T.checkHumanInstansce(),T.dhServer&&T.dhServer.sendMessage({requestId:t||d(),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;T.dhServer&&T.dhServer.sendMessage({requestId:t||d(),action:"TEXT_QUERY",body:r,clientTs:(new Date).getTime()},n)})),r(this,"destory",o(a().mark((function e(){return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,T.dhServer&&T.dhServer.closeSocket();case 2:T.rtcServer&&T.rtcServer.closeRtc(),y(),T.dhServer=null,T.rtcServer=null;case 6:case"end":return e.stop()}}),e)})))),r(this,"pauseHuman",(function(){return I(!1)})),r(this,"playHuman",(function(){return I(!0)})),r(this,"muteHuman",(function(){return R(!0)})),r(this,"unMuteHuman",(function(){var e=R(!1);try{return T.isHuawei?(e.pause(),e.play()):e.paused&&e.play()}catch(e){console.info(e)}}));var E=e.wrapperId,H=e.token,_=e.appKey,M=e.appId,P=e.connectParams,A=e.renderParams,U=void 0===A?{}:A,L=e.rtcConnectParams,x=e.brtcParams,q=e.wsUrl,N=e.rtcServerUrl,B=e.onDigitalHumanCallback;if(this.token=H,this.appKey=_,this.appId=M,this.rtcServerUrl=N,this.connectParams=n(n({autoChromaKey:(null==U?void 0:U.autoChromaKey)||!1},P),{},{pickAudioMode:null!=P&&P.fullDuplex?"free":"pressButton"}),this.connectParams.fullDuplex&&delete this.connectParams.fullDuplex,!M&&!_&&!H)throw new Error("appId and appKey or token is required");var O=U.fullStatus,K=U.closeLog;this.onDigitalHumanCallback=function(e){e.status!==l.DH_LIB_FULL_STATUS?B&&B(e):O&&B&&B(e)},this.dhServer=new p(q||"wss://open.xiling.baidu.com/cloud/digital-human-demonstration");var j=(f({autoChromaKey:!!U.autoChromaKey||!i(U.chromaEffects)})||{}).playerWrapper,F=document.getElementById(E);F||console.error("dom with wrapperId is not find"),j&&F&&F.appendChild(j),S();var Q=n({remotevideoviewid:E,showvideobps:!1,usingvideo:!1,usingaudio:!(null==P||!P.pullAudioFromRtc),aspublisher:!(null==P||!P.pullAudioFromRtc),autopublish:!(null==P||!P.pullAudioFromRtc),usingdatachannel:!0,autoplaymuted:!1},x);this.rtcServer=new v({closeLog:K,videoWrapperId:g,rtcConfig:Q,bizConfig:{},rtcCallback:{onRemoteVideoComing:this.onRemoteVideoComing,onDigitalHumanCallback:this.onDigitalHumanCallback,onLocalStream:this.onLocalStream}}),this.cutoutInstance=new k({sourceId:g,effects:null==U?void 0:U.chromaEffects}),i(L)||(this.rtcConnectParams=L,this.rtcServer.openRtc(L)),null!=P&&P.pullAudioFromRtc?this.recordController=null:this.recordController=new D({pickAudioMode:null==P?void 0:P.pickAudioMode,onAudioData:function(e){1===T.wsReadyState&&T.sendMessage(e,null)},onError:function(e){T.onDigitalHumanCallback&&T.onDigitalHumanCallback({status:l.DH_LIB_ERROR,content:{type:m.CONNECT_ERROR,msg:{code:-1,errMsg:e.message}}})}})}return e(w,[{key:"startRecord",value:function(){this.connectParams.pullAudioFromRtc?this.rtcServer&&this.rtcServer.muteMicphone(!1):this.recordController&&this.recordController.start()}},{key:"stopRecord",value:function(){if(this.connectParams.pullAudioFromRtc)return this.rtcServer&&this.rtcServer.muteMicphone(!0),void this.sendMessage({action:"AUDIO_QUERY_INTERRUPT",requestId:d(),clientTs:Date.now(),body:""},null);this.recordController&&this.recordController.stop(),this.sendMessage({action:"AUDIO_QUERY_INTERRUPT",requestId:d(),clientTs:Date.now(),body:""},null)}}]),w}();export{w as default};
@@ -7,24 +7,14 @@ interface RecordControllerOptions {
7
7
  brtcClient?: any;
8
8
  }
9
9
  declare class RecordController {
10
- private pickAudioMode;
11
10
  private readonly onAudioData;
12
11
  private readonly onError?;
13
12
  private audioContext;
14
13
  private processor;
15
14
  private mediaStream;
16
15
  private recording;
17
- private keydownHandler;
18
- private keyupHandler;
19
- private readonly pullAudioFromRtc;
20
- private readonly brtcClient;
21
16
  constructor(options: RecordControllerOptions);
22
- setPickAudioMode(mode: PickAudioMode): void;
23
17
  start(): Promise<void>;
24
18
  stop(): void;
25
- private _bindKeyEvents;
26
- private _unbindKeyEvents;
27
- private _onPressStart;
28
- private _onPressStop;
29
19
  }
30
20
  export default RecordController;
@@ -1 +1 @@
1
- import{createClass as t,asyncToGenerator as e,classCallCheck as i,defineProperty as o,regeneratorRuntime as n}from"./_virtual/_rollupPluginBabelHelpers.js";function r(t,e,i,o){try{for(var n=(o=o||{})&&"number"==typeof o.index?o.index:0,r=o&&"number"==typeof o.offset?o.offset:0,s=0,a=n;a<t.length;a++)s+=t[a].length;s=Math.max(0,s-Math.floor(r));var d=e/i;d>1?s=Math.floor(s/d):(d=1,i=e);for(var u=new Int16Array(s),c=0,h=t.length;n<h;n++){for(var l=t[n],p=r,f=l.length;p<f;){var v=Math.floor(p),k=Math.ceil(p),m=p-v;u[c]=l[v]+(l[k]-l[v])*m,c++,p+=d}r=p-f}return{index:n,offset:r,sampleRate:i,data:u}}catch(t){console.log("转音错误了",t)}}function s(t){for(var e=t,i=new Int16Array(t.length),o=0;o<e.length;o++){var n=Math.max(-1,Math.min(1,e[o]));i[o]=n<0?32768*n:32767*n}return i}var a=function(a){function d(t){i(this,d),o(this,"pickAudioMode",void 0),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,"keydownHandler",null),o(this,"keyupHandler",null),o(this,"pullAudioFromRtc",void 0),o(this,"brtcClient",void 0),this.pickAudioMode=t.pickAudioMode||"free",this.onAudioData=t.onAudioData,this.onError=t.onError,this.pullAudioFromRtc=!!t.pullAudioFromRtc,this.brtcClient=t.brtcClient}return t(d,[{key:"setPickAudioMode",value:function(t){this.pickAudioMode=t}},{key:"start",value:function(){return(a=a||e(n().mark((function t(){var e,i=this;return n().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!this.recording){t.next=2;break}return t.abrupt("return");case 2:return t.prev=2,this.audioContext=new(window.AudioContext||window.webkitAudioContext)({sampleRate:16e3}),t.next=6,navigator.mediaDevices.getUserMedia({audio:!0,video:!1});case 6:this.mediaStream=t.sent,e=this.audioContext.createMediaStreamSource(this.mediaStream),this.processor=this.audioContext.createScriptProcessor(1024,1,1),e.connect(this.processor),this.processor.connect(this.audioContext.destination),this.processor.onaudioprocess=function(t){if(i.recording){var e=r([s(t.inputBuffer.getChannelData(0))],i.audioContext.sampleRate,16e3,null);e&&e.data&&i.onAudioData(e.data.buffer)}},this.recording=!0,"pressButton"===this.pickAudioMode&&this._bindKeyEvents(),t.next=19;break;case 16:t.prev=16,t.t0=t.catch(2),this.onError&&this.onError(t.t0);case 19:case"end":return t.stop()}}),t,this,[[2,16]])})))).apply(this,arguments)}},{key:"stop",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()})),this._unbindKeyEvents()}},{key:"_bindKeyEvents",value:function(){var t=this;this.keydownHandler=function(e){"Space"===e.code&&t._onPressStart()},this.keyupHandler=function(e){"Space"===e.code&&t._onPressStop()},window.addEventListener("keydown",this.keydownHandler),window.addEventListener("keyup",this.keyupHandler)}},{key:"_unbindKeyEvents",value:function(){this.keydownHandler&&window.removeEventListener("keydown",this.keydownHandler),this.keyupHandler&&window.removeEventListener("keyup",this.keyupHandler)}},{key:"_onPressStart",value:function(){this.recording=!0,this.pullAudioFromRtc&&this.brtcClient&&this.brtcClient.muteMicphone(!1)}},{key:"_onPressStop",value:function(){this.recording=!1,this.pullAudioFromRtc&&this.brtcClient&&this.brtcClient.muteMicphone(!0)}}]),d}();export{a as default};
1
+ import{createClass as t,asyncToGenerator as e,classCallCheck as r,defineProperty as o,regeneratorRuntime as a}from"./_virtual/_rollupPluginBabelHelpers.js";function n(t,e,r,o){try{for(var a=(o=o||{})&&"number"==typeof o.index?o.index:0,n=o&&"number"==typeof o.offset?o.offset:0,i=0,s=a;s<t.length;s++)i+=t[s].length;i=Math.max(0,i-Math.floor(n));var c=e/r;c>1?i=Math.floor(i/c):(c=1,r=e);for(var u=new Int16Array(i),h=0,d=t.length;a<d;a++){for(var l=t[a],f=n,p=l.length;f<p;){var m=Math.floor(f),v=Math.ceil(f),x=f-m;u[h]=l[m]+(l[v]-l[m])*x,h++,f+=c}n=f-p}return{index:a,offset:n,sampleRate:r,data:u}}catch(t){console.log("转音错误了",t)}}function i(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 s=function(s){function c(t){r(this,c),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),this.onAudioData=t.onAudioData,this.onError=t.onError}return t(c,[{key:"start",value:function(){return(s=s||e(a().mark((function t(){var e,r=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:return t.prev=2,this.audioContext=new(window.AudioContext||window.webkitAudioContext)({sampleRate:16e3}),t.next=6,navigator.mediaDevices.getUserMedia({audio:!0,video:!1});case 6:this.mediaStream=t.sent,e=this.audioContext.createMediaStreamSource(this.mediaStream),this.processor=this.audioContext.createScriptProcessor(1024,1,1),e.connect(this.processor),this.processor.connect(this.audioContext.destination),this.processor.onaudioprocess=function(t){if(r.recording){var e=n([i(t.inputBuffer.getChannelData(0))],r.audioContext.sampleRate,16e3,null);e&&e.data&&r.onAudioData(e.data.buffer)}},this.recording=!0,t.next=18;break;case 15:t.prev=15,t.t0=t.catch(2),this.onError&&this.onError(t.t0);case 18:case"end":return t.stop()}}),t,this,[[2,15]])})))).apply(this,arguments)}},{key:"stop",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()}))}}]),c}();export{s as default};
package/es/Server.d.ts CHANGED
@@ -31,6 +31,7 @@ export interface createSocketParamsType {
31
31
  appId?: string;
32
32
  sessionId?: string;
33
33
  parameters?: ConnectParamsType;
34
+ reConnect?: boolean;
34
35
  onConnect: ConnectListener;
35
36
  onDigitalHumanCallback?: (data: CallbackMsgType) => void;
36
37
  }
package/es/Server.js CHANGED
@@ -1 +1 @@
1
- import{createClass as e,asyncToGenerator as t,classCallCheck as r,defineProperty as n,regeneratorRuntime as o,objectSpread2 as s,typeof as a}from"./_virtual/_rollupPluginBabelHelpers.js";import{v4 as c}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{errorTypeEnum as p,CONNECT_MAIN_KEY as d,statusEnum as f,WS_STATUS_MAP as h}from"./interface.js";var k=function(k){function m(e){var a,k=this;r(this,m),n(this,"dhServerSocket",null),n(this,"socketClosingPromise",null),n(this,"url",void 0),n(this,"firstConnect",!0),n(this,"connectParams",null),n(this,"createSocket",(function(e){return(a=a||t(o().mark((function e(t){var r,n,s,a;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(k.connectParams=t,r=t.token,n=t.sessionId,s=t.onConnect,a=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,t){var o=i(k.url,{reopen:!0,keepAlive:"heartbeat",combine:function(e,t){return e&&t&&e.requestId===t.requestId},onOpen:function(){if(k.dhServerSocket=o,n&&k.firstConnect)return o.request({action:"RE_CONNECT",requestId:c(),body:JSON.stringify({token:r,sessionId:n})}).on((function(t,r){s(t),0!==t.code&&(r(),k.handleConnect()),e(o)})),void(k.firstConnect=!1);k.handleConnect()},onClose:function(){k.dhServerSocket=null,k.socketClosingPromise=null},onError:function(e){t(e)}});o.onReadyStateChange((function(e){0===e&&a&&a({status:f.DH_LIB_INIT}),a&&a({status:f.DH_LIB_FULL_STATUS,content:{type:"wsState",readyState:e,body:h[e]}})})),o.onMessage((function(e){var t=e.action;[p.TIMEOUT_EXIT,p.DISCONNECT_ALERT].includes(t)&&a&&a({status:f.DH_LIB_STATUS,content:{type:t}})})),o.open()})));case 9:case"end":return e.stop()}}),e)})))).apply(this,arguments)})),n(this,"closeSocket",t(o().mark((function e(){return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(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)})))),n(this,"handleConnect",t(o().mark((function e(){var t,r,n,a,i,p;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,r=t.appId,n=t.appKey,a=t.token,i=t.parameters,p=t.onConnect,r||n||a){e.next=5;break}return e.abrupt("return");case 5:k.dhServerSocket&&k.dhServerSocket.request({action:"CONNECT",clientTs:(new Date).getTime(),requestId:c(),body:JSON.stringify(s(s({token:a,appId:r,appKey:n},u(k.connectParams,d)),{},{parameters:s(s({},l(i,["parameters"])),i&&i.parameters?i.parameters:{})}))}).on((function(e,t){p(e),0!==e.code&&t()}));case 6:case"end":return e.stop()}}),e)})))),this.url=e}return e(m,[{key:"sendMessage",value:function(e,r){return(k=k||t(o().mark((function e(t,r){var n;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:try{this.dhServerSocket&&this.dhServerSocket&&this.dhServerSocket.request(t).on((function(e){r&&r(e)}))}catch(e){n="object"===a(t)&&"requestId"in t?t.requestId:c(),r&&r({code:-11,body:null,action:"RENDER_ERROR",requestId:n,message:JSON.stringify(e)})}case 1:case"end":return e.stop()}}),e,this)})))).apply(this,arguments)}}]),m}();export{k as default};
1
+ import{createClass as e,asyncToGenerator as t,classCallCheck as r,defineProperty as n,regeneratorRuntime as o,objectSpread2 as s,typeof as a}from"./_virtual/_rollupPluginBabelHelpers.js";import{v4 as c}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 p from"lodash/get";import{errorTypeEnum as d,CONNECT_MAIN_KEY as f,statusEnum as h,WS_STATUS_MAP as m}from"./interface.js";var k=function(k){function S(e){var a,k=this;r(this,S),n(this,"dhServerSocket",null),n(this,"socketClosingPromise",null),n(this,"url",void 0),n(this,"firstConnect",!0),n(this,"connectParams",null),n(this,"createSocket",(function(e){return(a=a||t(o().mark((function e(t){var r,n,s,a;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(k.connectParams=t,r=t.token,n=t.sessionId,s=t.onConnect,a=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,t){var o=i(k.url,{reopen:p(k.connectParams,"reConnect",!0),keepAlive:"heartbeat",combine:function(e,t){return e&&t&&e.requestId===t.requestId},onOpen:function(){if(k.dhServerSocket=o,n&&k.firstConnect)return o.request({action:"RE_CONNECT",requestId:c(),body:JSON.stringify({token:r,sessionId:n})}).on((function(t,r){s(t),0!==t.code&&(r(),k.handleConnect()),e(o)})),void(k.firstConnect=!1);k.handleConnect()},onClose:function(){k.dhServerSocket=null,k.socketClosingPromise=null},onError:function(e){t(e)}});o.onReadyStateChange((function(e){0===e&&a&&a({status:h.DH_LIB_INIT}),a&&a({status:h.DH_LIB_FULL_STATUS,content:{type:"wsState",readyState:e,body:m[e]}})})),o.onMessage((function(e){var t=e.action;[d.TIMEOUT_EXIT,d.DISCONNECT_ALERT].includes(t)&&a&&a({status:h.DH_LIB_STATUS,content:{type:t}})})),o.open()})));case 9:case"end":return e.stop()}}),e)})))).apply(this,arguments)})),n(this,"closeSocket",t(o().mark((function e(){return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(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)})))),n(this,"handleConnect",t(o().mark((function e(){var t,r,n,a,i,p;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,r=t.appId,n=t.appKey,a=t.token,i=t.parameters,p=t.onConnect,r||n||a){e.next=5;break}return e.abrupt("return");case 5:k.dhServerSocket&&k.dhServerSocket.request({action:"CONNECT",clientTs:(new Date).getTime(),requestId:c(),body:JSON.stringify(s(s({token:a,appId:r,appKey:n},u(k.connectParams,f)),{},{parameters:s(s({},l(i,["parameters"])),i&&i.parameters?i.parameters:{})}))}).on((function(e,t){p(e),0!==e.code&&t()}));case 6:case"end":return e.stop()}}),e)})))),this.url=e}return e(S,[{key:"sendMessage",value:function(e,r){return(k=k||t(o().mark((function e(t,r){var n;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:try{this.dhServerSocket&&this.dhServerSocket&&this.dhServerSocket.request(t).on((function(e){r&&r(e)}))}catch(e){n="object"===a(t)&&"requestId"in t?t.requestId:c(),r&&r({code:-11,body:null,action:"RENDER_ERROR",requestId:n,message:JSON.stringify(e)})}case 1:case"end":return e.stop()}}),e,this)})))).apply(this,arguments)}}]),S}();export{k as default};
package/es/interface.d.ts CHANGED
@@ -6,12 +6,14 @@ export interface ConnectDataType {
6
6
  message: string;
7
7
  }
8
8
  export interface ConnectParamsType {
9
- figureId: string | number;
9
+ figureId?: string | number;
10
10
  resolutionHeight: number;
11
11
  resolutionWidth: number;
12
+ x264BitRate?: number;
12
13
  cameraId?: string | number;
13
14
  characterOffset?: string;
14
15
  pickAudioMode?: 'pressButton' | 'free';
16
+ fullDuplex: boolean;
15
17
  autoChromaKey?: boolean;
16
18
  usingVideo?: boolean;
17
19
  ttsPer?: string | number;
@@ -22,7 +24,6 @@ export interface ConnectParamsType {
22
24
  pullAudioFromRtc?: boolean;
23
25
  inactiveDisconnectSec?: number;
24
26
  preAlertSec?: number;
25
- x264BitRate?: number;
26
27
  backgroundImageUrl?: string;
27
28
  projectId?: string;
28
29
  characterConfigId?: string;
@@ -36,6 +37,7 @@ export interface ConnectParamsType {
36
37
  paintWidgetOnPicture?: boolean;
37
38
  extraParameters?: any;
38
39
  parameters?: any;
40
+ reConnect?: boolean;
39
41
  }
40
42
  export declare const CONNECT_MAIN_KEY: string[];
41
43
  export interface RenderParamsType {
@@ -91,18 +93,14 @@ export interface CallbackMsgType {
91
93
  content?: ErrorType | WsStateType | RtcStateType | ConnectDataType;
92
94
  }
93
95
  export interface DhRealtimeHumanType {
94
- token: string;
96
+ token?: string;
95
97
  wsUrl?: string;
96
98
  rtcServerUrl?: string;
97
99
  appKey?: string;
98
100
  appId?: string;
99
101
  wrapperId: string;
100
- /**
101
- * connectParams.pickAudioMode: 'pressButton' | 'free',拾音模式
102
- * connectParams.pullAudioFromRtc: boolean,是否用rtc拾音
103
- */
104
- connectParams: ConnectParamsType;
105
- renderParams: RenderParamsType;
102
+ connectParams?: ConnectParamsType;
103
+ renderParams?: RenderParamsType;
106
104
  rtcConnectParams?: RtcConnectionType;
107
105
  brtcParams?: any;
108
106
  onDigitalHumanCallback: (data: CallbackMsgType) => void;
package/es/interface.js CHANGED
@@ -1 +1 @@
1
- var _,I,E=["projectId","characterConfigId","configVersion","selectors","figureName"];!function(_){_.DH_LIB_INIT="DH_LIB_INIT",_.DH_LIB_WS_SUCCESS="DH_LIB_WS_SUCCESS",_.DH_LIB_OPEN="DH_LIB_OPEN",_.DH_LIB_STATUS="DH_LIB_STATUS",_.DH_LIB_CLOSE="DH_LIB_CLOSE",_.DH_LIB_ERROR="DH_LIB_ERROR",_.DH_LIB_WARNING="DH_LIB_WARNING",_.DH_LIB_FULL_STATUS="DH_LIB_FULL_STATUS"}(_||(_={})),function(_){_.CONNECT_ERROR="CONNECT_ERROR",_.DISCONNECT_ALERT="DISCONNECT_ALERT",_.TIMEOUT_EXIT="TIMEOUT_EXIT",_.LOCAL_VIDEO_MUTED="LOCAL_VIDEO_MUTED",_.LOCAL_VIDEO_ERROR="LOCAL_VIDEO_ERROR",_.RTC_ERROR="RTC_ERROR"}(I||(I={}));var L={"-1":"UNINSTANTIATED",0:"CONNECTING",1:"OPEN",2:"CLOSING",3:"CLOSED"};export{E as CONNECT_MAIN_KEY,L as WS_STATUS_MAP,I as errorTypeEnum,_ as statusEnum};
1
+ var _,I,E=["projectId","characterConfigId","configVersion","selectors","figureName","reConnect"];!function(_){_.DH_LIB_INIT="DH_LIB_INIT",_.DH_LIB_WS_SUCCESS="DH_LIB_WS_SUCCESS",_.DH_LIB_OPEN="DH_LIB_OPEN",_.DH_LIB_STATUS="DH_LIB_STATUS",_.DH_LIB_CLOSE="DH_LIB_CLOSE",_.DH_LIB_ERROR="DH_LIB_ERROR",_.DH_LIB_WARNING="DH_LIB_WARNING",_.DH_LIB_FULL_STATUS="DH_LIB_FULL_STATUS"}(_||(_={})),function(_){_.CONNECT_ERROR="CONNECT_ERROR",_.DISCONNECT_ALERT="DISCONNECT_ALERT",_.TIMEOUT_EXIT="TIMEOUT_EXIT",_.LOCAL_VIDEO_MUTED="LOCAL_VIDEO_MUTED",_.LOCAL_VIDEO_ERROR="LOCAL_VIDEO_ERROR",_.RTC_ERROR="RTC_ERROR"}(I||(I={}));var L={"-1":"UNINSTANTIATED",0:"CONNECTING",1:"OPEN",2:"CLOSING",3:"CLOSED"};export{E as CONNECT_MAIN_KEY,L as WS_STATUS_MAP,I as errorTypeEnum,_ as statusEnum};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bddh/starling-realtime-client",
3
- "version": "2.0.0-beta.1",
3
+ "version": "2.0.0-beta.3",
4
4
  "keywords": [
5
5
  "react",
6
6
  "indexDB"
@@ -44,5 +44,5 @@
44
44
  "lodash": "^4.17.21",
45
45
  "uuid": "^9.0.0"
46
46
  },
47
- "gitHead": "4b939d48e9218bfb784cade384b79980080b4771"
47
+ "gitHead": "8695e15da646e456c84b5f4469ec5bf4f3d38dfc"
48
48
  }