@huolala-tech/page-spy-alipay
Advanced tools
Comparing version 1.7.7 to 1.7.8
@@ -1,2 +0,2 @@ | ||
"use strict";const e=e=>{const t=[];return Object.entries(e).forEach((e=>{let[n,s]=e;t.push("".concat(n,"=").concat(s))})),t.join("&")};let t;const n=()=>{if(!t)throw Error("the mp sdk is not set");return t};function s(e){return s="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},s(e)}function o(e){var t=function(e,t){if("object"!=s(e)||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var o=n.call(e,t||"default");if("object"!=s(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==s(t)?t:String(t)}function r(e,t,n){return(t=o(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function i(){return Math.random().toString(36).slice(2)}function a(e){return Object.prototype.toString.call(e)}function c(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function l(e){return"[object BigInt]"===a(e)}function u(e){return e instanceof Array}function h(e){return"object"==typeof e&&null!==e}const d=e=>"".concat(e),g=e=>({ok:!0,value:e});function p(e){return void 0===e?g(d(e)):null===e?g(e):function(e){return"number"==typeof e}(e)&&(e===-1/0||e===1/0||Number.isNaN(e))?g(d(e)):l(e)?g("".concat(e,"n")):"symbol"==typeof e||"function"==typeof e?g(d(e.toString())):e instanceof Error?g(d(e.stack)):e===Object.prototype?{value:null,ok:!1}:e instanceof Object||"object"==typeof e?{value:e,ok:!1}:g(e)}function m(e){return void 0===e?"undefined":null===e?"null":l(e)?"bigint":e instanceof Object?e instanceof Error?"error":e instanceof Function?"function":"object":typeof e}const f={...console},y=["log","info","error","warn"].reduce(((e,t)=>(e[t]=function(){for(var e=arguments.length,n=new Array(e),s=0;s<e;s++)n[s]=arguments[s];f[t]("[PageSpy] [".concat(t.toLocaleUpperCase(),"]: "),...n)},e)),{}),S="message",v="broadcast",b="ping";var T=Object.freeze({__proto__:null,BROADCAST:v,CLOSE:"close",CONNECT:"connect",ERROR:"error",JOIN:"join",LEAVE:"leave",MESSAGE:S,PING:b,PONG:"pong"});const O="console",E="debug",I="refresh",w="atom-detail",k="atom-getter",P="public-data";function C(e,t){return{role:"client",type:e,data:{...(!(arguments.length>2&&void 0!==arguments[2])||arguments[2])&&{id:i()},...t}}}class j{constructor(){r(this,"store",{}),r(this,"instanceStore",{})}getStore(){return this.store}resetStore(){this.store={}}getInstanceStore(){return this.instanceStore}resetInstanceStore(){this.instanceStore={}}transformToAtom(e){const{value:t,ok:n}=p(e);return n?{id:i(),type:m(e),value:t}:this.add(e)}get(e){const t=this.store[e],n=this.instanceStore[e];if(!t)return null;const s={},o=Object.getOwnPropertyDescriptors(t);Object.keys(o).forEach((e=>{const t=o[e];c(t,"value")&&(t.value=this.transformToAtom(t.value)),s[e]=j.getAtomOverview({atomId:i(),instanceId:n,value:t})}));const r=this.addExtraProperty(e);return{...s,...r}}getOrigin(e){const t=this.store[e];return t||null}add(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";const n=i();let s=n;var o;h(o=e)&&c(o,"constructor")&&"function"==typeof o.constructor&&(s=t),this.store[n]=e,this.instanceStore[n]=s;const r=j.getSemanticValue(e);return j.getAtomOverview({atomId:n,value:r,instanceId:s})}static getAtomOverview(e){let{instanceId:t="",atomId:n,value:s}=e;return{id:i(),type:"atom",__atomId:n,instanceId:t,value:s}}static getSemanticValue(e){if(h(t=e)&&"[object Object]"===a(t))return"Object {...}";var t;if(u(e))return"Array (".concat(e.length,")");return e.constructor.name}addExtraProperty(e){const t=this.store[e],n=this.instanceStore[e],s={};if((t instanceof String||t instanceof Number||t instanceof Boolean)&&(s["[[PrimitiveValue]]"]=this.transformToAtom(t.valueOf())),t instanceof Set){const e={};let n=0;for(const s of t)e[n++]=s;e.size=t.size,s["[[Entries]]"]=this.transformToAtom(e)}if(t instanceof Map){const e={};let n=0;for(const[s,o]of t.entries())e[n++]={key:s,value:o};e.size=t.size,s["[[Entries]]"]=this.transformToAtom(e)}var o;return(u(t)||(o=t,"function"==typeof NodeList&&"NodeList"===NodeList.name&&o instanceof NodeList||"function"==typeof HTMLCollection&&"HTMLCollection"===HTMLCollection.name&&o instanceof HTMLCollection))&&(s.length=this.transformToAtom(t.length)),null!==Object.getPrototypeOf(t)?s["[[Prototype]]"]=this.add(Object.getPrototypeOf(t),n):s.___proto___=this.transformToAtom(null),s}}var R,N=new j;!function(e){e[e.CONNECTING=0]="CONNECTING",e[e.OPEN=1]="OPEN",e[e.CLOSING=2]="CLOSING",e[e.CLOSED=3]="CLOSED"}(R||(R={}));class q{constructor(){r(this,"events",{open:[],close:[],error:[],message:[]})}emit(e,t){this.events[e].forEach((e=>{e(t)})),"close"!==e&&"error"!==e||this.clearListeners()}onOpen(e){this.events.open.push(e)}onClose(e){this.events.close.push(e)}onError(e){this.events.error.push(e)}onMessage(e){this.events.message.push(e)}clearListeners(){Object.entries(this.events).forEach((e=>{let[,t]=e;t.splice(0)}))}}class D{constructor(){r(this,"socketUrl",""),r(this,"socketConnection",null),r(this,"pingTimer",null),r(this,"pongTimer",null),r(this,"retryTimer",null),r(this,"messages",[]),r(this,"events",{[I]:[],[E]:[],[w]:[],[k]:[],"debugger-online":[],"database-pagination":[],[P]:[]}),r(this,"reconnectable",!0),r(this,"reconnectTimes",3),r(this,"connectionStatus",!1),this.addListener("debug",D.handleDebugger),this.addListener("atom-detail",D.handleResolveAtom),this.addListener("atom-getter",D.handleAtomPropertyGetter),this.addListener("debugger-online",this.handleFlushBuffer)}init(e){try{var t,n,s,o,r;if(!e)throw Error("WebSocket url cannot be empty");this.socketWrapper.getState()===R.OPEN&&this.socketWrapper.close(),null===(t=this.socketWrapper)||void 0===t||t.onOpen((()=>{this.connectOnline()})),null===(n=this.socketWrapper)||void 0===n||n.onMessage((e=>{this.handleMessage(e)})),null===(s=this.socketWrapper)||void 0===s||s.onClose((()=>{this.connectOffline()})),null===(o=this.socketWrapper)||void 0===o||o.onError((()=>{this.connectOffline()})),this.socketUrl=e,null===(r=this.socketWrapper)||void 0===r||r.init(e)}catch(e){y.error(e.message)}}addListener(e,t){this.events[e]||(this.events[e]=[]),this.events[e].push(t)}broadcastMessage(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];const n=function(e){return{type:v,content:{data:e}}}(e);this.send(n,t)}close(){var e;this.clearPing(),this.reconnectTimes=0,this.reconnectable=!1,null===(e=this.socketWrapper)||void 0===e||e.close(),this.messages=[],Object.entries(this.events).forEach((e=>{let[,t]=e;t.splice(0)}))}connectOnline(){this.connectionStatus=!0,this.reconnectTimes=3,this.ping()}connectOffline(){this.connectionStatus=!1,this.socketConnection=null,this.clearPing(),!this.reconnectable||this.reconnectTimes<=0?this.onOffline():(this.retryTimer&&clearTimeout(this.retryTimer),this.retryTimer=setTimeout((()=>{this.retryTimer=null,this.tryReconnect()}),2e3))}tryReconnect(){this.reconnectTimes-=1,this.reconnectTimes<=0&&(this.reconnectable=!1),this.init(this.socketUrl)}ping(){this.pingTimer&&clearTimeout(this.pingTimer),this.pongTimer&&clearTimeout(this.pongTimer),this.pingTimer=setTimeout((()=>{this.send({type:"ping",content:null}),this.pingTimer=null,this.pongTimer=setTimeout((()=>{this.connectOffline(),this.pongTimer=null}),5e3)}),5e3)}clearPing(){this.pingTimer&&(clearTimeout(this.pingTimer),this.pingTimer=null),this.pongTimer&&(clearTimeout(this.pongTimer),this.pongTimer=null)}handlePong(){clearTimeout(this.pongTimer),this.pongTimer=null,this.ping()}handleMessage(e){var t;D.messageFilters.length&&D.messageFilters.forEach((t=>{e=t(e)}));const{CONNECT:n,MESSAGE:s,ERROR:o,JOIN:r,PING:i,PONG:a,LEAVE:c,CLOSE:l,BROADCAST:u}=T,h=JSON.parse(e.data),{type:d}=h;switch(d){case n:const{selfConnection:e}=h.content;this.socketConnection=e;break;case s:const{data:r,from:i,to:a}=h.content;a.address===(null===(t=this.socketConnection)||void 0===t?void 0:t.address)&&this.dispatchEvent(r.type,{source:r,from:i,to:a});break;case o:this.reconnectable=!1,this.connectOffline()}this.handlePong()}dispatchEvent(e,t){[P].includes(e)?this.events[e].forEach((e=>{e(t)})):this.events[e].forEach((e=>{e.call(this,t,(e=>{this.unicastMessage(e,t.from)}))}))}unicastMessage(e,t){const n=function(e,t,n){return{type:S,content:{data:e,from:t,to:n}}}(e,this.socketConnection,t);this.send(n)}handleFlushBuffer(e){const{latestId:t}=e.source.data,n=this.messages.findIndex((e=>e.content.data.data.id===t));this.messages.slice(n+1).forEach((t=>{const n={type:S,content:{data:t.content.data,from:this.socketConnection,to:e.from}};this.send(n,!0)}))}static handleDebugger(e,t){let{source:n}=e;const{type:s,data:o}=n;if(s===E){t(C(O,{logType:"debug-origin",logs:[{id:i(),type:"debug-origin",value:o}]}));try{const e=new Function("return ".concat(o))();t(C(O,{logType:"debug-eval",logs:[N.transformToAtom(e)]}))}catch(e){t(C(O,{logType:"error",logs:[{type:"error",value:e.stack}]}))}}}static handleResolveAtom(e,t){let{source:n}=e;const{type:s,data:o}=n;if(s===w){const e=N.get(o)||{};t(C("atom-detail-".concat(o),e,!1))}}static handleAtomPropertyGetter(e,t){let{source:n}=e;const{type:s,data:o}=n;if(s===k){const{id:e,parentId:n,key:s,instanceId:i}=o,a=N.getOrigin(i),c=N.getOrigin(n);let l={};var r;if(a&&c)l=null===(r=Object.getOwnPropertyDescriptor(c,s))||void 0===r||null===(r=r.get)||void 0===r?void 0:r.call(a);else l=new Error("Getter computed failed");t(C("atom-getter-".concat(e),N.transformToAtom(l)))}}send(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(this.connectionStatus)try{var n;const t=e;t.createdAt=Date.now(),t.requestId=i();const s=function(e){const{ok:t,value:n}=p(e);return t?n:JSON.stringify(e,((e,t)=>p(t).value),2)}(t);null===(n=this.socketWrapper)||void 0===n||n.send(s)}catch(e){throw Error("Incompatible: ".concat(e.message))}if(!t){if([S,b].indexOf(e.type)>-1)return;this.messages.push(e)}}}r(D,"messageFilters",[]);const A="page-spy-room";class L extends q{constructor(){super(...arguments),r(this,"socketInstance",null),r(this,"state",0)}init(e){this.state=R.CONNECTING;const t=n(),s=e=>{this.state=R.CLOSED,this.emit("close",e)},o=e=>{this.state=R.OPEN,this.emit("open",e)},r=e=>{this.state=R.CLOSED,this.emit("error",e)},i=e=>{this.emit("message",e)};L.isSingleSocket?(t.connectSocket({url:e}),t.onSocketClose(s),t.onSocketError(r),t.onSocketMessage(i),t.onSocketOpen(o)):(this.socketInstance=t.connectSocket({url:e,multiple:!0,complete(){}}),this.socketInstance.onClose(s),this.socketInstance.onError(r),this.socketInstance.onOpen(o),this.socketInstance.onMessage(i))}send(e){var t;L.isSingleSocket?n().sendSocketMessage({data:e}):null===(t=this.socketInstance)||void 0===t||t.send({data:e})}close(){var e;L.isSingleSocket?n().closeSocket({}):null===(e=this.socketInstance)||void 0===e||e.close({});this.state=R.CLOSED,this.clearListeners()}getState(){return this.state}}r(L,"isSingleSocket",!1);var U,M=new class extends D{constructor(){super(...arguments),r(this,"socketWrapper",new L)}getSocket(){return this.socketWrapper}onOffline(){n().setStorageSync(A,JSON.stringify({usable:!1}))}};class x{constructor(){r(this,"name","ConsolePlugin"),r(this,"console",{}),r(this,"proxyTypes",["log","info","error","warn","debug"])}async onInit(){if(x.hasInitd)return;x.hasInitd=!0;const t=this;this.proxyTypes.forEach((n=>{this.console[n]=console[n]||console.log||(()=>{}),Object.defineProperty(console,n,{value(){const s=getCurrentPages().pop();let o="/";s&&(o=s.route,s.options&&Object.keys(s.options).length>0&&(o+="?"+e(s.options)));for(var r=arguments.length,i=new Array(r),a=0;a<r;a++)i[a]=arguments[a];t.printLog({logType:n,logs:i,url:o})},configurable:!0,enumerable:!0,writable:!0})}))}onReset(){this.proxyTypes.forEach((e=>{console[e]=this.console[e]})),x.hasInitd=!1}printLog(e){if(e.logs&&e.logs.length){this.console[e.logType](...e.logs),e.logs=e.logs.map((e=>N.transformToAtom(e)));const t=C(O,{time:Date.now(),...e});M.dispatchEvent(P,t),M.broadcastMessage(t)}}}r(x,"hasInitd",!1);class H{constructor(){r(this,"name","ErrorPlugin")}onInit(){H.hasInitd||(H.hasInitd=!0,this.onUncaughtError(),this.onUnhandledRejectionError())}onReset(){const e=n();e.canIUse("offError")&&e.offError(this.errorHandler),e.canIUse("offUnHandledRejection")&&e.offUnHandledRejection(this.unhandledRejectionHandler),H.hasInitd=!1}errorHandler(e){if(H.hasInitd)if(e.stack||e.message){const{message:t,stack:n}=e;H.sendMessage(n||t,{name:"uncaught error",...e})}else{const e="[PageSpy] An unknown error occurred and no message or stack trace available";H.sendMessage(e,null)}}unhandledRejectionHandler(e){H.hasInitd&&H.sendMessage("UnHandled Rejection",{name:"unhandledrejection",message:e.reason})}onUncaughtError(){const e=n();e.canIUse("onError")&&e.onError(this.errorHandler)}onUnhandledRejectionError(){const e=n();e.canIUse("onUnHandledRejection")&&e.onUnHandledRejection(this.unhandledRejectionHandler)}static sendMessage(e,t){const n={logType:"error",logs:[N.transformToAtom(e)],time:Date.now(),url:"wx:light-app",errorDetail:t},s=C(O,n);M.dispatchEvent(P,s),M.broadcastMessage(s)}}function F(e,t){try{let n,s;if("object"==typeof window&&"object"==typeof document&&"[object HTMLDocument]"===Object.prototype.toString.call(document)){const{searchParams:o,href:r}=new URL(e,t);n=r,s=[...o.entries()]}else n=e.toString(),s=function(e){const t=/[?&]([^=#]+)=([^&#]*)/g,n=[];let s;for(;null!==(s=t.exec(e));){const e=decodeURIComponent(s[1]),t=decodeURIComponent(s[2]);n.push([e,t])}return n}(n);const o=n.replace(/^.*?([^/]+)(\/)*(\?.*?)?$/,"$1$2$3")||"";return{url:n,name:o,query:s}}catch(e){return{url:"Unknown",name:"Unknown",query:null}}}r(H,"hasInitd",!1),function(e){e[e.UNSENT=0]="UNSENT",e[e.OPENED=1]="OPENED",e[e.HEADERS_RECEIVED=2]="HEADERS_RECEIVED",e[e.LOADING=3]="LOADING",e[e.DONE=4]="DONE"}(U||(U={}));class G{constructor(e){r(this,"id",""),r(this,"name",""),r(this,"method",""),r(this,"url",""),r(this,"requestType","xhr"),r(this,"requestHeader",null),r(this,"status",0),r(this,"statusText",""),r(this,"readyState",0),r(this,"responseReason",null),r(this,"responseType",""),r(this,"responseHeader",null),r(this,"startTime",0),r(this,"endTime",0),r(this,"costTime",0),r(this,"getData",null),r(this,"postData",null),r(this,"requestPayload",null),r(this,"withCredentials",!1),this.id=e}}class V{constructor(e){r(this,"reqMap",Object.create(null)),this.socketStore=e}getRequestMap(){return this.reqMap}getRequest(e){return this.reqMap[e]}createRequest(e){return e?this.reqMap[e]?(y.warn("The request object has been in store, disallow duplicate create"),!1):(this.reqMap[e]=new G(e),!0):(y.error('The "id" is required when init request object'),!1)}setRequest(e,t){return!(!e||!t)&&(this.reqMap[e]=t,!0)}sendRequestItem(e,t){this.reqMap[e]||(this.reqMap[e]=t);const n=C("network",{...t},!1);Number(t.readyState)===U.DONE&&this.socketStore.dispatchEvent(P,n),this.socketStore.broadcastMessage(n,t.readyState!==U.DONE),this.deferDeleteRequest(e)}deferDeleteRequest(e){const t=this.getRequest(e);t&&t.readyState===U.DONE&&setTimeout((()=>{delete this.reqMap[e]}),3e3)}}class W extends V{constructor(){super(M)}}class _ extends W{constructor(){super(),r(this,"request",null),this.initProxyHandler()}reset(){if(this.request){const e=n();Object.defineProperty(e,"request",{value:this.request})}}initProxyHandler(){const e=this,t=n(),s=t.request;s&&(this.request=s,Object.defineProperty(t,"request",{value(t){const n=i();e.createRequest(n);const o=e.getRequest(n);if(o){const r=t.method||"GET",{url:i}=t,c=t.header||null,l=F(i);if(o.url=l.url,o.name=l.name,o.getData=l.query,o.method=r.toUpperCase(),o.requestType="mp-request",o.status=0,o.statusText="Pending",o.startTime=Date.now(),o.readyState=U.UNSENT,h(c)?o.requestHeader=Object.entries(c):o.requestHeader=c,"GET"!==o.method){o.requestHeader=[["Content-Type","application/json"]];const{data:e}=t;if(e)if("string"==typeof e)o.requestPayload=e;else if(e instanceof ArrayBuffer)o.requestPayload="[object ArrayBuffer]";else try{o.requestPayload=JSON.stringify(e)}catch(t){o.requestPayload=a(e)}}e.sendRequestItem(n,o);const u=t.success,d=t.fail,g=t.complete,p=()=>{o.endTime=Date.now(),o.costTime=o.endTime-(o.startTime||o.endTime)};t.success=function(t){if(p(),o.status=(null==t?void 0:t.statusCode)||200,o.statusText="Done",o.responseHeader=[...Object.entries((null==t?void 0:t.header)||{})],o.readyState=U.HEADERS_RECEIVED,e.sendRequestItem(n,o),(s=t.statusCode)>=200&&s<400){const e=function(e){const t=Object.keys(e),n={};for(let s=0;s<t.length;s++){const o=t[s];n[o.toLowerCase()]=e[o]}return n}((null==t?void 0:t.header)||{})["content-type"];switch(e&&(e.includes("application/json")&&(o.responseType="json"),(e.includes("text/html")||e.includes("text/plain"))&&(o.responseType="text")),o.responseType||(o.responseType="arraybuffer"),o.responseType){case"json":case"text":if("string"==typeof(null==t?void 0:t.data))try{o.response=JSON.parse(t.data)}catch(e){o.response=t.data,o.responseType="text"}else o.response=null==t?void 0:t.data;break;case"arraybuffer":o.response="[object ArrayBuffer]"}}var s;null==u||u(t)},t.fail=function(e){p(),null==d||d(e)},t.complete=function(t){o.readyState=U.DONE,e.sendRequestItem(n,o),null==g||g(t)};return s(t)}return y.warn("The request object is not found on request event"),null}}))}}class B{constructor(){r(this,"name","NetworkPlugin"),r(this,"requestProxy",null)}onInit(){B.hasInitd||(B.hasInitd=!0,this.requestProxy=new _)}onReset(){var e;null===(e=this.requestProxy)||void 0===e||e.reset(),B.hasInitd=!1}}r(B,"hasInitd",!1);class J{}r(J,"info",{osType:"unknown",osVersion:"unknown",browserType:"unknown",browserVersion:"unknown",framework:"unknown"});const z=e=>{let{osType:t,osVersion:n,browserType:s,browserVersion:o}=e;return"".concat(t,"/").concat(n," ").concat(s,"/").concat(o)};class ${constructor(){r(this,"name","SystemPlugin")}onInit(){if($.hasInitd)return;$.hasInitd=!0;const e=i(),t=J.info;M.broadcastMessage(C("system",{id:e,system:{ua:z(t)},features:{}}),!1)}onReset(){$.hasInitd=!1}}function K(e){const t=typeof e;let n=e;return"string"===t||"boolean"===t||"number"===t?n=String(e):"object"===t&&(n=e instanceof Date?e.toDateString():JSON.stringify(e)),n}r($,"hasInitd",!1);class Q{constructor(){r(this,"name","StoragePlugin")}onInit(){Q.hasInitd||(Q.hasInitd=!0,Q.initStorageProxy(),Q.listenRefreshEvent())}onReset(){const e=n();Object.entries(Q.originFunctions).forEach((t=>{let[n,s]=t;Object.defineProperty(e,n,{value:s})})),Q.hasInitd=!1}static sendRefresh(){const e=n();try{const t=e.getStorageInfoSync(),n={type:"mpStorage",action:"get",data:t.keys.map((t=>({name:t,value:K(e.getStorageSync(t))})))};Q.sendStorageItem(n)}catch(e){}}static listenRefreshEvent(){M.addListener(I,(async e=>{let{source:t}=e;const{data:n}=t;"mpStorage"===n&&Q.sendRefresh()}))}static initStorageProxy(){const e=n(),{sendClearItem:t,sendRemoveItem:s,sendSetItem:o}=Q;["setStorage","setStorageSync","removeStorage","removeStorageSync","clearStorage","clearStorageSync","batchSetStorageSync","batchSetStorage"].forEach((t=>{e[t]&&(Q.originFunctions[t]=e[t])})),Object.defineProperties(e,{setStorage:{value:e=>Q.originFunctions.setStorage({...e,success(t){var n;o(e.key,e.data),null===(n=e.success)||void 0===n||n.call(e,t)}})},setStorageSync:{value(e,t){try{const n=Q.originFunctions.setStorageSync(e,t);return o(e,t),n}catch(t){throw y.error("Failed to set storage synchronously: ".concat(e)),t}}},removeStorage:{value:e=>Q.originFunctions.removeStorage({...e,success(t){var n;s(e.key),null===(n=e.success)||void 0===n||n.call(e,t)}})},removeStorageSync:{value(e){try{const t=Q.originFunctions.removeStorageSync(e);return s(t),t}catch(t){throw y.error("Failed to remove storage synchronously: ".concat(e)),t}}},clearStorage:{value:e=>Q.originFunctions.clearStorage({...e,success(n){var s;t(),null===(s=e.success)||void 0===s||s.call(e,n)}})},clearStorageSync:{value(){try{const e=Q.originFunctions.clearStorageSync();return t(),e}catch(e){throw y.error("Failed to clear storage synchronously"),e}}}}),e.canIUse("batchSetStorageSync")&&Object.defineProperty(e,"batchSetStorageSync",{value(e){try{const t=Q.originFunctions.batchSetStorageSync(e);return e.forEach((e=>{o(e.key,e.value)})),t}catch(t){throw y.error("Failed to batch set storage synchronously: ".concat(JSON.stringify(e.map((e=>e.key))))),t}}}),e.canIUse("batchSetStorage")&&Object.defineProperty(e,"batchSetStorage",{value:e=>Q.originFunctions.batchSetStorage({...e,success(t){var n;e.kvList.forEach((e=>{o(e.key,e.value)})),null===(n=e.success)||void 0===n||n.call(e,t)}})})}static sendSetItem(e,t){Q.sendStorageItem({type:"mpStorage",action:"set",name:e,value:K(t)})}static sendRemoveItem(e){Q.sendStorageItem({type:"mpStorage",action:"remove",name:e})}static sendClearItem(){Q.sendStorageItem({type:"mpStorage",action:"clear"})}static sendStorageItem(e){const t=C("storage",e);M.dispatchEvent(P,t),M.broadcastMessage(t,!0)}}r(Q,"hasInitd",!1),r(Q,"originFunctions",{});const X=e=>!1===e?["http://","ws://"]:["https://","wss://"];class Y{constructor(e){if(this.config=e,!e.get().api)throw Error("The api base url cannot be empty")}get base(){return this.config.get().api}createRoom(){const t=this.config.get(),s=X(t.enableSSL),o=J.info,r=z(o),i=e({name:encodeURIComponent(r),group:t.project,title:t.title});return(a=n().request,e=>new Promise(((t,n)=>{a({...e,success(e){t(e)},fail(e){n(e)}})})))({url:"".concat(s[0]).concat(this.base,"/api/v1/room/create?").concat(i),method:"POST"}).then((e=>e.data),(e=>{throw Error("Request create room failed: ".concat(e.message))}));var a}getRoomUrl(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const n=this.config.get(),s=X(n.enableSSL);return"".concat(s[1]).concat(this.base,"/api/v1/ws/room/join?").concat(e(t))}}class Z{defaultConfig(){return{}}constructor(){r(this,"mergeConfig",(e=>(this.value={...this.defaultConfig(),...e},this.value))),this.value=this.defaultConfig()}get(){return this.value}}class ee extends Z{constructor(){super(...arguments),r(this,"mergeConfig",(e=>(this.value={...this.defaultConfig(),...e},this.value)))}defaultConfig(){return{api:"",project:"default",title:"",enableSSL:null,disabledOnProd:!0,disabledPlugins:[],singletonSocket:!1}}get(){return this.value}}class te{static get pluginsWithOrder(){return[...te.plugins.pre,...te.plugins.normal,...te.plugins.post]}static registerPlugin(e){if(!e)return;if("function"==typeof(t=e)&&void 0!==t.prototype)return void y.error("PageSpy.registerPlugin() expect to pass an instance, not a class");var t;if(!e.name)return void y.error("The ".concat(e.constructor.name,' plugin should provide a "name" property'));if(te.pluginsWithOrder.some((t=>t.name===e.name)))return void y.error("The ".concat(e.name,' has registered. Consider the following reasons:\n - Duplicate register one same plugin;\n - Plugin\'s "name" conflict with others, you can print all registered plugins by "PageSpy.plugins";'));te.plugins[e.enforce||"normal"].push(e)}constructor(e){if(r(this,"root",null),r(this,"version","1.7.7"),r(this,"request",null),r(this,"name",""),r(this,"address",""),r(this,"roomUrl",""),r(this,"socketStore",M),r(this,"config",new ee),te.instance)return y.warn("Cannot initialize PageSpy multiple times"),te.instance;const t=this.config.mergeConfig(e);t.singletonSocket&&(L.isSingleSocket=!0);const s=n();if(s.canIUse("getAccountInfoSync")){if("release"===s.getAccountInfoSync().miniProgram.envVersion&&!1!==t.disabledOnProd)return void y.warn("PageSpy is not allowed on release env of mini program")}this.request=new Y(this.config),te.instance=this,this.triggerPlugins("onInit",{socketStore:M,config:t}),this.init()}triggerPlugins(e,t){const{disabledPlugins:n}=this.config.get();te.pluginsWithOrder.forEach((s=>{var o;u(n)&&n.length&&n.includes(s.name)||null===(o=s[e])||void 0===o||o.call(s,t)}))}async init(){const e=n(),t=this.config.get(),s=e.getStorageSync(A);if(s&&"object"==typeof s){const{name:e,address:n,roomUrl:o,usable:r,project:i,time:a}=s;!r||t.project!==i||a<Date.now()-3e4?await this.createNewConnection():(this.name=e,this.address=n,this.roomUrl=o,this.useOldConnection())}else await this.createNewConnection();e.canIUse("onAppShow")&&e.onAppShow((()=>{const e=M.getSocket().getState();e!==R.CLOSED&&e!==R.CLOSING||this.useOldConnection()})),y.log("Plugins inited")}abort(){this.triggerPlugins("onReset"),M.close(),te.instance=null}async createNewConnection(){if(!this.request)return void y.error("Cannot get the Request");const{data:e}=await this.request.createRoom(),t=this.request.getRoomUrl({address:e.address,name:"client:".concat(i()),userId:"Client"});this.name=e.name,this.address=e.address,this.roomUrl=t,this.refreshRoomInfo(),M.init(t)}useOldConnection(){this.refreshRoomInfo(),M.init(this.roomUrl)}refreshRoomInfo(){this.saveSession();const e=setInterval((()=>{const t=n().getStorageSync(A);if(t&&"object"==typeof t){const{usable:n}=t;if(!1===n)return void clearInterval(e)}this.saveSession()}),15e3);y.log("Room ID: ".concat(this.address.slice(0,4)))}saveSession(){const{name:e,address:t,roomUrl:s}=this,o={name:e,address:t,roomUrl:s,usable:!0,project:this.config.get().project,time:Date.now()};n().setStorageSync(A,o)}}r(te,"plugins",{pre:[],normal:[],post:[]}),r(te,"instance",null);var ne;[new x,new H,new B,new Q,new $].forEach((e=>{te.registerPlugin(e)})),ne=my,t=ne;const se=my.getSystemInfoSync();J.info.osType=se.platform.toLowerCase(),J.info.browserType="mp-alipay",J.info.osVersion=se.system,J.info.browserVersion=se.version,D.messageFilters.push((e=>e.data)),module.exports=te; | ||
"use strict";const e=e=>{const t=[];return Object.entries(e).forEach((e=>{let[n,s]=e;t.push("".concat(n,"=").concat(s))})),t.join("&")};let t;const n=()=>{if(!t)throw Error("the mp sdk is not set");return t};function s(e){return s="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},s(e)}function o(e){var t=function(e,t){if("object"!=s(e)||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var o=n.call(e,t||"default");if("object"!=s(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==s(t)?t:String(t)}function r(e,t,n){return(t=o(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function i(){return Math.random().toString(36).slice(2)}function a(e){return Object.prototype.toString.call(e)}function c(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function l(e){return"[object BigInt]"===a(e)}function u(e){return e instanceof Array}function h(e){return"object"==typeof e&&null!==e}const d=e=>"".concat(e),g=e=>({ok:!0,value:e});function p(e){return void 0===e?g(d(e)):null===e?g(e):function(e){return"number"==typeof e}(e)&&(e===-1/0||e===1/0||Number.isNaN(e))?g(d(e)):l(e)?g("".concat(e,"n")):"symbol"==typeof e||"function"==typeof e?g(d(e.toString())):e instanceof Error?g(d(e.stack)):e===Object.prototype?{value:null,ok:!1}:e instanceof Object||"object"==typeof e?{value:e,ok:!1}:g(e)}function m(e){return void 0===e?"undefined":null===e?"null":l(e)?"bigint":e instanceof Object?e instanceof Error?"error":e instanceof Function?"function":"object":typeof e}const f={...console},y=["log","info","error","warn"].reduce(((e,t)=>(e[t]=function(){for(var e=arguments.length,n=new Array(e),s=0;s<e;s++)n[s]=arguments[s];f[t]("[PageSpy] [".concat(t.toLocaleUpperCase(),"]: "),...n)},e)),{}),S="message",v="broadcast",b="ping";var T=Object.freeze({__proto__:null,BROADCAST:v,CLOSE:"close",CONNECT:"connect",ERROR:"error",JOIN:"join",LEAVE:"leave",MESSAGE:S,PING:b,PONG:"pong"});const O="console",E="debug",I="refresh",k="atom-detail",w="atom-getter",P="public-data";function C(e,t){return{role:"client",type:e,data:{...(!(arguments.length>2&&void 0!==arguments[2])||arguments[2])&&{id:i()},...t}}}class j{constructor(){r(this,"store",{}),r(this,"instanceStore",{})}getStore(){return this.store}resetStore(){this.store={}}getInstanceStore(){return this.instanceStore}resetInstanceStore(){this.instanceStore={}}transformToAtom(e){const{value:t,ok:n}=p(e);return n?{id:i(),type:m(e),value:t}:this.add(e)}get(e){const t=this.store[e],n=this.instanceStore[e];if(!t)return null;const s={},o=Object.getOwnPropertyDescriptors(t);Object.keys(o).forEach((e=>{const t=o[e];c(t,"value")&&(t.value=this.transformToAtom(t.value)),s[e]=j.getAtomOverview({atomId:i(),instanceId:n,value:t})}));const r=this.addExtraProperty(e);return{...s,...r}}getOrigin(e){const t=this.store[e];return t||null}add(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";const n=i();let s=n;var o;h(o=e)&&c(o,"constructor")&&"function"==typeof o.constructor&&(s=t),this.store[n]=e,this.instanceStore[n]=s;const r=j.getSemanticValue(e);return j.getAtomOverview({atomId:n,value:r,instanceId:s})}static getAtomOverview(e){let{instanceId:t="",atomId:n,value:s}=e;return{id:i(),type:"atom",__atomId:n,instanceId:t,value:s}}static getSemanticValue(e){if(h(t=e)&&"[object Object]"===a(t))return"Object {...}";var t;if(u(e))return"Array (".concat(e.length,")");return e.constructor.name}addExtraProperty(e){const t=this.store[e],n=this.instanceStore[e],s={};if((t instanceof String||t instanceof Number||t instanceof Boolean)&&(s["[[PrimitiveValue]]"]=this.transformToAtom(t.valueOf())),t instanceof Set){const e={};let n=0;for(const s of t)e[n++]=s;e.size=t.size,s["[[Entries]]"]=this.transformToAtom(e)}if(t instanceof Map){const e={};let n=0;for(const[s,o]of t.entries())e[n++]={key:s,value:o};e.size=t.size,s["[[Entries]]"]=this.transformToAtom(e)}var o;return(u(t)||(o=t,"function"==typeof NodeList&&"NodeList"===NodeList.name&&o instanceof NodeList||"function"==typeof HTMLCollection&&"HTMLCollection"===HTMLCollection.name&&o instanceof HTMLCollection))&&(s.length=this.transformToAtom(t.length)),null!==Object.getPrototypeOf(t)?s["[[Prototype]]"]=this.add(Object.getPrototypeOf(t),n):s.___proto___=this.transformToAtom(null),s}}var R,N=new j;!function(e){e[e.CONNECTING=0]="CONNECTING",e[e.OPEN=1]="OPEN",e[e.CLOSING=2]="CLOSING",e[e.CLOSED=3]="CLOSED"}(R||(R={}));class q{constructor(){r(this,"events",{open:[],close:[],error:[],message:[]})}emit(e,t){this.events[e].forEach((e=>{e(t)})),"close"!==e&&"error"!==e||this.clearListeners()}onOpen(e){this.events.open.push(e)}onClose(e){this.events.close.push(e)}onError(e){this.events.error.push(e)}onMessage(e){this.events.message.push(e)}clearListeners(){Object.entries(this.events).forEach((e=>{let[,t]=e;t.splice(0)}))}}class D{constructor(){r(this,"socketUrl",""),r(this,"socketConnection",null),r(this,"pingTimer",null),r(this,"pongTimer",null),r(this,"retryTimer",null),r(this,"messages",[]),r(this,"events",{[I]:[],[E]:[],[k]:[],[w]:[],"debugger-online":[],"database-pagination":[],[P]:[]}),r(this,"reconnectable",!0),r(this,"reconnectTimes",3),r(this,"connectionStatus",!1),this.addListener("debug",D.handleDebugger),this.addListener("atom-detail",D.handleResolveAtom),this.addListener("atom-getter",D.handleAtomPropertyGetter),this.addListener("debugger-online",this.handleFlushBuffer)}init(e){try{var t,n,s,o,r;if(!e)throw Error("WebSocket url cannot be empty");this.socketWrapper.getState()===R.OPEN&&this.socketWrapper.close(),null===(t=this.socketWrapper)||void 0===t||t.onOpen((()=>{this.connectOnline()})),null===(n=this.socketWrapper)||void 0===n||n.onMessage((e=>{this.handleMessage(e)})),null===(s=this.socketWrapper)||void 0===s||s.onClose((()=>{this.connectOffline()})),null===(o=this.socketWrapper)||void 0===o||o.onError((()=>{this.connectOffline()})),this.socketUrl=e,null===(r=this.socketWrapper)||void 0===r||r.init(e)}catch(e){y.error(e.message)}}addListener(e,t){this.events[e]||(this.events[e]=[]),this.events[e].push(t)}broadcastMessage(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];const n=function(e){return{type:v,content:{data:e}}}(e);this.send(n,t)}close(){var e;this.clearPing(),this.reconnectTimes=0,this.reconnectable=!1,null===(e=this.socketWrapper)||void 0===e||e.close(),this.messages=[],Object.entries(this.events).forEach((e=>{let[,t]=e;t.splice(0)}))}connectOnline(){this.connectionStatus=!0,this.reconnectTimes=3,this.ping()}connectOffline(){this.connectionStatus=!1,this.socketConnection=null,this.clearPing(),!this.reconnectable||this.reconnectTimes<=0?this.onOffline():(this.retryTimer&&clearTimeout(this.retryTimer),this.retryTimer=setTimeout((()=>{this.retryTimer=null,this.tryReconnect()}),2e3))}tryReconnect(){this.reconnectTimes-=1,this.reconnectTimes<=0&&(this.reconnectable=!1),this.init(this.socketUrl)}ping(){this.pingTimer&&clearTimeout(this.pingTimer),this.pongTimer&&clearTimeout(this.pongTimer),this.pingTimer=setTimeout((()=>{this.send({type:"ping",content:null}),this.pingTimer=null,this.pongTimer=setTimeout((()=>{this.connectOffline(),this.pongTimer=null}),5e3)}),5e3)}clearPing(){this.pingTimer&&(clearTimeout(this.pingTimer),this.pingTimer=null),this.pongTimer&&(clearTimeout(this.pongTimer),this.pongTimer=null)}handlePong(){clearTimeout(this.pongTimer),this.pongTimer=null,this.ping()}handleMessage(e){var t;D.messageFilters.length&&D.messageFilters.forEach((t=>{e=t(e)}));const{CONNECT:n,MESSAGE:s,ERROR:o,JOIN:r,PING:i,PONG:a,LEAVE:c,CLOSE:l,BROADCAST:u}=T,h=JSON.parse(e.data),{type:d}=h;switch(d){case n:const{selfConnection:e}=h.content;this.socketConnection=e;break;case s:const{data:r,from:i,to:a}=h.content;a.address===(null===(t=this.socketConnection)||void 0===t?void 0:t.address)&&this.dispatchEvent(r.type,{source:r,from:i,to:a});break;case o:this.reconnectable=!1,this.connectOffline()}this.handlePong()}dispatchEvent(e,t){[P].includes(e)?this.events[e].forEach((e=>{e(t)})):this.events[e].forEach((e=>{e.call(this,t,(e=>{this.unicastMessage(e,t.from)}))}))}unicastMessage(e,t){const n=function(e,t,n){return{type:S,content:{data:e,from:t,to:n}}}(e,this.socketConnection,t);this.send(n)}handleFlushBuffer(e){const{latestId:t}=e.source.data,n=this.messages.findIndex((e=>e.content.data.data.id===t));this.messages.slice(n+1).forEach((t=>{const n={type:S,content:{data:t.content.data,from:this.socketConnection,to:e.from}};this.send(n,!0)}))}static handleDebugger(e,t){let{source:n}=e;const{type:s,data:o}=n;if(s===E){t(C(O,{logType:"debug-origin",logs:[{id:i(),type:"debug-origin",value:o}]}));try{const e=new Function("return ".concat(o))();t(C(O,{logType:"debug-eval",logs:[N.transformToAtom(e)]}))}catch(e){t(C(O,{logType:"error",logs:[{type:"error",value:e.stack}]}))}}}static handleResolveAtom(e,t){let{source:n}=e;const{type:s,data:o}=n;if(s===k){const e=N.get(o)||{};t(C("atom-detail-".concat(o),e,!1))}}static handleAtomPropertyGetter(e,t){let{source:n}=e;const{type:s,data:o}=n;if(s===w){const{id:e,parentId:n,key:s,instanceId:i}=o,a=N.getOrigin(i),c=N.getOrigin(n);let l={};var r;if(a&&c)l=null===(r=Object.getOwnPropertyDescriptor(c,s))||void 0===r||null===(r=r.get)||void 0===r?void 0:r.call(a);else l=new Error("Getter computed failed");t(C("atom-getter-".concat(e),N.transformToAtom(l)))}}send(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(this.connectionStatus)try{var n;const t=e;t.createdAt=Date.now(),t.requestId=i();const s=function(e){const{ok:t,value:n}=p(e);return t?n:JSON.stringify(e,((e,t)=>p(t).value),2)}(t);null===(n=this.socketWrapper)||void 0===n||n.send(s)}catch(e){throw Error("Incompatible: ".concat(e.message))}if(!t){if([S,b].indexOf(e.type)>-1)return;this.messages.push(e)}}}r(D,"messageFilters",[]);const A="page-spy-room";class L extends q{constructor(){super(...arguments),r(this,"socketInstance",null),r(this,"state",0)}init(e){this.state=R.CONNECTING;const t=n(),s=e=>{this.state=R.CLOSED,this.emit("close",e)},o=e=>{this.state=R.OPEN,this.emit("open",e)},r=e=>{this.state=R.CLOSED,this.emit("error",e)},i=e=>{this.emit("message",e)};L.isSingleSocket?(t.connectSocket({url:e}),t.onSocketClose(s),t.onSocketError(r),t.onSocketMessage(i),t.onSocketOpen(o)):(this.socketInstance=t.connectSocket({url:e,multiple:!0,complete(){}}),this.socketInstance.onClose(s),this.socketInstance.onError(r),this.socketInstance.onOpen(o),this.socketInstance.onMessage(i))}send(e){var t;L.isSingleSocket?n().sendSocketMessage({data:e}):null===(t=this.socketInstance)||void 0===t||t.send({data:e})}close(){var e;L.isSingleSocket?n().closeSocket({}):null===(e=this.socketInstance)||void 0===e||e.close({});this.state=R.CLOSED,this.clearListeners()}getState(){return this.state}}r(L,"isSingleSocket",!1);var U,M=new class extends D{constructor(){super(...arguments),r(this,"socketWrapper",new L)}getSocket(){return this.socketWrapper}onOffline(){n().setStorageSync(A,JSON.stringify({usable:!1}))}};class x{constructor(){r(this,"name","ConsolePlugin"),r(this,"console",{}),r(this,"proxyTypes",["log","info","error","warn","debug"])}async onInit(){if(x.hasInitd)return;x.hasInitd=!0;const t=this;this.proxyTypes.forEach((n=>{this.console[n]=console[n]||console.log||(()=>{}),Object.defineProperty(console,n,{value(){const s=getCurrentPages().pop();let o="/";s&&(o=s.route,s.options&&Object.keys(s.options).length>0&&(o+="?"+e(s.options)));for(var r=arguments.length,i=new Array(r),a=0;a<r;a++)i[a]=arguments[a];t.printLog({logType:n,logs:i,url:o})},configurable:!0,enumerable:!0,writable:!0})}))}onReset(){this.proxyTypes.forEach((e=>{console[e]=this.console[e]})),x.hasInitd=!1}printLog(e){if(e.logs&&e.logs.length){this.console[e.logType](...e.logs),e.logs=e.logs.map((e=>N.transformToAtom(e)));const t=C(O,{time:Date.now(),...e});M.dispatchEvent(P,t),M.broadcastMessage(t)}}}r(x,"hasInitd",!1);class H{constructor(){r(this,"name","ErrorPlugin")}onInit(){H.hasInitd||(H.hasInitd=!0,this.onUncaughtError(),this.onUnhandledRejectionError())}onReset(){const e=n();e.canIUse("offError")&&e.offError(this.errorHandler),e.canIUse("offUnHandledRejection")&&e.offUnHandledRejection(this.unhandledRejectionHandler),H.hasInitd=!1}errorHandler(e){if(H.hasInitd)if(e.stack||e.message){const{message:t,stack:n}=e;H.sendMessage(n||t,{name:"uncaught error",...e})}else{const e="[PageSpy] An unknown error occurred and no message or stack trace available";H.sendMessage(e,null)}}unhandledRejectionHandler(e){H.hasInitd&&H.sendMessage("UnHandled Rejection",{name:"unhandledrejection",message:e.reason})}onUncaughtError(){const e=n();e.canIUse("onError")&&e.onError(this.errorHandler)}onUnhandledRejectionError(){const e=n();e.canIUse("onUnHandledRejection")&&e.onUnHandledRejection(this.unhandledRejectionHandler)}static sendMessage(e,t){const n={logType:"error",logs:[N.transformToAtom(e)],time:Date.now(),url:"wx:light-app",errorDetail:t},s=C(O,n);M.dispatchEvent(P,s),M.broadcastMessage(s)}}function F(e,t){try{let n,s;if("object"==typeof window&&"object"==typeof document&&"[object HTMLDocument]"===Object.prototype.toString.call(document)){const{searchParams:o,href:r}=new URL(e,t);n=r,s=[...o.entries()]}else n=e.toString(),s=function(e){const t=/[?&]([^=#]+)=([^&#]*)/g,n=[];let s;for(;null!==(s=t.exec(e));){const e=decodeURIComponent(s[1]),t=decodeURIComponent(s[2]);n.push([e,t])}return n}(n);const o=n.replace(/^.*?([^/]+)(\/)*(\?.*?)?$/,"$1$2$3")||"";return{url:n,name:o,query:s}}catch(e){return{url:"Unknown",name:"Unknown",query:null}}}r(H,"hasInitd",!1),function(e){e[e.UNSENT=0]="UNSENT",e[e.OPENED=1]="OPENED",e[e.HEADERS_RECEIVED=2]="HEADERS_RECEIVED",e[e.LOADING=3]="LOADING",e[e.DONE=4]="DONE"}(U||(U={}));class G{constructor(e){r(this,"id",""),r(this,"name",""),r(this,"method",""),r(this,"url",""),r(this,"requestType","xhr"),r(this,"requestHeader",null),r(this,"status",0),r(this,"statusText",""),r(this,"readyState",0),r(this,"responseReason",null),r(this,"responseType",""),r(this,"responseHeader",null),r(this,"startTime",0),r(this,"endTime",0),r(this,"costTime",0),r(this,"getData",null),r(this,"postData",null),r(this,"requestPayload",null),r(this,"withCredentials",!1),this.id=e}}class V{constructor(e){r(this,"reqMap",Object.create(null)),this.socketStore=e}getRequestMap(){return this.reqMap}getRequest(e){return this.reqMap[e]}createRequest(e){return e?this.reqMap[e]?(y.warn("The request object has been in store, disallow duplicate create"),!1):(this.reqMap[e]=new G(e),!0):(y.error('The "id" is required when init request object'),!1)}setRequest(e,t){return!(!e||!t)&&(this.reqMap[e]=t,!0)}sendRequestItem(e,t){this.reqMap[e]||(this.reqMap[e]=t);const n=C("network",{...t},!1);Number(t.readyState)===U.DONE&&this.socketStore.dispatchEvent(P,n),this.socketStore.broadcastMessage(n,t.readyState!==U.DONE),this.deferDeleteRequest(e)}deferDeleteRequest(e){const t=this.getRequest(e);t&&t.readyState===U.DONE&&setTimeout((()=>{delete this.reqMap[e]}),3e3)}}class W extends V{constructor(){super(M)}}class _ extends W{constructor(){super(),r(this,"request",null),this.initProxyHandler()}reset(){if(this.request){const e=n();Object.defineProperty(e,"request",{value:this.request})}}initProxyHandler(){const e=this,t=n(),s=t.request;s&&(this.request=s,Object.defineProperty(t,"request",{value(t){const n=i();e.createRequest(n);const o=e.getRequest(n);if(o){const r=t.method||"GET",{url:i}=t,c=t.header||null,l=F(i);if(o.url=l.url,o.name=l.name,o.getData=l.query,o.method=r.toUpperCase(),o.requestType="mp-request",o.status=0,o.statusText="Pending",o.startTime=Date.now(),o.readyState=U.UNSENT,h(c)?o.requestHeader=Object.entries(c):o.requestHeader=c,"GET"!==o.method){o.requestHeader=[["Content-Type","application/json"]];const{data:e}=t;if(e)if("string"==typeof e)o.requestPayload=e;else if(e instanceof ArrayBuffer)o.requestPayload="[object ArrayBuffer]";else try{o.requestPayload=JSON.stringify(e)}catch(t){o.requestPayload=a(e)}}e.sendRequestItem(n,o);const u=t.success,d=t.fail,g=t.complete,p=()=>{o.endTime=Date.now(),o.costTime=o.endTime-(o.startTime||o.endTime)};t.success=function(t){if(p(),o.status=(null==t?void 0:t.statusCode)||200,o.statusText="Done",o.responseHeader=[...Object.entries((null==t?void 0:t.header)||{})],o.readyState=U.HEADERS_RECEIVED,e.sendRequestItem(n,o),(s=t.statusCode)>=200&&s<400){const e=function(e){const t=Object.keys(e),n={};for(let s=0;s<t.length;s++){const o=t[s];n[o.toLowerCase()]=e[o]}return n}((null==t?void 0:t.header)||{})["content-type"];switch(e&&(e.includes("application/json")&&(o.responseType="json"),(e.includes("text/html")||e.includes("text/plain"))&&(o.responseType="text")),o.responseType||(o.responseType="arraybuffer"),o.responseType){case"json":case"text":if("string"==typeof(null==t?void 0:t.data))try{o.response=JSON.parse(t.data)}catch(e){o.response=t.data,o.responseType="text"}else o.response=null==t?void 0:t.data;break;case"arraybuffer":o.response="[object ArrayBuffer]"}}var s;null==u||u(t)},t.fail=function(e){p(),null==d||d(e)},t.complete=function(t){o.readyState=U.DONE,e.sendRequestItem(n,o),null==g||g(t)};return s(t)}return y.warn("The request object is not found on request event"),null}}))}}class B{constructor(){r(this,"name","NetworkPlugin"),r(this,"requestProxy",null)}onInit(){B.hasInitd||(B.hasInitd=!0,this.requestProxy=new _)}onReset(){var e;null===(e=this.requestProxy)||void 0===e||e.reset(),B.hasInitd=!1}}r(B,"hasInitd",!1);class J{}r(J,"info",{osType:"unknown",osVersion:"unknown",browserType:"unknown",browserVersion:"unknown",framework:"unknown"});const z=e=>{let{osType:t,osVersion:n,browserType:s,browserVersion:o}=e;return"".concat(t,"/").concat(n," ").concat(s,"/").concat(o)};class ${constructor(){r(this,"name","SystemPlugin")}onInit(){if($.hasInitd)return;$.hasInitd=!0;const e=i(),t=J.info;M.broadcastMessage(C("system",{id:e,system:{ua:z(t)},features:{}}),!1)}onReset(){$.hasInitd=!1}}function K(e){const t=typeof e;let n=e;return"string"===t||"boolean"===t||"number"===t?n=String(e):"object"===t&&(n=e instanceof Date?e.toDateString():JSON.stringify(e)),n}r($,"hasInitd",!1);class Q{constructor(){r(this,"name","StoragePlugin")}onInit(){Q.hasInitd||(Q.hasInitd=!0,Q.initStorageProxy(),Q.listenRefreshEvent())}onReset(){const e=n();Object.entries(Q.originFunctions).forEach((t=>{let[n,s]=t;Object.defineProperty(e,n,{value:s})})),Q.hasInitd=!1}static sendRefresh(){const e=n();try{const t=e.getStorageInfoSync(),n={type:"mpStorage",action:"get",data:t.keys.map((t=>({name:t,value:K(e.getStorageSync(t))})))};Q.sendStorageItem(n)}catch(e){}}static listenRefreshEvent(){M.addListener(I,(async e=>{let{source:t}=e;const{data:n}=t;"mpStorage"===n&&Q.sendRefresh()}))}static initStorageProxy(){const e=n(),{sendClearItem:t,sendRemoveItem:s,sendSetItem:o}=Q;["setStorage","setStorageSync","removeStorage","removeStorageSync","clearStorage","clearStorageSync","batchSetStorageSync","batchSetStorage"].forEach((t=>{e[t]&&(Q.originFunctions[t]=e[t])})),Object.defineProperties(e,{setStorage:{value:e=>Q.originFunctions.setStorage({...e,success(t){var n;o(e.key,e.data),null===(n=e.success)||void 0===n||n.call(e,t)}})},setStorageSync:{value(e,t){try{const n=Q.originFunctions.setStorageSync(e,t);return o(e,t),n}catch(t){throw y.error("Failed to set storage synchronously: ".concat(e)),t}}},removeStorage:{value:e=>Q.originFunctions.removeStorage({...e,success(t){var n;s(e.key),null===(n=e.success)||void 0===n||n.call(e,t)}})},removeStorageSync:{value(e){try{const t=Q.originFunctions.removeStorageSync(e);return s(t),t}catch(t){throw y.error("Failed to remove storage synchronously: ".concat(e)),t}}},clearStorage:{value:e=>Q.originFunctions.clearStorage({...e,success(n){var s;t(),null===(s=e.success)||void 0===s||s.call(e,n)}})},clearStorageSync:{value(){try{const e=Q.originFunctions.clearStorageSync();return t(),e}catch(e){throw y.error("Failed to clear storage synchronously"),e}}}}),e.canIUse("batchSetStorageSync")&&Object.defineProperty(e,"batchSetStorageSync",{value(e){try{const t=Q.originFunctions.batchSetStorageSync(e);return e.forEach((e=>{o(e.key,e.value)})),t}catch(t){throw y.error("Failed to batch set storage synchronously: ".concat(JSON.stringify(e.map((e=>e.key))))),t}}}),e.canIUse("batchSetStorage")&&Object.defineProperty(e,"batchSetStorage",{value:e=>Q.originFunctions.batchSetStorage({...e,success(t){var n;e.kvList.forEach((e=>{o(e.key,e.value)})),null===(n=e.success)||void 0===n||n.call(e,t)}})})}static sendSetItem(e,t){Q.sendStorageItem({type:"mpStorage",action:"set",name:e,value:K(t)})}static sendRemoveItem(e){Q.sendStorageItem({type:"mpStorage",action:"remove",name:e})}static sendClearItem(){Q.sendStorageItem({type:"mpStorage",action:"clear"})}static sendStorageItem(e){const t=C("storage",e);M.dispatchEvent(P,t),M.broadcastMessage(t,!0)}}r(Q,"hasInitd",!1),r(Q,"originFunctions",{});const X=e=>!1===e?["http://","ws://"]:["https://","wss://"];class Y{constructor(e){if(this.config=e,!e.get().api)throw Error("The api base url cannot be empty")}get base(){return this.config.get().api}createRoom(){const t=this.config.get(),s=X(t.enableSSL),o=J.info,r=z(o),i=e({name:encodeURIComponent(r),group:t.project,title:t.title});return(a=n().request,e=>new Promise(((t,n)=>{a({...e,success(e){t(e)},fail(e){n(e)}})})))({url:"".concat(s[0]).concat(this.base,"/api/v1/room/create?").concat(i),method:"POST"}).then((e=>e.data),(e=>{throw Error("Request create room failed: ".concat(e.message))}));var a}getRoomUrl(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const n=this.config.get(),s=X(n.enableSSL);return"".concat(s[1]).concat(this.base,"/api/v1/ws/room/join?").concat(e(t))}}class Z{defaultConfig(){return{}}constructor(){r(this,"mergeConfig",(e=>(this.value={...this.defaultConfig(),...e},this.value))),this.value=this.defaultConfig()}get(){return this.value}}class ee extends Z{constructor(){super(...arguments),r(this,"mergeConfig",(e=>(this.value={...this.defaultConfig(),...e},this.value)))}defaultConfig(){return{api:"",project:"default",title:"",enableSSL:null,disabledOnProd:!0,disabledPlugins:[],singletonSocket:!1}}get(){return this.value}}class te{static get pluginsWithOrder(){return[...te.plugins.pre,...te.plugins.normal,...te.plugins.post]}static registerPlugin(e){if(!e)return;if("function"==typeof(t=e)&&void 0!==t.prototype)return void y.error("PageSpy.registerPlugin() expect to pass an instance, not a class");var t;if(!e.name)return void y.error("The ".concat(e.constructor.name,' plugin should provide a "name" property'));if(te.pluginsWithOrder.some((t=>t.name===e.name)))return void y.error("The ".concat(e.name,' has registered. Consider the following reasons:\n - Duplicate register one same plugin;\n - Plugin\'s "name" conflict with others, you can print all registered plugins by "PageSpy.plugins";'));te.plugins[e.enforce||"normal"].push(e)}constructor(e){if(r(this,"root",null),r(this,"version","1.7.8"),r(this,"request",null),r(this,"name",""),r(this,"address",""),r(this,"roomUrl",""),r(this,"socketStore",M),r(this,"config",new ee),te.instance)return y.warn("Cannot initialize PageSpy multiple times"),te.instance;const t=this.config.mergeConfig(e);t.singletonSocket&&(L.isSingleSocket=!0);const s=n();if(s.canIUse("getAccountInfoSync")){if("release"===s.getAccountInfoSync().miniProgram.envVersion&&!1!==t.disabledOnProd)return void y.warn("PageSpy is not allowed on release env of mini program")}this.request=new Y(this.config),te.instance=this,this.triggerPlugins("onInit",{socketStore:M,config:t}),this.init()}triggerPlugins(e,t){const{disabledPlugins:n}=this.config.get();te.pluginsWithOrder.forEach((s=>{var o;u(n)&&n.length&&n.includes(s.name)||null===(o=s[e])||void 0===o||o.call(s,t)}))}async init(){const e=n(),t=this.config.get(),s=e.getStorageSync(A);if(s&&"object"==typeof s){const{name:e,address:n,roomUrl:o,usable:r,project:i,time:a}=s;!r||t.project!==i||a<Date.now()-3e4?await this.createNewConnection():(this.name=e,this.address=n,this.roomUrl=o,this.useOldConnection())}else await this.createNewConnection();e.canIUse("onAppShow")&&e.onAppShow((()=>{const e=M.getSocket().getState();e!==R.CLOSED&&e!==R.CLOSING||this.useOldConnection()})),y.log("Plugins inited")}abort(){this.triggerPlugins("onReset"),M.close(),te.instance=null}async createNewConnection(){if(!this.request)return void y.error("Cannot get the Request");const{data:e}=await this.request.createRoom(),t=this.request.getRoomUrl({address:e.address,name:"client:".concat(i()),userId:"Client"});this.name=e.name,this.address=e.address,this.roomUrl=t,this.refreshRoomInfo(),M.init(t)}useOldConnection(){this.refreshRoomInfo(),M.init(this.roomUrl)}refreshRoomInfo(){this.saveSession();const e=setInterval((()=>{const t=n().getStorageSync(A);if(t&&"object"==typeof t){const{usable:n}=t;if(!1===n)return void clearInterval(e)}this.saveSession()}),15e3);y.log("Room ID: ".concat(this.address.slice(0,4)))}saveSession(){const{name:e,address:t,roomUrl:s}=this,o={name:e,address:t,roomUrl:s,usable:!0,project:this.config.get().project,time:Date.now()};n().setStorageSync(A,o)}}r(te,"plugins",{pre:[],normal:[],post:[]}),r(te,"instance",null);var ne;[new x,new H,new B,new Q,new $].forEach((e=>{te.registerPlugin(e)})),ne={...my,getStorageSync(e){const t=my.getStorageSync({key:e});if(t.success)return t.data},setStorageSync:(e,t)=>my.setStorageSync({key:e,data:t}),removeStorageSync:e=>my.removeStorageSync({key:e})},t=ne;const se=my.getSystemInfoSync();J.info.osType=se.platform.toLowerCase(),J.info.browserType="mp-alipay",J.info.osVersion=se.system,J.info.browserVersion=se.version,D.messageFilters.push((e=>e.data)),module.exports=te; | ||
//# sourceMappingURL=index.min.js.map |
@@ -1,2 +0,2 @@ | ||
const e=e=>{const t=[];return Object.entries(e).forEach((e=>{let[n,s]=e;t.push("".concat(n,"=").concat(s))})),t.join("&")};let t;const n=()=>{if(!t)throw Error("the mp sdk is not set");return t};function s(e){return s="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},s(e)}function o(e){var t=function(e,t){if("object"!=s(e)||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var o=n.call(e,t||"default");if("object"!=s(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==s(t)?t:String(t)}function r(e,t,n){return(t=o(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function i(){return Math.random().toString(36).slice(2)}function a(e){return Object.prototype.toString.call(e)}function c(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function l(e){return"[object BigInt]"===a(e)}function u(e){return e instanceof Array}function h(e){return"object"==typeof e&&null!==e}const d=e=>"".concat(e),g=e=>({ok:!0,value:e});function p(e){return void 0===e?g(d(e)):null===e?g(e):function(e){return"number"==typeof e}(e)&&(e===-1/0||e===1/0||Number.isNaN(e))?g(d(e)):l(e)?g("".concat(e,"n")):"symbol"==typeof e||"function"==typeof e?g(d(e.toString())):e instanceof Error?g(d(e.stack)):e===Object.prototype?{value:null,ok:!1}:e instanceof Object||"object"==typeof e?{value:e,ok:!1}:g(e)}function f(e){return void 0===e?"undefined":null===e?"null":l(e)?"bigint":e instanceof Object?e instanceof Error?"error":e instanceof Function?"function":"object":typeof e}const m={...console},y=["log","info","error","warn"].reduce(((e,t)=>(e[t]=function(){for(var e=arguments.length,n=new Array(e),s=0;s<e;s++)n[s]=arguments[s];m[t]("[PageSpy] [".concat(t.toLocaleUpperCase(),"]: "),...n)},e)),{}),S="message",v="broadcast",b="ping";var T=Object.freeze({__proto__:null,BROADCAST:v,CLOSE:"close",CONNECT:"connect",ERROR:"error",JOIN:"join",LEAVE:"leave",MESSAGE:S,PING:b,PONG:"pong"});const O="console",E="debug",I="refresh",w="atom-detail",k="atom-getter",P="public-data";function C(e,t){return{role:"client",type:e,data:{...(!(arguments.length>2&&void 0!==arguments[2])||arguments[2])&&{id:i()},...t}}}class j{constructor(){r(this,"store",{}),r(this,"instanceStore",{})}getStore(){return this.store}resetStore(){this.store={}}getInstanceStore(){return this.instanceStore}resetInstanceStore(){this.instanceStore={}}transformToAtom(e){const{value:t,ok:n}=p(e);return n?{id:i(),type:f(e),value:t}:this.add(e)}get(e){const t=this.store[e],n=this.instanceStore[e];if(!t)return null;const s={},o=Object.getOwnPropertyDescriptors(t);Object.keys(o).forEach((e=>{const t=o[e];c(t,"value")&&(t.value=this.transformToAtom(t.value)),s[e]=j.getAtomOverview({atomId:i(),instanceId:n,value:t})}));const r=this.addExtraProperty(e);return{...s,...r}}getOrigin(e){const t=this.store[e];return t||null}add(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";const n=i();let s=n;var o;h(o=e)&&c(o,"constructor")&&"function"==typeof o.constructor&&(s=t),this.store[n]=e,this.instanceStore[n]=s;const r=j.getSemanticValue(e);return j.getAtomOverview({atomId:n,value:r,instanceId:s})}static getAtomOverview(e){let{instanceId:t="",atomId:n,value:s}=e;return{id:i(),type:"atom",__atomId:n,instanceId:t,value:s}}static getSemanticValue(e){if(h(t=e)&&"[object Object]"===a(t))return"Object {...}";var t;if(u(e))return"Array (".concat(e.length,")");return e.constructor.name}addExtraProperty(e){const t=this.store[e],n=this.instanceStore[e],s={};if((t instanceof String||t instanceof Number||t instanceof Boolean)&&(s["[[PrimitiveValue]]"]=this.transformToAtom(t.valueOf())),t instanceof Set){const e={};let n=0;for(const s of t)e[n++]=s;e.size=t.size,s["[[Entries]]"]=this.transformToAtom(e)}if(t instanceof Map){const e={};let n=0;for(const[s,o]of t.entries())e[n++]={key:s,value:o};e.size=t.size,s["[[Entries]]"]=this.transformToAtom(e)}var o;return(u(t)||(o=t,"function"==typeof NodeList&&"NodeList"===NodeList.name&&o instanceof NodeList||"function"==typeof HTMLCollection&&"HTMLCollection"===HTMLCollection.name&&o instanceof HTMLCollection))&&(s.length=this.transformToAtom(t.length)),null!==Object.getPrototypeOf(t)?s["[[Prototype]]"]=this.add(Object.getPrototypeOf(t),n):s.___proto___=this.transformToAtom(null),s}}var R,N=new j;!function(e){e[e.CONNECTING=0]="CONNECTING",e[e.OPEN=1]="OPEN",e[e.CLOSING=2]="CLOSING",e[e.CLOSED=3]="CLOSED"}(R||(R={}));class q{constructor(){r(this,"events",{open:[],close:[],error:[],message:[]})}emit(e,t){this.events[e].forEach((e=>{e(t)})),"close"!==e&&"error"!==e||this.clearListeners()}onOpen(e){this.events.open.push(e)}onClose(e){this.events.close.push(e)}onError(e){this.events.error.push(e)}onMessage(e){this.events.message.push(e)}clearListeners(){Object.entries(this.events).forEach((e=>{let[,t]=e;t.splice(0)}))}}class D{constructor(){r(this,"socketUrl",""),r(this,"socketConnection",null),r(this,"pingTimer",null),r(this,"pongTimer",null),r(this,"retryTimer",null),r(this,"messages",[]),r(this,"events",{[I]:[],[E]:[],[w]:[],[k]:[],"debugger-online":[],"database-pagination":[],[P]:[]}),r(this,"reconnectable",!0),r(this,"reconnectTimes",3),r(this,"connectionStatus",!1),this.addListener("debug",D.handleDebugger),this.addListener("atom-detail",D.handleResolveAtom),this.addListener("atom-getter",D.handleAtomPropertyGetter),this.addListener("debugger-online",this.handleFlushBuffer)}init(e){try{var t,n,s,o,r;if(!e)throw Error("WebSocket url cannot be empty");this.socketWrapper.getState()===R.OPEN&&this.socketWrapper.close(),null===(t=this.socketWrapper)||void 0===t||t.onOpen((()=>{this.connectOnline()})),null===(n=this.socketWrapper)||void 0===n||n.onMessage((e=>{this.handleMessage(e)})),null===(s=this.socketWrapper)||void 0===s||s.onClose((()=>{this.connectOffline()})),null===(o=this.socketWrapper)||void 0===o||o.onError((()=>{this.connectOffline()})),this.socketUrl=e,null===(r=this.socketWrapper)||void 0===r||r.init(e)}catch(e){y.error(e.message)}}addListener(e,t){this.events[e]||(this.events[e]=[]),this.events[e].push(t)}broadcastMessage(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];const n=function(e){return{type:v,content:{data:e}}}(e);this.send(n,t)}close(){var e;this.clearPing(),this.reconnectTimes=0,this.reconnectable=!1,null===(e=this.socketWrapper)||void 0===e||e.close(),this.messages=[],Object.entries(this.events).forEach((e=>{let[,t]=e;t.splice(0)}))}connectOnline(){this.connectionStatus=!0,this.reconnectTimes=3,this.ping()}connectOffline(){this.connectionStatus=!1,this.socketConnection=null,this.clearPing(),!this.reconnectable||this.reconnectTimes<=0?this.onOffline():(this.retryTimer&&clearTimeout(this.retryTimer),this.retryTimer=setTimeout((()=>{this.retryTimer=null,this.tryReconnect()}),2e3))}tryReconnect(){this.reconnectTimes-=1,this.reconnectTimes<=0&&(this.reconnectable=!1),this.init(this.socketUrl)}ping(){this.pingTimer&&clearTimeout(this.pingTimer),this.pongTimer&&clearTimeout(this.pongTimer),this.pingTimer=setTimeout((()=>{this.send({type:"ping",content:null}),this.pingTimer=null,this.pongTimer=setTimeout((()=>{this.connectOffline(),this.pongTimer=null}),5e3)}),5e3)}clearPing(){this.pingTimer&&(clearTimeout(this.pingTimer),this.pingTimer=null),this.pongTimer&&(clearTimeout(this.pongTimer),this.pongTimer=null)}handlePong(){clearTimeout(this.pongTimer),this.pongTimer=null,this.ping()}handleMessage(e){var t;D.messageFilters.length&&D.messageFilters.forEach((t=>{e=t(e)}));const{CONNECT:n,MESSAGE:s,ERROR:o,JOIN:r,PING:i,PONG:a,LEAVE:c,CLOSE:l,BROADCAST:u}=T,h=JSON.parse(e.data),{type:d}=h;switch(d){case n:const{selfConnection:e}=h.content;this.socketConnection=e;break;case s:const{data:r,from:i,to:a}=h.content;a.address===(null===(t=this.socketConnection)||void 0===t?void 0:t.address)&&this.dispatchEvent(r.type,{source:r,from:i,to:a});break;case o:this.reconnectable=!1,this.connectOffline()}this.handlePong()}dispatchEvent(e,t){[P].includes(e)?this.events[e].forEach((e=>{e(t)})):this.events[e].forEach((e=>{e.call(this,t,(e=>{this.unicastMessage(e,t.from)}))}))}unicastMessage(e,t){const n=function(e,t,n){return{type:S,content:{data:e,from:t,to:n}}}(e,this.socketConnection,t);this.send(n)}handleFlushBuffer(e){const{latestId:t}=e.source.data,n=this.messages.findIndex((e=>e.content.data.data.id===t));this.messages.slice(n+1).forEach((t=>{const n={type:S,content:{data:t.content.data,from:this.socketConnection,to:e.from}};this.send(n,!0)}))}static handleDebugger(e,t){let{source:n}=e;const{type:s,data:o}=n;if(s===E){t(C(O,{logType:"debug-origin",logs:[{id:i(),type:"debug-origin",value:o}]}));try{const e=new Function("return ".concat(o))();t(C(O,{logType:"debug-eval",logs:[N.transformToAtom(e)]}))}catch(e){t(C(O,{logType:"error",logs:[{type:"error",value:e.stack}]}))}}}static handleResolveAtom(e,t){let{source:n}=e;const{type:s,data:o}=n;if(s===w){const e=N.get(o)||{};t(C("atom-detail-".concat(o),e,!1))}}static handleAtomPropertyGetter(e,t){let{source:n}=e;const{type:s,data:o}=n;if(s===k){const{id:e,parentId:n,key:s,instanceId:i}=o,a=N.getOrigin(i),c=N.getOrigin(n);let l={};var r;if(a&&c)l=null===(r=Object.getOwnPropertyDescriptor(c,s))||void 0===r||null===(r=r.get)||void 0===r?void 0:r.call(a);else l=new Error("Getter computed failed");t(C("atom-getter-".concat(e),N.transformToAtom(l)))}}send(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(this.connectionStatus)try{var n;const t=e;t.createdAt=Date.now(),t.requestId=i();const s=function(e){const{ok:t,value:n}=p(e);return t?n:JSON.stringify(e,((e,t)=>p(t).value),2)}(t);null===(n=this.socketWrapper)||void 0===n||n.send(s)}catch(e){throw Error("Incompatible: ".concat(e.message))}if(!t){if([S,b].indexOf(e.type)>-1)return;this.messages.push(e)}}}r(D,"messageFilters",[]);const A="page-spy-room";class L extends q{constructor(){super(...arguments),r(this,"socketInstance",null),r(this,"state",0)}init(e){this.state=R.CONNECTING;const t=n(),s=e=>{this.state=R.CLOSED,this.emit("close",e)},o=e=>{this.state=R.OPEN,this.emit("open",e)},r=e=>{this.state=R.CLOSED,this.emit("error",e)},i=e=>{this.emit("message",e)};L.isSingleSocket?(t.connectSocket({url:e}),t.onSocketClose(s),t.onSocketError(r),t.onSocketMessage(i),t.onSocketOpen(o)):(this.socketInstance=t.connectSocket({url:e,multiple:!0,complete(){}}),this.socketInstance.onClose(s),this.socketInstance.onError(r),this.socketInstance.onOpen(o),this.socketInstance.onMessage(i))}send(e){var t;L.isSingleSocket?n().sendSocketMessage({data:e}):null===(t=this.socketInstance)||void 0===t||t.send({data:e})}close(){var e;L.isSingleSocket?n().closeSocket({}):null===(e=this.socketInstance)||void 0===e||e.close({});this.state=R.CLOSED,this.clearListeners()}getState(){return this.state}}r(L,"isSingleSocket",!1);var U,M=new class extends D{constructor(){super(...arguments),r(this,"socketWrapper",new L)}getSocket(){return this.socketWrapper}onOffline(){n().setStorageSync(A,JSON.stringify({usable:!1}))}};class x{constructor(){r(this,"name","ConsolePlugin"),r(this,"console",{}),r(this,"proxyTypes",["log","info","error","warn","debug"])}async onInit(){if(x.hasInitd)return;x.hasInitd=!0;const t=this;this.proxyTypes.forEach((n=>{this.console[n]=console[n]||console.log||(()=>{}),Object.defineProperty(console,n,{value(){const s=getCurrentPages().pop();let o="/";s&&(o=s.route,s.options&&Object.keys(s.options).length>0&&(o+="?"+e(s.options)));for(var r=arguments.length,i=new Array(r),a=0;a<r;a++)i[a]=arguments[a];t.printLog({logType:n,logs:i,url:o})},configurable:!0,enumerable:!0,writable:!0})}))}onReset(){this.proxyTypes.forEach((e=>{console[e]=this.console[e]})),x.hasInitd=!1}printLog(e){if(e.logs&&e.logs.length){this.console[e.logType](...e.logs),e.logs=e.logs.map((e=>N.transformToAtom(e)));const t=C(O,{time:Date.now(),...e});M.dispatchEvent(P,t),M.broadcastMessage(t)}}}r(x,"hasInitd",!1);class H{constructor(){r(this,"name","ErrorPlugin")}onInit(){H.hasInitd||(H.hasInitd=!0,this.onUncaughtError(),this.onUnhandledRejectionError())}onReset(){const e=n();e.canIUse("offError")&&e.offError(this.errorHandler),e.canIUse("offUnHandledRejection")&&e.offUnHandledRejection(this.unhandledRejectionHandler),H.hasInitd=!1}errorHandler(e){if(H.hasInitd)if(e.stack||e.message){const{message:t,stack:n}=e;H.sendMessage(n||t,{name:"uncaught error",...e})}else{const e="[PageSpy] An unknown error occurred and no message or stack trace available";H.sendMessage(e,null)}}unhandledRejectionHandler(e){H.hasInitd&&H.sendMessage("UnHandled Rejection",{name:"unhandledrejection",message:e.reason})}onUncaughtError(){const e=n();e.canIUse("onError")&&e.onError(this.errorHandler)}onUnhandledRejectionError(){const e=n();e.canIUse("onUnHandledRejection")&&e.onUnHandledRejection(this.unhandledRejectionHandler)}static sendMessage(e,t){const n={logType:"error",logs:[N.transformToAtom(e)],time:Date.now(),url:"wx:light-app",errorDetail:t},s=C(O,n);M.dispatchEvent(P,s),M.broadcastMessage(s)}}function F(e,t){try{let n,s;if("object"==typeof window&&"object"==typeof document&&"[object HTMLDocument]"===Object.prototype.toString.call(document)){const{searchParams:o,href:r}=new URL(e,t);n=r,s=[...o.entries()]}else n=e.toString(),s=function(e){const t=/[?&]([^=#]+)=([^&#]*)/g,n=[];let s;for(;null!==(s=t.exec(e));){const e=decodeURIComponent(s[1]),t=decodeURIComponent(s[2]);n.push([e,t])}return n}(n);const o=n.replace(/^.*?([^/]+)(\/)*(\?.*?)?$/,"$1$2$3")||"";return{url:n,name:o,query:s}}catch(e){return{url:"Unknown",name:"Unknown",query:null}}}r(H,"hasInitd",!1),function(e){e[e.UNSENT=0]="UNSENT",e[e.OPENED=1]="OPENED",e[e.HEADERS_RECEIVED=2]="HEADERS_RECEIVED",e[e.LOADING=3]="LOADING",e[e.DONE=4]="DONE"}(U||(U={}));class G{constructor(e){r(this,"id",""),r(this,"name",""),r(this,"method",""),r(this,"url",""),r(this,"requestType","xhr"),r(this,"requestHeader",null),r(this,"status",0),r(this,"statusText",""),r(this,"readyState",0),r(this,"responseReason",null),r(this,"responseType",""),r(this,"responseHeader",null),r(this,"startTime",0),r(this,"endTime",0),r(this,"costTime",0),r(this,"getData",null),r(this,"postData",null),r(this,"requestPayload",null),r(this,"withCredentials",!1),this.id=e}}class V{constructor(e){r(this,"reqMap",Object.create(null)),this.socketStore=e}getRequestMap(){return this.reqMap}getRequest(e){return this.reqMap[e]}createRequest(e){return e?this.reqMap[e]?(y.warn("The request object has been in store, disallow duplicate create"),!1):(this.reqMap[e]=new G(e),!0):(y.error('The "id" is required when init request object'),!1)}setRequest(e,t){return!(!e||!t)&&(this.reqMap[e]=t,!0)}sendRequestItem(e,t){this.reqMap[e]||(this.reqMap[e]=t);const n=C("network",{...t},!1);Number(t.readyState)===U.DONE&&this.socketStore.dispatchEvent(P,n),this.socketStore.broadcastMessage(n,t.readyState!==U.DONE),this.deferDeleteRequest(e)}deferDeleteRequest(e){const t=this.getRequest(e);t&&t.readyState===U.DONE&&setTimeout((()=>{delete this.reqMap[e]}),3e3)}}class W extends V{constructor(){super(M)}}class _ extends W{constructor(){super(),r(this,"request",null),this.initProxyHandler()}reset(){if(this.request){const e=n();Object.defineProperty(e,"request",{value:this.request})}}initProxyHandler(){const e=this,t=n(),s=t.request;s&&(this.request=s,Object.defineProperty(t,"request",{value(t){const n=i();e.createRequest(n);const o=e.getRequest(n);if(o){const r=t.method||"GET",{url:i}=t,c=t.header||null,l=F(i);if(o.url=l.url,o.name=l.name,o.getData=l.query,o.method=r.toUpperCase(),o.requestType="mp-request",o.status=0,o.statusText="Pending",o.startTime=Date.now(),o.readyState=U.UNSENT,h(c)?o.requestHeader=Object.entries(c):o.requestHeader=c,"GET"!==o.method){o.requestHeader=[["Content-Type","application/json"]];const{data:e}=t;if(e)if("string"==typeof e)o.requestPayload=e;else if(e instanceof ArrayBuffer)o.requestPayload="[object ArrayBuffer]";else try{o.requestPayload=JSON.stringify(e)}catch(t){o.requestPayload=a(e)}}e.sendRequestItem(n,o);const u=t.success,d=t.fail,g=t.complete,p=()=>{o.endTime=Date.now(),o.costTime=o.endTime-(o.startTime||o.endTime)};t.success=function(t){if(p(),o.status=(null==t?void 0:t.statusCode)||200,o.statusText="Done",o.responseHeader=[...Object.entries((null==t?void 0:t.header)||{})],o.readyState=U.HEADERS_RECEIVED,e.sendRequestItem(n,o),(s=t.statusCode)>=200&&s<400){const e=function(e){const t=Object.keys(e),n={};for(let s=0;s<t.length;s++){const o=t[s];n[o.toLowerCase()]=e[o]}return n}((null==t?void 0:t.header)||{})["content-type"];switch(e&&(e.includes("application/json")&&(o.responseType="json"),(e.includes("text/html")||e.includes("text/plain"))&&(o.responseType="text")),o.responseType||(o.responseType="arraybuffer"),o.responseType){case"json":case"text":if("string"==typeof(null==t?void 0:t.data))try{o.response=JSON.parse(t.data)}catch(e){o.response=t.data,o.responseType="text"}else o.response=null==t?void 0:t.data;break;case"arraybuffer":o.response="[object ArrayBuffer]"}}var s;null==u||u(t)},t.fail=function(e){p(),null==d||d(e)},t.complete=function(t){o.readyState=U.DONE,e.sendRequestItem(n,o),null==g||g(t)};return s(t)}return y.warn("The request object is not found on request event"),null}}))}}class B{constructor(){r(this,"name","NetworkPlugin"),r(this,"requestProxy",null)}onInit(){B.hasInitd||(B.hasInitd=!0,this.requestProxy=new _)}onReset(){var e;null===(e=this.requestProxy)||void 0===e||e.reset(),B.hasInitd=!1}}r(B,"hasInitd",!1);class J{}r(J,"info",{osType:"unknown",osVersion:"unknown",browserType:"unknown",browserVersion:"unknown",framework:"unknown"});const z=e=>{let{osType:t,osVersion:n,browserType:s,browserVersion:o}=e;return"".concat(t,"/").concat(n," ").concat(s,"/").concat(o)};class ${constructor(){r(this,"name","SystemPlugin")}onInit(){if($.hasInitd)return;$.hasInitd=!0;const e=i(),t=J.info;M.broadcastMessage(C("system",{id:e,system:{ua:z(t)},features:{}}),!1)}onReset(){$.hasInitd=!1}}function K(e){const t=typeof e;let n=e;return"string"===t||"boolean"===t||"number"===t?n=String(e):"object"===t&&(n=e instanceof Date?e.toDateString():JSON.stringify(e)),n}r($,"hasInitd",!1);class Q{constructor(){r(this,"name","StoragePlugin")}onInit(){Q.hasInitd||(Q.hasInitd=!0,Q.initStorageProxy(),Q.listenRefreshEvent())}onReset(){const e=n();Object.entries(Q.originFunctions).forEach((t=>{let[n,s]=t;Object.defineProperty(e,n,{value:s})})),Q.hasInitd=!1}static sendRefresh(){const e=n();try{const t=e.getStorageInfoSync(),n={type:"mpStorage",action:"get",data:t.keys.map((t=>({name:t,value:K(e.getStorageSync(t))})))};Q.sendStorageItem(n)}catch(e){}}static listenRefreshEvent(){M.addListener(I,(async e=>{let{source:t}=e;const{data:n}=t;"mpStorage"===n&&Q.sendRefresh()}))}static initStorageProxy(){const e=n(),{sendClearItem:t,sendRemoveItem:s,sendSetItem:o}=Q;["setStorage","setStorageSync","removeStorage","removeStorageSync","clearStorage","clearStorageSync","batchSetStorageSync","batchSetStorage"].forEach((t=>{e[t]&&(Q.originFunctions[t]=e[t])})),Object.defineProperties(e,{setStorage:{value:e=>Q.originFunctions.setStorage({...e,success(t){var n;o(e.key,e.data),null===(n=e.success)||void 0===n||n.call(e,t)}})},setStorageSync:{value(e,t){try{const n=Q.originFunctions.setStorageSync(e,t);return o(e,t),n}catch(t){throw y.error("Failed to set storage synchronously: ".concat(e)),t}}},removeStorage:{value:e=>Q.originFunctions.removeStorage({...e,success(t){var n;s(e.key),null===(n=e.success)||void 0===n||n.call(e,t)}})},removeStorageSync:{value(e){try{const t=Q.originFunctions.removeStorageSync(e);return s(t),t}catch(t){throw y.error("Failed to remove storage synchronously: ".concat(e)),t}}},clearStorage:{value:e=>Q.originFunctions.clearStorage({...e,success(n){var s;t(),null===(s=e.success)||void 0===s||s.call(e,n)}})},clearStorageSync:{value(){try{const e=Q.originFunctions.clearStorageSync();return t(),e}catch(e){throw y.error("Failed to clear storage synchronously"),e}}}}),e.canIUse("batchSetStorageSync")&&Object.defineProperty(e,"batchSetStorageSync",{value(e){try{const t=Q.originFunctions.batchSetStorageSync(e);return e.forEach((e=>{o(e.key,e.value)})),t}catch(t){throw y.error("Failed to batch set storage synchronously: ".concat(JSON.stringify(e.map((e=>e.key))))),t}}}),e.canIUse("batchSetStorage")&&Object.defineProperty(e,"batchSetStorage",{value:e=>Q.originFunctions.batchSetStorage({...e,success(t){var n;e.kvList.forEach((e=>{o(e.key,e.value)})),null===(n=e.success)||void 0===n||n.call(e,t)}})})}static sendSetItem(e,t){Q.sendStorageItem({type:"mpStorage",action:"set",name:e,value:K(t)})}static sendRemoveItem(e){Q.sendStorageItem({type:"mpStorage",action:"remove",name:e})}static sendClearItem(){Q.sendStorageItem({type:"mpStorage",action:"clear"})}static sendStorageItem(e){const t=C("storage",e);M.dispatchEvent(P,t),M.broadcastMessage(t,!0)}}r(Q,"hasInitd",!1),r(Q,"originFunctions",{});const X=e=>!1===e?["http://","ws://"]:["https://","wss://"];class Y{constructor(e){if(this.config=e,!e.get().api)throw Error("The api base url cannot be empty")}get base(){return this.config.get().api}createRoom(){const t=this.config.get(),s=X(t.enableSSL),o=J.info,r=z(o),i=e({name:encodeURIComponent(r),group:t.project,title:t.title});return(a=n().request,e=>new Promise(((t,n)=>{a({...e,success(e){t(e)},fail(e){n(e)}})})))({url:"".concat(s[0]).concat(this.base,"/api/v1/room/create?").concat(i),method:"POST"}).then((e=>e.data),(e=>{throw Error("Request create room failed: ".concat(e.message))}));var a}getRoomUrl(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const n=this.config.get(),s=X(n.enableSSL);return"".concat(s[1]).concat(this.base,"/api/v1/ws/room/join?").concat(e(t))}}class Z{defaultConfig(){return{}}constructor(){r(this,"mergeConfig",(e=>(this.value={...this.defaultConfig(),...e},this.value))),this.value=this.defaultConfig()}get(){return this.value}}class ee extends Z{constructor(){super(...arguments),r(this,"mergeConfig",(e=>(this.value={...this.defaultConfig(),...e},this.value)))}defaultConfig(){return{api:"",project:"default",title:"",enableSSL:null,disabledOnProd:!0,disabledPlugins:[],singletonSocket:!1}}get(){return this.value}}class te{static get pluginsWithOrder(){return[...te.plugins.pre,...te.plugins.normal,...te.plugins.post]}static registerPlugin(e){if(!e)return;if("function"==typeof(t=e)&&void 0!==t.prototype)return void y.error("PageSpy.registerPlugin() expect to pass an instance, not a class");var t;if(!e.name)return void y.error("The ".concat(e.constructor.name,' plugin should provide a "name" property'));if(te.pluginsWithOrder.some((t=>t.name===e.name)))return void y.error("The ".concat(e.name,' has registered. Consider the following reasons:\n - Duplicate register one same plugin;\n - Plugin\'s "name" conflict with others, you can print all registered plugins by "PageSpy.plugins";'));te.plugins[e.enforce||"normal"].push(e)}constructor(e){if(r(this,"root",null),r(this,"version","1.7.7"),r(this,"request",null),r(this,"name",""),r(this,"address",""),r(this,"roomUrl",""),r(this,"socketStore",M),r(this,"config",new ee),te.instance)return y.warn("Cannot initialize PageSpy multiple times"),te.instance;const t=this.config.mergeConfig(e);t.singletonSocket&&(L.isSingleSocket=!0);const s=n();if(s.canIUse("getAccountInfoSync")){if("release"===s.getAccountInfoSync().miniProgram.envVersion&&!1!==t.disabledOnProd)return void y.warn("PageSpy is not allowed on release env of mini program")}this.request=new Y(this.config),te.instance=this,this.triggerPlugins("onInit",{socketStore:M,config:t}),this.init()}triggerPlugins(e,t){const{disabledPlugins:n}=this.config.get();te.pluginsWithOrder.forEach((s=>{var o;u(n)&&n.length&&n.includes(s.name)||null===(o=s[e])||void 0===o||o.call(s,t)}))}async init(){const e=n(),t=this.config.get(),s=e.getStorageSync(A);if(s&&"object"==typeof s){const{name:e,address:n,roomUrl:o,usable:r,project:i,time:a}=s;!r||t.project!==i||a<Date.now()-3e4?await this.createNewConnection():(this.name=e,this.address=n,this.roomUrl=o,this.useOldConnection())}else await this.createNewConnection();e.canIUse("onAppShow")&&e.onAppShow((()=>{const e=M.getSocket().getState();e!==R.CLOSED&&e!==R.CLOSING||this.useOldConnection()})),y.log("Plugins inited")}abort(){this.triggerPlugins("onReset"),M.close(),te.instance=null}async createNewConnection(){if(!this.request)return void y.error("Cannot get the Request");const{data:e}=await this.request.createRoom(),t=this.request.getRoomUrl({address:e.address,name:"client:".concat(i()),userId:"Client"});this.name=e.name,this.address=e.address,this.roomUrl=t,this.refreshRoomInfo(),M.init(t)}useOldConnection(){this.refreshRoomInfo(),M.init(this.roomUrl)}refreshRoomInfo(){this.saveSession();const e=setInterval((()=>{const t=n().getStorageSync(A);if(t&&"object"==typeof t){const{usable:n}=t;if(!1===n)return void clearInterval(e)}this.saveSession()}),15e3);y.log("Room ID: ".concat(this.address.slice(0,4)))}saveSession(){const{name:e,address:t,roomUrl:s}=this,o={name:e,address:t,roomUrl:s,usable:!0,project:this.config.get().project,time:Date.now()};n().setStorageSync(A,o)}}r(te,"plugins",{pre:[],normal:[],post:[]}),r(te,"instance",null);var ne;[new x,new H,new B,new Q,new $].forEach((e=>{te.registerPlugin(e)})),ne=my,t=ne;const se=my.getSystemInfoSync();J.info.osType=se.platform.toLowerCase(),J.info.browserType="mp-alipay",J.info.osVersion=se.system,J.info.browserVersion=se.version,D.messageFilters.push((e=>e.data));export{te as default}; | ||
const e=e=>{const t=[];return Object.entries(e).forEach((e=>{let[n,s]=e;t.push("".concat(n,"=").concat(s))})),t.join("&")};let t;const n=()=>{if(!t)throw Error("the mp sdk is not set");return t};function s(e){return s="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},s(e)}function o(e){var t=function(e,t){if("object"!=s(e)||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var o=n.call(e,t||"default");if("object"!=s(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==s(t)?t:String(t)}function r(e,t,n){return(t=o(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function i(){return Math.random().toString(36).slice(2)}function a(e){return Object.prototype.toString.call(e)}function c(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function l(e){return"[object BigInt]"===a(e)}function u(e){return e instanceof Array}function h(e){return"object"==typeof e&&null!==e}const d=e=>"".concat(e),g=e=>({ok:!0,value:e});function p(e){return void 0===e?g(d(e)):null===e?g(e):function(e){return"number"==typeof e}(e)&&(e===-1/0||e===1/0||Number.isNaN(e))?g(d(e)):l(e)?g("".concat(e,"n")):"symbol"==typeof e||"function"==typeof e?g(d(e.toString())):e instanceof Error?g(d(e.stack)):e===Object.prototype?{value:null,ok:!1}:e instanceof Object||"object"==typeof e?{value:e,ok:!1}:g(e)}function m(e){return void 0===e?"undefined":null===e?"null":l(e)?"bigint":e instanceof Object?e instanceof Error?"error":e instanceof Function?"function":"object":typeof e}const f={...console},y=["log","info","error","warn"].reduce(((e,t)=>(e[t]=function(){for(var e=arguments.length,n=new Array(e),s=0;s<e;s++)n[s]=arguments[s];f[t]("[PageSpy] [".concat(t.toLocaleUpperCase(),"]: "),...n)},e)),{}),S="message",v="broadcast",b="ping";var T=Object.freeze({__proto__:null,BROADCAST:v,CLOSE:"close",CONNECT:"connect",ERROR:"error",JOIN:"join",LEAVE:"leave",MESSAGE:S,PING:b,PONG:"pong"});const O="console",E="debug",I="refresh",k="atom-detail",w="atom-getter",P="public-data";function C(e,t){return{role:"client",type:e,data:{...(!(arguments.length>2&&void 0!==arguments[2])||arguments[2])&&{id:i()},...t}}}class j{constructor(){r(this,"store",{}),r(this,"instanceStore",{})}getStore(){return this.store}resetStore(){this.store={}}getInstanceStore(){return this.instanceStore}resetInstanceStore(){this.instanceStore={}}transformToAtom(e){const{value:t,ok:n}=p(e);return n?{id:i(),type:m(e),value:t}:this.add(e)}get(e){const t=this.store[e],n=this.instanceStore[e];if(!t)return null;const s={},o=Object.getOwnPropertyDescriptors(t);Object.keys(o).forEach((e=>{const t=o[e];c(t,"value")&&(t.value=this.transformToAtom(t.value)),s[e]=j.getAtomOverview({atomId:i(),instanceId:n,value:t})}));const r=this.addExtraProperty(e);return{...s,...r}}getOrigin(e){const t=this.store[e];return t||null}add(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";const n=i();let s=n;var o;h(o=e)&&c(o,"constructor")&&"function"==typeof o.constructor&&(s=t),this.store[n]=e,this.instanceStore[n]=s;const r=j.getSemanticValue(e);return j.getAtomOverview({atomId:n,value:r,instanceId:s})}static getAtomOverview(e){let{instanceId:t="",atomId:n,value:s}=e;return{id:i(),type:"atom",__atomId:n,instanceId:t,value:s}}static getSemanticValue(e){if(h(t=e)&&"[object Object]"===a(t))return"Object {...}";var t;if(u(e))return"Array (".concat(e.length,")");return e.constructor.name}addExtraProperty(e){const t=this.store[e],n=this.instanceStore[e],s={};if((t instanceof String||t instanceof Number||t instanceof Boolean)&&(s["[[PrimitiveValue]]"]=this.transformToAtom(t.valueOf())),t instanceof Set){const e={};let n=0;for(const s of t)e[n++]=s;e.size=t.size,s["[[Entries]]"]=this.transformToAtom(e)}if(t instanceof Map){const e={};let n=0;for(const[s,o]of t.entries())e[n++]={key:s,value:o};e.size=t.size,s["[[Entries]]"]=this.transformToAtom(e)}var o;return(u(t)||(o=t,"function"==typeof NodeList&&"NodeList"===NodeList.name&&o instanceof NodeList||"function"==typeof HTMLCollection&&"HTMLCollection"===HTMLCollection.name&&o instanceof HTMLCollection))&&(s.length=this.transformToAtom(t.length)),null!==Object.getPrototypeOf(t)?s["[[Prototype]]"]=this.add(Object.getPrototypeOf(t),n):s.___proto___=this.transformToAtom(null),s}}var R,N=new j;!function(e){e[e.CONNECTING=0]="CONNECTING",e[e.OPEN=1]="OPEN",e[e.CLOSING=2]="CLOSING",e[e.CLOSED=3]="CLOSED"}(R||(R={}));class q{constructor(){r(this,"events",{open:[],close:[],error:[],message:[]})}emit(e,t){this.events[e].forEach((e=>{e(t)})),"close"!==e&&"error"!==e||this.clearListeners()}onOpen(e){this.events.open.push(e)}onClose(e){this.events.close.push(e)}onError(e){this.events.error.push(e)}onMessage(e){this.events.message.push(e)}clearListeners(){Object.entries(this.events).forEach((e=>{let[,t]=e;t.splice(0)}))}}class D{constructor(){r(this,"socketUrl",""),r(this,"socketConnection",null),r(this,"pingTimer",null),r(this,"pongTimer",null),r(this,"retryTimer",null),r(this,"messages",[]),r(this,"events",{[I]:[],[E]:[],[k]:[],[w]:[],"debugger-online":[],"database-pagination":[],[P]:[]}),r(this,"reconnectable",!0),r(this,"reconnectTimes",3),r(this,"connectionStatus",!1),this.addListener("debug",D.handleDebugger),this.addListener("atom-detail",D.handleResolveAtom),this.addListener("atom-getter",D.handleAtomPropertyGetter),this.addListener("debugger-online",this.handleFlushBuffer)}init(e){try{var t,n,s,o,r;if(!e)throw Error("WebSocket url cannot be empty");this.socketWrapper.getState()===R.OPEN&&this.socketWrapper.close(),null===(t=this.socketWrapper)||void 0===t||t.onOpen((()=>{this.connectOnline()})),null===(n=this.socketWrapper)||void 0===n||n.onMessage((e=>{this.handleMessage(e)})),null===(s=this.socketWrapper)||void 0===s||s.onClose((()=>{this.connectOffline()})),null===(o=this.socketWrapper)||void 0===o||o.onError((()=>{this.connectOffline()})),this.socketUrl=e,null===(r=this.socketWrapper)||void 0===r||r.init(e)}catch(e){y.error(e.message)}}addListener(e,t){this.events[e]||(this.events[e]=[]),this.events[e].push(t)}broadcastMessage(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];const n=function(e){return{type:v,content:{data:e}}}(e);this.send(n,t)}close(){var e;this.clearPing(),this.reconnectTimes=0,this.reconnectable=!1,null===(e=this.socketWrapper)||void 0===e||e.close(),this.messages=[],Object.entries(this.events).forEach((e=>{let[,t]=e;t.splice(0)}))}connectOnline(){this.connectionStatus=!0,this.reconnectTimes=3,this.ping()}connectOffline(){this.connectionStatus=!1,this.socketConnection=null,this.clearPing(),!this.reconnectable||this.reconnectTimes<=0?this.onOffline():(this.retryTimer&&clearTimeout(this.retryTimer),this.retryTimer=setTimeout((()=>{this.retryTimer=null,this.tryReconnect()}),2e3))}tryReconnect(){this.reconnectTimes-=1,this.reconnectTimes<=0&&(this.reconnectable=!1),this.init(this.socketUrl)}ping(){this.pingTimer&&clearTimeout(this.pingTimer),this.pongTimer&&clearTimeout(this.pongTimer),this.pingTimer=setTimeout((()=>{this.send({type:"ping",content:null}),this.pingTimer=null,this.pongTimer=setTimeout((()=>{this.connectOffline(),this.pongTimer=null}),5e3)}),5e3)}clearPing(){this.pingTimer&&(clearTimeout(this.pingTimer),this.pingTimer=null),this.pongTimer&&(clearTimeout(this.pongTimer),this.pongTimer=null)}handlePong(){clearTimeout(this.pongTimer),this.pongTimer=null,this.ping()}handleMessage(e){var t;D.messageFilters.length&&D.messageFilters.forEach((t=>{e=t(e)}));const{CONNECT:n,MESSAGE:s,ERROR:o,JOIN:r,PING:i,PONG:a,LEAVE:c,CLOSE:l,BROADCAST:u}=T,h=JSON.parse(e.data),{type:d}=h;switch(d){case n:const{selfConnection:e}=h.content;this.socketConnection=e;break;case s:const{data:r,from:i,to:a}=h.content;a.address===(null===(t=this.socketConnection)||void 0===t?void 0:t.address)&&this.dispatchEvent(r.type,{source:r,from:i,to:a});break;case o:this.reconnectable=!1,this.connectOffline()}this.handlePong()}dispatchEvent(e,t){[P].includes(e)?this.events[e].forEach((e=>{e(t)})):this.events[e].forEach((e=>{e.call(this,t,(e=>{this.unicastMessage(e,t.from)}))}))}unicastMessage(e,t){const n=function(e,t,n){return{type:S,content:{data:e,from:t,to:n}}}(e,this.socketConnection,t);this.send(n)}handleFlushBuffer(e){const{latestId:t}=e.source.data,n=this.messages.findIndex((e=>e.content.data.data.id===t));this.messages.slice(n+1).forEach((t=>{const n={type:S,content:{data:t.content.data,from:this.socketConnection,to:e.from}};this.send(n,!0)}))}static handleDebugger(e,t){let{source:n}=e;const{type:s,data:o}=n;if(s===E){t(C(O,{logType:"debug-origin",logs:[{id:i(),type:"debug-origin",value:o}]}));try{const e=new Function("return ".concat(o))();t(C(O,{logType:"debug-eval",logs:[N.transformToAtom(e)]}))}catch(e){t(C(O,{logType:"error",logs:[{type:"error",value:e.stack}]}))}}}static handleResolveAtom(e,t){let{source:n}=e;const{type:s,data:o}=n;if(s===k){const e=N.get(o)||{};t(C("atom-detail-".concat(o),e,!1))}}static handleAtomPropertyGetter(e,t){let{source:n}=e;const{type:s,data:o}=n;if(s===w){const{id:e,parentId:n,key:s,instanceId:i}=o,a=N.getOrigin(i),c=N.getOrigin(n);let l={};var r;if(a&&c)l=null===(r=Object.getOwnPropertyDescriptor(c,s))||void 0===r||null===(r=r.get)||void 0===r?void 0:r.call(a);else l=new Error("Getter computed failed");t(C("atom-getter-".concat(e),N.transformToAtom(l)))}}send(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(this.connectionStatus)try{var n;const t=e;t.createdAt=Date.now(),t.requestId=i();const s=function(e){const{ok:t,value:n}=p(e);return t?n:JSON.stringify(e,((e,t)=>p(t).value),2)}(t);null===(n=this.socketWrapper)||void 0===n||n.send(s)}catch(e){throw Error("Incompatible: ".concat(e.message))}if(!t){if([S,b].indexOf(e.type)>-1)return;this.messages.push(e)}}}r(D,"messageFilters",[]);const A="page-spy-room";class L extends q{constructor(){super(...arguments),r(this,"socketInstance",null),r(this,"state",0)}init(e){this.state=R.CONNECTING;const t=n(),s=e=>{this.state=R.CLOSED,this.emit("close",e)},o=e=>{this.state=R.OPEN,this.emit("open",e)},r=e=>{this.state=R.CLOSED,this.emit("error",e)},i=e=>{this.emit("message",e)};L.isSingleSocket?(t.connectSocket({url:e}),t.onSocketClose(s),t.onSocketError(r),t.onSocketMessage(i),t.onSocketOpen(o)):(this.socketInstance=t.connectSocket({url:e,multiple:!0,complete(){}}),this.socketInstance.onClose(s),this.socketInstance.onError(r),this.socketInstance.onOpen(o),this.socketInstance.onMessage(i))}send(e){var t;L.isSingleSocket?n().sendSocketMessage({data:e}):null===(t=this.socketInstance)||void 0===t||t.send({data:e})}close(){var e;L.isSingleSocket?n().closeSocket({}):null===(e=this.socketInstance)||void 0===e||e.close({});this.state=R.CLOSED,this.clearListeners()}getState(){return this.state}}r(L,"isSingleSocket",!1);var U,M=new class extends D{constructor(){super(...arguments),r(this,"socketWrapper",new L)}getSocket(){return this.socketWrapper}onOffline(){n().setStorageSync(A,JSON.stringify({usable:!1}))}};class x{constructor(){r(this,"name","ConsolePlugin"),r(this,"console",{}),r(this,"proxyTypes",["log","info","error","warn","debug"])}async onInit(){if(x.hasInitd)return;x.hasInitd=!0;const t=this;this.proxyTypes.forEach((n=>{this.console[n]=console[n]||console.log||(()=>{}),Object.defineProperty(console,n,{value(){const s=getCurrentPages().pop();let o="/";s&&(o=s.route,s.options&&Object.keys(s.options).length>0&&(o+="?"+e(s.options)));for(var r=arguments.length,i=new Array(r),a=0;a<r;a++)i[a]=arguments[a];t.printLog({logType:n,logs:i,url:o})},configurable:!0,enumerable:!0,writable:!0})}))}onReset(){this.proxyTypes.forEach((e=>{console[e]=this.console[e]})),x.hasInitd=!1}printLog(e){if(e.logs&&e.logs.length){this.console[e.logType](...e.logs),e.logs=e.logs.map((e=>N.transformToAtom(e)));const t=C(O,{time:Date.now(),...e});M.dispatchEvent(P,t),M.broadcastMessage(t)}}}r(x,"hasInitd",!1);class H{constructor(){r(this,"name","ErrorPlugin")}onInit(){H.hasInitd||(H.hasInitd=!0,this.onUncaughtError(),this.onUnhandledRejectionError())}onReset(){const e=n();e.canIUse("offError")&&e.offError(this.errorHandler),e.canIUse("offUnHandledRejection")&&e.offUnHandledRejection(this.unhandledRejectionHandler),H.hasInitd=!1}errorHandler(e){if(H.hasInitd)if(e.stack||e.message){const{message:t,stack:n}=e;H.sendMessage(n||t,{name:"uncaught error",...e})}else{const e="[PageSpy] An unknown error occurred and no message or stack trace available";H.sendMessage(e,null)}}unhandledRejectionHandler(e){H.hasInitd&&H.sendMessage("UnHandled Rejection",{name:"unhandledrejection",message:e.reason})}onUncaughtError(){const e=n();e.canIUse("onError")&&e.onError(this.errorHandler)}onUnhandledRejectionError(){const e=n();e.canIUse("onUnHandledRejection")&&e.onUnHandledRejection(this.unhandledRejectionHandler)}static sendMessage(e,t){const n={logType:"error",logs:[N.transformToAtom(e)],time:Date.now(),url:"wx:light-app",errorDetail:t},s=C(O,n);M.dispatchEvent(P,s),M.broadcastMessage(s)}}function F(e,t){try{let n,s;if("object"==typeof window&&"object"==typeof document&&"[object HTMLDocument]"===Object.prototype.toString.call(document)){const{searchParams:o,href:r}=new URL(e,t);n=r,s=[...o.entries()]}else n=e.toString(),s=function(e){const t=/[?&]([^=#]+)=([^&#]*)/g,n=[];let s;for(;null!==(s=t.exec(e));){const e=decodeURIComponent(s[1]),t=decodeURIComponent(s[2]);n.push([e,t])}return n}(n);const o=n.replace(/^.*?([^/]+)(\/)*(\?.*?)?$/,"$1$2$3")||"";return{url:n,name:o,query:s}}catch(e){return{url:"Unknown",name:"Unknown",query:null}}}r(H,"hasInitd",!1),function(e){e[e.UNSENT=0]="UNSENT",e[e.OPENED=1]="OPENED",e[e.HEADERS_RECEIVED=2]="HEADERS_RECEIVED",e[e.LOADING=3]="LOADING",e[e.DONE=4]="DONE"}(U||(U={}));class G{constructor(e){r(this,"id",""),r(this,"name",""),r(this,"method",""),r(this,"url",""),r(this,"requestType","xhr"),r(this,"requestHeader",null),r(this,"status",0),r(this,"statusText",""),r(this,"readyState",0),r(this,"responseReason",null),r(this,"responseType",""),r(this,"responseHeader",null),r(this,"startTime",0),r(this,"endTime",0),r(this,"costTime",0),r(this,"getData",null),r(this,"postData",null),r(this,"requestPayload",null),r(this,"withCredentials",!1),this.id=e}}class V{constructor(e){r(this,"reqMap",Object.create(null)),this.socketStore=e}getRequestMap(){return this.reqMap}getRequest(e){return this.reqMap[e]}createRequest(e){return e?this.reqMap[e]?(y.warn("The request object has been in store, disallow duplicate create"),!1):(this.reqMap[e]=new G(e),!0):(y.error('The "id" is required when init request object'),!1)}setRequest(e,t){return!(!e||!t)&&(this.reqMap[e]=t,!0)}sendRequestItem(e,t){this.reqMap[e]||(this.reqMap[e]=t);const n=C("network",{...t},!1);Number(t.readyState)===U.DONE&&this.socketStore.dispatchEvent(P,n),this.socketStore.broadcastMessage(n,t.readyState!==U.DONE),this.deferDeleteRequest(e)}deferDeleteRequest(e){const t=this.getRequest(e);t&&t.readyState===U.DONE&&setTimeout((()=>{delete this.reqMap[e]}),3e3)}}class W extends V{constructor(){super(M)}}class _ extends W{constructor(){super(),r(this,"request",null),this.initProxyHandler()}reset(){if(this.request){const e=n();Object.defineProperty(e,"request",{value:this.request})}}initProxyHandler(){const e=this,t=n(),s=t.request;s&&(this.request=s,Object.defineProperty(t,"request",{value(t){const n=i();e.createRequest(n);const o=e.getRequest(n);if(o){const r=t.method||"GET",{url:i}=t,c=t.header||null,l=F(i);if(o.url=l.url,o.name=l.name,o.getData=l.query,o.method=r.toUpperCase(),o.requestType="mp-request",o.status=0,o.statusText="Pending",o.startTime=Date.now(),o.readyState=U.UNSENT,h(c)?o.requestHeader=Object.entries(c):o.requestHeader=c,"GET"!==o.method){o.requestHeader=[["Content-Type","application/json"]];const{data:e}=t;if(e)if("string"==typeof e)o.requestPayload=e;else if(e instanceof ArrayBuffer)o.requestPayload="[object ArrayBuffer]";else try{o.requestPayload=JSON.stringify(e)}catch(t){o.requestPayload=a(e)}}e.sendRequestItem(n,o);const u=t.success,d=t.fail,g=t.complete,p=()=>{o.endTime=Date.now(),o.costTime=o.endTime-(o.startTime||o.endTime)};t.success=function(t){if(p(),o.status=(null==t?void 0:t.statusCode)||200,o.statusText="Done",o.responseHeader=[...Object.entries((null==t?void 0:t.header)||{})],o.readyState=U.HEADERS_RECEIVED,e.sendRequestItem(n,o),(s=t.statusCode)>=200&&s<400){const e=function(e){const t=Object.keys(e),n={};for(let s=0;s<t.length;s++){const o=t[s];n[o.toLowerCase()]=e[o]}return n}((null==t?void 0:t.header)||{})["content-type"];switch(e&&(e.includes("application/json")&&(o.responseType="json"),(e.includes("text/html")||e.includes("text/plain"))&&(o.responseType="text")),o.responseType||(o.responseType="arraybuffer"),o.responseType){case"json":case"text":if("string"==typeof(null==t?void 0:t.data))try{o.response=JSON.parse(t.data)}catch(e){o.response=t.data,o.responseType="text"}else o.response=null==t?void 0:t.data;break;case"arraybuffer":o.response="[object ArrayBuffer]"}}var s;null==u||u(t)},t.fail=function(e){p(),null==d||d(e)},t.complete=function(t){o.readyState=U.DONE,e.sendRequestItem(n,o),null==g||g(t)};return s(t)}return y.warn("The request object is not found on request event"),null}}))}}class B{constructor(){r(this,"name","NetworkPlugin"),r(this,"requestProxy",null)}onInit(){B.hasInitd||(B.hasInitd=!0,this.requestProxy=new _)}onReset(){var e;null===(e=this.requestProxy)||void 0===e||e.reset(),B.hasInitd=!1}}r(B,"hasInitd",!1);class J{}r(J,"info",{osType:"unknown",osVersion:"unknown",browserType:"unknown",browserVersion:"unknown",framework:"unknown"});const z=e=>{let{osType:t,osVersion:n,browserType:s,browserVersion:o}=e;return"".concat(t,"/").concat(n," ").concat(s,"/").concat(o)};class ${constructor(){r(this,"name","SystemPlugin")}onInit(){if($.hasInitd)return;$.hasInitd=!0;const e=i(),t=J.info;M.broadcastMessage(C("system",{id:e,system:{ua:z(t)},features:{}}),!1)}onReset(){$.hasInitd=!1}}function K(e){const t=typeof e;let n=e;return"string"===t||"boolean"===t||"number"===t?n=String(e):"object"===t&&(n=e instanceof Date?e.toDateString():JSON.stringify(e)),n}r($,"hasInitd",!1);class Q{constructor(){r(this,"name","StoragePlugin")}onInit(){Q.hasInitd||(Q.hasInitd=!0,Q.initStorageProxy(),Q.listenRefreshEvent())}onReset(){const e=n();Object.entries(Q.originFunctions).forEach((t=>{let[n,s]=t;Object.defineProperty(e,n,{value:s})})),Q.hasInitd=!1}static sendRefresh(){const e=n();try{const t=e.getStorageInfoSync(),n={type:"mpStorage",action:"get",data:t.keys.map((t=>({name:t,value:K(e.getStorageSync(t))})))};Q.sendStorageItem(n)}catch(e){}}static listenRefreshEvent(){M.addListener(I,(async e=>{let{source:t}=e;const{data:n}=t;"mpStorage"===n&&Q.sendRefresh()}))}static initStorageProxy(){const e=n(),{sendClearItem:t,sendRemoveItem:s,sendSetItem:o}=Q;["setStorage","setStorageSync","removeStorage","removeStorageSync","clearStorage","clearStorageSync","batchSetStorageSync","batchSetStorage"].forEach((t=>{e[t]&&(Q.originFunctions[t]=e[t])})),Object.defineProperties(e,{setStorage:{value:e=>Q.originFunctions.setStorage({...e,success(t){var n;o(e.key,e.data),null===(n=e.success)||void 0===n||n.call(e,t)}})},setStorageSync:{value(e,t){try{const n=Q.originFunctions.setStorageSync(e,t);return o(e,t),n}catch(t){throw y.error("Failed to set storage synchronously: ".concat(e)),t}}},removeStorage:{value:e=>Q.originFunctions.removeStorage({...e,success(t){var n;s(e.key),null===(n=e.success)||void 0===n||n.call(e,t)}})},removeStorageSync:{value(e){try{const t=Q.originFunctions.removeStorageSync(e);return s(t),t}catch(t){throw y.error("Failed to remove storage synchronously: ".concat(e)),t}}},clearStorage:{value:e=>Q.originFunctions.clearStorage({...e,success(n){var s;t(),null===(s=e.success)||void 0===s||s.call(e,n)}})},clearStorageSync:{value(){try{const e=Q.originFunctions.clearStorageSync();return t(),e}catch(e){throw y.error("Failed to clear storage synchronously"),e}}}}),e.canIUse("batchSetStorageSync")&&Object.defineProperty(e,"batchSetStorageSync",{value(e){try{const t=Q.originFunctions.batchSetStorageSync(e);return e.forEach((e=>{o(e.key,e.value)})),t}catch(t){throw y.error("Failed to batch set storage synchronously: ".concat(JSON.stringify(e.map((e=>e.key))))),t}}}),e.canIUse("batchSetStorage")&&Object.defineProperty(e,"batchSetStorage",{value:e=>Q.originFunctions.batchSetStorage({...e,success(t){var n;e.kvList.forEach((e=>{o(e.key,e.value)})),null===(n=e.success)||void 0===n||n.call(e,t)}})})}static sendSetItem(e,t){Q.sendStorageItem({type:"mpStorage",action:"set",name:e,value:K(t)})}static sendRemoveItem(e){Q.sendStorageItem({type:"mpStorage",action:"remove",name:e})}static sendClearItem(){Q.sendStorageItem({type:"mpStorage",action:"clear"})}static sendStorageItem(e){const t=C("storage",e);M.dispatchEvent(P,t),M.broadcastMessage(t,!0)}}r(Q,"hasInitd",!1),r(Q,"originFunctions",{});const X=e=>!1===e?["http://","ws://"]:["https://","wss://"];class Y{constructor(e){if(this.config=e,!e.get().api)throw Error("The api base url cannot be empty")}get base(){return this.config.get().api}createRoom(){const t=this.config.get(),s=X(t.enableSSL),o=J.info,r=z(o),i=e({name:encodeURIComponent(r),group:t.project,title:t.title});return(a=n().request,e=>new Promise(((t,n)=>{a({...e,success(e){t(e)},fail(e){n(e)}})})))({url:"".concat(s[0]).concat(this.base,"/api/v1/room/create?").concat(i),method:"POST"}).then((e=>e.data),(e=>{throw Error("Request create room failed: ".concat(e.message))}));var a}getRoomUrl(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const n=this.config.get(),s=X(n.enableSSL);return"".concat(s[1]).concat(this.base,"/api/v1/ws/room/join?").concat(e(t))}}class Z{defaultConfig(){return{}}constructor(){r(this,"mergeConfig",(e=>(this.value={...this.defaultConfig(),...e},this.value))),this.value=this.defaultConfig()}get(){return this.value}}class ee extends Z{constructor(){super(...arguments),r(this,"mergeConfig",(e=>(this.value={...this.defaultConfig(),...e},this.value)))}defaultConfig(){return{api:"",project:"default",title:"",enableSSL:null,disabledOnProd:!0,disabledPlugins:[],singletonSocket:!1}}get(){return this.value}}class te{static get pluginsWithOrder(){return[...te.plugins.pre,...te.plugins.normal,...te.plugins.post]}static registerPlugin(e){if(!e)return;if("function"==typeof(t=e)&&void 0!==t.prototype)return void y.error("PageSpy.registerPlugin() expect to pass an instance, not a class");var t;if(!e.name)return void y.error("The ".concat(e.constructor.name,' plugin should provide a "name" property'));if(te.pluginsWithOrder.some((t=>t.name===e.name)))return void y.error("The ".concat(e.name,' has registered. Consider the following reasons:\n - Duplicate register one same plugin;\n - Plugin\'s "name" conflict with others, you can print all registered plugins by "PageSpy.plugins";'));te.plugins[e.enforce||"normal"].push(e)}constructor(e){if(r(this,"root",null),r(this,"version","1.7.8"),r(this,"request",null),r(this,"name",""),r(this,"address",""),r(this,"roomUrl",""),r(this,"socketStore",M),r(this,"config",new ee),te.instance)return y.warn("Cannot initialize PageSpy multiple times"),te.instance;const t=this.config.mergeConfig(e);t.singletonSocket&&(L.isSingleSocket=!0);const s=n();if(s.canIUse("getAccountInfoSync")){if("release"===s.getAccountInfoSync().miniProgram.envVersion&&!1!==t.disabledOnProd)return void y.warn("PageSpy is not allowed on release env of mini program")}this.request=new Y(this.config),te.instance=this,this.triggerPlugins("onInit",{socketStore:M,config:t}),this.init()}triggerPlugins(e,t){const{disabledPlugins:n}=this.config.get();te.pluginsWithOrder.forEach((s=>{var o;u(n)&&n.length&&n.includes(s.name)||null===(o=s[e])||void 0===o||o.call(s,t)}))}async init(){const e=n(),t=this.config.get(),s=e.getStorageSync(A);if(s&&"object"==typeof s){const{name:e,address:n,roomUrl:o,usable:r,project:i,time:a}=s;!r||t.project!==i||a<Date.now()-3e4?await this.createNewConnection():(this.name=e,this.address=n,this.roomUrl=o,this.useOldConnection())}else await this.createNewConnection();e.canIUse("onAppShow")&&e.onAppShow((()=>{const e=M.getSocket().getState();e!==R.CLOSED&&e!==R.CLOSING||this.useOldConnection()})),y.log("Plugins inited")}abort(){this.triggerPlugins("onReset"),M.close(),te.instance=null}async createNewConnection(){if(!this.request)return void y.error("Cannot get the Request");const{data:e}=await this.request.createRoom(),t=this.request.getRoomUrl({address:e.address,name:"client:".concat(i()),userId:"Client"});this.name=e.name,this.address=e.address,this.roomUrl=t,this.refreshRoomInfo(),M.init(t)}useOldConnection(){this.refreshRoomInfo(),M.init(this.roomUrl)}refreshRoomInfo(){this.saveSession();const e=setInterval((()=>{const t=n().getStorageSync(A);if(t&&"object"==typeof t){const{usable:n}=t;if(!1===n)return void clearInterval(e)}this.saveSession()}),15e3);y.log("Room ID: ".concat(this.address.slice(0,4)))}saveSession(){const{name:e,address:t,roomUrl:s}=this,o={name:e,address:t,roomUrl:s,usable:!0,project:this.config.get().project,time:Date.now()};n().setStorageSync(A,o)}}r(te,"plugins",{pre:[],normal:[],post:[]}),r(te,"instance",null);var ne;[new x,new H,new B,new Q,new $].forEach((e=>{te.registerPlugin(e)})),ne={...my,getStorageSync(e){const t=my.getStorageSync({key:e});if(t.success)return t.data},setStorageSync:(e,t)=>my.setStorageSync({key:e,data:t}),removeStorageSync:e=>my.removeStorageSync({key:e})},t=ne;const se=my.getSystemInfoSync();J.info.osType=se.platform.toLowerCase(),J.info.browserType="mp-alipay",J.info.osVersion=se.system,J.info.browserVersion=se.version,D.messageFilters.push((e=>e.data));export{te as default}; | ||
//# sourceMappingURL=index.min.js.map |
{ | ||
"name": "@huolala-tech/page-spy-alipay", | ||
"version": "1.7.7", | ||
"version": "1.7.8", | ||
"description": "A developer tool for debugging alipay miniprogram", | ||
@@ -73,3 +73,3 @@ "license": "MIT", | ||
}, | ||
"gitHead": "be7b1a410ae2a17820959a1f9cb377d23616e499" | ||
"gitHead": "dae5b1f5658e3c01254a9565f705a91bab5cedf2" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
62720
211
1