@huolala-tech/page-spy-alipay
Advanced tools
Comparing version 1.7.8 to 1.7.9
@@ -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",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; | ||
"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},s={setStorage(e,n){var s;return null===(s=t)||void 0===s?void 0:s.setStorageSync(e,n)},getStorage(e){var n;return null===(n=t)||void 0===n?void 0:n.getStorageSync(e)},removeStorage(e){var n;return null===(n=t)||void 0===n?void 0:n.getStorageSync(e)}};function o(e){return o="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},o(e)}function r(e){var t=function(e,t){if("object"!=o(e)||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var s=n.call(e,t||"default");if("object"!=o(s))return s;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==o(t)?t:String(t)}function i(e,t,n){return(t=r(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function a(){return Math.random().toString(36).slice(2)}function c(e){return Object.prototype.toString.call(e)}function l(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function u(e){return"[object BigInt]"===c(e)}function h(e){return e instanceof Array}function d(e){return"object"==typeof e&&null!==e}const g=e=>"".concat(e),p=e=>({ok:!0,value:e});function m(e){return void 0===e?p(g(e)):null===e?p(e):function(e){return"number"==typeof e}(e)&&(e===-1/0||e===1/0||Number.isNaN(e))?p(g(e)):u(e)?p("".concat(e,"n")):"symbol"==typeof e||"function"==typeof e?p(g(e.toString())):e instanceof Error?p(g(e.stack)):e===Object.prototype?{value:null,ok:!1}:e instanceof Object||"object"==typeof e?{value:e,ok:!1}:p(e)}function f(e){return void 0===e?"undefined":null===e?"null":u(e)?"bigint":e instanceof Object?e instanceof Error?"error":e instanceof Function?"function":"object":typeof e}const y={...console},S=["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];y[t]("[PageSpy] [".concat(t.toLocaleUpperCase(),"]: "),...n)},e)),{}),v="message",b="broadcast",T="ping";var O=Object.freeze({__proto__:null,BROADCAST:b,CLOSE:"close",CONNECT:"connect",ERROR:"error",JOIN:"join",LEAVE:"leave",MESSAGE:v,PING:T,PONG:"pong"});const E="console",I="debug",k="refresh",w="atom-detail",P="atom-getter",C="public-data";function j(e,t){return{role:"client",type:e,data:{...(!(arguments.length>2&&void 0!==arguments[2])||arguments[2])&&{id:a()},...t}}}class R{constructor(){i(this,"store",{}),i(this,"instanceStore",{})}getStore(){return this.store}resetStore(){this.store={}}getInstanceStore(){return this.instanceStore}resetInstanceStore(){this.instanceStore={}}transformToAtom(e){const{value:t,ok:n}=m(e);return n?{id:a(),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];l(t,"value")&&(t.value=this.transformToAtom(t.value)),s[e]=R.getAtomOverview({atomId:a(),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=a();let s=n;var o;d(o=e)&&l(o,"constructor")&&"function"==typeof o.constructor&&(s=t),this.store[n]=e,this.instanceStore[n]=s;const r=R.getSemanticValue(e);return R.getAtomOverview({atomId:n,value:r,instanceId:s})}static getAtomOverview(e){let{instanceId:t="",atomId:n,value:s}=e;return{id:a(),type:"atom",__atomId:n,instanceId:t,value:s}}static getSemanticValue(e){if(d(t=e)&&"[object Object]"===c(t))return"Object {...}";var t;if(h(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(h(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 N,q=new R;!function(e){e[e.CONNECTING=0]="CONNECTING",e[e.OPEN=1]="OPEN",e[e.CLOSING=2]="CLOSING",e[e.CLOSED=3]="CLOSED"}(N||(N={}));class D{constructor(){i(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 A{constructor(){i(this,"socketUrl",""),i(this,"socketConnection",null),i(this,"pingTimer",null),i(this,"pongTimer",null),i(this,"retryTimer",null),i(this,"messages",[]),i(this,"events",{[k]:[],[I]:[],[w]:[],[P]:[],"debugger-online":[],"database-pagination":[],[C]:[]}),i(this,"reconnectable",!0),i(this,"reconnectTimes",3),i(this,"connectionStatus",!1),this.addListener("debug",A.handleDebugger),this.addListener("atom-detail",A.handleResolveAtom),this.addListener("atom-getter",A.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()===N.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){S.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:b,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;A.messageFilters.length&&A.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}=O,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){[C].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:v,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:v,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===I){t(j(E,{logType:"debug-origin",logs:[{id:a(),type:"debug-origin",value:o}]}));try{const e=new Function("return ".concat(o))();t(j(E,{logType:"debug-eval",logs:[q.transformToAtom(e)]}))}catch(e){t(j(E,{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=q.get(o)||{};t(j("atom-detail-".concat(o),e,!1))}}static handleAtomPropertyGetter(e,t){let{source:n}=e;const{type:s,data:o}=n;if(s===P){const{id:e,parentId:n,key:s,instanceId:i}=o,a=q.getOrigin(i),c=q.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(j("atom-getter-".concat(e),q.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=a();const s=function(e){const{ok:t,value:n}=m(e);return t?n:JSON.stringify(e,((e,t)=>m(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([v,T].indexOf(e.type)>-1)return;this.messages.push(e)}}}i(A,"messageFilters",[]);const L="page-spy-room";class U extends D{constructor(){super(...arguments),i(this,"socketInstance",null),i(this,"state",0)}init(e){this.state=N.CONNECTING;const t=n(),s=e=>{this.state=N.CLOSED,this.emit("close",e)},o=e=>{this.state=N.OPEN,this.emit("open",e)},r=e=>{this.state=N.CLOSED,this.emit("error",e)},i=e=>{this.emit("message",e)};U.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;U.isSingleSocket?n().sendSocketMessage({data:e}):null===(t=this.socketInstance)||void 0===t||t.send({data:e})}close(){var e;U.isSingleSocket?n().closeSocket({}):null===(e=this.socketInstance)||void 0===e||e.close({});this.state=N.CLOSED,this.clearListeners()}getState(){return this.state}}i(U,"isSingleSocket",!1);var M,x=new class extends A{constructor(){super(...arguments),i(this,"socketWrapper",new U)}getSocket(){return this.socketWrapper}onOffline(){s.setStorage(L,JSON.stringify({usable:!1}))}};class H{constructor(){i(this,"name","ConsolePlugin"),i(this,"console",{}),i(this,"proxyTypes",["log","info","error","warn","debug"])}async onInit(){if(H.hasInitd)return;H.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]})),H.hasInitd=!1}printLog(e){if(e.logs&&e.logs.length){this.console[e.logType](...e.logs),e.logs=e.logs.map((e=>q.transformToAtom(e)));const t=j(E,{time:Date.now(),...e});x.dispatchEvent(C,t),x.broadcastMessage(t)}}}i(H,"hasInitd",!1);class F{constructor(){i(this,"name","ErrorPlugin")}onInit(){F.hasInitd||(F.hasInitd=!0,this.onUncaughtError(),this.onUnhandledRejectionError())}onReset(){const e=n();e.canIUse("offError")&&e.offError(this.errorHandler),e.canIUse("offUnHandledRejection")&&e.offUnHandledRejection(this.unhandledRejectionHandler),F.hasInitd=!1}errorHandler(e){if(F.hasInitd)if(e.stack||e.message){const{message:t,stack:n}=e;F.sendMessage(n||t,{name:"uncaught error",...e})}else{const e="[PageSpy] An unknown error occurred and no message or stack trace available";F.sendMessage(e,null)}}unhandledRejectionHandler(e){F.hasInitd&&F.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:[q.transformToAtom(e)],time:Date.now(),url:"wx:light-app",errorDetail:t},s=j(E,n);x.dispatchEvent(C,s),x.broadcastMessage(s)}}function G(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}}}i(F,"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"}(M||(M={}));class V{constructor(e){i(this,"id",""),i(this,"name",""),i(this,"method",""),i(this,"url",""),i(this,"requestType","xhr"),i(this,"requestHeader",null),i(this,"status",0),i(this,"statusText",""),i(this,"readyState",0),i(this,"responseReason",null),i(this,"responseType",""),i(this,"responseHeader",null),i(this,"startTime",0),i(this,"endTime",0),i(this,"costTime",0),i(this,"getData",null),i(this,"postData",null),i(this,"requestPayload",null),i(this,"withCredentials",!1),this.id=e}}class W{constructor(e){i(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]?(S.warn("The request object has been in store, disallow duplicate create"),!1):(this.reqMap[e]=new V(e),!0):(S.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=j("network",{...t},!1);Number(t.readyState)===M.DONE&&this.socketStore.dispatchEvent(C,n),this.socketStore.broadcastMessage(n,t.readyState!==M.DONE),this.deferDeleteRequest(e)}deferDeleteRequest(e){const t=this.getRequest(e);t&&t.readyState===M.DONE&&setTimeout((()=>{delete this.reqMap[e]}),3e3)}}class _ extends W{constructor(){super(x)}}class B extends _{constructor(){super(),i(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=a();e.createRequest(n);const o=e.getRequest(n);if(o){const r=t.method||"GET",{url:i}=t,a=t.header||null,l=G(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=M.UNSENT,d(a)?o.requestHeader=Object.entries(a):o.requestHeader=a,"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=c(e)}}e.sendRequestItem(n,o);const u=t.success,h=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=M.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==h||h(e)},t.complete=function(t){o.readyState=M.DONE,e.sendRequestItem(n,o),null==g||g(t)};return s(t)}return S.warn("The request object is not found on request event"),null}}))}}class J{constructor(){i(this,"name","NetworkPlugin"),i(this,"requestProxy",null)}onInit(){J.hasInitd||(J.hasInitd=!0,this.requestProxy=new B)}onReset(){var e;null===(e=this.requestProxy)||void 0===e||e.reset(),J.hasInitd=!1}}i(J,"hasInitd",!1);class z{}i(z,"info",{osType:"unknown",osVersion:"unknown",browserType:"unknown",browserVersion:"unknown",framework:"unknown"});const $=e=>{let{osType:t,osVersion:n,browserType:s,browserVersion:o}=e;return"".concat(t,"/").concat(n," ").concat(s,"/").concat(o)};class K{constructor(){i(this,"name","SystemPlugin")}onInit(){if(K.hasInitd)return;K.hasInitd=!0;const e=a(),t=z.info;x.broadcastMessage(j("system",{id:e,system:{ua:$(t)},features:{}}),!1)}onReset(){K.hasInitd=!1}}function Q(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}i(K,"hasInitd",!1);class X{constructor(){i(this,"name","StoragePlugin")}onInit(){X.hasInitd||(X.hasInitd=!0,X.initStorageProxy(),X.listenRefreshEvent())}onReset(){const e=n();Object.entries(X.originFunctions).forEach((t=>{let[n,s]=t;Object.defineProperty(e,n,{value:s})})),X.hasInitd=!1}static sendRefresh(){const e=n();try{const t=e.getStorageInfoSync(),n={type:"mpStorage",action:"get",data:t.keys.map((e=>({name:e,value:Q(s.getStorage(e))})))};X.sendStorageItem(n)}catch(e){}}static listenRefreshEvent(){x.addListener(k,(async e=>{let{source:t}=e;const{data:n}=t;"mpStorage"===n&&X.sendRefresh()}))}static initStorageProxy(){const e=n(),{sendClearItem:t,sendRemoveItem:s,sendSetItem:o}=X;["setStorage","setStorageSync","removeStorage","removeStorageSync","clearStorage","clearStorageSync","batchSetStorageSync","batchSetStorage"].forEach((t=>{e[t]&&(X.originFunctions[t]=e[t])})),Object.defineProperties(e,{setStorage:{value:e=>X.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{let n;if("mp-alipay"!==z.info.browserType||z.info.framework){const s=e;n=X.originFunctions.setStorageSync(s,t),o(s,t)}else{const t=e;n=X.originFunctions.setStorageSync(t),o(t.key,t.data)}return n}catch(t){throw S.error("Failed to set storage synchronously: ".concat(e)),t}}},removeStorage:{value:e=>X.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=X.originFunctions.removeStorageSync(e);return s(t),t}catch(t){throw S.error("Failed to remove storage synchronously: ".concat(e)),t}}},clearStorage:{value:e=>X.originFunctions.clearStorage({...e,success(n){var s;t(),null===(s=e.success)||void 0===s||s.call(e,n)}})},clearStorageSync:{value(){try{const e=X.originFunctions.clearStorageSync();return t(),e}catch(e){throw S.error("Failed to clear storage synchronously"),e}}}}),e.canIUse("batchSetStorageSync")&&Object.defineProperty(e,"batchSetStorageSync",{value(e){try{const t=X.originFunctions.batchSetStorageSync(e);return e.forEach((e=>{o(e.key,e.value)})),t}catch(t){throw S.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=>X.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){X.sendStorageItem({type:"mpStorage",action:"set",name:e,value:Q(t)})}static sendRemoveItem(e){X.sendStorageItem({type:"mpStorage",action:"remove",name:e})}static sendClearItem(){X.sendStorageItem({type:"mpStorage",action:"clear"})}static sendStorageItem(e){const t=j("storage",e);x.dispatchEvent(C,t),x.broadcastMessage(t,!0)}}i(X,"hasInitd",!1),i(X,"originFunctions",{});const Y=e=>!1===e?["http://","ws://"]:["https://","wss://"];class Z{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=Y(t.enableSSL),o=z.info,r=$(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=Y(n.enableSSL);return"".concat(s[1]).concat(this.base,"/api/v1/ws/room/join?").concat(e(t))}}class ee{defaultConfig(){return{}}constructor(){i(this,"mergeConfig",(e=>(this.value={...this.defaultConfig(),...e},this.value))),this.value=this.defaultConfig()}get(){return this.value}}class te extends ee{constructor(){super(...arguments),i(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 ne{static get pluginsWithOrder(){return[...ne.plugins.pre,...ne.plugins.normal,...ne.plugins.post]}static registerPlugin(e){if(!e)return;if("function"==typeof(t=e)&&void 0!==t.prototype)return void S.error("PageSpy.registerPlugin() expect to pass an instance, not a class");var t;if(!e.name)return void S.error("The ".concat(e.constructor.name,' plugin should provide a "name" property'));if(ne.pluginsWithOrder.some((t=>t.name===e.name)))return void S.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";'));ne.plugins[e.enforce||"normal"].push(e)}constructor(e){if(i(this,"root",null),i(this,"version","1.7.9"),i(this,"request",null),i(this,"name",""),i(this,"address",""),i(this,"roomUrl",""),i(this,"socketStore",x),i(this,"config",new te),ne.instance)return S.warn("Cannot initialize PageSpy multiple times"),ne.instance;const t=this.config.mergeConfig(e);t.singletonSocket&&(U.isSingleSocket=!0);const s=n();if(s.canIUse("getAccountInfoSync")){if("release"===s.getAccountInfoSync().miniProgram.envVersion&&!1!==t.disabledOnProd)return void S.warn("PageSpy is not allowed on release env of mini program")}this.request=new Z(this.config),ne.instance=this,this.triggerPlugins("onInit",{socketStore:x,config:t}),this.init()}triggerPlugins(e,t){const{disabledPlugins:n}=this.config.get();ne.pluginsWithOrder.forEach((s=>{var o;h(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(),o=s.getStorage(L);if(o&&"object"==typeof o){const{name:e,address:n,roomUrl:s,usable:r,project:i,time:a}=o;!r||t.project!==i||a<Date.now()-3e4?await this.createNewConnection():(this.name=e,this.address=n,this.roomUrl=s,this.useOldConnection())}else await this.createNewConnection();e.canIUse("onAppShow")&&e.onAppShow((()=>{const e=x.getSocket().getState();e!==N.CLOSED&&e!==N.CLOSING||this.useOldConnection()})),S.log("Plugins inited")}abort(){this.triggerPlugins("onReset"),x.close(),ne.instance=null}async createNewConnection(){if(!this.request)return void S.error("Cannot get the Request");const{data:e}=await this.request.createRoom(),t=this.request.getRoomUrl({address:e.address,name:"client:".concat(a()),userId:"Client"});this.name=e.name,this.address=e.address,this.roomUrl=t,this.refreshRoomInfo(),x.init(t)}useOldConnection(){this.refreshRoomInfo(),x.init(this.roomUrl)}refreshRoomInfo(){this.saveSession();const e=setInterval((()=>{const t=s.getStorage(L);if(t&&"object"==typeof t){const{usable:n}=t;if(!1===n)return void clearInterval(e)}this.saveSession()}),15e3);S.log("Room ID: ".concat(this.address.slice(0,4)))}saveSession(){const{name:e,address:t,roomUrl:n}=this,o={name:e,address:t,roomUrl:n,usable:!0,project:this.config.get().project,time:Date.now()};s.setStorage(L,o)}}i(ne,"plugins",{pre:[],normal:[],post:[]}),i(ne,"instance",null);var se;[new H,new F,new J,new X,new K].forEach((e=>{ne.registerPlugin(e)})),se=my,t=se,s.getStorage=e=>{const t=my.getStorageSync({key:e});if(t.success)return t.data},s.setStorage=(e,t)=>my.setStorageSync({key:e,data:t}),s.removeStorage=e=>my.removeStorageSync({key:e});const oe=my.getSystemInfoSync();z.info.osType=oe.platform.toLowerCase(),z.info.browserType="mp-alipay",z.info.osVersion=oe.system,z.info.browserVersion=oe.version,A.messageFilters.push((e=>e.data)),module.exports=ne; | ||
//# 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 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}; | ||
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},s={setStorage(e,n){var s;return null===(s=t)||void 0===s?void 0:s.setStorageSync(e,n)},getStorage(e){var n;return null===(n=t)||void 0===n?void 0:n.getStorageSync(e)},removeStorage(e){var n;return null===(n=t)||void 0===n?void 0:n.getStorageSync(e)}};function o(e){return o="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},o(e)}function r(e){var t=function(e,t){if("object"!=o(e)||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var s=n.call(e,t||"default");if("object"!=o(s))return s;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==o(t)?t:String(t)}function i(e,t,n){return(t=r(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function a(){return Math.random().toString(36).slice(2)}function c(e){return Object.prototype.toString.call(e)}function l(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function u(e){return"[object BigInt]"===c(e)}function h(e){return e instanceof Array}function d(e){return"object"==typeof e&&null!==e}const g=e=>"".concat(e),p=e=>({ok:!0,value:e});function m(e){return void 0===e?p(g(e)):null===e?p(e):function(e){return"number"==typeof e}(e)&&(e===-1/0||e===1/0||Number.isNaN(e))?p(g(e)):u(e)?p("".concat(e,"n")):"symbol"==typeof e||"function"==typeof e?p(g(e.toString())):e instanceof Error?p(g(e.stack)):e===Object.prototype?{value:null,ok:!1}:e instanceof Object||"object"==typeof e?{value:e,ok:!1}:p(e)}function f(e){return void 0===e?"undefined":null===e?"null":u(e)?"bigint":e instanceof Object?e instanceof Error?"error":e instanceof Function?"function":"object":typeof e}const y={...console},S=["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];y[t]("[PageSpy] [".concat(t.toLocaleUpperCase(),"]: "),...n)},e)),{}),v="message",b="broadcast",T="ping";var O=Object.freeze({__proto__:null,BROADCAST:b,CLOSE:"close",CONNECT:"connect",ERROR:"error",JOIN:"join",LEAVE:"leave",MESSAGE:v,PING:T,PONG:"pong"});const E="console",I="debug",k="refresh",w="atom-detail",P="atom-getter",C="public-data";function j(e,t){return{role:"client",type:e,data:{...(!(arguments.length>2&&void 0!==arguments[2])||arguments[2])&&{id:a()},...t}}}class R{constructor(){i(this,"store",{}),i(this,"instanceStore",{})}getStore(){return this.store}resetStore(){this.store={}}getInstanceStore(){return this.instanceStore}resetInstanceStore(){this.instanceStore={}}transformToAtom(e){const{value:t,ok:n}=m(e);return n?{id:a(),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];l(t,"value")&&(t.value=this.transformToAtom(t.value)),s[e]=R.getAtomOverview({atomId:a(),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=a();let s=n;var o;d(o=e)&&l(o,"constructor")&&"function"==typeof o.constructor&&(s=t),this.store[n]=e,this.instanceStore[n]=s;const r=R.getSemanticValue(e);return R.getAtomOverview({atomId:n,value:r,instanceId:s})}static getAtomOverview(e){let{instanceId:t="",atomId:n,value:s}=e;return{id:a(),type:"atom",__atomId:n,instanceId:t,value:s}}static getSemanticValue(e){if(d(t=e)&&"[object Object]"===c(t))return"Object {...}";var t;if(h(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(h(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 N,q=new R;!function(e){e[e.CONNECTING=0]="CONNECTING",e[e.OPEN=1]="OPEN",e[e.CLOSING=2]="CLOSING",e[e.CLOSED=3]="CLOSED"}(N||(N={}));class D{constructor(){i(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 A{constructor(){i(this,"socketUrl",""),i(this,"socketConnection",null),i(this,"pingTimer",null),i(this,"pongTimer",null),i(this,"retryTimer",null),i(this,"messages",[]),i(this,"events",{[k]:[],[I]:[],[w]:[],[P]:[],"debugger-online":[],"database-pagination":[],[C]:[]}),i(this,"reconnectable",!0),i(this,"reconnectTimes",3),i(this,"connectionStatus",!1),this.addListener("debug",A.handleDebugger),this.addListener("atom-detail",A.handleResolveAtom),this.addListener("atom-getter",A.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()===N.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){S.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:b,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;A.messageFilters.length&&A.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}=O,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){[C].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:v,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:v,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===I){t(j(E,{logType:"debug-origin",logs:[{id:a(),type:"debug-origin",value:o}]}));try{const e=new Function("return ".concat(o))();t(j(E,{logType:"debug-eval",logs:[q.transformToAtom(e)]}))}catch(e){t(j(E,{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=q.get(o)||{};t(j("atom-detail-".concat(o),e,!1))}}static handleAtomPropertyGetter(e,t){let{source:n}=e;const{type:s,data:o}=n;if(s===P){const{id:e,parentId:n,key:s,instanceId:i}=o,a=q.getOrigin(i),c=q.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(j("atom-getter-".concat(e),q.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=a();const s=function(e){const{ok:t,value:n}=m(e);return t?n:JSON.stringify(e,((e,t)=>m(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([v,T].indexOf(e.type)>-1)return;this.messages.push(e)}}}i(A,"messageFilters",[]);const L="page-spy-room";class U extends D{constructor(){super(...arguments),i(this,"socketInstance",null),i(this,"state",0)}init(e){this.state=N.CONNECTING;const t=n(),s=e=>{this.state=N.CLOSED,this.emit("close",e)},o=e=>{this.state=N.OPEN,this.emit("open",e)},r=e=>{this.state=N.CLOSED,this.emit("error",e)},i=e=>{this.emit("message",e)};U.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;U.isSingleSocket?n().sendSocketMessage({data:e}):null===(t=this.socketInstance)||void 0===t||t.send({data:e})}close(){var e;U.isSingleSocket?n().closeSocket({}):null===(e=this.socketInstance)||void 0===e||e.close({});this.state=N.CLOSED,this.clearListeners()}getState(){return this.state}}i(U,"isSingleSocket",!1);var M,x=new class extends A{constructor(){super(...arguments),i(this,"socketWrapper",new U)}getSocket(){return this.socketWrapper}onOffline(){s.setStorage(L,JSON.stringify({usable:!1}))}};class H{constructor(){i(this,"name","ConsolePlugin"),i(this,"console",{}),i(this,"proxyTypes",["log","info","error","warn","debug"])}async onInit(){if(H.hasInitd)return;H.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]})),H.hasInitd=!1}printLog(e){if(e.logs&&e.logs.length){this.console[e.logType](...e.logs),e.logs=e.logs.map((e=>q.transformToAtom(e)));const t=j(E,{time:Date.now(),...e});x.dispatchEvent(C,t),x.broadcastMessage(t)}}}i(H,"hasInitd",!1);class F{constructor(){i(this,"name","ErrorPlugin")}onInit(){F.hasInitd||(F.hasInitd=!0,this.onUncaughtError(),this.onUnhandledRejectionError())}onReset(){const e=n();e.canIUse("offError")&&e.offError(this.errorHandler),e.canIUse("offUnHandledRejection")&&e.offUnHandledRejection(this.unhandledRejectionHandler),F.hasInitd=!1}errorHandler(e){if(F.hasInitd)if(e.stack||e.message){const{message:t,stack:n}=e;F.sendMessage(n||t,{name:"uncaught error",...e})}else{const e="[PageSpy] An unknown error occurred and no message or stack trace available";F.sendMessage(e,null)}}unhandledRejectionHandler(e){F.hasInitd&&F.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:[q.transformToAtom(e)],time:Date.now(),url:"wx:light-app",errorDetail:t},s=j(E,n);x.dispatchEvent(C,s),x.broadcastMessage(s)}}function G(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}}}i(F,"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"}(M||(M={}));class V{constructor(e){i(this,"id",""),i(this,"name",""),i(this,"method",""),i(this,"url",""),i(this,"requestType","xhr"),i(this,"requestHeader",null),i(this,"status",0),i(this,"statusText",""),i(this,"readyState",0),i(this,"responseReason",null),i(this,"responseType",""),i(this,"responseHeader",null),i(this,"startTime",0),i(this,"endTime",0),i(this,"costTime",0),i(this,"getData",null),i(this,"postData",null),i(this,"requestPayload",null),i(this,"withCredentials",!1),this.id=e}}class W{constructor(e){i(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]?(S.warn("The request object has been in store, disallow duplicate create"),!1):(this.reqMap[e]=new V(e),!0):(S.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=j("network",{...t},!1);Number(t.readyState)===M.DONE&&this.socketStore.dispatchEvent(C,n),this.socketStore.broadcastMessage(n,t.readyState!==M.DONE),this.deferDeleteRequest(e)}deferDeleteRequest(e){const t=this.getRequest(e);t&&t.readyState===M.DONE&&setTimeout((()=>{delete this.reqMap[e]}),3e3)}}class _ extends W{constructor(){super(x)}}class B extends _{constructor(){super(),i(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=a();e.createRequest(n);const o=e.getRequest(n);if(o){const r=t.method||"GET",{url:i}=t,a=t.header||null,l=G(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=M.UNSENT,d(a)?o.requestHeader=Object.entries(a):o.requestHeader=a,"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=c(e)}}e.sendRequestItem(n,o);const u=t.success,h=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=M.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==h||h(e)},t.complete=function(t){o.readyState=M.DONE,e.sendRequestItem(n,o),null==g||g(t)};return s(t)}return S.warn("The request object is not found on request event"),null}}))}}class J{constructor(){i(this,"name","NetworkPlugin"),i(this,"requestProxy",null)}onInit(){J.hasInitd||(J.hasInitd=!0,this.requestProxy=new B)}onReset(){var e;null===(e=this.requestProxy)||void 0===e||e.reset(),J.hasInitd=!1}}i(J,"hasInitd",!1);class z{}i(z,"info",{osType:"unknown",osVersion:"unknown",browserType:"unknown",browserVersion:"unknown",framework:"unknown"});const $=e=>{let{osType:t,osVersion:n,browserType:s,browserVersion:o}=e;return"".concat(t,"/").concat(n," ").concat(s,"/").concat(o)};class K{constructor(){i(this,"name","SystemPlugin")}onInit(){if(K.hasInitd)return;K.hasInitd=!0;const e=a(),t=z.info;x.broadcastMessage(j("system",{id:e,system:{ua:$(t)},features:{}}),!1)}onReset(){K.hasInitd=!1}}function Q(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}i(K,"hasInitd",!1);class X{constructor(){i(this,"name","StoragePlugin")}onInit(){X.hasInitd||(X.hasInitd=!0,X.initStorageProxy(),X.listenRefreshEvent())}onReset(){const e=n();Object.entries(X.originFunctions).forEach((t=>{let[n,s]=t;Object.defineProperty(e,n,{value:s})})),X.hasInitd=!1}static sendRefresh(){const e=n();try{const t=e.getStorageInfoSync(),n={type:"mpStorage",action:"get",data:t.keys.map((e=>({name:e,value:Q(s.getStorage(e))})))};X.sendStorageItem(n)}catch(e){}}static listenRefreshEvent(){x.addListener(k,(async e=>{let{source:t}=e;const{data:n}=t;"mpStorage"===n&&X.sendRefresh()}))}static initStorageProxy(){const e=n(),{sendClearItem:t,sendRemoveItem:s,sendSetItem:o}=X;["setStorage","setStorageSync","removeStorage","removeStorageSync","clearStorage","clearStorageSync","batchSetStorageSync","batchSetStorage"].forEach((t=>{e[t]&&(X.originFunctions[t]=e[t])})),Object.defineProperties(e,{setStorage:{value:e=>X.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{let n;if("mp-alipay"!==z.info.browserType||z.info.framework){const s=e;n=X.originFunctions.setStorageSync(s,t),o(s,t)}else{const t=e;n=X.originFunctions.setStorageSync(t),o(t.key,t.data)}return n}catch(t){throw S.error("Failed to set storage synchronously: ".concat(e)),t}}},removeStorage:{value:e=>X.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=X.originFunctions.removeStorageSync(e);return s(t),t}catch(t){throw S.error("Failed to remove storage synchronously: ".concat(e)),t}}},clearStorage:{value:e=>X.originFunctions.clearStorage({...e,success(n){var s;t(),null===(s=e.success)||void 0===s||s.call(e,n)}})},clearStorageSync:{value(){try{const e=X.originFunctions.clearStorageSync();return t(),e}catch(e){throw S.error("Failed to clear storage synchronously"),e}}}}),e.canIUse("batchSetStorageSync")&&Object.defineProperty(e,"batchSetStorageSync",{value(e){try{const t=X.originFunctions.batchSetStorageSync(e);return e.forEach((e=>{o(e.key,e.value)})),t}catch(t){throw S.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=>X.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){X.sendStorageItem({type:"mpStorage",action:"set",name:e,value:Q(t)})}static sendRemoveItem(e){X.sendStorageItem({type:"mpStorage",action:"remove",name:e})}static sendClearItem(){X.sendStorageItem({type:"mpStorage",action:"clear"})}static sendStorageItem(e){const t=j("storage",e);x.dispatchEvent(C,t),x.broadcastMessage(t,!0)}}i(X,"hasInitd",!1),i(X,"originFunctions",{});const Y=e=>!1===e?["http://","ws://"]:["https://","wss://"];class Z{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=Y(t.enableSSL),o=z.info,r=$(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=Y(n.enableSSL);return"".concat(s[1]).concat(this.base,"/api/v1/ws/room/join?").concat(e(t))}}class ee{defaultConfig(){return{}}constructor(){i(this,"mergeConfig",(e=>(this.value={...this.defaultConfig(),...e},this.value))),this.value=this.defaultConfig()}get(){return this.value}}class te extends ee{constructor(){super(...arguments),i(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 ne{static get pluginsWithOrder(){return[...ne.plugins.pre,...ne.plugins.normal,...ne.plugins.post]}static registerPlugin(e){if(!e)return;if("function"==typeof(t=e)&&void 0!==t.prototype)return void S.error("PageSpy.registerPlugin() expect to pass an instance, not a class");var t;if(!e.name)return void S.error("The ".concat(e.constructor.name,' plugin should provide a "name" property'));if(ne.pluginsWithOrder.some((t=>t.name===e.name)))return void S.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";'));ne.plugins[e.enforce||"normal"].push(e)}constructor(e){if(i(this,"root",null),i(this,"version","1.7.9"),i(this,"request",null),i(this,"name",""),i(this,"address",""),i(this,"roomUrl",""),i(this,"socketStore",x),i(this,"config",new te),ne.instance)return S.warn("Cannot initialize PageSpy multiple times"),ne.instance;const t=this.config.mergeConfig(e);t.singletonSocket&&(U.isSingleSocket=!0);const s=n();if(s.canIUse("getAccountInfoSync")){if("release"===s.getAccountInfoSync().miniProgram.envVersion&&!1!==t.disabledOnProd)return void S.warn("PageSpy is not allowed on release env of mini program")}this.request=new Z(this.config),ne.instance=this,this.triggerPlugins("onInit",{socketStore:x,config:t}),this.init()}triggerPlugins(e,t){const{disabledPlugins:n}=this.config.get();ne.pluginsWithOrder.forEach((s=>{var o;h(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(),o=s.getStorage(L);if(o&&"object"==typeof o){const{name:e,address:n,roomUrl:s,usable:r,project:i,time:a}=o;!r||t.project!==i||a<Date.now()-3e4?await this.createNewConnection():(this.name=e,this.address=n,this.roomUrl=s,this.useOldConnection())}else await this.createNewConnection();e.canIUse("onAppShow")&&e.onAppShow((()=>{const e=x.getSocket().getState();e!==N.CLOSED&&e!==N.CLOSING||this.useOldConnection()})),S.log("Plugins inited")}abort(){this.triggerPlugins("onReset"),x.close(),ne.instance=null}async createNewConnection(){if(!this.request)return void S.error("Cannot get the Request");const{data:e}=await this.request.createRoom(),t=this.request.getRoomUrl({address:e.address,name:"client:".concat(a()),userId:"Client"});this.name=e.name,this.address=e.address,this.roomUrl=t,this.refreshRoomInfo(),x.init(t)}useOldConnection(){this.refreshRoomInfo(),x.init(this.roomUrl)}refreshRoomInfo(){this.saveSession();const e=setInterval((()=>{const t=s.getStorage(L);if(t&&"object"==typeof t){const{usable:n}=t;if(!1===n)return void clearInterval(e)}this.saveSession()}),15e3);S.log("Room ID: ".concat(this.address.slice(0,4)))}saveSession(){const{name:e,address:t,roomUrl:n}=this,o={name:e,address:t,roomUrl:n,usable:!0,project:this.config.get().project,time:Date.now()};s.setStorage(L,o)}}i(ne,"plugins",{pre:[],normal:[],post:[]}),i(ne,"instance",null);var se;[new H,new F,new J,new X,new K].forEach((e=>{ne.registerPlugin(e)})),se=my,t=se,s.getStorage=e=>{const t=my.getStorageSync({key:e});if(t.success)return t.data},s.setStorage=(e,t)=>my.setStorageSync({key:e,data:t}),s.removeStorage=e=>my.removeStorageSync({key:e});const oe=my.getSystemInfoSync();z.info.osType=oe.platform.toLowerCase(),z.info.browserType="mp-alipay",z.info.osVersion=oe.system,z.info.browserVersion=oe.version,A.messageFilters.push((e=>e.data));export{ne as default}; | ||
//# sourceMappingURL=index.min.js.map |
{ | ||
"name": "@huolala-tech/page-spy-alipay", | ||
"version": "1.7.8", | ||
"version": "1.7.9", | ||
"description": "A developer tool for debugging alipay miniprogram", | ||
@@ -73,3 +73,3 @@ "license": "MIT", | ||
}, | ||
"gitHead": "dae5b1f5658e3c01254a9565f705a91bab5cedf2" | ||
"gitHead": "7820448f4f89aa33b57f6e3e6688e2773c635965" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
63422
213