| 1 |
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).TRTC=t()}(this,(function(){"use strict";function e(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function t(e,t){for(var r=0;r<t.length;r++){var s=t[r];s.enumerable=s.enumerable||!1,s.configurable=!0,"value"in s&&(s.writable=!0),Object.defineProperty(e,s.key,s)}}function r(e,r,s){return r&&t(e.prototype,r),s&&t(e,s),e}function s(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function i(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(e);t&&(s=s.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,s)}return r}function a(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?i(Object(r),!0).forEach((function(t){s(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):i(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function n(){var e=(new Date).getTime(),t=new Date(e),r=t.getHours(),s=t.getMinutes(),i=t.getSeconds(),a=t.getMilliseconds();return r=r<10?"0".concat(r):r,s=s<10?"0".concat(s):s,i=i<10?"0".concat(i):i,"".concat(r,":").concat(s,":").concat(i,".").concat(a)}var o="TRTC-WX",u=0,c=1,l=new(function(){function t(){e(this,t),this.logLevel=0}return r(t,[{key:"setLogLevel",value:function(e){this.logLevel=e}},{key:"log",value:function(){var e;this.logLevel===u&&(e=console).log.apply(e,[o,n()].concat(Array.prototype.slice.call(arguments)))}},{key:"warn",value:function(){var e;this.logLevel<=c&&(e=console).warn.apply(e,[o,n()].concat(Array.prototype.slice.call(arguments)))}},{key:"error",value:function(){var e;(e=console).error.apply(e,[o,n()].concat(Array.prototype.slice.call(arguments)))}}]),t}());var h=function(e){var t=/[\u4e00-\u9fa5]/;return e.sdkAppID?void 0===e.roomID&&void 0===e.strRoomID?(l.error("未设置 roomID"),!1):!e.strRoomID&&(e.roomID<1||e.roomID>4294967296)?(l.error("roomID 超出取值范围 1 ~ 4294967295"),!1):e.strRoomID&&t.test(e.strRoomID)?(l.error("strRoomID 请勿使用中文字符"),!1):e.userID?e.userID&&t.test(e.userID)?(l.error("userID 请勿使用中文字符"),!1):!!e.userSig||(l.error("未设置 userSig"),!1):(l.error("未设置 userID"),!1):(l.error("未设置 sdkAppID"),!1)},p={LOCAL_JOIN:"LOCAL_JOIN",LOCAL_LEAVE:"LOCAL_LEAVE",KICKED_OUT:"KICKED_OUT",REMOTE_USER_JOIN:"REMOTE_USER_JOIN",REMOTE_USER_LEAVE:"REMOTE_USER_LEAVE",REMOTE_VIDEO_ADD:"REMOTE_VIDEO_ADD",REMOTE_VIDEO_REMOVE:"REMOTE_VIDEO_REMOVE",REMOTE_AUDIO_ADD:"REMOTE_AUDIO_ADD",REMOTE_AUDIO_REMOVE:"REMOTE_AUDIO_REMOVE",REMOTE_STATE_UPDATE:"REMOTE_STATE_UPDATE",LOCAL_NET_STATE_UPDATE:"LOCAL_NET_STATE_UPDATE",REMOTE_NET_STATE_UPDATE:"REMOTE_NET_STATE_UPDATE",LOCAL_AUDIO_VOLUME_UPDATE:"LOCAL_AUDIO_VOLUME_UPDATE",REMOTE_AUDIO_VOLUME_UPDATE:"REMOTE_AUDIO_VOLUME_UPDATE",VIDEO_FULLSCREEN_UPDATE:"VIDEO_FULLSCREEN_UPDATE",BGM_PLAY_START:"BGM_PLAY_START",BGM_PLAY_FAIL:"BGM_PLAY_FAIL",BGM_PLAY_PROGRESS:"BGM_PLAY_PROGRESS",BGM_PLAY_COMPLETE:"BGM_PLAY_COMPLETE",ERROR:"ERROR",IM_READY:"IM_READY",IM_MESSAGE_RECEIVED:"IM_MESSAGE_RECEIVED",IM_NOT_READY:"IM_NOT_READY",IM_KICKED_OUT:"IM_KICKED_OUT",IM_ERROR:"IM_ERROR"},m={url:"",mode:"RTC",autopush:!1,enableCamera:!1,enableMic:!1,enableAgc:!1,enableAns:!1,enableEarMonitor:!1,enableAutoFocus:!0,enableZoom:!1,minBitrate:600,maxBitrate:900,videoWidth:360,videoHeight:640,beautyLevel:0,whitenessLevel:0,videoOrientation:"vertical",videoAspect:"9:16",frontCamera:"front",enableRemoteMirror:!1,localMirror:"auto",enableBackgroundMute:!1,audioQuality:"high",audioVolumeType:"voicecall",audioReverbType:0,waitingImage:"https://mc.qcloudimg.com/static/img/daeed8616ac5df256c0591c22a65c4d3/pause_publish.jpg",waitingImageHash:"",beautyStyle:"smooth",filter:"",netStatus:{}},f={src:"",mode:"RTC",autoplay:!0,muteAudio:!0,muteVideo:!0,orientation:"vertical",objectFit:"fillCrop",enableBackgroundMute:!1,minCache:1,maxCache:2,soundMode:"speaker",enableRecvMessage:!1,autoPauseIfNavigate:!0,autoPauseIfOpenNative:!0,isVisible:!0,_definitionType:"main",netStatus:{}};(new Date).getTime();function d(){var e=new Date;return e.setTime((new Date).getTime()+0),e.toLocaleString()}function v(e){var t=this,r=[],s=[];this.length=function(){return r.length},this.sent=function(){return s.length},this.push=function(t){r.push(t),r.length>e&&r.shift()},this.send=function(){return s.length||(s=r,r=[]),s},this.confirm=function(){s=[],t.content=""},this.fail=function(){r=s.concat(r),t.confirm();var i=1+r.length+s.length-e;i>0&&(s.splice(0,i),r=s.concat(r),t.confirm())}}var g=new(function(){function t(){e(this,t),this.sdkAppId="",this.userId="",this.version="",this.queue=new v(20)}return r(t,[{key:"setConfig",value:function(e){this.sdkAppId="".concat(e.sdkAppId),this.userId="".concat(e.userId),this.version="".concat(e.version)}},{key:"push",value:function(e){this.queue.push(e)}},{key:"log",value:function(e){wx.request({url:"https://yun.tim.qq.com/v5/AVQualityReportSvc/C2S?sdkappid=1&cmdtype=jssdk_log",method:"POST",header:{"content-type":"application/json"},data:{timestamp:d(),sdkAppId:this.sdkAppId,userId:this.userId,version:this.version,log:e}})}},{key:"send",value:function(){var e=this;if(!this.queue.sent()){if(!this.queue.length())return;var t=this.queue.send();this.queue.content="string"!=typeof log?'{"logs":['.concat(t.join(","),"]}"):t.join("\n"),wx.request({url:"https://yun.tim.qq.com/v5/AVQualityReportSvc/C2S?sdkappid=1&cmdtype=jssdk_log",method:"POST",header:{"content-type":"application/json"},data:{timestamp:d(),sdkAppId:this.sdkAppId,userId:this.userId,version:this.version,log:this.queue.content},success:function(){e.queue.confirm()},fail:function(){e.queue.fail()}})}}}]),t}()),y=function(){function t(r,s){e(this,t),this.context=wx.createLivePusherContext(s),this.pusherAttributes={},Object.assign(this.pusherAttributes,m,r)}return r(t,[{key:"setPusherAttributes",value:function(e){return Object.assign(this.pusherAttributes,e),this.pusherAttributes}},{key:"start",value:function(e){l.log("[apiLog][pusherStart]"),g.log("pusherStart"),this.context.start(e)}},{key:"stop",value:function(e){l.log("[apiLog][pusherStop]"),g.log("pusherStop"),this.context.stop(e)}},{key:"pause",value:function(e){l.log("[apiLog] pusherPause()"),g.log("pusherPause"),this.context.pause(e)}},{key:"resume",value:function(e){l.log("[apiLog][pusherResume]"),g.log("pusherResume"),this.context.resume(e)}},{key:"switchCamera",value:function(e){return l.log("[apiLog][switchCamera]"),this.pusherAttributes.frontCamera="front"===this.pusherAttributes.frontCamera?"back":"front",this.context.switchCamera(e),this.pusherAttributes}},{key:"sendMessage",value:function(e){l.log("[apiLog][sendMessage]",e.msg),this.context.sendMessage(e)}},{key:"snapshot",value:function(){var e=this;return l.log("[apiLog][pusherSnapshot]"),new Promise((function(t,r){e.context.snapshot({quality:"raw",complete:function(e){e.tempImagePath?(wx.saveImageToPhotosAlbum({filePath:e.tempImagePath,success:function(r){t(e)},fail:function(e){l.error("[error] pusher截图失败: ",e),r(new Error("截图失败"))}}),t(e)):(l.error("[error] snapShot 回调失败",e),r(new Error("截图失败")))}})}))}},{key:"toggleTorch",value:function(e){this.context.toggleTorch(e)}},{key:"startDumpAudio",value:function(e){this.context.startDumpAudio(e)}},{key:"stopDumpAudio",value:function(e){this.context.startDumpAudio(e)}},{key:"playBGM",value:function(e){l.log("[apiLog] playBGM() url: ",e.url),this.context.playBGM(e)}},{key:"pauseBGM",value:function(e){l.log("[apiLog] pauseBGM()"),this.context.pauseBGM(e)}},{key:"resumeBGM",value:function(e){l.log("[apiLog] resumeBGM()"),this.context.resumeBGM(e)}},{key:"stopBGM",value:function(e){l.log("[apiLog] stopBGM()"),this.context.stopBGM(e)}},{key:"setBGMVolume",value:function(e){l.log("[apiLog] setBGMVolume() volume:",e.volume),this.context.setBGMVolume(e.volume)}},{key:"setMICVolume",value:function(e){l.log("[apiLog] setMICVolume() volume:",e.volume),this.context.setMICVolume(e.volume)}},{key:"startPreview",value:function(e){l.log("[apiLog] startPreview()"),this.context.startPreview(e)}},{key:"stopPreview",value:function(e){l.log("[apiLog] stopPreview()"),this.context.stopPreview(e)}},{key:"reset",value:function(){return console.log("Pusher reset",this.context),this.pusherConfig={},this.context&&(this.stop({success:function(){console.log("Pusher context.stop()")}}),this.context=null),this.pusherAttributes}}]),t}(),E=function t(r){e(this,t),Object.assign(this,{userID:"",streams:{}},r)},A=function(){function t(r,s){e(this,t),this.ctx=s,this.playerAttributes={},Object.assign(this.playerAttributes,f,{userID:"",streamType:"",streamID:"",id:"",hasVideo:!1,hasAudio:!1,volume:0,playerContext:void 0},r)}return r(t,[{key:"play",value:function(e){this.getPlayerContext().play(e)}},{key:"stop",value:function(e){this.getPlayerContext().stop(e)}},{key:"mute",value:function(e){this.getPlayerContext().mute(e)}},{key:"pause",value:function(e){this.getPlayerContext().pause(e)}},{key:"resume",value:function(e){this.getPlayerContext().resume(e)}},{key:"requestFullScreen",value:function(e){var t=this;return new Promise((function(r,s){t.getPlayerContext().requestFullScreen({direction:e.direction,success:function(e){r(e)},fail:function(e){s(e)}})}))}},{key:"requestExitFullScreen",value:function(){var e=this;return new Promise((function(t,r){e.getPlayerContext().exitFullScreen({success:function(e){t(e)},fail:function(e){r(e)}})}))}},{key:"snapshot",value:function(e){var t=this;return l.log("[playerSnapshot]",e),new Promise((function(e,r){t.getPlayerContext().snapshot({quality:"raw",complete:function(t){t.tempImagePath?(wx.saveImageToPhotosAlbum({filePath:t.tempImagePath,success:function(r){l.log("save photo is success",r),e(t)},fail:function(e){l.error("save photo is fail",e),r(e)}}),e(t)):(l.error("snapShot 回调失败",t),r(new Error("截图失败")))}})}))}},{key:"setPlayerAttributes",value:function(e){Object.assign(this.playerAttributes,e)}},{key:"getPlayerContext",value:function(){return this.playerContext||(this.playerContext=wx.createLivePlayerContext(this.playerAttributes.id,this.ctx)),this.playerContext}},{key:"reset",value:function(){this.playerContext&&(this.playerContext.stop(),this.playerContext=void 0),Object.assign(this.playerAttributes,f,{userID:"",streamType:"",streamID:"",hasVideo:!1,hasAudio:!1,volume:0,playerContext:void 0})}}]),t}(),_="UserController",I=function(){function t(r,s){e(this,t),this.ctx=s,this.userMap=new Map,this.userList=[],this.streamList=[],this.emitter=r}return r(t,[{key:"userEventHandler",value:function(e){var t=e.detail.code,r=e.detail.message;switch(t){case 0:l.log(r,t);break;case 1001:l.log("已经连接推流服务器",t);break;case 1002:l.log("已经与服务器握手完毕,开始推流",t);break;case 1003:l.log("打开摄像头成功",t);break;case 1004:l.log("录屏启动成功",t);break;case 1005:l.log("推流动态调整分辨率",t);break;case 1006:l.log("推流动态调整码率",t);break;case 1007:l.log("首帧画面采集完成",t);break;case 1008:l.log("编码器启动",t);break;case 1018:l.log("进房成功",t),g.log("event enterRoom success ".concat(t)),this.emitter.emit(p.LOCAL_JOIN);break;case 1019:l.log("退出房间",t),r.indexOf("reason[0]")>-1?g.log("event exitRoom ".concat(t)):(g.log("event abnormal exitRoom ".concat(r)),this.emitter.emit(p.KICKED_OUT));break;case 2003:l.log("渲染首帧视频",t);break;case-1301:l.error("打开摄像头失败: ",t),g.log("event start camera failed: ".concat(t)),this.emitter.emit(p.ERROR,{code:t,message:r});break;case-1302:l.error("打开麦克风失败: ",t),g.log("event start microphone failed: ".concat(t)),this.emitter.emit(p.ERROR,{code:t,message:r});break;case-1303:l.error("视频编码失败: ",t),g.log("event video encode failed: ".concat(t)),this.emitter.static/js/trtc-wx.js
|