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

1 line
16 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 ownKeys(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function _objectSpread(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?ownKeys(Object(r),!0).forEach(function(t){_defineProperty(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):ownKeys(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function _defineProperty(e,t,r){return(t=_toPropertyKey(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,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 _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 _createForOfIteratorHelper(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=_unsupportedIterableToArray(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0,o=function(){};return{s:o,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,c=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return a=e.done,e},e:function(e){c=!0,i=e},f:function(){try{a||null==r.return||r.return()}finally{if(c)throw i}}}}function _unsupportedIterableToArray(e,t){if(e){if("string"==typeof e)return _arrayLikeToArray(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?_arrayLikeToArray(e,t):void 0}}function _arrayLikeToArray(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function _regeneratorRuntime(){_regeneratorRuntime=function(){return e};var e={},t=Object.prototype,r=t.hasOwnProperty,n=Object.defineProperty||function(e,t,r){e[t]=r.value},o="function"==typeof Symbol?Symbol:{},i=o.iterator||"@@iterator",a=o.asyncIterator||"@@asyncIterator",c=o.toStringTag||"@@toStringTag";function u(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{u({},"")}catch(e){u=function(e,t,r){return e[t]=r}}function s(e,t,r,o){var i=t&&t.prototype instanceof d?t:d,a=Object.create(i.prototype),c=new x(o||[]);return n(a,"_invoke",{value:w(e,r,c)}),a}function l(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}e.wrap=s;var f={};function d(){}function h(){}function p(){}var y={};u(y,i,function(){return this});var v=Object.getPrototypeOf,m=v&&v(v(j([])));m&&m!==t&&r.call(m,i)&&(y=m);var b=p.prototype=d.prototype=Object.create(y);function _(e){["next","throw","return"].forEach(function(t){u(e,t,function(e){return this._invoke(t,e)})})}function g(e,t){function o(n,i,a,c){var u=l(e[n],e,i);if("throw"!==u.type){var s=u.arg,f=s.value;return f&&"object"==_typeof(f)&&r.call(f,"__await")?t.resolve(f.__await).then(function(e){o("next",e,a,c)},function(e){o("throw",e,a,c)}):t.resolve(f).then(function(e){s.value=e,a(s)},function(e){return o("throw",e,a,c)})}c(u.arg)}var i;n(this,"_invoke",{value:function(e,r){function n(){return new t(function(t,n){o(e,r,t,n)})}return i=i?i.then(n,n):n()}})}function w(e,t,r){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return{value:void 0,done:!0}}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var c=I(a,r);if(c){if(c===f)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var u=l(e,t,r);if("normal"===u.type){if(n=r.done?"completed":"suspendedYield",u.arg===f)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(n="completed",r.method="throw",r.arg=u.arg)}}}function I(e,t){var r=t.method,n=e.iterator[r];if(void 0===n)return t.delegate=null,"throw"===r&&e.iterator.return&&(t.method="return",t.arg=void 0,I(e,t),"throw"===t.method)||"return"!==r&&(t.method="throw",t.arg=new TypeError("The iterator does not provide a '"+r+"' method")),f;var o=l(n,e.iterator,t.arg);if("throw"===o.type)return t.method="throw",t.arg=o.arg,t.delegate=null,f;var i=o.arg;return i?i.done?(t[e.resultName]=i.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,f):i:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,f)}function k(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 S(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function x(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(k,this),this.reset(!0)}function j(e){if(e){var t=e[i];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var n=-1,o=function t(){for(;++n<e.length;)if(r.call(e,n))return t.value=e[n],t.done=!1,t;return t.value=void 0,t.done=!0,t};return o.next=o}}return{next:L}}function L(){return{value:void 0,done:!0}}return h.prototype=p,n(b,"constructor",{value:p,configurable:!0}),n(p,"constructor",{value:h,configurable:!0}),h.displayName=u(p,c,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===h||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,p):(e.__proto__=p,u(e,c,"GeneratorFunction")),e.prototype=Object.create(b),e},e.awrap=function(e){return{__await:e}},_(g.prototype),u(g.prototype,a,function(){return this}),e.AsyncIterator=g,e.async=function(t,r,n,o,i){void 0===i&&(i=Promise);var a=new g(s(t,r,n,o),i);return e.isGeneratorFunction(r)?a:a.next().then(function(e){return e.done?e.value:a.next()})},_(b),u(b,c,"Generator"),u(b,i,function(){return this}),u(b,"toString",function(){return"[object Generator]"}),e.keys=function(e){var t=Object(e),r=[];for(var n in t)r.push(n);return r.reverse(),function e(){for(;r.length;){var n=r.pop();if(n in t)return e.value=n,e.done=!1,e}return e.done=!0,e}},e.values=j,x.prototype={constructor:x,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(S),!e)for(var t in this)"t"===t.charAt(0)&&r.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 n(r,n){return a.type="throw",a.arg=e,t.next=r,n&&(t.method="next",t.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var c=r.call(i,"catchLoc"),u=r.call(i,"finallyLoc");if(c&&u){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(c){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.finallyLoc)}}}},abrupt:function(e,t){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===e||"continue"===e)&&i.tryLoc<=t&&t<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=e,a.arg=t,i?(this.method="next",this.next=i.finallyLoc,f):this.complete(a)},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),f},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),S(r),f}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var o=n.arg;S(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:j(e),resultName:t,nextLoc:r},"next"===this.method&&(this.arg=void 0),f}},e}function asyncGeneratorStep(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void r(e)}c.done?t(u):Promise.resolve(u).then(n,o)}function _asyncToGenerator(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function a(e){asyncGeneratorStep(i,n,o,a,c,"next",e)}function c(e){asyncGeneratorStep(i,n,o,a,c,"throw",e)}a(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 r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,_toPropertyKey(n.key),n)}}function _createClass(e,t,r){return t&&_defineProperties(e.prototype,t),r&&_defineProperties(e,r),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 r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!==_typeof(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var RtcSdk=require("../../../lib/vertc/VolcEngineRTC_MiniApp_3.0.1"),RTCClient=function(){function e(t){_classCallCheck(this,e),this.report=t,this.client=new RtcSdk.Client,this.appId="5f63075096688300c5a5a874",this.curUserList=[]}var t,r,n;return _createClass(e,[{key:"join",value:(n=_asyncToGenerator(_regeneratorRuntime().mark(function e(t){var r,n,o,i=this;return _regeneratorRuntime().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.token,n=t.roomId,o=t.userId,this.roomId=n,this.userId=o,e.abrupt("return",new Promise(function(e,t){i.client.init(i.appId).then(function(){i.client.join(r,"".concat(n),"".concat(o),function(){i.report("mini_sdk_connect_join_success",{roomId:n,userId:o}),e()},function(e){console.log("加入连麦失败"),i.report("mini_sdk_connect_join_fail",{roomId:n,userId:o,err:e}),t()})})}));case 4:case"end":return e.stop()}},e,this)})),function(e){return n.apply(this,arguments)})},{key:"publish",value:function(){var e=this;return new Promise(function(t,r){e.client.publish().then(function(r){e.report("mini_sdk_connect_publish_success",{roomId:e.roomId,userId:e.userId,url:r}),t(r)}).catch(function(t){console.log("推流报错:",t),e.report("mini_sdk_connect_publish_fail",{roomId:e.roomId,userId:e.userId,err:t}),r()})})}},{key:"unpublish",value:function(){try{this.client.unpublish()}catch(e){this.report("mini_sdk_connect_publish_fail",{roomId:this.roomId,userId:this.userId,err:err})}}},{key:"autoSubscribe",value:(r=_asyncToGenerator(_regeneratorRuntime().mark(function e(t){var r,n,o,i,a,c,u,s,l,f,d,h,p,y,v,m,b,_,g,w,I,k,S,x;return _regeneratorRuntime().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:r=this.compare(t,this.curUserList),n=r.added,o=void 0===n?[]:n,i=r.deled,a=void 0===i?[]:i,c=r.streamList,u=void 0===c?[]:c,s=_createForOfIteratorHelper(a);try{for(s.s();!(l=s.n()).done;)f=l.value,this.unsubscribe(f)}catch(e){s.e(e)}finally{s.f()}d=_createForOfIteratorHelper(o),e.prev=4,d.s();case 6:if((h=d.n()).done){e.next=38;break}return p=h.value,e.prev=8,e.next=11,this.subscribe(p);case 11:if(!(y=e.sent).url){e.next=31;break}v=_createForOfIteratorHelper(u),e.prev=14,v.s();case 16:if((m=v.n()).done){e.next=23;break}if((b=m.value).userId!=y.userId||b.isScreen!==y.isScreen){e.next=21;break}return b.url=y.url,e.abrupt("break",23);case 21:e.next=16;break;case 23:e.next=28;break;case 25:e.prev=25,e.t0=e.catch(14),v.e(e.t0);case 28:return e.prev=28,v.f(),e.finish(28);case 31:e.next=36;break;case 33:e.prev=33,e.t1=e.catch(8),console.log("订阅失败:",p,e.t1);case 36:e.next=6;break;case 38:e.next=43;break;case 40:e.prev=40,e.t2=e.catch(4),d.e(e.t2);case 43:return e.prev=43,d.f(),e.finish(43);case 46:_=_createForOfIteratorHelper(u);try{for(_.s();!(g=_.n()).done;)w=g.value,I=w.userId,k=w.isScreen,S=w.hasAudio,x=w.hasVideo,this.muteRemote({userId:"".concat(I),screen:k,audio:S,video:x})}catch(e){_.e(e)}finally{_.f()}return this.curUserList=_toConsumableArray(u),this.report("mini_sdk_connect_autoSub",{roomId:this.roomId,userId:this.userId,userList:_toConsumableArray(t),added:_toConsumableArray(o),deled:_toConsumableArray(a),streamList:_toConsumableArray(u)}),e.abrupt("return",_toConsumableArray(u));case 51:case"end":return e.stop()}},e,this,[[4,40,43,46],[8,33],[14,25,28,31]])})),function(e){return r.apply(this,arguments)})},{key:"compare",value:function(e,t){var r=_toConsumableArray(e),n=_toConsumableArray(t),o=[];return{streamList:r.map(function(e){var t;if(n.filter(function(r,n){if(e.userId==r.userId&&e.isScreen==e.isScreen)return t=n,!0})[0]){if(void 0!==t){var r,i,a=_objectSpread(_objectSpread({},null!==(r=null===(i=n.splice(t,1))||void 0===i?void 0:i[0])&&void 0!==r?r:{}),e);return a.url||o.push(a),a}return e}return o.push(e),e}),added:o,deled:n}}},{key:"subscribe",value:function(e){var t=this,r=e.userId,n=e.isScreen;return new Promise(function(o,i){t.client.subscribe("".concat(r),{video:!0,audio:!0,screen:n}).then(function(t){o(_objectSpread(_objectSpread({},e),{},{url:t}))}).catch(function(o){console.log("订阅失败:",e,o),t.report("mini_sdk_connect_sub_fail",{roomId:t.roomId,userId:t.userId,remote:r,isScreen:n,err:o}),i(o)})})}},{key:"unsubscribe",value:function(e){var t=e.userId,r=e.isScreen;try{this.client.unsubscribe("".concat(t),{screen:r})}catch(e){console.log("取消订阅报错:",e),this.report("mini_sdk_connect_unSub_fail",{roomId:this.roomId,userId:this.userId,remote:t,isScreen:r,err:e})}}},{key:"muteLocal",value:function(e){var t=e.audio,r=e.video;try{this.client.muteLocal({video:r,audio:t})}catch(e){console.log("本地闭麦报错:",e),this.report("mini_sdk_connect_muteLocal_fail",{roomId:this.roomId,userId:this.userId,video:r,audio:t,err:e})}}},{key:"muteRemote",value:function(e){var t=e.userId,r=e.audio,n=e.video,o=e.screen;try{this.client.muteRemote("".concat(t),{audio:r,video:n,screen:o})}catch(e){console.log("远端禁麦报错:",e),this.report("mini_sdk_connect_muteRemote_fail",{roomId:this.roomId,userId:this.userId,remote:t,video:n,audio:r,screen:o,err:e})}}},{key:"leave",value:(t=_asyncToGenerator(_regeneratorRuntime().mark(function e(){return _regeneratorRuntime().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,this.client.leave();case 3:this.client.destroy(),e.next=10;break;case 6:e.prev=6,e.t0=e.catch(0),console.log("离开rtc房间报错:",e.t0),this.report("mini_sdk_connect_leave_fail",{roomId:this.roomId,userId:this.userId,err:e.t0});case 10:case"end":return e.stop()}},e,this,[[0,6]])})),function(){return t.apply(this,arguments)})}]),e}();exports.default=RTCClient;