- 电子药箱: 药品库存管理 + 手动录入 + 今日用药打卡 - 药品百科: 搜索 + 分类筛选 + 20种药品静态数据 - 惠教中心: 4条药品使用指南课程 - 我的: 家庭成员信息管理 - 自定义TabBar + navigation-bar组件 - SVG药品分类插图
1 line
46 KiB
JavaScript
1 line
46 KiB
JavaScript
"use strict";function _typeof(e){return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},_typeof(e)}!function(e,t){"object"==("undefined"==typeof exports?"undefined":_typeof(exports))&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).MiniappRtc=t()}(void 0,function(){var e=function(t,n){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(t,n)};function t(t,n){function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}var n=function(){return(n=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)};function r(e,t,n,r){var o,i=arguments.length,s=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==("undefined"==typeof Reflect?"undefined":_typeof(Reflect))&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,n,r);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(s=(i<3?o(s):i>3?o(t,n,s):o(t,n))||s);return i>3&&s&&Object.defineProperty(t,n,s),s}function o(e,t,n,r){return new(n||(n=Promise))(function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,a)}c((r=r.apply(e,t||[])).next())})}function i(e,t){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=t.call(e,s)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}}var s,a,c=function(){var e={exports:{}};return function(e){var t=Object.prototype.hasOwnProperty,n="~";function r(){}function o(e,t,n){this.fn=e,this.context=t,this.once=n||!1}function i(e,t,r,i,s){if("function"!=typeof r)throw new TypeError("The listener must be a function");var a=new o(r,i||e,s),c=n?n+t:t;return e._events[c]?e._events[c].fn?e._events[c]=[e._events[c],a]:e._events[c].push(a):(e._events[c]=a,e._eventsCount++),e}function s(e,t){0==--e._eventsCount?e._events=new r:delete e._events[t]}function a(){this._events=new r,this._eventsCount=0}Object.create&&(r.prototype=Object.create(null),(new r).__proto__||(n=!1)),a.prototype.eventNames=function(){var e,r,o=[];if(0===this._eventsCount)return o;for(r in e=this._events)t.call(e,r)&&o.push(n?r.slice(1):r);return Object.getOwnPropertySymbols?o.concat(Object.getOwnPropertySymbols(e)):o},a.prototype.listeners=function(e){var t=n?n+e:e,r=this._events[t];if(!r)return[];if(r.fn)return[r.fn];for(var o=0,i=r.length,s=new Array(i);o<i;o++)s[o]=r[o].fn;return s},a.prototype.listenerCount=function(e){var t=n?n+e:e,r=this._events[t];return r?r.fn?1:r.length:0},a.prototype.emit=function(e,t,r,o,i,s){var a=n?n+e:e;if(!this._events[a])return!1;var c,u,d=this._events[a],l=arguments.length;if(d.fn){switch(d.once&&this.removeListener(e,d.fn,void 0,!0),l){case 1:return d.fn.call(d.context),!0;case 2:return d.fn.call(d.context,t),!0;case 3:return d.fn.call(d.context,t,r),!0;case 4:return d.fn.call(d.context,t,r,o),!0;case 5:return d.fn.call(d.context,t,r,o,i),!0;case 6:return d.fn.call(d.context,t,r,o,i,s),!0}for(u=1,c=new Array(l-1);u<l;u++)c[u-1]=arguments[u];d.fn.apply(d.context,c)}else{var _,h=d.length;for(u=0;u<h;u++)switch(d[u].once&&this.removeListener(e,d[u].fn,void 0,!0),l){case 1:d[u].fn.call(d[u].context);break;case 2:d[u].fn.call(d[u].context,t);break;case 3:d[u].fn.call(d[u].context,t,r);break;case 4:d[u].fn.call(d[u].context,t,r,o);break;default:if(!c)for(_=1,c=new Array(l-1);_<l;_++)c[_-1]=arguments[_];d[u].fn.apply(d[u].context,c)}}return!0},a.prototype.on=function(e,t,n){return i(this,e,t,n,!1)},a.prototype.once=function(e,t,n){return i(this,e,t,n,!0)},a.prototype.removeListener=function(e,t,r,o){var i=n?n+e:e;if(!this._events[i])return this;if(!t)return s(this,i),this;var a=this._events[i];if(a.fn)a.fn!==t||o&&!a.once||r&&a.context!==r||s(this,i);else{for(var c=0,u=[],d=a.length;c<d;c++)(a[c].fn!==t||o&&!a[c].once||r&&a[c].context!==r)&&u.push(a[c]);u.length?this._events[i]=1===u.length?u[0]:u:s(this,i)}return this},a.prototype.removeAllListeners=function(e){var t;return e?(t=n?n+e:e,this._events[t]&&s(this,t)):(this._events=new r,this._eventsCount=0),this},a.prototype.off=a.prototype.removeListener,a.prototype.addListener=a.prototype.on,a.prefixed=n,a.EventEmitter=a,e.exports=a}(e),e.exports}();(a=s||(s={})).userLeave="userLeave",a.connectionLost="connectionLost",a.roleChanged="roleChanged",a.userDuplicateLogin="userDuplicateLogin",a.kickedByAdmin="kickedByAdmin",a.roomDismissed="roomDismissed",a.roomForbidden="roomForbidden",a.userForbidden="userForbidden",a.serverError="serverError";var u=function(){for(var e=[],t="0123456789abcdef",n=0;n<36;n++)e[n]=t.substr(Math.floor(16*Math.random()),1);return e[14]="4",e[19]=t.substr(3&e[19]|8,1),e[8]=e[13]=e[18]=e[23]="-",e.join("")},d=function(){function e(){}return e.setCache=function(e,t){return new Promise(function(n,r){wx.setStorage({key:e,data:t,success:n,fail:r})})},e.setCacheSync=function(e,t){try{return wx.setStorageSync(e,t),!0}catch(e){return!1}},e.getCache=function(e){return new Promise(function(e,t){wx.getStorage({key:"key",success:function(t){e(t.data)},fail:t})})},e.getCacheSync=function(e,t){void 0===t&&(t=null);try{return wx.getStorageSync(e)||t}catch(e){return t}},e}(),l="keep_alive_url",_="device_id";function h(){var e=d.getCacheSync(_);return e||(e=u(),d.setCache(_,e),e)}function p(e,t){return new Promise(function(n,r){wx.request({url:e,data:t.body,method:t.method,header:{"content-type":"application/json"},success:function(e){n(e.data)},fail:r})})}var m,f=function(e,t){return new Promise(function(n,r){var o=(e=Array.isArray(e)?e:[]).length,i=[],s=!1;0===o?r([]):e.forEach(function(e){e.then(function(e){s&&t&&t(e),s=!0,n(e)},function(e){o--,i.push(e),0===o&&r(i)})})})};!function(e){e.Init="init",e.Connecting="connecting",e.Connected="connected",e.Disconnected="disconnected",e.Reconnecting="reconnecting"}(m||(m={}));var v=new(function(){function e(){this._ongoing=!1,this._header={product_line:"rtc",project_key:"_app_name_",report_version:"5",rtc_sdk_version:"3.0.1",rtc_sdk_version_num:"3.0.1",user_agent:"miniapp",device_id:h(),engine_id:"",rtc_app_id:"",room_id:"",user_id:"",rtc_call_id:"",report_time:"",report_log_count:0,config_server:""},this._data=[],this._reportId=0,this.resume()}return e.prototype.updateHeader=function(e){this._header=n(n({},this._header),e)},e.prototype.report=function(e,t){"rtc_media_statistics"!==e&&console.log("monitor> ",e,t);var r=Date.now();this._data.push(n(n({event_key:e},t),{message:JSON.stringify(t.message),event_type:"event",report_id:this._reportId++,time:r,rtc_time:r}))},e.prototype.resume=function(){this._ongoing||(this._ongoing=!0,this._send2server())},e.prototype.stop=function(){this._ongoing=!1},e.prototype._send2server=function(){var e=this;if(this._data.length){var t=this._data.splice(0,1e3);this._header.report_time=Date.now(),this._header.report_log_count=t.length,p("https://log.snssdk.com/video/v1/webrtc_log/",{method:"POST",body:{data:t,header:this._header,os:"miniapp",from:"miniapp",version:"3"}}).then(function(){}).catch(function(){e._data=[].concat(t,e._data)})}this._ongoing&&(this._reportTimer=setTimeout(this._send2server.bind(this),5e3))},e}());wx.__monitor=v;var g=100001,y=100002,b=100003,I=100004,S=100005,k=100007,w=100008,R=200001,C=200003,E=300001,T=300002,A=300003,O=300004,D=300005,N=300006,P=300007,U=300008,M=300009,L=300010,x=300011,j=300012,q=300013,V=300014,K=500001,B=500002,F=Object.freeze({__proto__:null,INVALID_PARAMS:g,NOT_IN_ROOM:y,ALREADY_IN_ROOM:b,CONNECTING:I,ALREADY_PUBLISHED:S,NOT_PUBLISHED:100006,UID_NOT_FOUND:k,HAS_INITED:w,STREAM_ID_NOT_FOUND:R,GET_CONFIG_ERROR:200002,NO_WEBSOCLET_URL:C,SUBSCRIBE_FAILED:E,UNSUBSCRIBE_FAILED:T,MUTE_LOCAL_ERROR:A,MUTE_REMOTE_ERROR:O,LEAVE_ERROR:D,PUBLISH_ERROR:N,UNPUBLISH_ERROR:P,JOIN_ROOM_ERROR:U,SIGNALING_TIMEOUT:M,WEBSOCKET_NOT_CONNECTED:L,KICKED_OUT:x,DUPLICATE_LOGIN:j,ROOM_DISMISS:q,SERVER_ERROR:V,WEBSOCKET_FAILED:K,DOMAIN_IN_BLACKLIST:B}),H=function(e){function r(t){var n=e.call(this)||this;n._pingInterval=5e3,n._pingTimeout=1e4,n._pingTimer=null,n._ackTimeout=1e4,n._maxRetryTime=3,n._signalingResolveCallbacks={},n._signalingRejectCallbacks={},n._signalingTimer={},n._requestId=-1,n._reqSigMap={};var r=t.appId,o=t.roomId,i=t.userId,s=t.token,a=t.role;return n._clsName="Signaling",n._appId=r,n._roomId=o,n._userId=i,n._token=s,n._role=a,n._sessionId=u(),wx.__test__1006=function(){n._socketTask.close({success:function(){n.emit("@signaling/onClose",{code:1006,reason:""})}})},n}return t(r,e),r.prototype.connect=function(e){var t=this;return this._url=e,new Promise(function(r,o){var i=u(),s=e+"?wsid="+i+"&appid="+t._appId+"&ua=miniapp-3.0.1&EIO=3&transport=websocket";t._report("rtc_invoke_status",{sdk_api_name:"websocket url",message:s}),t._report("rtc_websocket",{error_code:0,signaling_server:s,message:s,signaling_event:"connecting"});var a=wx.connectSocket({url:s});a.onError(function(e){o({code:K,reason:e.errMsg}),t.emit("@signaling/error",n(n({},e),{code:e.code||K}))}),a.onOpen(function(e){t._socketTask=a,t._ping(),t._report("rtc_websocket",{error_code:0,signaling_server:s,message:s,signaling_event:"connected"}),r()}),a.onClose(function(e){t._report("rtc_websocket",{error_code:e.code,signaling_server:s,message:JSON.stringify(e),signaling_event:"failed"}),t.emit("@signaling/onClose",e)}),a.onMessage(function(e){"string"==typeof(null==e?void 0:e.data)&&t._handleMessage(e.data)})})},r.prototype.disconnect=function(){var e=this;return new Promise(function(t,n){if(e._socketTask.readyState!==e._socketTask.OPEN)return t();e._socketTask.close({success:t,fail:n})})},r.prototype.sendSignaling=function(e,t,n){return void 0===n&&(n=0),o(this,void 0,void 0,function(){var r;return i(this,function(o){switch(o.label){case 0:return[4,this._sendSignaling(e,t)];case 1:return r=o.sent(),n<this._maxRetryTime&&/5[0-9][0-9]/.test(""+r.code)?[4,this.sendSignaling(e,t,n+1)]:[3,3];case 2:r=o.sent(),o.label=3;case 3:return[2,r]}})})},r.prototype._sendSignaling=function(e,t){var n=this;return new Promise(function(r,o){var i;if(n._socketTask&&(null===(i=n._socketTask)||void 0===i?void 0:i.readyState)===n._socketTask.OPEN){t.sessionId=n._sessionId,t.timestamp=(new Date).valueOf(),n._requestId++,n._reqSigMap[n._requestId]=e,n._signalingResolveCallbacks[n._requestId]=r,n._signalingRejectCallbacks[n._requestId]=o,n._signalingTimer[n._requestId]=setTimeout(function(){var t=n._signalingRejectCallbacks[n._requestId];"function"==typeof t&&(delete n._signalingRejectCallbacks[n._requestId],t({code:M,reason:e+" signaling timeout"})),delete n._signalingResolveCallbacks[n._requestId]},n._ackTimeout);var s=[e,t];n._report("rtc_signaling",{signaling_event:"call-"+e,direction:"up",message:t}),n._socketTask.send({data:"42"+n._requestId+JSON.stringify(s)})}else o({code:L,reason:"websocket not open"})})},r.prototype._feedbackMessage=function(e,t){var n;if(this._socketTask&&(null===(n=this._socketTask)||void 0===n?void 0:n.readyState)===this._socketTask.OPEN){var r=[e,t];this._report("rtc_signaling",{signaling_event:e,direction:"up",message:t}),this._socketTask.send({data:"42"+JSON.stringify(r)})}},r.prototype._ping=function(){var e,t=this;this._socketTask&&(null===(e=this._socketTask)||void 0===e?void 0:e.readyState)===this._socketTask.OPEN&&(this._socketTask.send({data:"2"}),this._pingTimer=setTimeout(function(){t._report("rtc_websocket",{error_code:0,signaling_server:t._url,message:"pong timeout",signaling_event:"failed"}),t.emit("@signaling/onClose",{code:1006,reason:"pong timeout"}),t._socketTask.close({})},this._pingTimeout))},r.prototype._handleMessage=function(e){var t,n=this;if("3"===e)return this._clearPingTimer(),void setTimeout(function(){return n._ping()},this._pingInterval);var r=this._parseMessage(e);if(0===r.type){var o=(null==r?void 0:r.payload)||{},i=o.pingInterval,s=void 0===i?5e3:i,a=o.pingTimeout,c=void 0===a?1e4:a;return this._pingInterval=s,void(this._pingTimeout=c)}if(4===r.type)if(3===r.packetType){var u=r.requestId;if(u){this._report("rtc_signaling",{signaling_event:r.signalingType,direction:"down",message:r.payload});var d=this._signalingResolveCallbacks[u];clearTimeout(this._signalingTimer[u]),delete this._signalingTimer[u],"function"==typeof d&&(delete this._signalingResolveCallbacks[u],d(r.payload)),delete this._signalingRejectCallbacks[u]}}else 2===r.packetType&&(this._report("rtc_signaling",{signaling_event:"on-"+r.signalingType,direction:"down",message:r.payload}),setTimeout(function(){n.emit("@signaling/"+r.signalingType,r.payload)},0),r.signalingType&&r.payload&&this._feedbackMessage(r.signalingType+"-res",{messageId:null===(t=null==r?void 0:r.payload)||void 0===t?void 0:t.messageId}))},r.prototype._report=function(e,t){t.session_id=this._sessionId,v.report(e,t)},r.prototype._isDigitChar=function(e){return/\d/.test(e)},r.prototype._parseMessage=function(e){for(var t={type:-1,packetType:-1,requestId:"",payload:null,signalingType:""},n=0,r="",o=0;o<e.length;o++){var i=e[o];if(!this._isDigitChar(i)){n=o;break}0===o?t.type=+i:1===o?t.packetType=+i:r+=i}if(t.requestId=r,3===t.packetType){var s=this._reqSigMap[r];s&&(t.signalingType=s)}try{var a=JSON.parse(e.substr(n));Array.isArray(a)?1===a.length?t.payload=a[0]:2===a.length&&(t.signalingType=a[0],t.payload=a[1]):t.payload=a}catch(e){}return t},r.prototype.destroy=function(){this._appId="",this._roomId="",this._userId="",this._token="",this._role="",this._reqSigMap={},e.prototype.removeAllListeners.call(this),this._clearPingTimer(),this.disconnect().catch(function(){})},r.prototype._clearPingTimer=function(){this._pingTimer&&(clearInterval(this._pingTimer),this._pingTimer=null)},r}(c.EventEmitter),J="peer-online",G="peer-leave",z="client-banned",W="stream-added",Y="stream-removed",Q="unmute-audio",X="mute-audio",Z="unmute-video",$="mute-video",ee="disconnect",te="error",ne="close",re="update-url",oe="stream-failed",ie=Object.freeze({__proto__:null,PEER_ONLINE:J,PEER_LEAVE:G,CLIENT_BANNED:z,STREAM_ADDED:W,STREAM_REMOVED:Y,UNMUTE_AUDIO:Q,MUTE_AUDIO:X,UNMUTE_VIDEO:Z,MUTE_VIDEO:$,RECONNECTING:"connecting",RECONNECTED:"reconnected",DISCONNECT:ee,ERROR:te,CLOSE:ne,UPDATE_URL:re,STREAM_FAILED:oe}),se={host:"ws.rtc.volcvideo.com",path:"/rtmp_socket/"},ae=["common.rtc.volcvideo.com","common-hl.rtc.volcvideo.com"];function ce(e){return"boolean"==typeof e}var ue=function(e){function r(t){var n=e.call(this)||this;return n._options=t,n._clsName="Room",n._servers=n._options.servers,n._sshost=n._options.sshost,n._appId=n._options.appId,n._roomId=n._options.roomId,n._userId=n._options.userId,n._token=n._options.token,n._role=n._options.role,n._userAgentIP=n._options._userAgentIP,n._lambdaAddr=n._options._lambdaAddr,n._systemInfo={},n._state=m.Init,n._enableCamera=!0,n._enableMic=!0,n._publishing=!1,n._remoteClients=new Map,n._reconnectFailed=!1,wx.getSystemInfo({success:function(e){n._systemInfo=e}}),n}return t(r,e),r.prototype.connect=function(){return o(this,void 0,void 0,function(){var e,t,n,r,o,s;return i(this,function(i){switch(i.label){case 0:(e=d.getCacheSync(l))&&0!==e.length||(e=[se]),this._state=m.Connecting,i.label=1;case 1:return i.trys.push([1,12,,13]),"string"!=typeof this._sshost?[3,2]:(e=[{host:this._sshost,path:"/rtmp_socket/"}],[3,4]);case 2:return this._servers?[4,this._getKeepAliveUrlsAndCache(this._servers)]:[3,4];case 3:e=i.sent(),i.label=4;case 4:if(!Array.isArray(e)||0===e.length)throw{code:C,reason:"get websocket url failed"};t=e.shift(),i.label=5;case 5:return i.trys.push([5,7,,11]),n=this,[4,this._connectSignaling(t.host)];case 6:return n._signaling=i.sent(),[3,11];case 7:return i.sent(),[4,this._getKeepAliveUrlsAndCache(ae)];case 8:return(r=i.sent())&&r.length>0?(t=r[0],o=this,[4,this._connectSignaling(t.host)]):[3,10];case 9:o._signaling=i.sent(),i.label=10;case 10:return[3,11];case 11:return this._wsDoamin=t,this._handleSignaling(),[3,13];case 12:throw s=i.sent(),this._state=m.Disconnected,s;case 13:return[2]}})})},r.prototype._connectSignaling=function(e){return o(this,void 0,void 0,function(){var t,n;return i(this,function(r){switch(r.label){case 0:return t="wss://"+e+"/rtmp_socket/",[4,(n=new H(this._options)).connect(t)];case 1:return r.sent(),[2,n]}})})},r.prototype.join=function(e){return void 0===e&&(e=!1),o(this,void 0,void 0,function(){var t,n,r,o,s,a,c,u=this;return i(this,function(i){return t=this._systemInfo,n=t.system,r=t.model,o=t.version,s=t.SDKVersion,a=t.platform,c=t.brand,this._checkConnect(),[2,this._signaling.sendSignaling(e?"reconnected":"joinRoom",{roomId:this._roomId,userAttributes:{role:this._role},params:{deviceType:"miniapp",userAgent:"system: "+n+", model: "+r+", version: "+o+", SDKVersion: "+s+", platform: "+a+", brand: "+c,sdkVersion:"3.0.1",deviceId:h(),appId:this._appId,roomId:this._roomId,userId:this._userId,businessId:"",rtcSid:""},Authorization:this._token.startsWith("Basic")?this._token:"Bearer "+this._token,_userAgentIP:this._userAgentIP||"",_lambdaAddr:this._lambdaAddr||""}).then(function(e){if(200!==(null==e?void 0:e.code))throw{code:U,reason:"joinRoom failed",detail:null==e?void 0:e.message};return u._state=m.Connected,u._handleJoinRoomACK(e),e}).catch(function(e){throw u._state=m.Disconnected,e})]})})},r.prototype.leave=function(){return o(this,void 0,void 0,function(){var e=this;return i(this,function(t){return this._checkConnect(),[2,this._signaling.sendSignaling("leaveRoom",{roomId:this._roomId,Authorization:this._token.startsWith("Basic")?this._token:"Bearer "+this._token}).then(function(t){var n,r;if(200!==(null==t?void 0:t.code))throw{code:D,reason:null==t?void 0:t.message};return e._state=m.Disconnected,null===(n=e._signaling)||void 0===n||n.disconnect(),null===(r=e._signaling)||void 0===r||r.removeAllListeners(),t}).catch(function(e){throw e})]})})},r.prototype.getLocalStreamId=function(){return this._publishStreamId},r.prototype.getRemoteStreamId=function(e,t){var n,r,o=this._remoteClients.get(e);return t?null===(n=null==o?void 0:o.screenStream)||void 0===n?void 0:n.streamId:null===(r=null==o?void 0:o.stream)||void 0===r?void 0:r.streamId},r.prototype.destroy=function(){var e;this.leave().catch(function(){}),this._servers=[],this._appId="",this._roomId="",this._userId="",this._token="",this._role="normalUser",null===(e=this._signaling)||void 0===e||e.removeAllListeners(),this._state=m.Init,this._remoteClients.clear(),this._publishRtmp="",this._publishStreamId="",this._enableCamera=!0,this._enableMic=!0,this._reconnectFailed=!1,this._reconnectTimer&&(clearTimeout(this._reconnectTimer),delete this._reconnectTimer)},r.prototype.publish=function(e){return void 0===e&&(e=!1),o(this,void 0,void 0,function(){var t,n;return i(this,function(r){switch(r.label){case 0:this._publishing=!0,r.label=1;case 1:return r.trys.push([1,3,,4]),[4,this._publish(e)];case 2:return t=r.sent(),this._publishing=!1,[2,t];case 3:throw n=r.sent(),this._publishing=!1,n;case 4:return[2]}})})},r.prototype._publish=function(e){return void 0===e&&(e=!1),o(this,void 0,void 0,function(){var t;return i(this,function(n){switch(n.label){case 0:if(this._checkConnect(),!e&&this._publishRtmp)throw{code:S,reason:"published"};return[4,this._signaling.sendSignaling("publish",{roomId:this._roomId,screen:!1,streamId:this._publishStreamId||"",eventSessionId:u(),attributes:{audiostream:this._enableMic,videostream:this._enableCamera},_expectedMSAddr:this._options._expectedMSAddr})];case 1:if(200!==(null==(t=n.sent())?void 0:t.code))throw{code:N,reason:"publish failed",detail:null==t?void 0:t.message};return this._publishRtmp=t.publishRtmpAddr,this._publishStreamId=t.streamId,[2,{rtmp:this._publishRtmp,streamId:this._publishStreamId}]}})})},r.prototype.unpublish=function(){return o(this,void 0,void 0,function(){var e;return i(this,function(t){switch(t.label){case 0:return this._publishRtmp?(this._checkConnect(),[4,this._signaling.sendSignaling("unpublish",{roomId:this._roomId,streamId:this._publishStreamId,eventSessionId:u()})]):[2];case 1:if(200!==(null==(e=t.sent())?void 0:e.code))throw{code:P,reason:"unpublish failed"};return this._publishRtmp="",this._publishStreamId="",[2]}})})},r.prototype.subscribe=function(e,t){return o(this,void 0,void 0,function(){var n=this;return i(this,function(r){return this._checkConnect(),[2,new Promise(function(r,o){var i,s=n._remoteClients.get(e);if(!s)return o({code:k,reason:"uid not found"});var a=t.audio,c=t.video,d=t.screen,l=d?s.screenStream:s.stream;if(!l)return o({code:R,reason:"stream not found"});l.subOption=t,d?("boolean"==typeof s.recvScreenVideo?c=s.recvScreenVideo:"boolean"!=typeof c&&(c=!0),a=c):("boolean"==typeof s.recvAudio?a=s.recvAudio:"boolean"!=typeof a&&(a=!0),"boolean"==typeof s.recvVideo?c=s.recvVideo:"boolean"!=typeof c&&(c=!0)),null===(i=n._signaling)||void 0===i||i.sendSignaling("subscribe",{roomId:n._roomId,streamUserId:e,screen:!!d,uniqueKey:l.uniqueKey,eventSessionId:u(),config:{enableMediaType:{audio:a,video:c}},_expectedMSAddr:n._options._expectedMSAddr}).then(function(e){if(200!==(null==e?void 0:e.code))throw{code:E,reason:"subscribe failed"};t.screen?s.screenStream&&(s.screenStream.rtmp=e.subscribeRtmpAddr,s.screenStream.streamId=e.streamId):s.stream&&(s.stream.rtmp=e.subscribeRtmpAddr,s.stream.streamId=e.streamId),r({rtmp:e.subscribeRtmpAddr,streamId:e.streamId})}).catch(function(e){return o(e)})})]})})},r.prototype.unsubscribe=function(e,t){return o(this,void 0,void 0,function(){var n=this;return i(this,function(r){return this._checkConnect(),[2,new Promise(function(r,o){var i,s,a,c=n._remoteClients.get(e),d="";return c?(d=(null==t?void 0:t.screen)?null===(i=null==c?void 0:c.screenStream)||void 0===i?void 0:i.streamId:null===(s=null==c?void 0:c.stream)||void 0===s?void 0:s.streamId)?void(null===(a=n._signaling)||void 0===a||a.sendSignaling("unsubscribe",{roomId:n._roomId,streamId:d,eventSessionId:u()}).then(function(e){if(200!==(null==e?void 0:e.code))throw{code:T,reason:"unsubscribe failed"};r()}).catch(function(e){return o(e)})):o({code:R,reason:"stream not found"}):o({code:k,reason:"uid not found"})})]})})},r.prototype.muteLocal=function(e){return o(this,void 0,void 0,function(){var t=this;return i(this,function(n){return this._checkConnect(),[2,new Promise(function(n,r){if("boolean"==typeof e.audio&&(t._enableMic=e.audio),"boolean"==typeof e.video&&(t._enableCamera=e.video),!t._publishRtmp&&!t._publishing)return n();var o={};"boolean"==typeof e.audio&&(o.audiostream=e.audio),"boolean"==typeof e.video&&(o.videostream=e.video),t._signaling.sendSignaling("updateStreamAttributes",{roomId:t._roomId,streamId:t._publishStreamId,attributes:o,eventSessionId:u()}).then(function(e){if(200!==(null==e?void 0:e.code))throw{code:A,reason:"muteLocal/unmuteLocal failed"};n()}).catch(function(e){return r(e)})})]})})},r.prototype.muteRemote=function(e,t){return o(this,void 0,void 0,function(){var n=this;return i(this,function(r){return this._checkConnect(),[2,new Promise(function(r,o){var i,s,a,c,d=n._remoteClients.get(e);return d?(c=t.screen?null===(i=null==d?void 0:d.screenStream)||void 0===i?void 0:i.streamId:null===(s=null==d?void 0:d.stream)||void 0===s?void 0:s.streamId,t.screen?("boolean"==typeof t.video?d.recvScreenVideo=t.video:t.video=!!d.recvScreenVideo,t.audio=t.video):("boolean"==typeof t.audio?d.recvAudio=t.audio:t.audio="boolean"!=typeof d.recvAudio||d.recvAudio,"boolean"==typeof t.video?d.recvVideo=t.video:t.video="boolean"!=typeof d.recvVideo||d.recvVideo),c?(delete t.screen,void(null===(a=n._signaling)||void 0===a||a.sendSignaling("updateSubscribe",{roomId:n._roomId,streamId:c,config:{enableMediaType:{audio:t.audio,video:t.video}},eventSessionId:u()}).then(function(e){if(200!==(null==e?void 0:e.code))throw{code:O,reason:"mute/unmute failed"};r()}).catch(function(e){return o(e)}))):r()):o({code:k,reason:"uid not found"})})]})})},r.prototype.updateUserAttributes=function(e){return o(this,void 0,void 0,function(){return i(this,function(t){switch(t.label){case 0:return this._checkConnect(),this._role=e.role,[4,this._signaling.sendSignaling("updateUserAttributes",{roomId:this._roomId,attributes:e,eventSessionId:u()})];case 1:return t.sent(),[2]}})})},r.prototype.getStreamInfo=function(e){var t,n,r={streamId:"",rtmp:""},o=this._remoteClients.get(e);return(null==o?void 0:o.stream)&&(r.streamId=null===(t=o.stream)||void 0===t?void 0:t.streamId,r.rtmp=null===(n=o.stream)||void 0===n?void 0:n.rtmp),r},r.prototype._getKeepAliveUrlsAndCache=function(e){return o(this,void 0,void 0,function(){var t,n=this;return i(this,function(r){return t=e.map(function(t){var r={appID:n._appId,roomID:n._roomId,keys:["multiDomain"],labelSelector:"serviceType=rtmp",sdkVersion:"3.0.1",deviceType:"miniapp"};return v.report("rtc_get_config",{error_code:0,host:e,type:"request",message:JSON.stringify(r)}),p("https://"+t+"/decision/v1/multi",{method:"POST",body:r})}),[2,f(t).then(function(e){var t;void 0===e&&(e={});var r=e.multiDomain,o=e.domainBlacklist;return v.report("rtc_get_config",{error_code:0,message:JSON.stringify(e),type:"response"}),d.setCacheSync(l,r),Array.isArray(o)&&o.find(function(e){var t;return e===(null===(t=n._wsDoamin)||void 0===t?void 0:t.host)})&&n._clientEmit(ne,{code:B,reason:"current websocket domain "+(null===(t=n._wsDoamin)||void 0===t?void 0:t.host)+" in blacklist"}),r}).catch(function(e){throw v.report("rtc_get_config",{error_code:e.code,message:e.reason,type:"response"}),e})]})})},r.prototype._handleSignaling=function(){var e,t,n,r,o,i,s,a,c=this;null===(e=this._signaling)||void 0===e||e.on("@signaling/onClose",function(e){var t,n;if(1006===e.code)return v.report("rtc_invoke_status",{sdk_api_name:"1006"}),null===(t=c._signaling)||void 0===t||t.destroy(),c._signaling=new H({appId:c._appId,roomId:c._roomId,userId:c._userId,token:c._token,role:c._role}),c._handleSignaling(),void(c._reconnectTimer=setTimeout(function(){var e,t="wss://"+c._wsDoamin.host+c._wsDoamin.path;v.report("rtc_invoke_status",{sdk_api_name:"socket_reconnect",message:"start"}),null===(e=c._signaling)||void 0===e||e.connect(t).then(function(){c.join(!0).then(c._reconnectSuccess.bind(c)),c._reconnectFailed=!1,delete c._reconnectTimer,v.report("rtc_invoke_status",{sdk_api_name:"socket_reconnect",message:"success"})}).catch(function(){c._reconnectFailed=!0,delete c._reconnectTimer,v.report("rtc_invoke_status",{sdk_api_name:"socket_reconnect",message:"failed"})})},c._reconnectFailed?3e3:0));c._state=m.Disconnected,null===(n=c._signaling)||void 0===n||n.destroy(),delete c._signaling,c._clientEmit(ee,e)}),null===(t=this._signaling)||void 0===t||t.on("@signaling/error",function(e){var t;v.report("rtc_error",{error_code:e.code,message:{from:"wx.socket onerror",reason:e.reason}}),null===(t=c._signaling)||void 0===t||t.destroy(),delete c._signaling,c._state=m.Disconnected,c._clientEmit(te,e)}),null===(n=this._signaling)||void 0===n||n.on("@signaling/userConnection",this._onUserConnect.bind(this)),null===(r=this._signaling)||void 0===r||r.on("@signaling/userDisconnection",this._onUserDisconnect.bind(this)),null===(o=this._signaling)||void 0===o||o.on("@signaling/onAddStream",this._onAddStream.bind(this)),null===(i=this._signaling)||void 0===i||i.on("@signaling/onRemoveStream",this._onRemoveStream.bind(this)),null===(s=this._signaling)||void 0===s||s.on("@signaling/streamFailed",this._onStreamFailed.bind(this)),null===(a=this._signaling)||void 0===a||a.on("@signaling/onUpdateStreamAttributes",this._onUpdateStreamAttributes.bind(this))},r.prototype._handleJoinRoomACK=function(e){var t=this,n=e.clients,r=e.streams,o=new Map(this._remoteClients);Array.isArray(n)&&n.forEach(function(e){o.has(e)?o.delete(e):t._onUserConnect({clientId:e})}),o.forEach(function(e){t._onUserDisconnect({clientId:e.clientId})}),Array.isArray(r)&&r.forEach(this._onAddStream.bind(this))},r.prototype._reconnectSuccess=function(){return o(this,void 0,void 0,function(){var e,t;return i(this,function(n){switch(n.label){case 0:if(!this._publishRtmp)return[3,4];e=this._publishRtmp,n.label=1;case 1:return n.trys.push([1,3,,4]),[4,this.publish(!0)];case 2:return(t=n.sent().rtmp)!==e&&this._clientEmit(re,{uid:this._userId,screen:!1,url:t}),[3,4];case 3:return n.sent(),this._clientEmit(oe,{uid:this._userId,screen:!1,reason:"publish failed after reconnection"}),[3,4];case 4:return[2]}})})},r.prototype._onUserConnect=function(e){var t=e.clientId;t!==this._userId&&(this._remoteClients.set(t,{clientId:t}),this._clientEmit(J,{uid:t}))},r.prototype._onUserDisconnect=function(e){var t=e.clientId,n=e.tag;if(t===this._userId){var r=null;n===s.kickedByAdmin?r=x:n===s.roomDismissed?r=q:n===s.userDuplicateLogin?r=j:n===s.serverError&&(r=V),r&&(this._clientEmit(z,{errorCode:r}),this.emit("@room/client-banned",{errorCode:r}))}else this._onRemoveStream({clientId:t,screen:!0,roomId:this._roomId}),this._onRemoveStream({clientId:t,screen:!1,roomId:this._roomId}),this._clientEmit(G,{uid:t}),this._remoteClients.delete(t)},r.prototype._onAddStream=function(e){var t,n;return o(this,void 0,void 0,function(){var r,o,s,a,c;return i(this,function(i){switch(i.label){case 0:return r=this._remoteClients.get(e.streamUserId),o=e.screen?"screenStream":"stream",r?(s=r[o])?[3,1]:(r[o]={uniqueKey:e.uniqueKey,attributes:e.attributes},this._clientEmit(W,{uid:e.streamUserId,screen:e.screen}),[3,6]):[3,6];case 1:if(s.uniqueKey===e.uniqueKey)return[3,6];v.report("rtc_invoke_status",{sdk_api_name:"uniqueKey.change",message:JSON.stringify({stream:s,uniqueKey:e.uniqueKey})}),s.uniqueKey=e.uniqueKey,a="",i.label=2;case 2:return i.trys.push([2,4,,5]),[4,this.subscribe(e.streamUserId,{screen:e.screen,audio:null===(t=s.subOption)||void 0===t?void 0:t.audio,video:null===(n=s.subOption)||void 0===n?void 0:n.video})];case 3:return c=i.sent(),a=c.rtmp,[3,5];case 4:return i.sent(),[3,5];case 5:a?this._clientEmit(re,{uid:e.streamUserId,screen:e.screen,url:a}):this._clientEmit(oe,{uid:e.streamUserId,screen:e.screen,reason:"re-subscribe failed."}),i.label=6;case 6:return[2]}})})},r.prototype._onRemoveStream=function(e){var t=e.clientId,n=e.screen;if(t!==this._userId){var r=this._remoteClients.get(t);if(r){if(n){if(!r.screenStream)return;delete r.screenStream}else{if(!r.stream)return;delete r.stream}this._clientEmit(Y,{uid:t,screen:n})}}},r.prototype._onStreamFailed=function(e){var t,n,r,s;return o(this,void 0,void 0,function(){var o,a,c,u,d,l,_,h,p;return i(this,function(i){switch(i.label){case 0:if(o=/4[0-9][0-9]/.test(e.code.toString()),e.streamId!==this._publishStreamId)return[3,6];this._publishRtmp="",h="",i.label=1;case 1:return i.trys.push([1,4,,5]),o?[3,3]:[4,this.publish()];case 2:p=i.sent(),h=p.rtmp,i.label=3;case 3:return[3,5];case 4:return i.sent(),[3,5];case 5:return h?this._clientEmit(re,{uid:this._userId,screen:!1,url:h}):this._clientEmit(oe,{uid:this._userId,screen:!1,reason:e.message}),[3,12];case 6:for(a=void 0,c=!1,u=this._remoteClients.values(),d=0;d<this._remoteClients.size;d++){if(l=u.next().value,(null===(t=null==l?void 0:l.stream)||void 0===t?void 0:t.streamId)===e.streamId){a=l;break}if((null===(n=null==l?void 0:l.screenStream)||void 0===n?void 0:n.streamId)===e.streamId){a=l,c=!0;break}}if(!a)return[3,12];_=a[c?"screenStream":"stream"],h="",i.label=7;case 7:return i.trys.push([7,10,,11]),o?[3,9]:[4,this.subscribe(a.clientId,{audio:null===(r=null==_?void 0:_.subOption)||void 0===r?void 0:r.audio,video:null===(s=null==_?void 0:_.subOption)||void 0===s?void 0:s.video,screen:c})];case 8:p=i.sent(),h=p.rtmp,i.label=9;case 9:return[3,11];case 10:return i.sent(),[3,11];case 11:h?this._clientEmit(re,{uid:a.clientId,screen:c,url:h}):(this._clientEmit(Y,{uid:a.clientId,screen:c}),c?delete a.screenStream:delete a.stream),i.label=12;case 12:return[2]}})})},r.prototype._onUpdateStreamAttributes=function(e){for(var t,r,o=e.streamId,i=e.attributes,s=null,a=null,c=!1,u=this._remoteClients.values(),d=0;d<this._remoteClients.size;d++){var l=u.next().value;if((null===(t=null==l?void 0:l.stream)||void 0===t?void 0:t.streamId)===o){s=l,a=l.stream;break}if((null===(r=null==l?void 0:l.screenStream)||void 0===r?void 0:r.streamId)===o){c=!0,s=l,a=l.screenStream;break}}if(s&&a){var _=i.audiostream,h=i.videostream,p=a.attributes,m=p.audiostream,f=p.videostream;ce(_)&&ce(m)&&_!==m&&(_?this._clientEmit(Q,{uid:s.clientId,screen:c}):this._clientEmit(X,{uid:s.clientId,screen:c})),ce(h)&&ce(f)&&h!==f&&(h?this._clientEmit(Z,{uid:s.clientId,screen:c}):this._clientEmit($,{uid:s.clientId,screen:c})),a.attributes||(a.attributes={}),a.attributes=n(n({},a.attributes),i)}},r.prototype._checkConnect=function(){if(!this._signaling)throw{code:L,reason:"websocket not open"}},r.prototype._clientEmit=function(e,t){v.report("rtc_sdk_callback",{sdk_callback_name:e,message:t}),this._options.emit.call(null,e,t)},Object.defineProperty(r.prototype,"state",{get:function(){return this._state},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"localRtmp",{get:function(){return this._publishRtmp},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"localStreamId",{get:function(){return this._publishStreamId},enumerable:!1,configurable:!0}),r}(c.EventEmitter),de=h();function le(e){var t={event:e.event,streamID:e.streamID,streamAddr:e.streamAddr,userID:e.userID,roomID:e.roomID,deviceID:de,rtcSID:de,appID:e.appID,sdkVersion:"3.0.1",result:e.result,reason:e.reason,code:e.code};v.report("rtc_invoke_status",{sdk_api_name:"UploadRTMPResult",message:"start"+JSON.stringify(t)}),p("https://"+(e.logHost||"common.rtc.volcvideo.com")+"/dispatch/v1/Report?Action=UploadRTMPResult",{method:"POST",body:t}).then(function(){v.report("rtc_invoke_status",{sdk_api_name:"UploadRTMPResult",message:"success"})}).catch(function(e){v.report("rtc_invoke_status",{sdk_api_name:"UploadRTMPResult",message:"error"+JSON.stringify(e)})})}function _e(e){return void 0===e&&(e=0),function(t,n,r){var o=r.value;r.value=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];var r=o.apply(this,t);return r.then(t[e],t[e+1]),r}}}function he(e){return new Promise(function(t){setTimeout(function(){t()},e)})}function pe(){return function(e,t,n){if("function"==typeof n.value){var r=n.value;n.value=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];v.report("rtc_sdk_api_call",{sdk_api_name:t,message:e.filter(function(e){return"function"!=typeof e})});var o=r.apply(this,e);return"function"==typeof(null==o?void 0:o.then)?o.then(function(e){return v.report("rtc_sdk_callback",{sdk_callback_name:t,errorCode:0,message:JSON.stringify(e||{})}),e}).catch(function(e){throw v.report("rtc_sdk_callback",{sdk_callback_name:t,errorCode:e.code,message:JSON.stringify(e.message)}),e}):(v.report("rtc_sdk_callback",{sdk_callback_name:t,errorCode:0,message:JSON.stringify(o||{})}),o)}}}}return{Client:function(e){function s(t){void 0===t&&(t={});var n=e.call(this)||this;n._role="normalUser",n._inited=!1,n._clsName="Client";var r=t.servers,o=t.sshost,i=t.logHost,s=t._userAgentIP,a=t._lambdaAddr;return n._servers=r,n._sshost=o,n._logHost=i,n._reported={},n._userAgentIP=s,n._lambdaAddr=a,n._expectedMSAddr=t._expectedMSAddr,wx.__client=n,n}return t(s,e),s.prototype.init=function(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];return o(this,void 0,void 0,function(){return i(this,function(t){if(!e||"string"!=typeof e)throw{code:g,reason:"appId must be a string"};if(this._inited)throw{code:w,reason:"Has been initialized"};return this._appId=e,this._inited=!0,[2]})})},s.prototype.destroy=function(){for(var e,t,n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];return o(this,void 0,void 0,function(){return i(this,function(n){(null===(e=this._room)||void 0===e?void 0:e.state)===m.Connected&&this.leave().catch(function(){}),this._room&&this._room.removeAllListeners("@room/client-banned");try{null===(t=this._room)||void 0===t||t.destroy(),this._inited=!1,this._appId="",this._roomId="",this._userId="",this._token="",this._room=null,this._reported={}}catch(e){}return[2]})})},s.prototype.setUserVisibility=function(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];return o(this,void 0,void 0,function(){var t;return i(this,function(n){switch(n.label){case 0:if(t=e?"normalUser":"silentUser",this._role===t)return[2];if(!this._room)return this._role=t,[2];if(this._room.state===m.Connecting||this._room.state===m.Reconnecting)throw{code:I,reason:"connecting"};return e?[3,2]:[4,this._room.unpublish()];case 1:n.sent(),n.label=2;case 2:return[4,this._room.updateUserAttributes({role:t})];case 3:return n.sent(),this._role=t,[2]}})})},s.prototype.join=function(e,t,n){for(var r,s,a,c=[],u=3;u<arguments.length;u++)c[u-3]=arguments[u];return o(this,void 0,void 0,function(){var o,c,u;return i(this,function(i){switch(i.label){case 0:if(!t||"string"!=typeof t||!n||"string"!=typeof n)throw{code:g,reason:"roomId: "+t+" or userId: "+n+" must be a string"};if((null===(r=this._room)||void 0===r?void 0:r.state)===m.Connecting||(null===(s=this._room)||void 0===s?void 0:s.state)===m.Reconnecting)throw{code:I,reason:"connecting"};if((null===(a=this._room)||void 0===a?void 0:a.state)===m.Connected)throw{code:b,reason:"you are already in room"};v.report("join_room",{type:"begin",start:Date.now()}),v.updateHeader({rtc_app_id:this._appId,room_id:t,user_id:n}),this._roomId=t,this._userId=n,this._token=e,this._room=new ue({servers:this._servers,sshost:this._sshost,appId:this._appId,roomId:t,userId:n,token:e,role:this._role,_userAgentIP:this._userAgentIP,_lambdaAddr:this._lambdaAddr,_expectedMSAddr:this._expectedMSAddr,emit:this.emit.bind(this)}),this._handleRoom(),i.label=1;case 1:return i.trys.push([1,3,,4]),[4,this._room.connect()];case 2:return i.sent(),[3,4];case 3:throw o=i.sent(),v.report("join_room",{type:"end",result:!1,start:Date.now()}),o;case 4:return[4,he(0)];case 5:i.sent(),i.label=6;case 6:return i.trys.push([6,8,,9]),[4,this._room.join()];case 7:return c=i.sent(),v.report("rtc_join_room",{error_code:0,message:c,start:Date.now()}),v.report("join_room",{type:"end",result:!0,start:Date.now()}),v.resume(),[2,c.clientId];case 8:throw u=i.sent(),v.report("join_room",{type:"end",result:!1,start:Date.now()}),u;case 9:return[2]}})})},s.prototype.leave=function(){for(var e,t,n,r=[],s=0;s<arguments.length;s++)r[s]=arguments[s];return o(this,void 0,void 0,function(){return i(this,function(r){return(null===(e=this._room)||void 0===e?void 0:e.localRtmp)&&this.unpublish().catch(function(){}),null===(t=this._room)||void 0===t||t.leave().catch(function(){}),null===(n=this._room)||void 0===n||n.destroy(),this._room=null,v.report("rtc_leave_room",{error_code:0,start:Date.now()}),v.stop(),[2]})})},s.prototype.publish=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return o(this,void 0,void 0,function(){var e,t,n,r;return i(this,function(o){switch(o.label){case 0:if(!this._room||this._room.state!==m.Connected)throw{code:y,reason:"you are not in room"};if("silentUser"===this._role)throw{code:N,reason:"no publish permission"};o.label=1;case 1:return o.trys.push([1,3,,4]),[4,this._room.publish()];case 2:return e=o.sent(),t=e.rtmp,n=e.streamId,v.report("rtc_publish",{error_code:0,is_screen:!1,direction:"up",stream_id:n}),[2,t];case 3:throw r=o.sent(),v.report("rtc_publish_fail",{error_code:r.code,message:r.reason,is_screen:!1,direction:"up"}),r;case 4:return[2]}})})},s.prototype.unpublish=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return o(this,void 0,void 0,function(){return i(this,function(e){switch(e.label){case 0:if(!this._room||this._room.state!==m.Connected)throw{code:y,reason:"you are not in room"};return[4,this._room.unpublish()];case 1:return[2,e.sent()]}})})},s.prototype.subscribe=function(e,t){for(var r=[],s=2;s<arguments.length;s++)r[s-2]=arguments[s];return o(this,void 0,void 0,function(){var r,o,s,a;return i(this,function(i){switch(i.label){case 0:if(t=n(n({},{audio:!0,video:!0,screen:!1}),t),"string"!=typeof e)throw{code:g,reason:"userId: "+e+" must be a string"};if(!this._room||this._room.state!==m.Connected)throw{code:y,reason:"you are not in room"};i.label=1;case 1:return i.trys.push([1,3,,4]),[4,this._room.subscribe(e,t)];case 2:return r=i.sent(),o=r.rtmp,s=r.streamId,v.report("rtc_subscribe",{error_code:0,direction:"down",stream_id:s}),[2,o];case 3:throw a=i.sent(),v.report("rtc_subscribe_fail",{error_code:a.code,message:a.reason,direction:"down"}),a;case 4:return[2]}})})},s.prototype.unsubscribe=function(e,t){for(var r=[],s=2;s<arguments.length;s++)r[s-2]=arguments[s];return o(this,void 0,void 0,function(){return i(this,function(r){switch(r.label){case 0:if(t=n(n({},{screen:!1}),t),"string"!=typeof e)throw{code:g,reason:"userId: "+e+" must be a string"};if(!this._room||this._room.state!==m.Connected)throw{code:y,reason:"you are not in room"};return[4,this._room.unsubscribe(e,t)];case 1:return[2,r.sent()]}})})},s.prototype.muteLocal=function(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];return o(this,void 0,void 0,function(){return i(this,function(t){switch(t.label){case 0:if(!this._room||this._room.state!==m.Connected)throw{code:y,reason:"you are not in room"};return[4,this._room.muteLocal(e)];case 1:return[2,t.sent()]}})})},s.prototype.muteRemote=function(e,t){for(var r=[],s=2;s<arguments.length;s++)r[s-2]=arguments[s];return o(this,void 0,void 0,function(){return i(this,function(r){switch(r.label){case 0:if(t=n(n({},{screen:!1}),t),!this._room||this._room.state!==m.Connected)throw{code:y,reason:"you are not in room"};if(!e||"string"!=typeof e)throw{code:g,reason:"userId: "+e+" must be a string"};if("boolean"!=typeof(null==t?void 0:t.audio)&&"boolean"!=typeof(null==t?void 0:t.video))throw{code:g,reason:"options.audio or audio.video must be present"};return[4,this._room.muteRemote(e,t)];case 1:return[2,r.sent()]}})})},s.prototype._handleRoom=function(){var e=this;this._room&&this._room.on("@room/client-banned",function(){var t;null===(t=e._room)||void 0===t||t.destroy(),e.destroy()})},s.prototype.reportPusherStateChange=function(e,t){var n,r,o,i,s,a,c;if(v.report("rtc_media_statistics",{direction:"up",error_code:e,message:t,stream_id:null===(n=this._room)||void 0===n?void 0:n.getLocalStreamId()}),1008===e){var u=this._userId+"_"+(null===(r=null==this?void 0:this._room)||void 0===r?void 0:r.localStreamId)+"_success";if(this._reported[u])return;this._reported[u]=!0,le({event:"publish",streamID:(null===(o=this._room)||void 0===o?void 0:o.localStreamId)||"",streamAddr:(null===(i=this._room)||void 0===i?void 0:i.localRtmp)||"",userID:this._userId,roomID:this._roomId,appID:this._appId,result:"success",reason:t,code:e,logHost:this._logHost})}else if(-1307===e){if(u=this._userId+"_"+(null===(s=null==this?void 0:this._room)||void 0===s?void 0:s.localStreamId)+"_failed",this._reported[u])return;le({event:"publish",streamID:(null===(a=this._room)||void 0===a?void 0:a.localStreamId)||"",streamAddr:(null===(c=this._room)||void 0===c?void 0:c.localRtmp)||"",userID:this._userId,roomID:this._roomId,appID:this._appId,result:"failed",reason:t,code:e,logHost:this._logHost})}},s.prototype.reportPusherNetStatusChange=function(e){var t;v.report("rtc_media_statistics",n(n({direction:"up"},e),{frame_rate_sent:e.videoFPS,stream_id:null===(t=this._room)||void 0===t?void 0:t.getLocalStreamId()}))},s.prototype.reportPlayerStateChange=function(e,t,n,r){var o,i,s;if(void 0===r&&(r=!1),v.report("rtc_media_statistics",{direction:"down",user_id:this._userId,stream_user_id:e,error_code:t,message:n,stream_id:null===(o=this._room)||void 0===o?void 0:o.getRemoteStreamId(e,!!r)}),2004===t){var a=e+"_"+(null==(c=null===(i=this._room)||void 0===i?void 0:i.getStreamInfo(e))?void 0:c.streamId)+"_success";if(this._reported[a])return;this._reported[a]=!0,le({event:"subscribe",streamID:(null==c?void 0:c.streamId)||"",streamAddr:(null==c?void 0:c.rtmp)||"",userID:this._userId,roomID:this._roomId,appID:this._appId,result:"success",reason:n,code:t,logHost:this._logHost})}else if([-2301,3001,3002,3003,3005].includes(t)){var c;if(a=e+"_"+(null==(c=null===(s=this._room)||void 0===s?void 0:s.getStreamInfo(e))?void 0:c.streamId)+"_failed",this._reported[a])return;this._reported[a]=!0,le({event:"subscribe",streamID:(null==c?void 0:c.streamId)||"",streamAddr:(null==c?void 0:c.rtmp)||"",userID:this._userId,roomID:this._roomId,appID:this._appId,result:"failed",reason:n,code:t,logHost:this._logHost})}},s.prototype.reportPlayerNetStatusChange=function(e,t,r){var o;void 0===r&&(r=!1),v.report("rtc_media_statistics",n(n({direction:"down",user_id:this._userId,stream_user_id:e},t),{frame_rate_received:t.videoFPS,stream_id:null===(o=this._room)||void 0===o?void 0:o.getRemoteStreamId(e,!!r)}))},Object.defineProperty(s.prototype,"state",{get:function(){var e,t;return null!==(t=null===(e=this._room)||void 0===e?void 0:e.state)&&void 0!==t?t:m.Init},enumerable:!1,configurable:!0}),r([pe(),_e(1)],s.prototype,"init",null),r([pe(),_e()],s.prototype,"destroy",null),r([pe(),_e(1)],s.prototype,"setUserVisibility",null),r([pe(),_e(3)],s.prototype,"join",null),r([pe(),_e()],s.prototype,"leave",null),r([pe(),_e()],s.prototype,"publish",null),r([pe(),_e()],s.prototype,"unpublish",null),r([pe(),_e(2)],s.prototype,"subscribe",null),r([pe(),_e(2)],s.prototype,"unsubscribe",null),r([pe(),_e(1)],s.prototype,"muteLocal",null),r([pe(),_e(2)],s.prototype,"muteRemote",null),s}(c.EventEmitter),EVENTS:ie,ERROR_CODES:F,getSdkVersion:function(){return"3.0.1"}}}); |