This repository has been archived on 2024-10-30. You can view files and clone it, but cannot push or open issues or pull requests.
rage-framework-rpc/dist/rage-rpc.min.js

1 line
7.1 KiB
JavaScript
Raw Normal View History

2019-03-06 16:35:39 +00:00
!function(e,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define([],r):"object"==typeof exports?exports=r():e.rpc=r()}("undefined"!=typeof self?self:this,function(){return function(e){var r={};function n(t){if(r[t])return r[t].exports;var o=r[t]={i:t,l:!1,exports:{}};return e[t].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=r,n.d=function(e,r,t){n.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:t})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,r){if(1&r&&(e=n(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(n.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var o in e)n.d(t,o,function(r){return e[r]}.bind(null,o));return t},n.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(r,"a",r),r},n.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},n.p="",n(n.s=1)}([function(e,r,n){"use strict";function t(){const e=46656*Math.random()|0,r=46656*Math.random()|0;return("000"+e.toString(36)).slice(-3)+("000"+r.toString(36)).slice(-3)}function o(){return mp.joaat?"server":mp.game&&mp.game.joaat?"client":mp.trigger?"cef":void 0}function c(e){return JSON.stringify(e)}function s(e){return JSON.parse(e)}function i(e){return new Promise(r=>setTimeout(()=>r(e),0))}function u(e){return new Promise((r,n)=>setTimeout(()=>n(e),0))}function a(e){try{e.url}catch(e){return!1}return!0}n.d(r,"g",function(){return t}),n.d(r,"a",function(){return o}),n.d(r,"f",function(){return c}),n.d(r,"c",function(){return s}),n.d(r,"e",function(){return i}),n.d(r,"d",function(){return u}),n.d(r,"b",function(){return a})},function(e,r,n){"use strict";n.r(r),function(e){n.d(r,"register",function(){return p}),n.d(r,"unregister",function(){return g}),n.d(r,"call",function(){return m}),n.d(r,"callServer",function(){return v}),n.d(r,"callClient",function(){return w}),n.d(r,"callBrowsers",function(){return y}),n.d(r,"callBrowser",function(){return P});var t=n(0);const o=t.a();if(!o)throw"Unknown RAGE environment";const c="PROCEDURE_NOT_FOUND",s="__rpc:id",i="__rpc:process",u="__rpc:browserRegister",a="__rpc:browserUnregister",l="cef"===o?window:e;if(!l[i])if(l.__rpcListeners={},l.__rpcPending={},l[i]=((e,r)=>{"server"!==o&&(r=e);const n=t.c(r);if(n.req){const r={id:n.id,environment:n.fenv||n.env};"server"===o&&(r.player=e);const c=d(n.name,n.args,r),s={ret:1,id:n.id,env:o};let u;switch(o){case"server":u=(e=>r.player.call(i,[t.f(e)]));break;case"client":if("server"===n.env)u=(e=>mp.events.callRemote(i,t.f(e)));else if("cef"===n.env){const e=n.b&&l.__rpcBrowsers[n.b];u=(r=>e&&t.b(e)&&f(e,r,!0))}break;case"cef":u=(e=>mp.trigger(i,t.f(e)))}u&&c.then(e=>u({...s,res:e})).catch(e=>u({...s,err:e}))}else if(n.ret){const r=l.__rpcPending[n.id];if("server"===o&&r.player!==e)return;r&&(r.resolve(n.err?t.d(n.err):t.e(n.res)),delete l.__rpcPending[n.id])}}),"cef"!==o){if(mp.events.add(i,l[i]),"client"===o){p("__rpc:callServer",([e,r],n)=>_(e,r,{fenv:n.environment})),p("__rpc:callBrowsers",([e,r],n)=>b(null,e,r,{fenv:n.environment})),l.__rpcBrowsers={};const e=e=>{const r=t.g();Object.keys(l.__rpcBrowsers).forEach(r=>{const n=l.__rpcBrowsers[r];n&&t.b(n)&&n!==e||delete l.__rpcBrowsers[r]}),l.__rpcBrowsers[r]=e,e.execute(`if(typeof window['${s}'] === 'undefined'){ window['${s}'] = Promise.resolve('${r}'); }else{ window['${s}:resolve']('${r}'); }`)};mp.browsers.forEach(e),mp.events.add("browserCreated",e),l.__rpcBrowserProcedures={},mp.events.add(u,e=>{const[r,n]=JSON.parse(e);l.__rpcBrowserProcedures[n]=r}),mp.events.add(a,e=>{const[r,n]=JSON.parse(e);l.__rpcBrowserProcedures[n]===r&&delete l.__rpcBrowserProcedures[n]})}}else void 0===l[s]&&(l[s]=new Promise(e=>{l[s+":resolve"]=e}));function f(e,r,n){const o=t.f(r).replace(/'/g,"\\'");e.execute(`var process = window["${i}"]; if(process){ process('${o}'); }