@bddh/starling-realtime-client 1.0.11 → 2.0.0-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.
- package/cjs/BrtcClient.d.ts +1 -0
- package/cjs/BrtcClient.js +1 -1
- package/cjs/Client.d.ts +10 -1
- package/cjs/Client.js +1 -1
- package/cjs/RecordController.d.ts +30 -0
- package/cjs/RecordController.js +1 -0
- package/cjs/Server.d.ts +3 -2
- package/cjs/Server.js +1 -1
- package/cjs/_virtual/_rollupPluginBabelHelpers.js +1 -1
- package/cjs/interface.d.ts +7 -6
- package/cjs/interface.js +1 -1
- package/es/BrtcClient.d.ts +1 -0
- package/es/BrtcClient.js +1 -1
- package/es/Client.d.ts +10 -1
- package/es/Client.js +1 -1
- package/es/RecordController.d.ts +30 -0
- package/es/RecordController.js +1 -0
- package/es/Server.d.ts +3 -2
- package/es/Server.js +1 -1
- package/es/_virtual/_rollupPluginBabelHelpers.js +1 -1
- package/es/interface.d.ts +7 -6
- package/es/interface.js +1 -1
- package/package.json +2 -2
package/cjs/BrtcClient.d.ts
CHANGED
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"),
|
|
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,C=s.rtcCallback||{},f=C.onRemotedata,b=C.onLocalStream,g=C.onRemoteVideoComing,y=C.onLocalVideoPublished,h=C.onLocalVideoPublishing,v=C.onRemoteVideoOn,p=C.onRemoteVideoOff,R=C.onRemoteVideoLoading,L=C.onSuccess,S=C.onError,k=C.onLocalVideoConnected,E=C.onRemoteVideoConnected,V=C.onRemoteMediaState,P=C.onPlayingError,_=C.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");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(f)&&f(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,C=void 0===m||m,f=l.rtcCallback;this.rtcConnection=d,this.rtcConfig=u,this.rtcCallback=f,this.closeLog=C,this.timeoutEvent=new o.TimeoutController(6e4,(function(){if(!s.rtcConnection)return!s.closeLog&&console.warn("remotevideoon事件超时, rtcConnectionRef is null");s.timeoutEvent.clear(),s.restartRtc&&s.restartRtc(s.rtcConnection)}))}return e.createClass(a,[{key:"muteMicphone",value:function(e){this.client&&this.client.muteMicphone&&this.client.muteMicphone(e)}}]),a}();exports.default=a;
|
package/cjs/Client.d.ts
CHANGED
|
@@ -17,13 +17,15 @@ export default class DhRealtimeHuman {
|
|
|
17
17
|
private readonly cutoutInstance;
|
|
18
18
|
private readonly isHuawei;
|
|
19
19
|
private readonly rtcServerUrl;
|
|
20
|
+
private readonly recordController;
|
|
21
|
+
private wsReadyState;
|
|
20
22
|
constructor(props: DhRealtimeHumanType);
|
|
21
23
|
onRemoteVideoComing: (id: number) => void;
|
|
22
24
|
onRemoteVideoOn: () => void;
|
|
23
25
|
connectListener: (data: ConnectDataType) => void;
|
|
24
26
|
createServer: (sessionId?: string) => void;
|
|
25
27
|
checkHumanInstansce: () => void;
|
|
26
|
-
sendMessage: (message: DHServerInterface, listener: RenderCallback | null) => Promise<void> | null;
|
|
28
|
+
sendMessage: (message: DHServerInterface | ArrayBuffer, listener: RenderCallback | null) => Promise<void> | null;
|
|
27
29
|
interrupt: () => Promise<void>;
|
|
28
30
|
textRender: (renderData: {
|
|
29
31
|
requestId: string;
|
|
@@ -44,9 +46,16 @@ export default class DhRealtimeHuman {
|
|
|
44
46
|
body: string;
|
|
45
47
|
onCallbackMsg: RenderCallback;
|
|
46
48
|
}) => void;
|
|
49
|
+
textQuery: (queryData: {
|
|
50
|
+
requestId: string;
|
|
51
|
+
body: string;
|
|
52
|
+
onCallbackMsg: RenderCallback;
|
|
53
|
+
}) => void;
|
|
47
54
|
destory: () => Promise<void>;
|
|
48
55
|
pauseHuman: () => void | Promise<void>;
|
|
49
56
|
playHuman: () => void | Promise<void>;
|
|
50
57
|
muteHuman: () => HTMLVideoElement;
|
|
51
58
|
unMuteHuman: () => false | Promise<void> | undefined;
|
|
59
|
+
startRecord(): void;
|
|
60
|
+
stopRecord(): void;
|
|
52
61
|
}
|
package/cjs/Client.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./_virtual/_rollupPluginBabelHelpers.js"),
|
|
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=void 0===C?{}:C,R=m.rtcConnectParams,P=m.brtcParams,b=m.wsUrl,E=m.rtcServerUrl,D=m.onDigitalHumanCallback;if(this.token=f,this.appKey=y,this.appId=g,this.rtcServerUrl=E,this.connectParams=e.objectSpread2({autoChromaKey:(null==I?void 0:I.autoChromaKey)||!1},S),!g&&!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?D&&D(e):T&&D&&D(e)},this.dhServer=new s.default(b||"wss://open.xiling.baidu.com/cloud/digital-human-demonstration");var _=(d.createHumanDom({autoChromaKey:!!I.autoChromaKey||!r(I.chromaEffects)})||{}).playerWrapper,H=document.getElementById(v);H||console.error("dom with wrapperId is not find"),_&&H&&H.appendChild(_),d.appendRtcDomStyle();var w=e.objectSpread2({remotevideoviewid:v,showvideobps:!1,usingvideo:!1,usingaudio:!(null==S||!S.pullAudioFromRtc),aspublisher:!(null==S||!S.pullAudioFromRtc),autopublish:!(null==S||!S.pullAudioFromRtc),usingdatachannel:!0,autoplaymuted:!1},P);this.rtcServer=new c.default({closeLog:k,videoWrapperId:d.RTC_VIDEO_ID,rtcConfig:w,bizConfig:{},rtcCallback:{onRemoteVideoComing:this.onRemoteVideoComing,onDigitalHumanCallback:this.onDigitalHumanCallback}}),this.cutoutInstance=new u.default({sourceId:d.RTC_VIDEO_ID,effects:null==I?void 0:I.chromaEffects}),r(R)||(this.rtcConnectParams=R,this.rtcServer.openRtc(R)),null!=S&&S.pullAudioFromRtc?this.recordController=null:this.recordController=new l.default({pickAudioMode:null==S?void 0: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;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export type PickAudioMode = 'pressButton' | 'free';
|
|
2
|
+
interface RecordControllerOptions {
|
|
3
|
+
pickAudioMode?: PickAudioMode;
|
|
4
|
+
onAudioData: (pcmData: ArrayBuffer) => void;
|
|
5
|
+
onError?: (err: Error) => void;
|
|
6
|
+
pullAudioFromRtc?: boolean;
|
|
7
|
+
brtcClient?: any;
|
|
8
|
+
}
|
|
9
|
+
declare class RecordController {
|
|
10
|
+
private pickAudioMode;
|
|
11
|
+
private readonly onAudioData;
|
|
12
|
+
private readonly onError?;
|
|
13
|
+
private audioContext;
|
|
14
|
+
private processor;
|
|
15
|
+
private mediaStream;
|
|
16
|
+
private recording;
|
|
17
|
+
private keydownHandler;
|
|
18
|
+
private keyupHandler;
|
|
19
|
+
private readonly pullAudioFromRtc;
|
|
20
|
+
private readonly brtcClient;
|
|
21
|
+
constructor(options: RecordControllerOptions);
|
|
22
|
+
setPickAudioMode(mode: PickAudioMode): void;
|
|
23
|
+
start(): Promise<void>;
|
|
24
|
+
stop(): void;
|
|
25
|
+
private _bindKeyEvents;
|
|
26
|
+
private _unbindKeyEvents;
|
|
27
|
+
private _onPressStart;
|
|
28
|
+
private _onPressStop;
|
|
29
|
+
}
|
|
30
|
+
export default RecordController;
|
|
@@ -0,0 +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;
|
package/cjs/Server.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export interface DHServerInterface {
|
|
|
15
15
|
action: string;
|
|
16
16
|
requestId: string;
|
|
17
17
|
clientTs: number;
|
|
18
|
-
body: string;
|
|
18
|
+
body: string | ArrayBuffer;
|
|
19
19
|
}
|
|
20
20
|
export interface DHErrServerInterface {
|
|
21
21
|
action: string;
|
|
@@ -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
|
}
|
|
@@ -52,6 +53,6 @@ declare class Server {
|
|
|
52
53
|
createSocket: (props: createSocketParamsType) => Promise<WebSocketClient | null>;
|
|
53
54
|
closeSocket: () => Promise<void>;
|
|
54
55
|
handleConnect: () => Promise<void>;
|
|
55
|
-
sendMessage(message: DHServerInterface, listener: RenderCallback | null): Promise<void>;
|
|
56
|
+
sendMessage(message: DHServerInterface | ArrayBuffer, listener: RenderCallback | null): Promise<void>;
|
|
56
57
|
}
|
|
57
58
|
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("./interface.js"),
|
|
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;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";function t(t,r){var e=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(t,r).enumerable}))),e.push.apply(e,n)}return e}function r(){r=function(){return e};var t,e={},n=Object.prototype,o=n.hasOwnProperty,i=Object.defineProperty||function(t,r,e){t[r]=e.value},a="function"==typeof Symbol?Symbol:{},c=a.iterator||"@@iterator",u=a.asyncIterator||"@@asyncIterator",f=a.toStringTag||"@@toStringTag";function l(t,r,e){return Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}),t[r]}try{l({},"")}catch(t){l=function(t,r,e){return t[r]=e}}function s(t,r,e,n){var o=r&&r.prototype instanceof m?r:m,a=Object.create(o.prototype),c=new N(n||[]);return i(a,"_invoke",{value:
|
|
1
|
+
"use strict";function t(t,r){var e=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(t,r).enumerable}))),e.push.apply(e,n)}return e}function r(){r=function(){return e};var t,e={},n=Object.prototype,o=n.hasOwnProperty,i=Object.defineProperty||function(t,r,e){t[r]=e.value},a="function"==typeof Symbol?Symbol:{},c=a.iterator||"@@iterator",u=a.asyncIterator||"@@asyncIterator",f=a.toStringTag||"@@toStringTag";function l(t,r,e){return Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}),t[r]}try{l({},"")}catch(t){l=function(t,r,e){return t[r]=e}}function s(t,r,e,n){var o=r&&r.prototype instanceof m?r:m,a=Object.create(o.prototype),c=new N(n||[]);return i(a,"_invoke",{value:S(t,e,c)}),a}function h(t,r,e){try{return{type:"normal",arg:t.call(r,e)}}catch(t){return{type:"throw",arg:t}}}e.wrap=s;var p="suspendedStart",y="suspendedYield",v="executing",g="completed",d={};function m(){}function b(){}function w(){}var x={};l(x,c,(function(){return this}));var O=Object.getPrototypeOf,j=O&&O(O(T([])));j&&j!==n&&o.call(j,c)&&(x=j);var L=w.prototype=m.prototype=Object.create(x);function E(t){["next","throw","return"].forEach((function(r){l(t,r,(function(t){return this._invoke(r,t)}))}))}function P(t,r){function e(n,i,a,c){var u=h(t[n],t,i);if("throw"!==u.type){var f=u.arg,l=f.value;return l&&"object"==typeof l&&o.call(l,"__await")?r.resolve(l.__await).then((function(t){e("next",t,a,c)}),(function(t){e("throw",t,a,c)})):r.resolve(l).then((function(t){f.value=t,a(f)}),(function(t){return e("throw",t,a,c)}))}c(u.arg)}var n;i(this,"_invoke",{value:function(t,o){function i(){return new r((function(r,n){e(t,o,r,n)}))}return n=n?n.then(i,i):i()}})}function S(r,e,n){var o=p;return function(i,a){if(o===v)throw new Error("Generator is already running");if(o===g){if("throw"===i)throw a;return{value:t,done:!0}}for(n.method=i,n.arg=a;;){var c=n.delegate;if(c){var u=_(c,n);if(u){if(u===d)continue;return u}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(o===p)throw o=g,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o=v;var f=h(r,e,n);if("normal"===f.type){if(o=n.done?g:y,f.arg===d)continue;return{value:f.arg,done:n.done}}"throw"===f.type&&(o=g,n.method="throw",n.arg=f.arg)}}}function _(r,e){var n=e.method,o=r.iterator[n];if(o===t)return e.delegate=null,"throw"===n&&r.iterator.return&&(e.method="return",e.arg=t,_(r,e),"throw"===e.method)||"return"!==n&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+n+"' method")),d;var i=h(o,r.iterator,e.arg);if("throw"===i.type)return e.method="throw",e.arg=i.arg,e.delegate=null,d;var a=i.arg;return a?a.done?(e[r.resultName]=a.value,e.next=r.nextLoc,"return"!==e.method&&(e.method="next",e.arg=t),e.delegate=null,d):a:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,d)}function k(t){var r={tryLoc:t[0]};1 in t&&(r.catchLoc=t[1]),2 in t&&(r.finallyLoc=t[2],r.afterLoc=t[3]),this.tryEntries.push(r)}function G(t){var r=t.completion||{};r.type="normal",delete r.arg,t.completion=r}function N(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(k,this),this.reset(!0)}function T(r){if(r||""===r){var e=r[c];if(e)return e.call(r);if("function"==typeof r.next)return r;if(!isNaN(r.length)){var n=-1,i=function e(){for(;++n<r.length;)if(o.call(r,n))return e.value=r[n],e.done=!1,e;return e.value=t,e.done=!0,e};return i.next=i}}throw new TypeError(typeof r+" is not iterable")}return b.prototype=w,i(L,"constructor",{value:w,configurable:!0}),i(w,"constructor",{value:b,configurable:!0}),b.displayName=l(w,f,"GeneratorFunction"),e.isGeneratorFunction=function(t){var r="function"==typeof t&&t.constructor;return!!r&&(r===b||"GeneratorFunction"===(r.displayName||r.name))},e.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,w):(t.__proto__=w,l(t,f,"GeneratorFunction")),t.prototype=Object.create(L),t},e.awrap=function(t){return{__await:t}},E(P.prototype),l(P.prototype,u,(function(){return this})),e.AsyncIterator=P,e.async=function(t,r,n,o,i){void 0===i&&(i=Promise);var a=new P(s(t,r,n,o),i);return e.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},E(L),l(L,f,"Generator"),l(L,c,(function(){return this})),l(L,"toString",(function(){return"[object Generator]"})),e.keys=function(t){var r=Object(t),e=[];for(var n in r)e.push(n);return e.reverse(),function t(){for(;e.length;){var n=e.pop();if(n in r)return t.value=n,t.done=!1,t}return t.done=!0,t}},e.values=T,N.prototype={constructor:N,reset:function(r){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(G),!r)for(var e in this)"t"===e.charAt(0)&&o.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(r){if(this.done)throw r;var e=this;function n(n,o){return c.type="throw",c.arg=r,e.next=n,o&&(e.method="next",e.arg=t),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],c=a.completion;if("root"===a.tryLoc)return n("end");if(a.tryLoc<=this.prev){var u=o.call(a,"catchLoc"),f=o.call(a,"finallyLoc");if(u&&f){if(this.prev<a.catchLoc)return n(a.catchLoc,!0);if(this.prev<a.finallyLoc)return n(a.finallyLoc)}else if(u){if(this.prev<a.catchLoc)return n(a.catchLoc,!0)}else{if(!f)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return n(a.finallyLoc)}}}},abrupt:function(t,r){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.tryLoc<=this.prev&&o.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var i=n;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=r&&r<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=r,i?(this.method="next",this.next=i.finallyLoc,d):this.complete(a)},complete:function(t,r){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&r&&(this.next=r),d},finish:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.finallyLoc===t)return this.complete(e.completion,e.afterLoc),G(e),d}},catch:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.tryLoc===t){var n=e.completion;if("throw"===n.type){var o=n.arg;G(e)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(r,e,n){return this.delegate={iterator:T(r),resultName:e,nextLoc:n},"next"===this.method&&(this.arg=t),d}},e}function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},e(t)}function n(t,r,e,n,o,i,a){try{var c=t[i](a),u=c.value}catch(t){return void e(t)}c.done?r(u):Promise.resolve(u).then(n,o)}function o(t,r){for(var e=0;e<r.length;e++){var n=r[e];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,c(n.key),n)}}function i(t,r,e){return(r=c(r))in t?Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[r]=e,t}function a(t,r){if("object"!=typeof t||null===t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,r||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(t)}function c(t){var r=a(t,"string");return"symbol"==typeof r?r:String(r)}exports.asyncToGenerator=function(t){return function(){var r=this,e=arguments;return new Promise((function(o,i){var a=t.apply(r,e);function c(t){n(a,o,i,c,u,"next",t)}function u(t){n(a,o,i,c,u,"throw",t)}c(void 0)}))}},exports.classCallCheck=function(t,r){if(!(t instanceof r))throw new TypeError("Cannot call a class as a function")},exports.createClass=function(t,r,e){return r&&o(t.prototype,r),e&&o(t,e),Object.defineProperty(t,"prototype",{writable:!1}),t},exports.defineProperty=i,exports.objectSpread2=function(r){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?t(Object(n),!0).forEach((function(t){i(r,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(n)):t(Object(n)).forEach((function(t){Object.defineProperty(r,t,Object.getOwnPropertyDescriptor(n,t))}))}return r},exports.regeneratorRuntime=r,exports.toPrimitive=a,exports.toPropertyKey=c,exports.typeof=e;
|
package/cjs/interface.d.ts
CHANGED
|
@@ -6,12 +6,13 @@ export interface ConnectDataType {
|
|
|
6
6
|
message: string;
|
|
7
7
|
}
|
|
8
8
|
export interface ConnectParamsType {
|
|
9
|
-
figureId
|
|
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
|
-
pickAudioMode?:
|
|
15
|
+
pickAudioMode?: 'pressButton' | 'free';
|
|
15
16
|
autoChromaKey?: boolean;
|
|
16
17
|
usingVideo?: boolean;
|
|
17
18
|
ttsPer?: string | number;
|
|
@@ -22,7 +23,6 @@ export interface ConnectParamsType {
|
|
|
22
23
|
pullAudioFromRtc?: boolean;
|
|
23
24
|
inactiveDisconnectSec?: number;
|
|
24
25
|
preAlertSec?: number;
|
|
25
|
-
x264BitRate?: number;
|
|
26
26
|
backgroundImageUrl?: string;
|
|
27
27
|
projectId?: string;
|
|
28
28
|
characterConfigId?: string;
|
|
@@ -36,6 +36,7 @@ export interface ConnectParamsType {
|
|
|
36
36
|
paintWidgetOnPicture?: boolean;
|
|
37
37
|
extraParameters?: any;
|
|
38
38
|
parameters?: any;
|
|
39
|
+
reConnect?: boolean;
|
|
39
40
|
}
|
|
40
41
|
export declare const CONNECT_MAIN_KEY: string[];
|
|
41
42
|
export interface RenderParamsType {
|
|
@@ -91,14 +92,14 @@ export interface CallbackMsgType {
|
|
|
91
92
|
content?: ErrorType | WsStateType | RtcStateType | ConnectDataType;
|
|
92
93
|
}
|
|
93
94
|
export interface DhRealtimeHumanType {
|
|
94
|
-
token
|
|
95
|
+
token?: string;
|
|
95
96
|
wsUrl?: string;
|
|
96
97
|
rtcServerUrl?: string;
|
|
97
98
|
appKey?: string;
|
|
98
99
|
appId?: string;
|
|
99
100
|
wrapperId: string;
|
|
100
|
-
connectParams
|
|
101
|
-
renderParams
|
|
101
|
+
connectParams?: ConnectParamsType;
|
|
102
|
+
renderParams?: RenderParamsType;
|
|
102
103
|
rtcConnectParams?: RtcConnectionType;
|
|
103
104
|
brtcParams?: any;
|
|
104
105
|
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/BrtcClient.d.ts
CHANGED
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
|
|
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");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};
|
package/es/Client.d.ts
CHANGED
|
@@ -17,13 +17,15 @@ export default class DhRealtimeHuman {
|
|
|
17
17
|
private readonly cutoutInstance;
|
|
18
18
|
private readonly isHuawei;
|
|
19
19
|
private readonly rtcServerUrl;
|
|
20
|
+
private readonly recordController;
|
|
21
|
+
private wsReadyState;
|
|
20
22
|
constructor(props: DhRealtimeHumanType);
|
|
21
23
|
onRemoteVideoComing: (id: number) => void;
|
|
22
24
|
onRemoteVideoOn: () => void;
|
|
23
25
|
connectListener: (data: ConnectDataType) => void;
|
|
24
26
|
createServer: (sessionId?: string) => void;
|
|
25
27
|
checkHumanInstansce: () => void;
|
|
26
|
-
sendMessage: (message: DHServerInterface, listener: RenderCallback | null) => Promise<void> | null;
|
|
28
|
+
sendMessage: (message: DHServerInterface | ArrayBuffer, listener: RenderCallback | null) => Promise<void> | null;
|
|
27
29
|
interrupt: () => Promise<void>;
|
|
28
30
|
textRender: (renderData: {
|
|
29
31
|
requestId: string;
|
|
@@ -44,9 +46,16 @@ export default class DhRealtimeHuman {
|
|
|
44
46
|
body: string;
|
|
45
47
|
onCallbackMsg: RenderCallback;
|
|
46
48
|
}) => void;
|
|
49
|
+
textQuery: (queryData: {
|
|
50
|
+
requestId: string;
|
|
51
|
+
body: string;
|
|
52
|
+
onCallbackMsg: RenderCallback;
|
|
53
|
+
}) => void;
|
|
47
54
|
destory: () => Promise<void>;
|
|
48
55
|
pauseHuman: () => void | Promise<void>;
|
|
49
56
|
playHuman: () => void | Promise<void>;
|
|
50
57
|
muteHuman: () => HTMLVideoElement;
|
|
51
58
|
unMuteHuman: () => false | Promise<void> | undefined;
|
|
59
|
+
startRecord(): void;
|
|
60
|
+
stopRecord(): void;
|
|
52
61
|
}
|
package/es/Client.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createClass as e,classCallCheck as t,defineProperty as r,objectSpread2 as n,asyncToGenerator as
|
|
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 f,appendRtcDomStyle as g,RTC_VIDEO_ID as S,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,"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(S),e.next=3,T.cutoutInstance&&T.cutoutInstance.updateSource(S);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,d=o.roomName,u=o.clientId,h=o.feedId,p=o.chargeId;i&&d&&(T.rtcConnectParams={server:T.rtcServerUrl||a,appId:i,token:c,roomName:d,userId:u,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}:{}),d(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: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;T.checkHumanInstansce(),T.dhServer&&T.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;T.checkHumanInstansce(),T.dhServer&&T.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;T.checkHumanInstansce(),T.dhServer&&T.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;T.checkHumanInstansce(),T.dhServer&&T.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;T.dhServer&&T.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,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,U=e.renderParams,A=void 0===U?{}:U,q=e.rtcConnectParams,L=e.brtcParams,N=e.wsUrl,x=e.rtcServerUrl,O=e.onDigitalHumanCallback;if(this.token=H,this.appKey=_,this.appId=M,this.rtcServerUrl=x,this.connectParams=n({autoChromaKey:(null==A?void 0:A.autoChromaKey)||!1},P),!M&&!_&&!H)throw new Error("appId and appKey or token is required");var B=A.fullStatus,K=A.closeLog;this.onDigitalHumanCallback=function(e){e.status!==l.DH_LIB_FULL_STATUS?O&&O(e):B&&O&&O(e)},this.dhServer=new p(N||"wss://open.xiling.baidu.com/cloud/digital-human-demonstration");var j=(f({autoChromaKey:!!A.autoChromaKey||!i(A.chromaEffects)})||{}).playerWrapper,F=document.getElementById(E);F||console.error("dom with wrapperId is not find"),j&&F&&F.appendChild(j),g();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},L);this.rtcServer=new v({closeLog:K,videoWrapperId:S,rtcConfig:Q,bizConfig:{},rtcCallback:{onRemoteVideoComing:this.onRemoteVideoComing,onDigitalHumanCallback:this.onDigitalHumanCallback}}),this.cutoutInstance=new k({sourceId:S,effects:null==A?void 0:A.chromaEffects}),i(q)||(this.rtcConnectParams=q,this.rtcServer.openRtc(q)),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:u(),clientTs:Date.now(),body:""},null);this.recordController&&this.recordController.stop(),this.sendMessage({action:"AUDIO_QUERY_INTERRUPT",requestId:u(),clientTs:Date.now(),body:""},null)}}]),w}();export{w as default};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export type PickAudioMode = 'pressButton' | 'free';
|
|
2
|
+
interface RecordControllerOptions {
|
|
3
|
+
pickAudioMode?: PickAudioMode;
|
|
4
|
+
onAudioData: (pcmData: ArrayBuffer) => void;
|
|
5
|
+
onError?: (err: Error) => void;
|
|
6
|
+
pullAudioFromRtc?: boolean;
|
|
7
|
+
brtcClient?: any;
|
|
8
|
+
}
|
|
9
|
+
declare class RecordController {
|
|
10
|
+
private pickAudioMode;
|
|
11
|
+
private readonly onAudioData;
|
|
12
|
+
private readonly onError?;
|
|
13
|
+
private audioContext;
|
|
14
|
+
private processor;
|
|
15
|
+
private mediaStream;
|
|
16
|
+
private recording;
|
|
17
|
+
private keydownHandler;
|
|
18
|
+
private keyupHandler;
|
|
19
|
+
private readonly pullAudioFromRtc;
|
|
20
|
+
private readonly brtcClient;
|
|
21
|
+
constructor(options: RecordControllerOptions);
|
|
22
|
+
setPickAudioMode(mode: PickAudioMode): void;
|
|
23
|
+
start(): Promise<void>;
|
|
24
|
+
stop(): void;
|
|
25
|
+
private _bindKeyEvents;
|
|
26
|
+
private _unbindKeyEvents;
|
|
27
|
+
private _onPressStart;
|
|
28
|
+
private _onPressStop;
|
|
29
|
+
}
|
|
30
|
+
export default RecordController;
|
|
@@ -0,0 +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};
|
package/es/Server.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export interface DHServerInterface {
|
|
|
15
15
|
action: string;
|
|
16
16
|
requestId: string;
|
|
17
17
|
clientTs: number;
|
|
18
|
-
body: string;
|
|
18
|
+
body: string | ArrayBuffer;
|
|
19
19
|
}
|
|
20
20
|
export interface DHErrServerInterface {
|
|
21
21
|
action: string;
|
|
@@ -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
|
}
|
|
@@ -52,6 +53,6 @@ declare class Server {
|
|
|
52
53
|
createSocket: (props: createSocketParamsType) => Promise<WebSocketClient | null>;
|
|
53
54
|
closeSocket: () => Promise<void>;
|
|
54
55
|
handleConnect: () => Promise<void>;
|
|
55
|
-
sendMessage(message: DHServerInterface, listener: RenderCallback | null): Promise<void>;
|
|
56
|
+
sendMessage(message: DHServerInterface | ArrayBuffer, listener: RenderCallback | null): Promise<void>;
|
|
56
57
|
}
|
|
57
58
|
export default Server;
|
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}from"./_virtual/_rollupPluginBabelHelpers.js";import{v4 as
|
|
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};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function t(t,r){var e=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(t,r).enumerable}))),e.push.apply(e,n)}return e}function r(r){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?t(Object(n),!0).forEach((function(t){
|
|
1
|
+
function t(t,r){var e=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(t,r).enumerable}))),e.push.apply(e,n)}return e}function r(r){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?t(Object(n),!0).forEach((function(t){f(r,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(n)):t(Object(n)).forEach((function(t){Object.defineProperty(r,t,Object.getOwnPropertyDescriptor(n,t))}))}return r}function e(){e=function(){return r};var t,r={},n=Object.prototype,o=n.hasOwnProperty,i=Object.defineProperty||function(t,r,e){t[r]=e.value},a="function"==typeof Symbol?Symbol:{},c=a.iterator||"@@iterator",u=a.asyncIterator||"@@asyncIterator",f=a.toStringTag||"@@toStringTag";function l(t,r,e){return Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}),t[r]}try{l({},"")}catch(t){l=function(t,r,e){return t[r]=e}}function s(t,r,e,n){var o=r&&r.prototype instanceof m?r:m,a=Object.create(o.prototype),c=new N(n||[]);return i(a,"_invoke",{value:S(t,e,c)}),a}function h(t,r,e){try{return{type:"normal",arg:t.call(r,e)}}catch(t){return{type:"throw",arg:t}}}r.wrap=s;var p="suspendedStart",y="suspendedYield",v="executing",g="completed",d={};function m(){}function b(){}function w(){}var O={};l(O,c,(function(){return this}));var j=Object.getPrototypeOf,L=j&&j(j(T([])));L&&L!==n&&o.call(L,c)&&(O=L);var E=w.prototype=m.prototype=Object.create(O);function x(t){["next","throw","return"].forEach((function(r){l(t,r,(function(t){return this._invoke(r,t)}))}))}function P(t,r){function e(n,i,a,c){var u=h(t[n],t,i);if("throw"!==u.type){var f=u.arg,l=f.value;return l&&"object"==typeof l&&o.call(l,"__await")?r.resolve(l.__await).then((function(t){e("next",t,a,c)}),(function(t){e("throw",t,a,c)})):r.resolve(l).then((function(t){f.value=t,a(f)}),(function(t){return e("throw",t,a,c)}))}c(u.arg)}var n;i(this,"_invoke",{value:function(t,o){function i(){return new r((function(r,n){e(t,o,r,n)}))}return n=n?n.then(i,i):i()}})}function S(r,e,n){var o=p;return function(i,a){if(o===v)throw new Error("Generator is already running");if(o===g){if("throw"===i)throw a;return{value:t,done:!0}}for(n.method=i,n.arg=a;;){var c=n.delegate;if(c){var u=_(c,n);if(u){if(u===d)continue;return u}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(o===p)throw o=g,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o=v;var f=h(r,e,n);if("normal"===f.type){if(o=n.done?g:y,f.arg===d)continue;return{value:f.arg,done:n.done}}"throw"===f.type&&(o=g,n.method="throw",n.arg=f.arg)}}}function _(r,e){var n=e.method,o=r.iterator[n];if(o===t)return e.delegate=null,"throw"===n&&r.iterator.return&&(e.method="return",e.arg=t,_(r,e),"throw"===e.method)||"return"!==n&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+n+"' method")),d;var i=h(o,r.iterator,e.arg);if("throw"===i.type)return e.method="throw",e.arg=i.arg,e.delegate=null,d;var a=i.arg;return a?a.done?(e[r.resultName]=a.value,e.next=r.nextLoc,"return"!==e.method&&(e.method="next",e.arg=t),e.delegate=null,d):a:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,d)}function k(t){var r={tryLoc:t[0]};1 in t&&(r.catchLoc=t[1]),2 in t&&(r.finallyLoc=t[2],r.afterLoc=t[3]),this.tryEntries.push(r)}function G(t){var r=t.completion||{};r.type="normal",delete r.arg,t.completion=r}function N(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(k,this),this.reset(!0)}function T(r){if(r||""===r){var e=r[c];if(e)return e.call(r);if("function"==typeof r.next)return r;if(!isNaN(r.length)){var n=-1,i=function e(){for(;++n<r.length;)if(o.call(r,n))return e.value=r[n],e.done=!1,e;return e.value=t,e.done=!0,e};return i.next=i}}throw new TypeError(typeof r+" is not iterable")}return b.prototype=w,i(E,"constructor",{value:w,configurable:!0}),i(w,"constructor",{value:b,configurable:!0}),b.displayName=l(w,f,"GeneratorFunction"),r.isGeneratorFunction=function(t){var r="function"==typeof t&&t.constructor;return!!r&&(r===b||"GeneratorFunction"===(r.displayName||r.name))},r.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,w):(t.__proto__=w,l(t,f,"GeneratorFunction")),t.prototype=Object.create(E),t},r.awrap=function(t){return{__await:t}},x(P.prototype),l(P.prototype,u,(function(){return this})),r.AsyncIterator=P,r.async=function(t,e,n,o,i){void 0===i&&(i=Promise);var a=new P(s(t,e,n,o),i);return r.isGeneratorFunction(e)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},x(E),l(E,f,"Generator"),l(E,c,(function(){return this})),l(E,"toString",(function(){return"[object Generator]"})),r.keys=function(t){var r=Object(t),e=[];for(var n in r)e.push(n);return e.reverse(),function t(){for(;e.length;){var n=e.pop();if(n in r)return t.value=n,t.done=!1,t}return t.done=!0,t}},r.values=T,N.prototype={constructor:N,reset:function(r){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(G),!r)for(var e in this)"t"===e.charAt(0)&&o.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(r){if(this.done)throw r;var e=this;function n(n,o){return c.type="throw",c.arg=r,e.next=n,o&&(e.method="next",e.arg=t),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],c=a.completion;if("root"===a.tryLoc)return n("end");if(a.tryLoc<=this.prev){var u=o.call(a,"catchLoc"),f=o.call(a,"finallyLoc");if(u&&f){if(this.prev<a.catchLoc)return n(a.catchLoc,!0);if(this.prev<a.finallyLoc)return n(a.finallyLoc)}else if(u){if(this.prev<a.catchLoc)return n(a.catchLoc,!0)}else{if(!f)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return n(a.finallyLoc)}}}},abrupt:function(t,r){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.tryLoc<=this.prev&&o.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var i=n;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=r&&r<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=r,i?(this.method="next",this.next=i.finallyLoc,d):this.complete(a)},complete:function(t,r){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&r&&(this.next=r),d},finish:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.finallyLoc===t)return this.complete(e.completion,e.afterLoc),G(e),d}},catch:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.tryLoc===t){var n=e.completion;if("throw"===n.type){var o=n.arg;G(e)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(r,e,n){return this.delegate={iterator:T(r),resultName:e,nextLoc:n},"next"===this.method&&(this.arg=t),d}},r}function n(t){return n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},n(t)}function o(t,r,e,n,o,i,a){try{var c=t[i](a),u=c.value}catch(t){return void e(t)}c.done?r(u):Promise.resolve(u).then(n,o)}function i(t){return function(){var r=this,e=arguments;return new Promise((function(n,i){var a=t.apply(r,e);function c(t){o(a,n,i,c,u,"next",t)}function u(t){o(a,n,i,c,u,"throw",t)}c(void 0)}))}}function a(t,r){if(!(t instanceof r))throw new TypeError("Cannot call a class as a function")}function c(t,r){for(var e=0;e<r.length;e++){var n=r[e];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,s(n.key),n)}}function u(t,r,e){return r&&c(t.prototype,r),e&&c(t,e),Object.defineProperty(t,"prototype",{writable:!1}),t}function f(t,r,e){return(r=s(r))in t?Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[r]=e,t}function l(t,r){if("object"!=typeof t||null===t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,r||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(t)}function s(t){var r=l(t,"string");return"symbol"==typeof r?r:String(r)}export{i as asyncToGenerator,a as classCallCheck,u as createClass,f as defineProperty,r as objectSpread2,e as regeneratorRuntime,l as toPrimitive,s as toPropertyKey,n as typeof};
|
package/es/interface.d.ts
CHANGED
|
@@ -6,12 +6,13 @@ export interface ConnectDataType {
|
|
|
6
6
|
message: string;
|
|
7
7
|
}
|
|
8
8
|
export interface ConnectParamsType {
|
|
9
|
-
figureId
|
|
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
|
-
pickAudioMode?:
|
|
15
|
+
pickAudioMode?: 'pressButton' | 'free';
|
|
15
16
|
autoChromaKey?: boolean;
|
|
16
17
|
usingVideo?: boolean;
|
|
17
18
|
ttsPer?: string | number;
|
|
@@ -22,7 +23,6 @@ export interface ConnectParamsType {
|
|
|
22
23
|
pullAudioFromRtc?: boolean;
|
|
23
24
|
inactiveDisconnectSec?: number;
|
|
24
25
|
preAlertSec?: number;
|
|
25
|
-
x264BitRate?: number;
|
|
26
26
|
backgroundImageUrl?: string;
|
|
27
27
|
projectId?: string;
|
|
28
28
|
characterConfigId?: string;
|
|
@@ -36,6 +36,7 @@ export interface ConnectParamsType {
|
|
|
36
36
|
paintWidgetOnPicture?: boolean;
|
|
37
37
|
extraParameters?: any;
|
|
38
38
|
parameters?: any;
|
|
39
|
+
reConnect?: boolean;
|
|
39
40
|
}
|
|
40
41
|
export declare const CONNECT_MAIN_KEY: string[];
|
|
41
42
|
export interface RenderParamsType {
|
|
@@ -91,14 +92,14 @@ export interface CallbackMsgType {
|
|
|
91
92
|
content?: ErrorType | WsStateType | RtcStateType | ConnectDataType;
|
|
92
93
|
}
|
|
93
94
|
export interface DhRealtimeHumanType {
|
|
94
|
-
token
|
|
95
|
+
token?: string;
|
|
95
96
|
wsUrl?: string;
|
|
96
97
|
rtcServerUrl?: string;
|
|
97
98
|
appKey?: string;
|
|
98
99
|
appId?: string;
|
|
99
100
|
wrapperId: string;
|
|
100
|
-
connectParams
|
|
101
|
-
renderParams
|
|
101
|
+
connectParams?: ConnectParamsType;
|
|
102
|
+
renderParams?: RenderParamsType;
|
|
102
103
|
rtcConnectParams?: RtcConnectionType;
|
|
103
104
|
brtcParams?: any;
|
|
104
105
|
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": "
|
|
3
|
+
"version": "2.0.0-beta.2",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"react",
|
|
6
6
|
"indexDB"
|
|
@@ -44,5 +44,5 @@
|
|
|
44
44
|
"lodash": "^4.17.21",
|
|
45
45
|
"uuid": "^9.0.0"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "9068d88b2003b545a08db91d936ce473e481fa01"
|
|
48
48
|
}
|