Files
陈誉午 994b267f5c feat: 电子药箱小程序 - 4Tab药品管理
- 电子药箱: 药品库存管理 + 手动录入 + 今日用药打卡
- 药品百科: 搜索 + 分类筛选 + 20种药品静态数据
- 惠教中心: 4条药品使用指南课程
- 我的: 家庭成员信息管理
- 自定义TabBar + navigation-bar组件
- SVG药品分类插图
2026-07-29 11:20:52 +08:00

1 line
28 KiB
JavaScript

"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var _contants=require("../contants"),_rtcClient=_interopRequireDefault(require("./rtc-client")),_socket=require("../../../utils/socket");function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}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 _toConsumableArray(e){return _arrayWithoutHoles(e)||_iterableToArray(e)||_unsupportedIterableToArray(e)||_nonIterableSpread()}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(e,t){if(e){if("string"==typeof e)return _arrayLikeToArray(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?_arrayLikeToArray(e,t):void 0}}function _iterableToArray(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function _arrayWithoutHoles(e){if(Array.isArray(e))return _arrayLikeToArray(e)}function _arrayLikeToArray(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function ownKeys(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function _objectSpread(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?ownKeys(Object(n),!0).forEach(function(t){_defineProperty(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):ownKeys(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function _defineProperty(e,t,n){return(t=_toPropertyKey(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function _regeneratorRuntime(){_regeneratorRuntime=function(){return e};var e={},t=Object.prototype,n=t.hasOwnProperty,r=Object.defineProperty||function(e,t,n){e[t]=n.value},o="function"==typeof Symbol?Symbol:{},a=o.iterator||"@@iterator",i=o.asyncIterator||"@@asyncIterator",s=o.toStringTag||"@@toStringTag";function c(e,t,n){return Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{c({},"")}catch(e){c=function(e,t,n){return e[t]=n}}function u(e,t,n,o){var a=t&&t.prototype instanceof h?t:h,i=Object.create(a.prototype),s=new w(o||[]);return r(i,"_invoke",{value:S(e,n,s)}),i}function l(e,t,n){try{return{type:"normal",arg:e.call(t,n)}}catch(e){return{type:"throw",arg:e}}}e.wrap=u;var d={};function h(){}function p(){}function f(){}var y={};c(y,a,function(){return this});var v=Object.getPrototypeOf,m=v&&v(v(A([])));m&&m!==t&&n.call(m,a)&&(y=m);var _=f.prototype=h.prototype=Object.create(y);function g(e){["next","throw","return"].forEach(function(t){c(e,t,function(e){return this._invoke(t,e)})})}function k(e,t){function o(r,a,i,s){var c=l(e[r],e,a);if("throw"!==c.type){var u=c.arg,d=u.value;return d&&"object"==_typeof(d)&&n.call(d,"__await")?t.resolve(d.__await).then(function(e){o("next",e,i,s)},function(e){o("throw",e,i,s)}):t.resolve(d).then(function(e){u.value=e,i(u)},function(e){return o("throw",e,i,s)})}s(c.arg)}var a;r(this,"_invoke",{value:function(e,n){function r(){return new t(function(t,r){o(e,n,t,r)})}return a=a?a.then(r,r):r()}})}function S(e,t,n){var r="suspendedStart";return function(o,a){if("executing"===r)throw new Error("Generator is already running");if("completed"===r){if("throw"===o)throw a;return{value:void 0,done:!0}}for(n.method=o,n.arg=a;;){var i=n.delegate;if(i){var s=I(i,n);if(s){if(s===d)continue;return s}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if("suspendedStart"===r)throw r="completed",n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);r="executing";var c=l(e,t,n);if("normal"===c.type){if(r=n.done?"completed":"suspendedYield",c.arg===d)continue;return{value:c.arg,done:n.done}}"throw"===c.type&&(r="completed",n.method="throw",n.arg=c.arg)}}}function I(e,t){var n=t.method,r=e.iterator[n];if(void 0===r)return t.delegate=null,"throw"===n&&e.iterator.return&&(t.method="return",t.arg=void 0,I(e,t),"throw"===t.method)||"return"!==n&&(t.method="throw",t.arg=new TypeError("The iterator does not provide a '"+n+"' method")),d;var o=l(r,e.iterator,t.arg);if("throw"===o.type)return t.method="throw",t.arg=o.arg,t.delegate=null,d;var a=o.arg;return a?a.done?(t[e.resultName]=a.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,d):a:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,d)}function b(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function L(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function w(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(b,this),this.reset(!0)}function A(e){if(e){var t=e[a];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var r=-1,o=function t(){for(;++r<e.length;)if(n.call(e,r))return t.value=e[r],t.done=!1,t;return t.value=void 0,t.done=!0,t};return o.next=o}}return{next:E}}function E(){return{value:void 0,done:!0}}return p.prototype=f,r(_,"constructor",{value:f,configurable:!0}),r(f,"constructor",{value:p,configurable:!0}),p.displayName=c(f,s,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===p||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,f):(e.__proto__=f,c(e,s,"GeneratorFunction")),e.prototype=Object.create(_),e},e.awrap=function(e){return{__await:e}},g(k.prototype),c(k.prototype,i,function(){return this}),e.AsyncIterator=k,e.async=function(t,n,r,o,a){void 0===a&&(a=Promise);var i=new k(u(t,n,r,o),a);return e.isGeneratorFunction(n)?i:i.next().then(function(e){return e.done?e.value:i.next()})},g(_),c(_,s,"Generator"),c(_,a,function(){return this}),c(_,"toString",function(){return"[object Generator]"}),e.keys=function(e){var t=Object(e),n=[];for(var r in t)n.push(r);return n.reverse(),function e(){for(;n.length;){var r=n.pop();if(r in t)return e.value=r,e.done=!1,e}return e.done=!0,e}},e.values=A,w.prototype={constructor:w,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(L),!e)for(var t in this)"t"===t.charAt(0)&&n.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=void 0)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function r(n,r){return i.type="throw",i.arg=e,t.next=n,r&&(t.method="next",t.arg=void 0),!!r}for(var o=this.tryEntries.length-1;o>=0;--o){var a=this.tryEntries[o],i=a.completion;if("root"===a.tryLoc)return r("end");if(a.tryLoc<=this.prev){var s=n.call(a,"catchLoc"),c=n.call(a,"finallyLoc");if(s&&c){if(this.prev<a.catchLoc)return r(a.catchLoc,!0);if(this.prev<a.finallyLoc)return r(a.finallyLoc)}else if(s){if(this.prev<a.catchLoc)return r(a.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return r(a.finallyLoc)}}}},abrupt:function(e,t){for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var a=o;break}}a&&("break"===e||"continue"===e)&&a.tryLoc<=t&&t<=a.finallyLoc&&(a=null);var i=a?a.completion:{};return i.type=e,i.arg=t,a?(this.method="next",this.next=a.finallyLoc,d):this.complete(i)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),d},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),L(n),d}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.tryLoc===e){var r=n.completion;if("throw"===r.type){var o=r.arg;L(n)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,n){return this.delegate={iterator:A(e),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=void 0),d}},e}function asyncGeneratorStep(e,t,n,r,o,a,i){try{var s=e[a](i),c=s.value}catch(e){return void n(e)}s.done?t(c):Promise.resolve(c).then(r,o)}function _asyncToGenerator(e){return function(){var t=this,n=arguments;return new Promise(function(r,o){var a=e.apply(t,n);function i(e){asyncGeneratorStep(a,r,o,i,s,"next",e)}function s(e){asyncGeneratorStep(a,r,o,i,s,"throw",e)}i(void 0)})}}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,_toPropertyKey(r.key),r)}}function _createClass(e,t,n){return t&&_defineProperties(e.prototype,t),n&&_defineProperties(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function _toPropertyKey(e){var t=_toPrimitive(e,"string");return"symbol"===_typeof(t)?t:String(t)}function _toPrimitive(e,t){if("object"!==_typeof(e)||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,t||"default");if("object"!==_typeof(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}var RtcSdk=require("../../../lib/vertc/VolcEngineRTC_MiniApp_3.0.1"),API_PATH={GetLinkUserList:"/live/platform/v1/link/aggregation/get",UpdateLinkUserHeartBeat:"/live/platform/v1/link/heart/update",GetRTCToken:"/live/platform/v3/activity/rtc/token",UpdateAudienceLinkStatus:"/live/platform/v1/link/audience/status/update",GetAudienceLinkStatus:"/live/platform/v1/link/audience/status/get",UpdateLinkEnterRoomStatus:"/live/platform/v1/link/user/enter",UpdateLinkUserMediaStatus:"/live/platform/v1/link/user/media/update"},LOOP_KEY={GetApplyConnectStatus:null,GetLinkUserList:null,Heart:null},ConnectLogic=function(){function e(t,n){_classCallCheck(this,e),this.component=t,this.handleStateChange=n,this.LayoutGetInterval=5e3,this.publishUrl="",this.streamMap={},this.screenStreamMap={},this.sdkInstance=t.sdkInstance,this.store=t.store}var t,n,r,o,a,i,s,c,u,l;return _createClass(e,[{key:"updateApplyConnectStatus",value:(l=_asyncToGenerator(_regeneratorRuntime().mark(function e(t){var n,r,o,a,i;return _regeneratorRuntime().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return n=this.store.get("mainInfo"),r=n.activityId,o=this.store.get("userInfo"),a=o.userId,console.log("userId:",a),e.next=5,this.sdkInstance.request(API_PATH.UpdateAudienceLinkStatus,{method:"POST",data:{ActivityId:r,UserId:Number(a),DeviceId:a,LinkStatus:t}});case 5:if(null!=(i=e.sent)&&i.Success){e.next=10;break}return t===_contants.ApplyStatus.Apply&&wx.showToast({title:"申请连麦失败",icon:"error"}),t===_contants.ApplyStatus.Cancel&&wx.showToast({title:"挂断连麦失败",icon:"error"}),e.abrupt("return",!1);case 10:return t===_contants.ApplyStatus.Apply&&(this.handleStateChange("connectStatus",_contants.ConnectStatus.Applying),loopCreate("GetApplyConnectStatus",this.getApplyConnectStatus.bind(this),5e3)),t===_contants.ApplyStatus.Cancel&&(this.handleStateChange("connectStatus",_contants.ConnectStatus.Init),clearLoop("GetApplyConnectStatus")),e.abrupt("return",!0);case 13:case"end":return e.stop()}},e,this)})),function(e){return l.apply(this,arguments)})},{key:"getApplyConnectStatus",value:(u=_asyncToGenerator(_regeneratorRuntime().mark(function e(){var t,n,r,o,a;return _regeneratorRuntime().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return t=this.store.get("mainInfo"),n=t.activityId,r=this.store.get("userInfo"),o=r.userId,e.next=4,this.sdkInstance.request(API_PATH.GetAudienceLinkStatus,{method:"GET",query:{ActivityId:n,UserId:Number(o)}});case 4:if(void 0!==(null==(a=e.sent)?void 0:a.LinkStatus)){e.next=8;break}return console.log("GetAudienceLinkStatus 接口报错"),e.abrupt("return");case 8:if(a.LinkStatus===_contants.LinkStatus.APPLYING&&(this.handleStateChange("connectStatus",_contants.ConnectStatus.Applying),LOOP_KEY.GetApplyConnectStatus||loopCreate("GetApplyConnectStatus",this.getApplyConnectStatus.bind(this),5e3)),a.LinkStatus!==_contants.LinkStatus.ALLOWING&&a.LinkStatus!==_contants.LinkStatus.CONNECTING){e.next=20;break}return this.sdkInstance.reportLogger("mini_sdk_connect_joinConnect",{}),clearLoop("GetApplyConnectStatus"),e.next=14,this.updateLinkEnterRoomStatus(_contants.RoomStatus.ENTER);case 14:return e.next=16,this.initRTCClient();case 16:loopCreate("GetLinkUserList",this.getLinkUserList.bind(this),this.layoutGetInterval),this.handleStateChange("connectStatus",_contants.ConnectStatus.Connecting),this.updateMediaStatus(),this.bindSocketEvents();case 20:case"end":return e.stop()}},e,this)})),function(){return u.apply(this,arguments)})},{key:"updateLinkEnterRoomStatus",value:(c=_asyncToGenerator(_regeneratorRuntime().mark(function e(t){var n,r,o,a,i;return _regeneratorRuntime().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return n=this.store.get("mainInfo"),r=n.activityId,o=this.store.get("userInfo"),a=o.userId,e.next=4,this.sdkInstance.request(API_PATH.UpdateLinkEnterRoomStatus,{method:"POST",data:{ActivityId:r,UserId:Number(a),Status:t,EnableVideo:!1,EnableAudio:!1,LinkVersion:_contants.UserVersion.NEW,LinkControl:1}});case 4:null!=(i=e.sent)&&i.LayoutGetInterval&&(this.layoutGetInterval=1e3*i.LayoutGetInterval),i.AudioMute===_contants.AudioMuteMap.Mute&&t===_contants.RoomStatus.ENTER&&(this.sdkInstance.reportLogger("mini_sdk_connect_default_mute",{data:i}),this.handleStateChange("hasAudio",!1),wx.showToast({title:"主持人已设置全员静音",icon:"none"}));case 7:case"end":return e.stop()}},e,this)})),function(e){return c.apply(this,arguments)})},{key:"initRTCClient",value:(s=_asyncToGenerator(_regeneratorRuntime().mark(function e(){var t,n,r,o,a,i;return _regeneratorRuntime().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.rtcClient=new _rtcClient.default(this.sdkInstance.reportLogger),t=this.store.get("mainInfo"),n=t.activityId,r=this.store.get("userInfo"),o=r.userId,e.next=5,this.getRTCToken();case 5:return a=e.sent,this.bindRTCEvents(this.rtcClient.client),console.log("client:",this.rtcClient.client),e.prev=8,e.next=11,this.rtcClient.join({token:a,roomId:n,userId:o});case 11:return e.next=13,this.rtcClient.publish();case 13:i=e.sent,this.publishUrl=i,e.next=20;break;case 17:e.prev=17,e.t0=e.catch(8),console.log("推流报错:",e.t0);case 20:case"end":return e.stop()}},e,this,[[8,17]])})),function(){return s.apply(this,arguments)})},{key:"bindRTCEvents",value:function(e){var t=this;e&&(e.on(RtcSdk.EVENTS.STREAM_ADDED,function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=e.uid;(e.screen?t.screenStreamMap:t.streamMap)[n]={}}),e.on(RtcSdk.EVENTS.STREAM_REMOVED,function(e){var n=e.uid,r=e.screen?t.screenStreamMap:t.streamMap;Reflect.deleteProperty(r,n)}),e.on(RtcSdk.EVENTS.MUTE_AUDIO,function(e){var n=e.uid,r=e.screen,o=r?t.screenStreamMap:t.streamMap;o[n]?(o[n].hasAudio=!1,o[n].isV1&&t.updateStream({userId:n,isScreen:r,hasAudio:!1,hasVideo:Boolean(o[n].hasVideo)})):o[n]={hasAudio:!1}}),e.on(RtcSdk.EVENTS.UNMUTE_AUDIO,function(e){var n=e.uid,r=e.screen,o=r?t.screenStreamMap:t.streamMap;o[n]?(o[n].hasAudio=!0,o[n].isV1&&t.updateStream({userId:n,isScreen:r,hasAudio:!0,hasVideo:Boolean(o[n].hasVideo)})):o[n]={hasAudio:!0}}),e.on(RtcSdk.EVENTS.MUTE_VIDEO,function(e){var n=e.uid,r=e.screen,o=r?t.screenStreamMap:t.streamMap;o[n]?(o[n].hasVideo=!1,o[n].isV1&&t.updateStream({userId:n,isScreen:r,hasAudio:Boolean(o[n].hasAudio),hasVideo:!1})):o[n]={hasVideo:!1}}),e.on(RtcSdk.EVENTS.UNMUTE_VIDEO,function(e){var n=e.uid,r=e.screen,o=r?t.screenStreamMap:t.streamMap;o[n]?(o[n].hasVideo=!0,o[n].isV1&&t.updateStream({userId:n,isScreen:r,hasAudio:Boolean(o[n].hasAudio),hasVideo:!0})):o[n]={hasVideo:!0}}),e.on(RtcSdk.EVENTS.UPDATE_URL,function(e){var n=e.uid,r=e.screen,o=e.url;t.updateStreamUrl({userId:n,isScreen:r,url:o})}),e.on(RtcSdk.EVENTS.STREAM_FAILED,function(e){var n=e.uid,r=e.screen,o=e.reason;t.correctionConnect({userId:n,isScreen:r,reason:o})}))}},{key:"correctionConnect",value:(i=_asyncToGenerator(_regeneratorRuntime().mark(function e(t){var n,r,o,a,i,s,c;return _regeneratorRuntime().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(n=t.userId,r=t.isScreen,o=t.reason,a=this.store.get("userInfo"),i=a.userId,s="",n!==i){e.next=10;break}return e.next=7,this.rtcClient.publish();case 7:s=e.sent,e.next=14;break;case 10:return e.next=12,this.rtcClient.subscribe({userId:n,isScreen:r});case 12:c=e.sent,s=c.url;case 14:s&&this.updateStreamUrl({userId:i,isScreen:r,url:s}),this.sdkInstance.reportLogger("mini_sdk_connect_correctionConnect",{uid:i,userId:n,isScreen:r,url:s,reason:o});case 16:case"end":return e.stop()}},e,this)})),function(e){return i.apply(this,arguments)})},{key:"bindSocketEvents",value:function(){var e,t=this;this.socket=this.sdkInstance.socket,this.socket.on(_socket.WsMethod.linkUserMediaStatus,function(e){console.log("音视频状态变更",e);var n=e.Payload,r=void 0===n?{}:n,o=r.UserId,a=r.StreamType,i=r.EnableVideo,s=r.EnableAudio;t.updateStream({userId:o,isScreen:a==_contants.StreamType.SCREEN,hasAudio:s,hasVideo:i})}),this.socket.on(_socket.WsMethod.linkLayoutUpdate,function(e){console.log("布局信息变更",e);var n=e.Payload,r=void 0===n?{}:n;t.updateRenderList(r)}),this.socket.on(_socket.WsMethod.linkUserEnterRoom,function(e){console.log("用户离开房间",e);var n=e.Payload,r=void 0===n?{}:n,o=t.store.get("userInfo").userId==r.UserId,a=r.ForceStatus==_contants.LeaveStatus.KICKED;o&&a&&(console.log("被主持人踢出"),wx.showToast({title:"被主持人请出了连麦",icon:"none"}),t.sdkInstance.reportLogger("mini_sdk_connect_kicked",{}),t.leaveConnect(a))}),this.socket.on(_socket.WsMethod.closeAudienceLink,function(e){console.log("连麦结束:",e),t.leaveConnect(),wx.showToast({title:"主持人结束了连麦",icon:"none"}),t.sdkInstance.reportLogger("mini_sdk_connect_ended",{})}),this.socket.on(_socket.WsMethod.applyUserMedia,(e=_asyncToGenerator(_regeneratorRuntime().mark(function e(n){var r,o,a,i,s,c,u;return _regeneratorRuntime().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(console.log("主持人控制开闭麦:",n),r=n.Payload,o=void 0===r?{}:r,t.store.get("userInfo").userId==o.UserId){e.next=6;break}return e.abrupt("return");case 6:if(a=o.Media,i=o.Control,s=i==_contants.ControlStatus.OPEN,t.sdkInstance.reportLogger("mini_sdk_connect_control",{data:n}),!s){e.next=18;break}return e.next=12,t.askUserModal(a);case 12:if(c=e.sent){e.next=16;break}return t.sdkInstance.reportLogger("mini_sdk_connect_reject_control",{data:n,status:c}),e.abrupt("return");case 16:e.next=20;break;case 18:u={1:"麦克风",2:"摄像头",3:"摄像头和麦克风"},wx.showToast({title:"主持人已关闭你的".concat(u[a]),icon:"none"});case 20:a!=_contants.MediaType.VIDEO&&a!=_contants.MediaType.ALL||t.handleStateChange("hasVideo",s),a!=_contants.MediaType.AUDIO&&a!=_contants.MediaType.ALL||t.handleStateChange("hasAudio",s),t.updateMediaStatus();case 23:case"end":return e.stop()}},e)})),function(t){return e.apply(this,arguments)})),this.socket.on(_socket.WsMethod.linkMute,function(e){console.log("主持人全体静音:",e),t.component.data.hasAudio&&(wx.showToast({title:"主持人已设置全员静音",icon:"none"}),t.handleStateChange("hasAudio",!1),t.updateMediaStatus(),t.sdkInstance.reportLogger("mini_sdk_connect_all_mute",{payload:e}))}),this.socket.on(_socket.WsMethod.linkUserNameUpdate,function(e){console.log("主持人强制改名:",e);var n=e.Payload,r=void 0===n?{}:n;t.store.get("userInfo").userId==r.UserId&&(t.store.set("userInfo",_objectSpread(_objectSpread({},t.store.get("userInfo")),{},{username:r.NewName})),wx.showToast({title:"主持人已修改您的昵称",icon:"none"}),t.sdkInstance.reportLogger("mini_sdk_connect_change_name",{data:e}))}),this.socket.send(_socket.WsMethod.miniConnect)}},{key:"askUserModal",value:function(e){var t={1:"麦克风",2:"摄像头",3:"摄像头和麦克风"};return new Promise(function(n,r){wx.showModal({content:"主持人申请打开你的".concat(t[e]),success:function(e){e.confirm?n(!0):e.cancel&&n(!1)},fail:function(e){r(e)}})})}},{key:"offSocket",value:function(){this.socket.off(_socket.WsMethod.linkUserMediaStatus),this.socket.off(_socket.WsMethod.linkLayoutUpdate),this.socket.off(_socket.WsMethod.linkUserEnterRoom),this.socket.off(_socket.WsMethod.closeAudienceLink),this.socket.off(_socket.WsMethod.applyUserMedia),this.socket.off(_socket.WsMethod.linkMute),this.socket.off(_socket.WsMethod.linkUserNameUpdate)}},{key:"getRTCToken",value:(a=_asyncToGenerator(_regeneratorRuntime().mark(function e(){var t,n,r,o,a;return _regeneratorRuntime().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return t=this.store.get("mainInfo"),n=t.activityId,r=this.store.get("userInfo"),o=r.userId,e.next=4,this.sdkInstance.request(API_PATH.GetRTCToken,{method:"GET",query:{RoomId:"".concat(n),UserId:o}});case 4:if(a=e.sent,this.sdkInstance.reportLogger("mini_sdk_connect_getToken",{userId:o,activityId:n,res:a}),1!==a.Status){e.next=8;break}return e.abrupt("return",null==a?void 0:a.Token);case 8:return e.abrupt("return","error");case 9:case"end":return e.stop()}},e,this)})),function(){return a.apply(this,arguments)})},{key:"getLinkUserList",value:(o=_asyncToGenerator(_regeneratorRuntime().mark(function e(){var t,n,r;return _regeneratorRuntime().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return t=this.store.get("mainInfo"),n=t.activityId,e.next=3,this.sdkInstance.request(API_PATH.GetLinkUserList,{method:"GET",data:{ActivityId:n}});case 3:if(r=e.sent){e.next=6;break}return e.abrupt("return");case 6:this.updateRenderList(r);case 7:case"end":return e.stop()}},e,this)})),function(){return o.apply(this,arguments)})},{key:"updateStreamUrl",value:function(e){var t=e.userId,n=e.isScreen,r=e.url,o=this.store.get("userInfo").userId;t===o&&(this.publishUrl=r);var a=_toConsumableArray(this.component.data.renderList).map(function(e){return e.userId==t&&e.isScreen===n?_objectSpread(_objectSpread({},e),{},{url:r}):e});this.handleStateChange("renderList",a),this.sdkInstance.reportLogger("mini_sdk_connect_updateStreamUrl",{uid:o,userId:t,isScreen:n,url:r,newList:a})}},{key:"updateStream",value:function(e){var t=e.userId,n=e.isScreen,r=e.hasAudio,o=e.hasVideo,a=this.store.get("userInfo").userId;if(t!==a){this.rtcClient.muteRemote({userId:"".concat(t),screen:n,audio:r,video:o});var i=_toConsumableArray(this.component.data.renderList).map(function(e){return e.userId==t&&e.isScreen===n?_objectSpread(_objectSpread({},e),{},{hasAudio:r,hasVideo:o}):e});this.handleStateChange("renderList",i),this.sdkInstance.reportLogger("mini_sdk_connect_updateStream",{uid:a,userId:t,isScreen:n,hasAudio:r,hasVideo:o})}}},{key:"updateRenderList",value:(r=_asyncToGenerator(_regeneratorRuntime().mark(function e(t){var n,r,o,a,i,s,c,u,l,d,h,p=this;return _regeneratorRuntime().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(console.log("布局原始信息:",t),0!==Object.keys(t).length){e.next=3;break}return e.abrupt("return");case 3:return void 0===t.Layout&&_contants.LayoutMode.FullScreen,n=t.LayoutUsers,r=void 0===n?[]:n,o=t.NonLayoutUsers,a=void 0===o?[]:o,i=this.store.get("userInfo"),s=i.userId,c=null,u=[],r.forEach(function(e){var t,n=e.UserId,r=e.StreamType,o=e.UserInfo,a=void 0===o?{}:o,i=e.Region,l=e.IsPresentationWindow,d=void 0!==l&&l,h=a.Nickname,f=a.IsPresenter,y=a.Identity,v=a.StreamInfo,m=void 0===v?[]:v,_=null==m||null===(t=m.filter(function(t){return t.StreamType===e.StreamType}))||void 0===t?void 0:t[0],g=r==_contants.StreamType.SCREEN,k=p.getUserMediaStatus(g,a,_),S={left:"".concat(Math.floor(750*i.LocationX),"rpx"),top:"".concat(Math.floor(421*i.LocationY),"rpx"),width:"".concat(Math.floor(750*i.WidthProportion),"rpx"),height:"".concat(Math.floor(421*i.HeightProportion),"rpx"),zIndex:i.ZOrder,image:i.UserCoverImage},I={id:"".concat(n,"-").concat(r),userId:"".concat(n),isScreen:g,isMe:n==s,isShow:!0,styles:S,hasVideo:k.hasVideo,hasAudio:k.hasAudio,nickname:h,isPresenter:Boolean(f),isHost:y===_contants.Identity.Host,isGuest:y===_contants.Identity.Guest,isAudience:y===_contants.Identity.Audience,isShowLabel:!d};I.isMe?c=_objectSpread(_objectSpread({},I),{},{url:p.publishUrl}):u.push(I)}),a.forEach(function(e){var t,n=e.UserId,r=e.StreamType,o=e.UserInfo,a=void 0===o?{}:o,i=a.Nickname,l=a.StreamInfo,d=void 0===l?[]:l,h=a.UserCoverImage,f=null==d||null===(t=d.filter(function(t){return t.StreamType===e.StreamType}))||void 0===t?void 0:t[0],y=r==_contants.StreamType.SCREEN,v=p.getUserMediaStatus(y,a,f),m={id:"".concat(n,"-").concat(r),userId:"".concat(n),isScreen:y,isMe:n==s,isShow:!1,hasVideo:!1,hasAudio:v.hasAudio};if(m.isMe){var _={image:h};c=_objectSpread(_objectSpread({},m),{},{nickname:i,styles:_,url:p.publishUrl})}else u.push(m)}),e.next=11,this.rtcClient.autoSubscribe(u);case 11:(l=e.sent).push(c),console.log("拉流列表:",this.streamMap),console.log("屏幕流列表:",this.screenStreamMap),console.log("渲染列表:",l),d=this.store.get("mainInfo"),h=d.activityId,this.sdkInstance.reportLogger("mini_sdk_connect_render",{activityId:h,userId:s,origin:t,streamMap:this.streamMap,screenStreamMap:this.screenStreamMap,renderList:l}),console.log("client:",this.rtcClient),this.handleStateChange("renderList",l);case 20:case"end":return e.stop()}},e,this)})),function(e){return r.apply(this,arguments)})},{key:"getUserMediaStatus",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=t.UserId,o=t.LinkVersion,a=n.EnableAudio,i=n.EnableVideo;if(o===_contants.UserVersion.NEW)return{hasVideo:Boolean(i),hasAudio:Boolean(a)};var s=(e?this.screenStreamMap:this.streamMap)["".concat(r)];if(s){s.isV1=!0;var c=s.hasVideo,u=void 0===c||c,l=s.hasAudio,d=void 0===l||l;return{hasVideo:Boolean(u),hasAudio:Boolean(d)}}return _defineProperty({hasVideo:!1},"hasVideo",!1)}},{key:"updateMediaStatus",value:(n=_asyncToGenerator(_regeneratorRuntime().mark(function e(){var t,n,r,o,a,i,s;return _regeneratorRuntime().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return t=this.store.get("mainInfo"),n=t.activityId,r=this.store.get("userInfo"),o=r.userId,a=this.component.data,i=a.hasVideo,s=a.hasAudio,this.sdkInstance.reportLogger("mini_sdk_connect_update_media",{video:i,audio:s}),this.rtcClient.muteLocal({video:i,audio:s}),e.next=7,this.sdkInstance.request(API_PATH.UpdateLinkUserMediaStatus,{method:"POST",data:{ActivityId:n,UserId:Number(o),IsConsole:!1,StreamInfo:[{StreamType:_contants.StreamType.VIDEO,EnableVideo:i,EnableAudio:s}]}});case 7:case"end":return e.stop()}},e,this)})),function(){return n.apply(this,arguments)})},{key:"leaveConnect",value:(t=_asyncToGenerator(_regeneratorRuntime().mark(function e(){var t,n=arguments;return _regeneratorRuntime().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(t=n.length>0&&void 0!==n[0]&&n[0],this.rtcClient.leave(),clearLoop("GetLinkUserList"),this.offSocket(),t){e.next=7;break}return e.next=7,this.updateLinkEnterRoomStatus(_contants.RoomStatus.LEAVE);case 7:this.handleStateChange("connectStatus",_contants.ConnectStatus.Init);case 8:case"end":return e.stop()}},e,this)})),function(){return t.apply(this,arguments)})}]),e}();exports.default=ConnectLogic;var loopCreate=function(e,t,n){clearLoop(e),t(),LOOP_KEY[e]=setInterval(function(){t()},n)},clearLoop=function(e){LOOP_KEY[e]&&(clearInterval(LOOP_KEY[e]),LOOP_KEY[e]=null)};