@obb871001/api-integration-sdk 1.0.35 → 1.0.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.js +10 -8
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Fe=require("@tanstack/react-query"),I=require("react"),Zr=require("axios"),Ce=require("lodash"),et=require("react-dom"),qe=I.createContext(null),Je=()=>{const r=I.useContext(qe);if(!r)throw new Error("useApiContext must be used within ApiProvider");return r};function rt({baseURL:r,getToken:g,timeoutMs:O=15e3,currency:h="TWD",lng:v="tw",onError:_}={}){const S=Zr.create({baseURL:r,timeout:O,headers:{"Content-Type":"application/json"}});return S.interceptors.request.use(async d=>{if(d.headers=d.headers||{},g){const c=await g();c&&(d.headers.Authorization=`Bearer ${c}`)}return d.headers.Currency=h,d.headers["currency-code"]=h,d.headers.lang=v,d}),S.interceptors.response.use(d=>d.data,d=>_?_(d,{instance:S}):Promise.reject(d)),S}const tt=()=>{const{client:r}=Je(),g=I.useCallback(async S=>{const{mac_address:d="",app_version:c="",anydesk_id:l=""}=S,{data:u}=await r.post("/cash-register/login",{mac_address:d,app_version:c,anydesk_id:l});return u},[r]),O=I.useCallback(async()=>r.get("/member/getMemberInfo"),[r]),h=I.useCallback(async()=>{const{data:S}=await r.get("/getGameList");return S},[r]),v=I.useCallback(async()=>{const{data:S}=await r.get("/getNowCurrencyExchange");return S},[r]),_=I.useCallback(async()=>{const{data:S}=await r.get("/getFavoriteGame");return S},[r]);return{machineLoginApi:g,userInfoApi:O,userGameListApi:h,userFavoriteGameApi:_,userCurrencyExchangeApi:v}},nt=()=>{const{getToken:r}=Je(),{userInfoApi:g}=tt(),O=Fe.useQueries({queries:[{queryKey:["getMemberInfo"],queryFn:async()=>await g(),refetchInterval:5e4}],enabled:!!r}),{data:h,isFetching:v,error:_}=O[0]||{};return{data:h,isFetching:v,error:_}};function at(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}var De={},q={},je={},ir;function $(){return ir||(ir=1,(function(r){Object.defineProperty(r,"__esModule",{value:!0}),r.isEventSourceSupported=r.isReactNative=r.ReadyState=r.DEFAULT_HEARTBEAT=r.UNPARSABLE_JSON_OBJECT=r.DEFAULT_RECONNECT_INTERVAL_MS=r.DEFAULT_RECONNECT_LIMIT=r.SOCKET_IO_PING_CODE=r.SOCKET_IO_PATH=r.SOCKET_IO_PING_INTERVAL=r.DEFAULT_EVENT_SOURCE_OPTIONS=r.EMPTY_EVENT_HANDLERS=r.DEFAULT_OPTIONS=void 0;var g=1,O=1e3*g;r.DEFAULT_OPTIONS={},r.EMPTY_EVENT_HANDLERS={},r.DEFAULT_EVENT_SOURCE_OPTIONS={withCredentials:!1,events:r.EMPTY_EVENT_HANDLERS},r.SOCKET_IO_PING_INTERVAL=25*O,r.SOCKET_IO_PATH="/socket.io/?EIO=3&transport=websocket",r.SOCKET_IO_PING_CODE="2",r.DEFAULT_RECONNECT_LIMIT=20,r.DEFAULT_RECONNECT_INTERVAL_MS=5e3,r.UNPARSABLE_JSON_OBJECT={},r.DEFAULT_HEARTBEAT={message:"ping",timeout:6e4,interval:25e3};var h;(function(_){_[_.UNINSTANTIATED=-1]="UNINSTANTIATED",_[_.CONNECTING=0]="CONNECTING",_[_.OPEN=1]="OPEN",_[_.CLOSING=2]="CLOSING",_[_.CLOSED=3]="CLOSED"})(h||(r.ReadyState=h={}));var v=function(){try{return"EventSource"in globalThis}catch{return!1}};r.isReactNative=typeof navigator<"u"&&navigator.product==="ReactNative",r.isEventSourceSupported=!r.isReactNative&&v()})(je)),je}var _e={},Le={},sr;function Ge(){return sr||(sr=1,(function(r){Object.defineProperty(r,"__esModule",{value:!0}),r.resetWebSockets=r.sharedWebSockets=void 0,r.sharedWebSockets={};var g=function(O){if(O&&r.sharedWebSockets.hasOwnProperty(O))delete r.sharedWebSockets[O];else for(var h in r.sharedWebSockets)r.sharedWebSockets.hasOwnProperty(h)&&delete r.sharedWebSockets[h]};r.resetWebSockets=g})(Le)),Le}var ne={},K={},lr;function Ve(){if(lr)return K;lr=1,Object.defineProperty(K,"__esModule",{value:!0}),K.setUpSocketIOPing=K.appendQueryParams=K.parseSocketIOUrl=void 0;var r=$(),g=function(v){if(v){var _=/^https|wss/.test(v),S=v.replace(/^(https?|wss?)(:\/\/)?/,""),d=S.replace(/\/$/,""),c=_?"wss":"ws";return"".concat(c,"://").concat(d).concat(r.SOCKET_IO_PATH)}else if(v===""){var _=/^https/.test(window.location.protocol),c=_?"wss":"ws",l=window.location.port?":".concat(window.location.port):"";return"".concat(c,"://").concat(window.location.hostname).concat(l).concat(r.SOCKET_IO_PATH)}return v};K.parseSocketIOUrl=g;var O=function(v,_){_===void 0&&(_={});var S=/\?([\w]+=[\w]+)/,d=S.test(v),c="".concat(Object.entries(_).reduce(function(l,u){var a=u[0],i=u[1];return l+"".concat(a,"=").concat(i,"&")},"").slice(0,-1));return"".concat(v).concat(d?"&":"?").concat(c)};K.appendQueryParams=O;var h=function(v,_){_===void 0&&(_=r.SOCKET_IO_PING_INTERVAL);var S=function(){return v(r.SOCKET_IO_PING_CODE)};return window.setInterval(S,_)};return K.setUpSocketIOPing=h,K}var Re={},fr;function wr(){if(fr)return Re;fr=1,Object.defineProperty(Re,"__esModule",{value:!0}),Re.heartbeat=O;var r=$();function g(h){return Array.isArray(h)?h.reduce(function(v,_){return v.current>_.current?v:_}).current:h.current}function O(h,v,_){var S=_||{},d=S.interval,c=d===void 0?r.DEFAULT_HEARTBEAT.interval:d,l=S.timeout,u=l===void 0?r.DEFAULT_HEARTBEAT.timeout:l,a=S.message,i=a===void 0?r.DEFAULT_HEARTBEAT.message:a,t=Math.max(100,c/10),n=Date.now(),f=setInterval(function(){var E=Date.now(),o=g(v);if(o+u<=E)console.warn("Heartbeat timed out, closing connection, last message received ".concat(E-o,"ms ago, last ping sent ").concat(E-n,"ms ago")),h.close();else if(o+c<=E&&n+c<=E)try{typeof i=="function"?h.send(i()):h.send(i),n=E}catch(b){console.error("Heartbeat failed, closing connection",b instanceof Error?b.message:b),h.close()}},t);return h.addEventListener("close",function(){clearInterval(f)}),function(){}}return Re}var Ee={},Ue={},vr;function $e(){return vr||(vr=1,(function(r){Object.defineProperty(r,"__esModule",{value:!0}),r.resetSubscribers=r.removeSubscriber=r.addSubscriber=r.hasSubscribers=r.getSubscribers=void 0;var g={},O=[],h=function(c){return(0,r.hasSubscribers)(c)?Array.from(g[c]):O};r.getSubscribers=h;var v=function(c){var l;return((l=g[c])===null||l===void 0?void 0:l.size)>0};r.hasSubscribers=v;var _=function(c,l){g[c]=g[c]||new Set,g[c].add(l)};r.addSubscriber=_;var S=function(c,l){g[c].delete(l)};r.removeSubscriber=S;var d=function(c){if(c&&g.hasOwnProperty(c))delete g[c];else for(var l in g)g.hasOwnProperty(l)&&delete g[l]};r.resetSubscribers=d})(Ue)),Ue}var dr;function He(){if(dr)return Ee;dr=1,Object.defineProperty(Ee,"__esModule",{value:!0}),Ee.assertIsWebSocket=O,Ee.resetGlobalState=h;var r=Ge(),g=$e();function O(v,_){if(!_&&!(v instanceof WebSocket))throw new Error("")}function h(v){(0,g.resetSubscribers)(v),(0,r.resetWebSockets)(v)}return Ee}var _r;function ut(){if(_r)return ne;_r=1;var r=ne&&ne.__assign||function(){return r=Object.assign||function(u){for(var a,i=1,t=arguments.length;i<t;i++){a=arguments[i];for(var n in a)Object.prototype.hasOwnProperty.call(a,n)&&(u[n]=a[n])}return u},r.apply(this,arguments)};Object.defineProperty(ne,"__esModule",{value:!0}),ne.attachListeners=void 0;var g=Ve(),O=wr(),h=$(),v=He(),_=function(u,a,i,t){u.onmessage=function(n){var f;a.current.onMessage&&a.current.onMessage(n),typeof t?.current=="number"&&(t.current=Date.now()),!(typeof a.current.filter=="function"&&a.current.filter(n)!==!0)&&(a.current.heartbeat&&typeof a.current.heartbeat!="boolean"&&((f=a.current.heartbeat)===null||f===void 0?void 0:f.returnMessage)===n.data||i(n))}},S=function(u,a,i,t,n){u.onopen=function(f){if(a.current.onOpen&&a.current.onOpen(f),t.current=0,i(h.ReadyState.OPEN),a.current.heartbeat&&u instanceof WebSocket){var E=typeof a.current.heartbeat=="boolean"?void 0:a.current.heartbeat;n.current=Date.now(),(0,O.heartbeat)(u,n,E)}}},d=function(u,a,i,t,n){if(h.isEventSourceSupported&&u instanceof EventSource)return function(){};(0,v.assertIsWebSocket)(u,a.current.skipAssert);var f;return u.onclose=function(E){var o;if(a.current.onClose&&a.current.onClose(E),i(h.ReadyState.CLOSED),a.current.shouldReconnect&&a.current.shouldReconnect(E)){var b=(o=a.current.reconnectAttempts)!==null&&o!==void 0?o:h.DEFAULT_RECONNECT_LIMIT;if(n.current<b){var m=typeof a.current.reconnectInterval=="function"?a.current.reconnectInterval(n.current):a.current.reconnectInterval;f=window.setTimeout(function(){n.current++,t()},m??h.DEFAULT_RECONNECT_INTERVAL_MS)}else a.current.onReconnectStop&&a.current.onReconnectStop(b),console.warn("Max reconnect attempts of ".concat(b," exceeded"))}},function(){return f&&window.clearTimeout(f)}},c=function(u,a,i,t,n){var f;return u.onerror=function(E){var o;if(a.current.onError&&a.current.onError(E),h.isEventSourceSupported&&u instanceof EventSource&&(a.current.onClose&&a.current.onClose(r(r({},E),{code:1006,reason:"An error occurred with the EventSource: ".concat(E),wasClean:!1})),i(h.ReadyState.CLOSED),u.close()),a.current.retryOnError)if(n.current<((o=a.current.reconnectAttempts)!==null&&o!==void 0?o:h.DEFAULT_RECONNECT_LIMIT)){var b=typeof a.current.reconnectInterval=="function"?a.current.reconnectInterval(n.current):a.current.reconnectInterval;f=window.setTimeout(function(){n.current++,t()},b??h.DEFAULT_RECONNECT_INTERVAL_MS)}else a.current.onReconnectStop&&a.current.onReconnectStop(a.current.reconnectAttempts),console.warn("Max reconnect attempts of ".concat(a.current.reconnectAttempts," exceeded"))},function(){return f&&window.clearTimeout(f)}},l=function(u,a,i,t,n,f,E){var o=a.setLastMessage,b=a.setReadyState,m,D,T;return i.current.fromSocketIO&&(m=(0,g.setUpSocketIOPing)(E)),_(u,i,o,f),S(u,i,b,n,f),D=d(u,i,b,t,n),T=c(u,i,b,t,n),function(){b(h.ReadyState.CLOSING),D(),T(),u.close(),m&&clearInterval(m)}};return ne.attachListeners=l,ne}var ae={},Er;function ot(){if(Er)return ae;Er=1;var r=ae&&ae.__assign||function(){return r=Object.assign||function(a){for(var i,t=1,n=arguments.length;t<n;t++){i=arguments[t];for(var f in i)Object.prototype.hasOwnProperty.call(i,f)&&(a[f]=i[f])}return a},r.apply(this,arguments)};Object.defineProperty(ae,"__esModule",{value:!0}),ae.attachSharedListeners=void 0;var g=Ge(),O=$(),h=$e(),v=Ve(),_=wr(),S=function(a,i,t){a.onmessage=function(n){(0,h.getSubscribers)(i).forEach(function(f){var E;f.optionsRef.current.onMessage&&f.optionsRef.current.onMessage(n),typeof((E=f?.lastMessageTime)===null||E===void 0?void 0:E.current)=="number"&&(f.lastMessageTime.current=Date.now()),!(typeof f.optionsRef.current.filter=="function"&&f.optionsRef.current.filter(n)!==!0)&&(t&&typeof t!="boolean"&&t?.returnMessage===n.data||f.setLastMessage(n))})}},d=function(a,i,t){a.onopen=function(n){var f=(0,h.getSubscribers)(i);f.forEach(function(E){E.reconnectCount.current=0,E.optionsRef.current.onOpen&&E.optionsRef.current.onOpen(n),E.setReadyState(O.ReadyState.OPEN),t&&a instanceof WebSocket&&(E.lastMessageTime.current=Date.now())}),t&&a instanceof WebSocket&&(0,_.heartbeat)(a,f.map(function(E){return E.lastMessageTime}),typeof t=="boolean"?void 0:t)}},c=function(a,i){a instanceof WebSocket&&(a.onclose=function(t){(0,h.getSubscribers)(i).forEach(function(n){n.optionsRef.current.onClose&&n.optionsRef.current.onClose(t),n.setReadyState(O.ReadyState.CLOSED)}),delete g.sharedWebSockets[i],(0,h.getSubscribers)(i).forEach(function(n){var f;if(n.optionsRef.current.shouldReconnect&&n.optionsRef.current.shouldReconnect(t)){var E=(f=n.optionsRef.current.reconnectAttempts)!==null&&f!==void 0?f:O.DEFAULT_RECONNECT_LIMIT;if(n.reconnectCount.current<E){var o=typeof n.optionsRef.current.reconnectInterval=="function"?n.optionsRef.current.reconnectInterval(n.reconnectCount.current):n.optionsRef.current.reconnectInterval;setTimeout(function(){n.reconnectCount.current++,n.reconnect.current()},o??O.DEFAULT_RECONNECT_INTERVAL_MS)}else n.optionsRef.current.onReconnectStop&&n.optionsRef.current.onReconnectStop(n.optionsRef.current.reconnectAttempts),console.warn("Max reconnect attempts of ".concat(E," exceeded"))}})})},l=function(a,i){a.onerror=function(t){(0,h.getSubscribers)(i).forEach(function(n){n.optionsRef.current.onError&&n.optionsRef.current.onError(t),O.isEventSourceSupported&&a instanceof EventSource&&(n.optionsRef.current.onClose&&n.optionsRef.current.onClose(r(r({},t),{code:1006,reason:"An error occurred with the EventSource: ".concat(t),wasClean:!1})),n.setReadyState(O.ReadyState.CLOSED))}),O.isEventSourceSupported&&a instanceof EventSource&&a.close()}},u=function(a,i,t,n){var f;return t.current.fromSocketIO&&(f=(0,v.setUpSocketIOPing)(n)),S(a,i,t.current.heartbeat),c(a,i),d(a,i,t.current.heartbeat),l(a,i),function(){f&&clearInterval(f)}};return ae.attachSharedListeners=u,ae}var Sr;function ct(){if(Sr)return _e;Sr=1,Object.defineProperty(_e,"__esModule",{value:!0}),_e.createOrJoinSocket=void 0;var r=Ge(),g=$(),O=ut(),h=ot(),v=$e(),_=function(d,c,l,u,a){return function(){if((0,v.removeSubscriber)(d,c),!(0,v.hasSubscribers)(d)){try{var i=r.sharedWebSockets[d];i instanceof WebSocket&&(i.onclose=function(t){l.current.onClose&&l.current.onClose(t),u(g.ReadyState.CLOSED)}),i.close()}catch{}a&&a(),delete r.sharedWebSockets[d]}}},S=function(d,c,l,u,a,i,t,n,f){if(!g.isEventSourceSupported&&u.current.eventSourceOptions)throw g.isReactNative?new Error("EventSource is not supported in ReactNative"):new Error("EventSource is not supported");if(u.current.share){var E=null;r.sharedWebSockets[c]===void 0?(r.sharedWebSockets[c]=u.current.eventSourceOptions?new EventSource(c,u.current.eventSourceOptions):new WebSocket(c,u.current.protocols),d.current=r.sharedWebSockets[c],l(g.ReadyState.CONNECTING),E=(0,h.attachSharedListeners)(r.sharedWebSockets[c],c,u,f)):(d.current=r.sharedWebSockets[c],l(r.sharedWebSockets[c].readyState));var o={setLastMessage:a,setReadyState:l,optionsRef:u,reconnectCount:t,lastMessageTime:n,reconnect:i};return(0,v.addSubscriber)(c,o),_(c,o,u,l,E)}else{if(d.current=u.current.eventSourceOptions?new EventSource(c,u.current.eventSourceOptions):new WebSocket(c,u.current.protocols),l(g.ReadyState.CONNECTING),!d.current)throw new Error("WebSocket failed to be created");return(0,O.attachListeners)(d.current,{setLastMessage:a,setReadyState:l},u,i.current,t,n,f)}};return _e.createOrJoinSocket=S,_e}var x={},hr;function it(){return hr||(hr=1,(function(r){var g=x&&x.__awaiter||function(c,l,u,a){function i(t){return t instanceof u?t:new u(function(n){n(t)})}return new(u||(u=Promise))(function(t,n){function f(b){try{o(a.next(b))}catch(m){n(m)}}function E(b){try{o(a.throw(b))}catch(m){n(m)}}function o(b){b.done?t(b.value):i(b.value).then(f,E)}o((a=a.apply(c,l||[])).next())})},O=x&&x.__generator||function(c,l){var u={label:0,sent:function(){if(t[0]&1)throw t[1];return t[1]},trys:[],ops:[]},a,i,t,n=Object.create((typeof Iterator=="function"?Iterator:Object).prototype);return n.next=f(0),n.throw=f(1),n.return=f(2),typeof Symbol=="function"&&(n[Symbol.iterator]=function(){return this}),n;function f(o){return function(b){return E([o,b])}}function E(o){if(a)throw new TypeError("Generator is already executing.");for(;n&&(n=0,o[0]&&(u=0)),u;)try{if(a=1,i&&(t=o[0]&2?i.return:o[0]?i.throw||((t=i.return)&&t.call(i),0):i.next)&&!(t=t.call(i,o[1])).done)return t;switch(i=0,t&&(o=[o[0]&2,t.value]),o[0]){case 0:case 1:t=o;break;case 4:return u.label++,{value:o[1],done:!1};case 5:u.label++,i=o[1],o=[0];continue;case 7:o=u.ops.pop(),u.trys.pop();continue;default:if(t=u.trys,!(t=t.length>0&&t[t.length-1])&&(o[0]===6||o[0]===2)){u=0;continue}if(o[0]===3&&(!t||o[1]>t[0]&&o[1]<t[3])){u.label=o[1];break}if(o[0]===6&&u.label<t[1]){u.label=t[1],t=o;break}if(t&&u.label<t[2]){u.label=t[2],u.ops.push(o);break}t[2]&&u.ops.pop(),u.trys.pop();continue}o=l.call(c,u)}catch(b){o=[6,b],i=0}finally{a=t=0}if(o[0]&5)throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}},h=x&&x.__spreadArray||function(c,l,u){if(u||arguments.length===2)for(var a=0,i=l.length,t;a<i;a++)(t||!(a in l))&&(t||(t=Array.prototype.slice.call(l,0,a)),t[a]=l[a]);return c.concat(t||Array.prototype.slice.call(l))};Object.defineProperty(r,"__esModule",{value:!0}),r.getUrl=void 0;var v=Ve(),_=$(),S=function(c){return new Promise(function(l){return window.setTimeout(l,c)})},d=function(c,l){for(var u=[],a=2;a<arguments.length;a++)u[a-2]=arguments[a];return g(void 0,h([c,l],u,!0),void 0,function(i,t,n){var f,E,o,b,m,D,T,A;return n===void 0&&(n=0),O(this,function(k){switch(k.label){case 0:if(typeof i!="function")return[3,10];k.label=1;case 1:return k.trys.push([1,3,,9]),[4,i()];case 2:return f=k.sent(),[3,9];case 3:return k.sent(),t.current.retryOnError?(E=(D=t.current.reconnectAttempts)!==null&&D!==void 0?D:_.DEFAULT_RECONNECT_LIMIT,n<E?(o=typeof t.current.reconnectInterval=="function"?t.current.reconnectInterval(n):t.current.reconnectInterval,[4,S(o??_.DEFAULT_RECONNECT_INTERVAL_MS)]):[3,5]):[3,7];case 4:return k.sent(),[2,(0,r.getUrl)(i,t,n+1)];case 5:return(A=(T=t.current).onReconnectStop)===null||A===void 0||A.call(T,n),[2,null];case 6:return[3,8];case 7:return[2,null];case 8:return[3,9];case 9:return[3,11];case 10:f=i,k.label=11;case 11:return b=t.current.fromSocketIO?(0,v.parseSocketIOUrl)(f):f,m=t.current.queryParams?(0,v.appendQueryParams)(b,t.current.queryParams):b,[2,m]}})})};r.getUrl=d})(x)),x}var We={},br;function st(){return br||(br=1,(function(r){Object.defineProperty(r,"__esModule",{value:!0}),r.websocketWrapper=void 0;var g=function(O,h){return new Proxy(O,{get:function(v,_){var S=v[_];return _==="reconnect"?h:typeof S=="function"?(console.error("Calling methods directly on the websocket is not supported at this moment. You must use the methods returned by useWebSocket."),function(){}):S},set:function(v,_,S){return/^on/.test(_)?(console.warn("The websocket's event handlers should be defined through the options object passed into useWebSocket."),!1):(v[_]=S,!0)}})};r.websocketWrapper=g,r.default=r.websocketWrapper})(We)),We}var yr;function Ye(){if(yr)return q;yr=1;var r=q&&q.__assign||function(){return r=Object.assign||function(i){for(var t,n=1,f=arguments.length;n<f;n++){t=arguments[n];for(var E in t)Object.prototype.hasOwnProperty.call(t,E)&&(i[E]=t[E])}return i},r.apply(this,arguments)},g=q&&q.__awaiter||function(i,t,n,f){function E(o){return o instanceof n?o:new n(function(b){b(o)})}return new(n||(n=Promise))(function(o,b){function m(A){try{T(f.next(A))}catch(k){b(k)}}function D(A){try{T(f.throw(A))}catch(k){b(k)}}function T(A){A.done?o(A.value):E(A.value).then(m,D)}T((f=f.apply(i,t||[])).next())})},O=q&&q.__generator||function(i,t){var n={label:0,sent:function(){if(o[0]&1)throw o[1];return o[1]},trys:[],ops:[]},f,E,o,b=Object.create((typeof Iterator=="function"?Iterator:Object).prototype);return b.next=m(0),b.throw=m(1),b.return=m(2),typeof Symbol=="function"&&(b[Symbol.iterator]=function(){return this}),b;function m(T){return function(A){return D([T,A])}}function D(T){if(f)throw new TypeError("Generator is already executing.");for(;b&&(b=0,T[0]&&(n=0)),n;)try{if(f=1,E&&(o=T[0]&2?E.return:T[0]?E.throw||((o=E.return)&&o.call(E),0):E.next)&&!(o=o.call(E,T[1])).done)return o;switch(E=0,o&&(T=[T[0]&2,o.value]),T[0]){case 0:case 1:o=T;break;case 4:return n.label++,{value:T[1],done:!1};case 5:n.label++,E=T[1],T=[0];continue;case 7:T=n.ops.pop(),n.trys.pop();continue;default:if(o=n.trys,!(o=o.length>0&&o[o.length-1])&&(T[0]===6||T[0]===2)){n=0;continue}if(T[0]===3&&(!o||T[1]>o[0]&&T[1]<o[3])){n.label=T[1];break}if(T[0]===6&&n.label<o[1]){n.label=o[1],o=T;break}if(o&&n.label<o[2]){n.label=o[2],n.ops.push(T);break}o[2]&&n.ops.pop(),n.trys.pop();continue}T=t.call(i,n)}catch(A){T=[6,A],E=0}finally{f=o=0}if(T[0]&5)throw T[1];return{value:T[0]?T[1]:void 0,done:!0}}},h=q&&q.__importDefault||function(i){return i&&i.__esModule?i:{default:i}};Object.defineProperty(q,"__esModule",{value:!0}),q.useWebSocket=void 0;var v=I,_=et,S=$(),d=ct(),c=it(),l=h(st()),u=He(),a=function(i,t,n){t===void 0&&(t=S.DEFAULT_OPTIONS),n===void 0&&(n=!0);var f=(0,v.useState)(null),E=f[0],o=f[1],b=(0,v.useState)({}),m=b[0],D=b[1],T=(0,v.useMemo)(function(){if(!t.disableJson&&E)try{return JSON.parse(E.data)}catch{return S.UNPARSABLE_JSON_OBJECT}return null},[E,t.disableJson]),A=(0,v.useRef)(null),k=(0,v.useRef)(null),le=(0,v.useRef)(function(){}),fe=(0,v.useRef)(0),Ae=(0,v.useRef)(Date.now()),be=(0,v.useRef)([]),V=(0,v.useRef)(null),L=(0,v.useRef)(t);L.current=t;var G=A.current&&m[A.current]!==void 0?m[A.current]:i!==null&&n===!0?S.ReadyState.CONNECTING:S.ReadyState.UNINSTANTIATED,Z=t.queryParams?JSON.stringify(t.queryParams):null,H=(0,v.useCallback)(function(j,U){var Y;if(U===void 0&&(U=!0),S.isEventSourceSupported&&k.current instanceof EventSource){console.warn("Unable to send a message from an eventSource");return}((Y=k.current)===null||Y===void 0?void 0:Y.readyState)===S.ReadyState.OPEN?((0,u.assertIsWebSocket)(k.current,L.current.skipAssert),k.current.send(j)):U&&be.current.push(j)},[]),ye=(0,v.useCallback)(function(j,U){U===void 0&&(U=!0),H(JSON.stringify(j),U)},[H]),ge=(0,v.useCallback)(function(){return L.current.share!==!0||S.isEventSourceSupported&&k.current instanceof EventSource?k.current:(V.current===null&&k.current&&((0,u.assertIsWebSocket)(k.current,L.current.skipAssert),V.current=(0,l.default)(k.current,le)),V.current)},[]);return(0,v.useEffect)(function(){if(i!==null&&n===!0){var j,U=!1,Y=!0,ve=function(){return g(void 0,void 0,void 0,function(){var ee,X,Oe;return O(this,function(oe){switch(oe.label){case 0:return ee=A,[4,(0,c.getUrl)(i,L)];case 1:return ee.current=oe.sent(),A.current===null?(console.error("Failed to get a valid URL. WebSocket connection aborted."),A.current="ABORTED",(0,_.flushSync)(function(){return D(function(B){return r(r({},B),{ABORTED:S.ReadyState.CLOSED})})}),[2]):(X=function(B){U||(0,_.flushSync)(function(){return o(B)})},Oe=function(B){U||(0,_.flushSync)(function(){return D(function(ce){var re;return r(r({},ce),A.current&&(re={},re[A.current]=B,re))})})},Y&&(j=(0,d.createOrJoinSocket)(k,A.current,Oe,L,X,le,fe,Ae,H)),[2])}})})};return le.current=function(){U||(V.current&&(V.current=null),j?.(),ve())},ve(),function(){U=!0,Y=!1,V.current&&(V.current=null),j?.(),o(null)}}else(i===null||n===!1)&&(fe.current=0,D(function(ee){var X;return r(r({},ee),A.current&&(X={},X[A.current]=S.ReadyState.CLOSED,X))}))},[i,n,Z,H]),(0,v.useEffect)(function(){G===S.ReadyState.OPEN&&be.current.splice(0).forEach(function(j){H(j)})},[G]),{sendMessage:H,sendJsonMessage:ye,lastMessage:E,lastJsonMessage:T,readyState:G,getWebSocket:ge}};return q.useWebSocket=a,q}var ue={},gr;function lt(){if(gr)return ue;gr=1;var r=ue&&ue.__assign||function(){return r=Object.assign||function(d){for(var c,l=1,u=arguments.length;l<u;l++){c=arguments[l];for(var a in c)Object.prototype.hasOwnProperty.call(c,a)&&(d[a]=c[a])}return d},r.apply(this,arguments)};Object.defineProperty(ue,"__esModule",{value:!0}),ue.useSocketIO=void 0;var g=I,O=Ye(),h=$(),v={type:"empty",payload:null},_=function(d){if(!d||!d.data)return v;var c=d.data.match(/\[.*]/);if(!c)return v;var l=JSON.parse(c);return!Array.isArray(l)||!l[1]?v:{type:l[0],payload:l[1]}},S=function(d,c,l){c===void 0&&(c=h.DEFAULT_OPTIONS),l===void 0&&(l=!0);var u=(0,g.useMemo)(function(){return r(r({},c),{fromSocketIO:!0})},[]),a=(0,O.useWebSocket)(d,u,l),i=a.sendMessage,t=a.sendJsonMessage,n=a.lastMessage,f=a.readyState,E=a.getWebSocket,o=(0,g.useMemo)(function(){return _(n)},[n]);return{sendMessage:i,sendJsonMessage:t,lastMessage:o,lastJsonMessage:o,readyState:f,getWebSocket:E}};return ue.useSocketIO=S,ue}var Q={},Or;function ft(){if(Or)return Q;Or=1;var r=Q&&Q.__assign||function(){return r=Object.assign||function(S){for(var d,c=1,l=arguments.length;c<l;c++){d=arguments[c];for(var u in d)Object.prototype.hasOwnProperty.call(d,u)&&(S[u]=d[u])}return S},r.apply(this,arguments)},g=Q&&Q.__rest||function(S,d){var c={};for(var l in S)Object.prototype.hasOwnProperty.call(S,l)&&d.indexOf(l)<0&&(c[l]=S[l]);if(S!=null&&typeof Object.getOwnPropertySymbols=="function")for(var u=0,l=Object.getOwnPropertySymbols(S);u<l.length;u++)d.indexOf(l[u])<0&&Object.prototype.propertyIsEnumerable.call(S,l[u])&&(c[l[u]]=S[l[u]]);return c};Object.defineProperty(Q,"__esModule",{value:!0}),Q.useEventSource=void 0;var O=I,h=Ye(),v=$(),_=function(S,d,c){d===void 0&&(d=v.DEFAULT_EVENT_SOURCE_OPTIONS);var l=d.withCredentials,u=d.events,a=g(d,["withCredentials","events"]);c===void 0&&(c=!0);var i=r(r({},a),{eventSourceOptions:{withCredentials:l}}),t=(0,O.useRef)(v.EMPTY_EVENT_HANDLERS);u&&(t.current=u);var n=(0,h.useWebSocket)(S,i,c),f=n.lastMessage,E=n.readyState,o=n.getWebSocket;return(0,O.useEffect)(function(){f?.type&&Object.entries(t.current).forEach(function(b){var m=b[0],D=b[1];m===f.type&&D(f)})},[f]),{lastEvent:f,readyState:E,getEventSource:o}};return Q.useEventSource=_,Q}var pr;function vt(){return pr||(pr=1,(function(r){Object.defineProperty(r,"__esModule",{value:!0}),r.resetGlobalState=r.useEventSource=r.ReadyState=r.useSocketIO=r.default=void 0;var g=Ye();Object.defineProperty(r,"default",{enumerable:!0,get:function(){return g.useWebSocket}});var O=lt();Object.defineProperty(r,"useSocketIO",{enumerable:!0,get:function(){return O.useSocketIO}});var h=$();Object.defineProperty(r,"ReadyState",{enumerable:!0,get:function(){return h.ReadyState}});var v=ft();Object.defineProperty(r,"useEventSource",{enumerable:!0,get:function(){return v.useEventSource}});var _=He();Object.defineProperty(r,"resetGlobalState",{enumerable:!0,get:function(){return _.resetGlobalState}})})(De)),De}var dt=vt();const _t=at(dt),z={DEPOSIT:"deposit",TRANS_CODE:"transCode",ERROR:"error",UPDATE_MEMBER:"update_member",MAINTAIN_NOTICE:"maintain_notice",MAINTAIN_NOTICE_MEMBER:"maintain_notice_member",RELOAD:"reload",TRANSFER_IN_GAME:"transfer_in_game",CHECK_REQUEST:"CHECK_RREQUEST"},Et=3e4,St=({socketUrl:r,socketHandlers:g={},options:O={}})=>{const h=I.useRef(!1),v=I.useRef(g);I.useEffect(()=>{v.current=g},[g]);const{sendMessage:_,sendJsonMessage:S,lastMessage:d,readyState:c}=_t(r,{queryParams:{key:"wsky"},onOpen:()=>console.log("連線成功"),shouldReconnect:()=>h.current===!1,reconnectAttempts:9999,reconnectInterval:1e3,...O}),l=I.useMemo(()=>{try{return JSON.parse(d?.data)}catch{return null}},[d?.data]);return I.useEffect(()=>{const u=setInterval(()=>_("ping"),Et);return()=>clearInterval(u)},[_]),I.useEffect(()=>{if(!l)return;const{onDeposit:u,onTransCode:a,onError:i,onUpdateMember:t,onMaintainNotice:n,onMaintainNoticeMember:f,onReload:E,onTransferInGame:o}=v.current,b=Ce.get(l,"type",""),m={memberInfoUid:Ce.get(l,"member_info_uid",null),data:Ce.get(l,"data",null),memo:Ce.get(l,"memo",null)};switch(b){case z.DEPOSIT:u?.(m);break;case z.TRANS_CODE:a?.(m);break;case z.ERROR:i?.(m);break;case z.UPDATE_MEMBER:t?.(m);break;case z.MAINTAIN_NOTICE:n?.(m);break;case z.MAINTAIN_NOTICE_MEMBER:f?.(m);break;case z.RELOAD:E?.(m);break;case z.TRANSFER_IN_GAME:case z.CHECK_REQUEST:o?.(m);break;default:console.warn("Unknown socket type:",b);break}},[l]),I.useEffect(()=>()=>h.current=!0,[]),{sendMessage:_,sendJsonMessage:S,readyState:c}};var we={exports:{}},Se={};/**
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Fe=require("@tanstack/react-query"),I=require("react"),Zr=require("axios"),Ce=require("lodash"),et=require("react-dom"),qe=I.createContext(null),Je=()=>{const r=I.useContext(qe);if(!r)throw new Error("useApiContext must be used within ApiProvider");return r};function rt({baseURL:r,getToken:g,timeoutMs:O=15e3,currency:h="TWD",lng:v="tw",onError:_}={}){const S=Zr.create({baseURL:r,timeout:O,headers:{"Content-Type":"application/json"}});return S.interceptors.request.use(async d=>{if(d.headers=d.headers||{},g){const c=await g();c&&(d.headers.Authorization=`Bearer ${c}`)}return d.headers.Currency=h,d.headers["currency-code"]=h,d.headers.lang=v,d}),S.interceptors.response.use(d=>d.data,d=>_?_(d,{instance:S}):Promise.reject(d)),S}const tt=()=>{const{client:r}=Je(),g=I.useCallback(async S=>{const{mac_address:d="",app_version:c="",anydesk_id:l=""}=S,{data:u}=await r.post("/cash-register/login",{mac_address:d,app_version:c,anydesk_id:l});return u},[r]),O=I.useCallback(async()=>r.get("/member/getMemberInfo"),[r]),h=I.useCallback(async()=>{const{data:S}=await r.get("/getGameList");return S},[r]),v=I.useCallback(async()=>{const{data:S}=await r.get("/getNowCurrencyExchange");return S},[r]),_=I.useCallback(async()=>{const{data:S}=await r.get("/getFavoriteGame");return S},[r]);return{machineLoginApi:g,userInfoApi:O,userGameListApi:h,userFavoriteGameApi:_,userCurrencyExchangeApi:v}},nt=()=>{const{getToken:r}=Je(),{userInfoApi:g}=tt(),O=Fe.useQueries({queries:[{queryKey:["getMemberInfo"],queryFn:async()=>await g(),refetchInterval:5e4}],enabled:!!r}),{data:h,isFetching:v,error:_}=O[0]||{};return{data:h,isFetching:v,error:_}};function at(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}var De={},q={},je={},ir;function $(){return ir||(ir=1,(function(r){Object.defineProperty(r,"__esModule",{value:!0}),r.isEventSourceSupported=r.isReactNative=r.ReadyState=r.DEFAULT_HEARTBEAT=r.UNPARSABLE_JSON_OBJECT=r.DEFAULT_RECONNECT_INTERVAL_MS=r.DEFAULT_RECONNECT_LIMIT=r.SOCKET_IO_PING_CODE=r.SOCKET_IO_PATH=r.SOCKET_IO_PING_INTERVAL=r.DEFAULT_EVENT_SOURCE_OPTIONS=r.EMPTY_EVENT_HANDLERS=r.DEFAULT_OPTIONS=void 0;var g=1,O=1e3*g;r.DEFAULT_OPTIONS={},r.EMPTY_EVENT_HANDLERS={},r.DEFAULT_EVENT_SOURCE_OPTIONS={withCredentials:!1,events:r.EMPTY_EVENT_HANDLERS},r.SOCKET_IO_PING_INTERVAL=25*O,r.SOCKET_IO_PATH="/socket.io/?EIO=3&transport=websocket",r.SOCKET_IO_PING_CODE="2",r.DEFAULT_RECONNECT_LIMIT=20,r.DEFAULT_RECONNECT_INTERVAL_MS=5e3,r.UNPARSABLE_JSON_OBJECT={},r.DEFAULT_HEARTBEAT={message:"ping",timeout:6e4,interval:25e3};var h;(function(_){_[_.UNINSTANTIATED=-1]="UNINSTANTIATED",_[_.CONNECTING=0]="CONNECTING",_[_.OPEN=1]="OPEN",_[_.CLOSING=2]="CLOSING",_[_.CLOSED=3]="CLOSED"})(h||(r.ReadyState=h={}));var v=function(){try{return"EventSource"in globalThis}catch{return!1}};r.isReactNative=typeof navigator<"u"&&navigator.product==="ReactNative",r.isEventSourceSupported=!r.isReactNative&&v()})(je)),je}var _e={},Le={},sr;function Ge(){return sr||(sr=1,(function(r){Object.defineProperty(r,"__esModule",{value:!0}),r.resetWebSockets=r.sharedWebSockets=void 0,r.sharedWebSockets={};var g=function(O){if(O&&r.sharedWebSockets.hasOwnProperty(O))delete r.sharedWebSockets[O];else for(var h in r.sharedWebSockets)r.sharedWebSockets.hasOwnProperty(h)&&delete r.sharedWebSockets[h]};r.resetWebSockets=g})(Le)),Le}var ne={},K={},lr;function Ve(){if(lr)return K;lr=1,Object.defineProperty(K,"__esModule",{value:!0}),K.setUpSocketIOPing=K.appendQueryParams=K.parseSocketIOUrl=void 0;var r=$(),g=function(v){if(v){var _=/^https|wss/.test(v),S=v.replace(/^(https?|wss?)(:\/\/)?/,""),d=S.replace(/\/$/,""),c=_?"wss":"ws";return"".concat(c,"://").concat(d).concat(r.SOCKET_IO_PATH)}else if(v===""){var _=/^https/.test(window.location.protocol),c=_?"wss":"ws",l=window.location.port?":".concat(window.location.port):"";return"".concat(c,"://").concat(window.location.hostname).concat(l).concat(r.SOCKET_IO_PATH)}return v};K.parseSocketIOUrl=g;var O=function(v,_){_===void 0&&(_={});var S=/\?([\w]+=[\w]+)/,d=S.test(v),c="".concat(Object.entries(_).reduce(function(l,u){var a=u[0],i=u[1];return l+"".concat(a,"=").concat(i,"&")},"").slice(0,-1));return"".concat(v).concat(d?"&":"?").concat(c)};K.appendQueryParams=O;var h=function(v,_){_===void 0&&(_=r.SOCKET_IO_PING_INTERVAL);var S=function(){return v(r.SOCKET_IO_PING_CODE)};return window.setInterval(S,_)};return K.setUpSocketIOPing=h,K}var Re={},fr;function wr(){if(fr)return Re;fr=1,Object.defineProperty(Re,"__esModule",{value:!0}),Re.heartbeat=O;var r=$();function g(h){return Array.isArray(h)?h.reduce(function(v,_){return v.current>_.current?v:_}).current:h.current}function O(h,v,_){var S=_||{},d=S.interval,c=d===void 0?r.DEFAULT_HEARTBEAT.interval:d,l=S.timeout,u=l===void 0?r.DEFAULT_HEARTBEAT.timeout:l,a=S.message,i=a===void 0?r.DEFAULT_HEARTBEAT.message:a,t=Math.max(100,c/10),n=Date.now(),f=setInterval(function(){var E=Date.now(),o=g(v);if(o+u<=E)console.warn("Heartbeat timed out, closing connection, last message received ".concat(E-o,"ms ago, last ping sent ").concat(E-n,"ms ago")),h.close();else if(o+c<=E&&n+c<=E)try{typeof i=="function"?h.send(i()):h.send(i),n=E}catch(b){console.error("Heartbeat failed, closing connection",b instanceof Error?b.message:b),h.close()}},t);return h.addEventListener("close",function(){clearInterval(f)}),function(){}}return Re}var Ee={},Ue={},vr;function $e(){return vr||(vr=1,(function(r){Object.defineProperty(r,"__esModule",{value:!0}),r.resetSubscribers=r.removeSubscriber=r.addSubscriber=r.hasSubscribers=r.getSubscribers=void 0;var g={},O=[],h=function(c){return(0,r.hasSubscribers)(c)?Array.from(g[c]):O};r.getSubscribers=h;var v=function(c){var l;return((l=g[c])===null||l===void 0?void 0:l.size)>0};r.hasSubscribers=v;var _=function(c,l){g[c]=g[c]||new Set,g[c].add(l)};r.addSubscriber=_;var S=function(c,l){g[c].delete(l)};r.removeSubscriber=S;var d=function(c){if(c&&g.hasOwnProperty(c))delete g[c];else for(var l in g)g.hasOwnProperty(l)&&delete g[l]};r.resetSubscribers=d})(Ue)),Ue}var dr;function He(){if(dr)return Ee;dr=1,Object.defineProperty(Ee,"__esModule",{value:!0}),Ee.assertIsWebSocket=O,Ee.resetGlobalState=h;var r=Ge(),g=$e();function O(v,_){if(!_&&!(v instanceof WebSocket))throw new Error("")}function h(v){(0,g.resetSubscribers)(v),(0,r.resetWebSockets)(v)}return Ee}var _r;function ut(){if(_r)return ne;_r=1;var r=ne&&ne.__assign||function(){return r=Object.assign||function(u){for(var a,i=1,t=arguments.length;i<t;i++){a=arguments[i];for(var n in a)Object.prototype.hasOwnProperty.call(a,n)&&(u[n]=a[n])}return u},r.apply(this,arguments)};Object.defineProperty(ne,"__esModule",{value:!0}),ne.attachListeners=void 0;var g=Ve(),O=wr(),h=$(),v=He(),_=function(u,a,i,t){u.onmessage=function(n){var f;a.current.onMessage&&a.current.onMessage(n),typeof t?.current=="number"&&(t.current=Date.now()),!(typeof a.current.filter=="function"&&a.current.filter(n)!==!0)&&(a.current.heartbeat&&typeof a.current.heartbeat!="boolean"&&((f=a.current.heartbeat)===null||f===void 0?void 0:f.returnMessage)===n.data||i(n))}},S=function(u,a,i,t,n){u.onopen=function(f){if(a.current.onOpen&&a.current.onOpen(f),t.current=0,i(h.ReadyState.OPEN),a.current.heartbeat&&u instanceof WebSocket){var E=typeof a.current.heartbeat=="boolean"?void 0:a.current.heartbeat;n.current=Date.now(),(0,O.heartbeat)(u,n,E)}}},d=function(u,a,i,t,n){if(h.isEventSourceSupported&&u instanceof EventSource)return function(){};(0,v.assertIsWebSocket)(u,a.current.skipAssert);var f;return u.onclose=function(E){var o;if(a.current.onClose&&a.current.onClose(E),i(h.ReadyState.CLOSED),a.current.shouldReconnect&&a.current.shouldReconnect(E)){var b=(o=a.current.reconnectAttempts)!==null&&o!==void 0?o:h.DEFAULT_RECONNECT_LIMIT;if(n.current<b){var m=typeof a.current.reconnectInterval=="function"?a.current.reconnectInterval(n.current):a.current.reconnectInterval;f=window.setTimeout(function(){n.current++,t()},m??h.DEFAULT_RECONNECT_INTERVAL_MS)}else a.current.onReconnectStop&&a.current.onReconnectStop(b),console.warn("Max reconnect attempts of ".concat(b," exceeded"))}},function(){return f&&window.clearTimeout(f)}},c=function(u,a,i,t,n){var f;return u.onerror=function(E){var o;if(a.current.onError&&a.current.onError(E),h.isEventSourceSupported&&u instanceof EventSource&&(a.current.onClose&&a.current.onClose(r(r({},E),{code:1006,reason:"An error occurred with the EventSource: ".concat(E),wasClean:!1})),i(h.ReadyState.CLOSED),u.close()),a.current.retryOnError)if(n.current<((o=a.current.reconnectAttempts)!==null&&o!==void 0?o:h.DEFAULT_RECONNECT_LIMIT)){var b=typeof a.current.reconnectInterval=="function"?a.current.reconnectInterval(n.current):a.current.reconnectInterval;f=window.setTimeout(function(){n.current++,t()},b??h.DEFAULT_RECONNECT_INTERVAL_MS)}else a.current.onReconnectStop&&a.current.onReconnectStop(a.current.reconnectAttempts),console.warn("Max reconnect attempts of ".concat(a.current.reconnectAttempts," exceeded"))},function(){return f&&window.clearTimeout(f)}},l=function(u,a,i,t,n,f,E){var o=a.setLastMessage,b=a.setReadyState,m,D,T;return i.current.fromSocketIO&&(m=(0,g.setUpSocketIOPing)(E)),_(u,i,o,f),S(u,i,b,n,f),D=d(u,i,b,t,n),T=c(u,i,b,t,n),function(){b(h.ReadyState.CLOSING),D(),T(),u.close(),m&&clearInterval(m)}};return ne.attachListeners=l,ne}var ae={},Er;function ot(){if(Er)return ae;Er=1;var r=ae&&ae.__assign||function(){return r=Object.assign||function(a){for(var i,t=1,n=arguments.length;t<n;t++){i=arguments[t];for(var f in i)Object.prototype.hasOwnProperty.call(i,f)&&(a[f]=i[f])}return a},r.apply(this,arguments)};Object.defineProperty(ae,"__esModule",{value:!0}),ae.attachSharedListeners=void 0;var g=Ge(),O=$(),h=$e(),v=Ve(),_=wr(),S=function(a,i,t){a.onmessage=function(n){(0,h.getSubscribers)(i).forEach(function(f){var E;f.optionsRef.current.onMessage&&f.optionsRef.current.onMessage(n),typeof((E=f?.lastMessageTime)===null||E===void 0?void 0:E.current)=="number"&&(f.lastMessageTime.current=Date.now()),!(typeof f.optionsRef.current.filter=="function"&&f.optionsRef.current.filter(n)!==!0)&&(t&&typeof t!="boolean"&&t?.returnMessage===n.data||f.setLastMessage(n))})}},d=function(a,i,t){a.onopen=function(n){var f=(0,h.getSubscribers)(i);f.forEach(function(E){E.reconnectCount.current=0,E.optionsRef.current.onOpen&&E.optionsRef.current.onOpen(n),E.setReadyState(O.ReadyState.OPEN),t&&a instanceof WebSocket&&(E.lastMessageTime.current=Date.now())}),t&&a instanceof WebSocket&&(0,_.heartbeat)(a,f.map(function(E){return E.lastMessageTime}),typeof t=="boolean"?void 0:t)}},c=function(a,i){a instanceof WebSocket&&(a.onclose=function(t){(0,h.getSubscribers)(i).forEach(function(n){n.optionsRef.current.onClose&&n.optionsRef.current.onClose(t),n.setReadyState(O.ReadyState.CLOSED)}),delete g.sharedWebSockets[i],(0,h.getSubscribers)(i).forEach(function(n){var f;if(n.optionsRef.current.shouldReconnect&&n.optionsRef.current.shouldReconnect(t)){var E=(f=n.optionsRef.current.reconnectAttempts)!==null&&f!==void 0?f:O.DEFAULT_RECONNECT_LIMIT;if(n.reconnectCount.current<E){var o=typeof n.optionsRef.current.reconnectInterval=="function"?n.optionsRef.current.reconnectInterval(n.reconnectCount.current):n.optionsRef.current.reconnectInterval;setTimeout(function(){n.reconnectCount.current++,n.reconnect.current()},o??O.DEFAULT_RECONNECT_INTERVAL_MS)}else n.optionsRef.current.onReconnectStop&&n.optionsRef.current.onReconnectStop(n.optionsRef.current.reconnectAttempts),console.warn("Max reconnect attempts of ".concat(E," exceeded"))}})})},l=function(a,i){a.onerror=function(t){(0,h.getSubscribers)(i).forEach(function(n){n.optionsRef.current.onError&&n.optionsRef.current.onError(t),O.isEventSourceSupported&&a instanceof EventSource&&(n.optionsRef.current.onClose&&n.optionsRef.current.onClose(r(r({},t),{code:1006,reason:"An error occurred with the EventSource: ".concat(t),wasClean:!1})),n.setReadyState(O.ReadyState.CLOSED))}),O.isEventSourceSupported&&a instanceof EventSource&&a.close()}},u=function(a,i,t,n){var f;return t.current.fromSocketIO&&(f=(0,v.setUpSocketIOPing)(n)),S(a,i,t.current.heartbeat),c(a,i),d(a,i,t.current.heartbeat),l(a,i),function(){f&&clearInterval(f)}};return ae.attachSharedListeners=u,ae}var Sr;function ct(){if(Sr)return _e;Sr=1,Object.defineProperty(_e,"__esModule",{value:!0}),_e.createOrJoinSocket=void 0;var r=Ge(),g=$(),O=ut(),h=ot(),v=$e(),_=function(d,c,l,u,a){return function(){if((0,v.removeSubscriber)(d,c),!(0,v.hasSubscribers)(d)){try{var i=r.sharedWebSockets[d];i instanceof WebSocket&&(i.onclose=function(t){l.current.onClose&&l.current.onClose(t),u(g.ReadyState.CLOSED)}),i.close()}catch{}a&&a(),delete r.sharedWebSockets[d]}}},S=function(d,c,l,u,a,i,t,n,f){if(!g.isEventSourceSupported&&u.current.eventSourceOptions)throw g.isReactNative?new Error("EventSource is not supported in ReactNative"):new Error("EventSource is not supported");if(u.current.share){var E=null;r.sharedWebSockets[c]===void 0?(r.sharedWebSockets[c]=u.current.eventSourceOptions?new EventSource(c,u.current.eventSourceOptions):new WebSocket(c,u.current.protocols),d.current=r.sharedWebSockets[c],l(g.ReadyState.CONNECTING),E=(0,h.attachSharedListeners)(r.sharedWebSockets[c],c,u,f)):(d.current=r.sharedWebSockets[c],l(r.sharedWebSockets[c].readyState));var o={setLastMessage:a,setReadyState:l,optionsRef:u,reconnectCount:t,lastMessageTime:n,reconnect:i};return(0,v.addSubscriber)(c,o),_(c,o,u,l,E)}else{if(d.current=u.current.eventSourceOptions?new EventSource(c,u.current.eventSourceOptions):new WebSocket(c,u.current.protocols),l(g.ReadyState.CONNECTING),!d.current)throw new Error("WebSocket failed to be created");return(0,O.attachListeners)(d.current,{setLastMessage:a,setReadyState:l},u,i.current,t,n,f)}};return _e.createOrJoinSocket=S,_e}var x={},hr;function it(){return hr||(hr=1,(function(r){var g=x&&x.__awaiter||function(c,l,u,a){function i(t){return t instanceof u?t:new u(function(n){n(t)})}return new(u||(u=Promise))(function(t,n){function f(b){try{o(a.next(b))}catch(m){n(m)}}function E(b){try{o(a.throw(b))}catch(m){n(m)}}function o(b){b.done?t(b.value):i(b.value).then(f,E)}o((a=a.apply(c,l||[])).next())})},O=x&&x.__generator||function(c,l){var u={label:0,sent:function(){if(t[0]&1)throw t[1];return t[1]},trys:[],ops:[]},a,i,t,n=Object.create((typeof Iterator=="function"?Iterator:Object).prototype);return n.next=f(0),n.throw=f(1),n.return=f(2),typeof Symbol=="function"&&(n[Symbol.iterator]=function(){return this}),n;function f(o){return function(b){return E([o,b])}}function E(o){if(a)throw new TypeError("Generator is already executing.");for(;n&&(n=0,o[0]&&(u=0)),u;)try{if(a=1,i&&(t=o[0]&2?i.return:o[0]?i.throw||((t=i.return)&&t.call(i),0):i.next)&&!(t=t.call(i,o[1])).done)return t;switch(i=0,t&&(o=[o[0]&2,t.value]),o[0]){case 0:case 1:t=o;break;case 4:return u.label++,{value:o[1],done:!1};case 5:u.label++,i=o[1],o=[0];continue;case 7:o=u.ops.pop(),u.trys.pop();continue;default:if(t=u.trys,!(t=t.length>0&&t[t.length-1])&&(o[0]===6||o[0]===2)){u=0;continue}if(o[0]===3&&(!t||o[1]>t[0]&&o[1]<t[3])){u.label=o[1];break}if(o[0]===6&&u.label<t[1]){u.label=t[1],t=o;break}if(t&&u.label<t[2]){u.label=t[2],u.ops.push(o);break}t[2]&&u.ops.pop(),u.trys.pop();continue}o=l.call(c,u)}catch(b){o=[6,b],i=0}finally{a=t=0}if(o[0]&5)throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}},h=x&&x.__spreadArray||function(c,l,u){if(u||arguments.length===2)for(var a=0,i=l.length,t;a<i;a++)(t||!(a in l))&&(t||(t=Array.prototype.slice.call(l,0,a)),t[a]=l[a]);return c.concat(t||Array.prototype.slice.call(l))};Object.defineProperty(r,"__esModule",{value:!0}),r.getUrl=void 0;var v=Ve(),_=$(),S=function(c){return new Promise(function(l){return window.setTimeout(l,c)})},d=function(c,l){for(var u=[],a=2;a<arguments.length;a++)u[a-2]=arguments[a];return g(void 0,h([c,l],u,!0),void 0,function(i,t,n){var f,E,o,b,m,D,T,A;return n===void 0&&(n=0),O(this,function(k){switch(k.label){case 0:if(typeof i!="function")return[3,10];k.label=1;case 1:return k.trys.push([1,3,,9]),[4,i()];case 2:return f=k.sent(),[3,9];case 3:return k.sent(),t.current.retryOnError?(E=(D=t.current.reconnectAttempts)!==null&&D!==void 0?D:_.DEFAULT_RECONNECT_LIMIT,n<E?(o=typeof t.current.reconnectInterval=="function"?t.current.reconnectInterval(n):t.current.reconnectInterval,[4,S(o??_.DEFAULT_RECONNECT_INTERVAL_MS)]):[3,5]):[3,7];case 4:return k.sent(),[2,(0,r.getUrl)(i,t,n+1)];case 5:return(A=(T=t.current).onReconnectStop)===null||A===void 0||A.call(T,n),[2,null];case 6:return[3,8];case 7:return[2,null];case 8:return[3,9];case 9:return[3,11];case 10:f=i,k.label=11;case 11:return b=t.current.fromSocketIO?(0,v.parseSocketIOUrl)(f):f,m=t.current.queryParams?(0,v.appendQueryParams)(b,t.current.queryParams):b,[2,m]}})})};r.getUrl=d})(x)),x}var We={},br;function st(){return br||(br=1,(function(r){Object.defineProperty(r,"__esModule",{value:!0}),r.websocketWrapper=void 0;var g=function(O,h){return new Proxy(O,{get:function(v,_){var S=v[_];return _==="reconnect"?h:typeof S=="function"?(console.error("Calling methods directly on the websocket is not supported at this moment. You must use the methods returned by useWebSocket."),function(){}):S},set:function(v,_,S){return/^on/.test(_)?(console.warn("The websocket's event handlers should be defined through the options object passed into useWebSocket."),!1):(v[_]=S,!0)}})};r.websocketWrapper=g,r.default=r.websocketWrapper})(We)),We}var yr;function Ye(){if(yr)return q;yr=1;var r=q&&q.__assign||function(){return r=Object.assign||function(i){for(var t,n=1,f=arguments.length;n<f;n++){t=arguments[n];for(var E in t)Object.prototype.hasOwnProperty.call(t,E)&&(i[E]=t[E])}return i},r.apply(this,arguments)},g=q&&q.__awaiter||function(i,t,n,f){function E(o){return o instanceof n?o:new n(function(b){b(o)})}return new(n||(n=Promise))(function(o,b){function m(A){try{T(f.next(A))}catch(k){b(k)}}function D(A){try{T(f.throw(A))}catch(k){b(k)}}function T(A){A.done?o(A.value):E(A.value).then(m,D)}T((f=f.apply(i,t||[])).next())})},O=q&&q.__generator||function(i,t){var n={label:0,sent:function(){if(o[0]&1)throw o[1];return o[1]},trys:[],ops:[]},f,E,o,b=Object.create((typeof Iterator=="function"?Iterator:Object).prototype);return b.next=m(0),b.throw=m(1),b.return=m(2),typeof Symbol=="function"&&(b[Symbol.iterator]=function(){return this}),b;function m(T){return function(A){return D([T,A])}}function D(T){if(f)throw new TypeError("Generator is already executing.");for(;b&&(b=0,T[0]&&(n=0)),n;)try{if(f=1,E&&(o=T[0]&2?E.return:T[0]?E.throw||((o=E.return)&&o.call(E),0):E.next)&&!(o=o.call(E,T[1])).done)return o;switch(E=0,o&&(T=[T[0]&2,o.value]),T[0]){case 0:case 1:o=T;break;case 4:return n.label++,{value:T[1],done:!1};case 5:n.label++,E=T[1],T=[0];continue;case 7:T=n.ops.pop(),n.trys.pop();continue;default:if(o=n.trys,!(o=o.length>0&&o[o.length-1])&&(T[0]===6||T[0]===2)){n=0;continue}if(T[0]===3&&(!o||T[1]>o[0]&&T[1]<o[3])){n.label=T[1];break}if(T[0]===6&&n.label<o[1]){n.label=o[1],o=T;break}if(o&&n.label<o[2]){n.label=o[2],n.ops.push(T);break}o[2]&&n.ops.pop(),n.trys.pop();continue}T=t.call(i,n)}catch(A){T=[6,A],E=0}finally{f=o=0}if(T[0]&5)throw T[1];return{value:T[0]?T[1]:void 0,done:!0}}},h=q&&q.__importDefault||function(i){return i&&i.__esModule?i:{default:i}};Object.defineProperty(q,"__esModule",{value:!0}),q.useWebSocket=void 0;var v=I,_=et,S=$(),d=ct(),c=it(),l=h(st()),u=He(),a=function(i,t,n){t===void 0&&(t=S.DEFAULT_OPTIONS),n===void 0&&(n=!0);var f=(0,v.useState)(null),E=f[0],o=f[1],b=(0,v.useState)({}),m=b[0],D=b[1],T=(0,v.useMemo)(function(){if(!t.disableJson&&E)try{return JSON.parse(E.data)}catch{return S.UNPARSABLE_JSON_OBJECT}return null},[E,t.disableJson]),A=(0,v.useRef)(null),k=(0,v.useRef)(null),le=(0,v.useRef)(function(){}),fe=(0,v.useRef)(0),Ae=(0,v.useRef)(Date.now()),be=(0,v.useRef)([]),V=(0,v.useRef)(null),L=(0,v.useRef)(t);L.current=t;var G=A.current&&m[A.current]!==void 0?m[A.current]:i!==null&&n===!0?S.ReadyState.CONNECTING:S.ReadyState.UNINSTANTIATED,Z=t.queryParams?JSON.stringify(t.queryParams):null,H=(0,v.useCallback)(function(j,U){var Y;if(U===void 0&&(U=!0),S.isEventSourceSupported&&k.current instanceof EventSource){console.warn("Unable to send a message from an eventSource");return}((Y=k.current)===null||Y===void 0?void 0:Y.readyState)===S.ReadyState.OPEN?((0,u.assertIsWebSocket)(k.current,L.current.skipAssert),k.current.send(j)):U&&be.current.push(j)},[]),ye=(0,v.useCallback)(function(j,U){U===void 0&&(U=!0),H(JSON.stringify(j),U)},[H]),ge=(0,v.useCallback)(function(){return L.current.share!==!0||S.isEventSourceSupported&&k.current instanceof EventSource?k.current:(V.current===null&&k.current&&((0,u.assertIsWebSocket)(k.current,L.current.skipAssert),V.current=(0,l.default)(k.current,le)),V.current)},[]);return(0,v.useEffect)(function(){if(i!==null&&n===!0){var j,U=!1,Y=!0,ve=function(){return g(void 0,void 0,void 0,function(){var ee,X,Oe;return O(this,function(oe){switch(oe.label){case 0:return ee=A,[4,(0,c.getUrl)(i,L)];case 1:return ee.current=oe.sent(),A.current===null?(console.error("Failed to get a valid URL. WebSocket connection aborted."),A.current="ABORTED",(0,_.flushSync)(function(){return D(function(B){return r(r({},B),{ABORTED:S.ReadyState.CLOSED})})}),[2]):(X=function(B){U||(0,_.flushSync)(function(){return o(B)})},Oe=function(B){U||(0,_.flushSync)(function(){return D(function(ce){var re;return r(r({},ce),A.current&&(re={},re[A.current]=B,re))})})},Y&&(j=(0,d.createOrJoinSocket)(k,A.current,Oe,L,X,le,fe,Ae,H)),[2])}})})};return le.current=function(){U||(V.current&&(V.current=null),j?.(),ve())},ve(),function(){U=!0,Y=!1,V.current&&(V.current=null),j?.(),o(null)}}else(i===null||n===!1)&&(fe.current=0,D(function(ee){var X;return r(r({},ee),A.current&&(X={},X[A.current]=S.ReadyState.CLOSED,X))}))},[i,n,Z,H]),(0,v.useEffect)(function(){G===S.ReadyState.OPEN&&be.current.splice(0).forEach(function(j){H(j)})},[G]),{sendMessage:H,sendJsonMessage:ye,lastMessage:E,lastJsonMessage:T,readyState:G,getWebSocket:ge}};return q.useWebSocket=a,q}var ue={},gr;function lt(){if(gr)return ue;gr=1;var r=ue&&ue.__assign||function(){return r=Object.assign||function(d){for(var c,l=1,u=arguments.length;l<u;l++){c=arguments[l];for(var a in c)Object.prototype.hasOwnProperty.call(c,a)&&(d[a]=c[a])}return d},r.apply(this,arguments)};Object.defineProperty(ue,"__esModule",{value:!0}),ue.useSocketIO=void 0;var g=I,O=Ye(),h=$(),v={type:"empty",payload:null},_=function(d){if(!d||!d.data)return v;var c=d.data.match(/\[.*]/);if(!c)return v;var l=JSON.parse(c);return!Array.isArray(l)||!l[1]?v:{type:l[0],payload:l[1]}},S=function(d,c,l){c===void 0&&(c=h.DEFAULT_OPTIONS),l===void 0&&(l=!0);var u=(0,g.useMemo)(function(){return r(r({},c),{fromSocketIO:!0})},[]),a=(0,O.useWebSocket)(d,u,l),i=a.sendMessage,t=a.sendJsonMessage,n=a.lastMessage,f=a.readyState,E=a.getWebSocket,o=(0,g.useMemo)(function(){return _(n)},[n]);return{sendMessage:i,sendJsonMessage:t,lastMessage:o,lastJsonMessage:o,readyState:f,getWebSocket:E}};return ue.useSocketIO=S,ue}var Q={},Or;function ft(){if(Or)return Q;Or=1;var r=Q&&Q.__assign||function(){return r=Object.assign||function(S){for(var d,c=1,l=arguments.length;c<l;c++){d=arguments[c];for(var u in d)Object.prototype.hasOwnProperty.call(d,u)&&(S[u]=d[u])}return S},r.apply(this,arguments)},g=Q&&Q.__rest||function(S,d){var c={};for(var l in S)Object.prototype.hasOwnProperty.call(S,l)&&d.indexOf(l)<0&&(c[l]=S[l]);if(S!=null&&typeof Object.getOwnPropertySymbols=="function")for(var u=0,l=Object.getOwnPropertySymbols(S);u<l.length;u++)d.indexOf(l[u])<0&&Object.prototype.propertyIsEnumerable.call(S,l[u])&&(c[l[u]]=S[l[u]]);return c};Object.defineProperty(Q,"__esModule",{value:!0}),Q.useEventSource=void 0;var O=I,h=Ye(),v=$(),_=function(S,d,c){d===void 0&&(d=v.DEFAULT_EVENT_SOURCE_OPTIONS);var l=d.withCredentials,u=d.events,a=g(d,["withCredentials","events"]);c===void 0&&(c=!0);var i=r(r({},a),{eventSourceOptions:{withCredentials:l}}),t=(0,O.useRef)(v.EMPTY_EVENT_HANDLERS);u&&(t.current=u);var n=(0,h.useWebSocket)(S,i,c),f=n.lastMessage,E=n.readyState,o=n.getWebSocket;return(0,O.useEffect)(function(){f?.type&&Object.entries(t.current).forEach(function(b){var m=b[0],D=b[1];m===f.type&&D(f)})},[f]),{lastEvent:f,readyState:E,getEventSource:o}};return Q.useEventSource=_,Q}var pr;function vt(){return pr||(pr=1,(function(r){Object.defineProperty(r,"__esModule",{value:!0}),r.resetGlobalState=r.useEventSource=r.ReadyState=r.useSocketIO=r.default=void 0;var g=Ye();Object.defineProperty(r,"default",{enumerable:!0,get:function(){return g.useWebSocket}});var O=lt();Object.defineProperty(r,"useSocketIO",{enumerable:!0,get:function(){return O.useSocketIO}});var h=$();Object.defineProperty(r,"ReadyState",{enumerable:!0,get:function(){return h.ReadyState}});var v=ft();Object.defineProperty(r,"useEventSource",{enumerable:!0,get:function(){return v.useEventSource}});var _=He();Object.defineProperty(r,"resetGlobalState",{enumerable:!0,get:function(){return _.resetGlobalState}})})(De)),De}var dt=vt();const _t=at(dt),z={DEPOSIT:"deposit",TRANS_CODE:"transCode",ERROR:"error",UPDATE_MEMBER:"update_member",MAINTAIN_NOTICE:"maintain_notice",MAINTAIN_NOTICE_MEMBER:"maintain_notice_member",RELOAD:"reload",TRANSFER_IN_GAME:"transfer_in_game",CHECK_REQUEST:"CHECK_RREQUEST"},Et=3e4,St=({socketUrl:r,socketHandlers:g={},options:O={}})=>{const h=I.useRef(!1),v=I.useRef(g),{sendMessage:_,sendJsonMessage:S,lastMessage:d,readyState:c}=_t(r,{queryParams:{key:"wsky"},onOpen:()=>console.log("連線成功"),shouldReconnect:()=>h.current===!1,reconnectAttempts:9999,reconnectInterval:1e3,...O}),l=I.useMemo(()=>{try{return JSON.parse(d?.data)}catch{return null}},[d?.data]);return I.useEffect(()=>{const u=setInterval(()=>_("ping"),Et);return()=>clearInterval(u)},[_]),I.useEffect(()=>{v.current=g},[g]),I.useEffect(()=>{if(!l)return;const{onDeposit:u,onTransCode:a,onError:i,onUpdateMember:t,onMaintainNotice:n,onMaintainNoticeMember:f,onReload:E,onTransferInGame:o}=v.current,b=Ce.get(l,"type",""),m={memberInfoUid:Ce.get(l,"member_info_uid",null),data:Ce.get(l,"data",null),memo:Ce.get(l,"memo",null)};switch(b){case z.DEPOSIT:u?.(m);break;case z.TRANS_CODE:a?.(m);break;case z.ERROR:i?.(m);break;case z.UPDATE_MEMBER:t?.(m);break;case z.MAINTAIN_NOTICE:n?.(m);break;case z.MAINTAIN_NOTICE_MEMBER:f?.(m);break;case z.RELOAD:E?.(m);break;case z.TRANSFER_IN_GAME:case z.CHECK_REQUEST:o?.(m);break;default:console.warn("Unknown socket type:",b);break}},[l]),I.useEffect(()=>()=>h.current=!0,[]),{sendMessage:_,sendJsonMessage:S,readyState:c}};var we={exports:{}},Se={};/**
|
|
2
2
|
* @license React
|
|
3
3
|
* react-jsx-runtime.production.min.js
|
|
4
4
|
*
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useQueries as tt, QueryClient as nt, QueryClientProvider as at } from "@tanstack/react-query";
|
|
2
|
-
import ye, { createContext as ut, useContext as ot, useCallback as de, useRef as ir,
|
|
2
|
+
import ye, { createContext as ut, useContext as ot, useCallback as de, useRef as ir, useMemo as Je, useEffect as Ce } from "react";
|
|
3
3
|
import ct from "axios";
|
|
4
4
|
import { get as we } from "lodash";
|
|
5
5
|
import it from "react-dom";
|
|
@@ -873,17 +873,17 @@ const Ot = /* @__PURE__ */ ft(gt), Q = {
|
|
|
873
873
|
socketHandlers: g = {},
|
|
874
874
|
options: O = {}
|
|
875
875
|
}) => {
|
|
876
|
-
const h = ir(!1), v = ir(g)
|
|
877
|
-
Ce(() => {
|
|
878
|
-
v.current = g;
|
|
879
|
-
}, [g]);
|
|
880
|
-
const {
|
|
876
|
+
const h = ir(!1), v = ir(g), {
|
|
881
877
|
sendMessage: _,
|
|
878
|
+
// 發送普通訊息
|
|
882
879
|
sendJsonMessage: S,
|
|
880
|
+
// 發送 JSON 訊息
|
|
883
881
|
lastMessage: d,
|
|
884
|
-
//
|
|
882
|
+
// 最後接收到的訊息
|
|
883
|
+
// lastJsonMessage, // 最後接收到的 JSON 訊息
|
|
885
884
|
readyState: c
|
|
886
|
-
//
|
|
885
|
+
// WebSocket 連線狀態
|
|
886
|
+
// getWebSocket, // 獲取 WebSocket 實例
|
|
887
887
|
} = Ot(r, {
|
|
888
888
|
queryParams: { key: "wsky" },
|
|
889
889
|
onOpen: () => console.log("連線成功"),
|
|
@@ -905,6 +905,8 @@ const Ot = /* @__PURE__ */ ft(gt), Q = {
|
|
|
905
905
|
);
|
|
906
906
|
return () => clearInterval(u);
|
|
907
907
|
}, [_]), Ce(() => {
|
|
908
|
+
v.current = g;
|
|
909
|
+
}, [g]), Ce(() => {
|
|
908
910
|
if (!l) return;
|
|
909
911
|
const {
|
|
910
912
|
onDeposit: u,
|