2018-11-02 05:29:47 +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.rpc=r():e.rpc=r()}("undefined"!=typeof self?self:this,function(){return function(e){var r={};function t(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,t),o.l=!0,o.exports}return t.m=e,t.c=r,t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:n})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,r){if(1&r&&(e=t(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(t.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var o in e)t.d(n,o,function(r){return e[r]}.bind(null,o));return n},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},t.p="",t(t.s=0)}([function(e,r,t){"use strict";function n(){let e=46656*Math.random()|0,r=46656*Math.random()|0;return(e=("000"+e.toString(36)).slice(-3))+(r=("000"+r.toString(36)).slice(-3))}function o(e){return JSON.stringify(e)}t.r(r),t.d(r,"register",function(){return d}),t.d(r,"unregister",function(){return v}),t.d(r,"call",function(){return h}),t.d(r,"callServer",function(){return b}),t.d(r,"callClient",function(){return y}),t.d(r,"callBrowsers",function(){return _}),t.d(r,"callBrowser",function(){return P});const c=function(){if(mp)return mp.joaat?"server":mp.game&&mp.game.joaat?"client":mp.trigger?"cef":void 0}();if(!c)throw"Unknown RAGE environment";const s="PROCEDURE_NOT_FOUND",i="__rpc:process",a="__rpc:exists",l={},u={};let f,m;async function p(e,r,t){if(!l[e])throw s;return l[e](r,t)}"client"===c&&(f=((e,r)=>{const t=o(r);e.execute(`var process = window["${i}"]; if(process){ process('${t}'); }else{ mp.trigger("${i}", '{"ret":1,"id":"${r.id}","err":"${s}"}'); }`)}),m=(e=>{mp.browsers.forEach(r=>f(r,e))}));const g=(...e)=>{let r=e[0];"server"===c&&(r=e[1]);const t=function(e){return JSON.parse(e)}(r);if(t.req){const r={id:t.id,environment:t.fenv||t.env};"server"===c&&(r.player=e[0]);const n=p(t.name,t.args,r),s={ret:1,id:t.id};switch(c){case"server":n.then(e=>{r.player.call(i,[o({...s,res:e})])}).catch(e=>{r.player.call(i,[o({...s,err:e})])});break;case"client":"server"===t.env?n.then(e=>{mp.events.callRemote(i,o({...s,res:e}))}).catch(e=>{mp.events.callRemote(i,o({...s,err:e}))}):"cef"===t.env&&n.then(e=>{m({...s,res:e})}).catch(e=>{m({...s,err:e})});break;case"cef":n.then(e=>{mp.trigger(i,o({...s,res:e}))}).catch(e=>{mp.trigger(i,o({...s,err:e}))})}}else if(t.ret){const e=u[t.id];e&&(t.err?e.reject(t.err):e.resolve(t.res),u[t.id]=void 0)}};function d(e,r){if(2!==arguments.length)throw'register expects 2 arguments: "name" and "cb"';l[e]=r}function v(e){if(1!==arguments.length)throw'unregister expects 1 argument: "name"';l[e]=void 0}function h(e,r){return 1!==arguments.length&&2!==arguments.length?Promise.reject('call expects 1 or 2 arguments: "name" and optional "args"'):p(e,r,{environment:c})}function w(e,r,t){switch(c){case"server":return h(e,r);case"client":{const s=n();return new Promise((n,a)=>{u[s]={resolve:n,reject:a},mp.events.callRemote(i,o({req:1,id:s,name:e,env:c,args:r,...t}))})}case"cef":return y("__rpc:callServer",[e,r])}}function b(e,r){return 1!==arguments.length&&2!==arguments.length?Promise.reject('callServer expects 1 or 2 arguments: "name" and optional "args"'):w(e,r,{})}function y(e,r,t){switch(c){case"client":return t=r,r=e,1!==arguments.length&&2!==arguments.length||"string"!=typeof r?Promise.reject('callClient from the client expects 1 or 2 arguments: "name" and optional "args"'):h(r,t);case"server":{if(2!==arguments.length&&3!==arguments.length||"object"!=typeof e)return Promise.reject('callClient from the server expects 2 or 3 arguments: "player", "name", and optio
|