Undo two-step "thru" technique

This commit is contained in:
Micah Allen 2018-11-01 18:59:45 -04:00
parent ac3ba8d1eb
commit a7bbc8032b

View File

@ -32,15 +32,6 @@ const processEvent = (...args) => {
if(environment === "server") rawData = args[1]; if(environment === "server") rawData = args[1];
const data = util.parseData(rawData); const data = util.parseData(rawData);
if(data.thru && environment === "client"){
if(data.req){ // a CEF request is trying to get to the server
mp.events.callRemote(PROCESS_EVENT, rawData);
}else if(data.ret){ // a server response is trying to get to a CEF instance
passEventToBrowsers(rawData);
}
return;
}
if(data.req){ // someone is trying to remotely call a procedure if(data.req){ // someone is trying to remotely call a procedure
const info = { const info = {
id: data.id, id: data.id,
@ -54,7 +45,6 @@ const processEvent = (...args) => {
}; };
switch(environment){ switch(environment){
case "server": { case "server": {
if(data.thru) part.thru = 1;
promise.then(res => { promise.then(res => {
info.player.call(PROCESS_EVENT, [util.stringifyData({ info.player.call(PROCESS_EVENT, [util.stringifyData({
...part, ...part,
@ -180,7 +170,7 @@ rpc.callServer = (name, args) => {
}); });
} }
case "cef": { case "cef": {
const id = util.uid(); /*const id = util.uid();
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
pending[id] = { pending[id] = {
resolve, resolve,
@ -194,7 +184,7 @@ rpc.callServer = (name, args) => {
args, args,
thru: 1 thru: 1
})); }));
}); });*/
} }
} }
}; };
@ -206,8 +196,11 @@ rpc.callServer = (name, args) => {
* @param args - Any parameters for the procedure. * @param args - Any parameters for the procedure.
* @returns {Promise} - The result from the procedure. * @returns {Promise} - The result from the procedure.
*/ */
//callClient(player, name, args) // serverside
//callClient(name, args) // callClient(player, name, args)
//
// clientside or cef
// callClient(name, args)
rpc.callClient = (player, name, args) => { rpc.callClient = (player, name, args) => {
if(typeof player === "string"){ if(typeof player === "string"){
if(environment === "server") return Promise.reject('This syntax can only be used in browser and client environments.'); if(environment === "server") return Promise.reject('This syntax can only be used in browser and client environments.');
@ -254,6 +247,20 @@ rpc.callClient = (player, name, args) => {
} }
}; };
/**
* Calls a remote procedure registered in any browser context.
* @param {string} name - The name of the registered procedure.
* @param args - Any parameters for the procedure.
* @returns {Promise} - The result from the procedure.
*/
//serverside
//callBrowser(player, name, args)
//
//clientside or cef
//callBrowser(name, args)
//
//clientside
//callBrowser(browser, name, args)
rpc.callBrowser = async (name, args) => { rpc.callBrowser = async (name, args) => {
const id = util.uid(); const id = util.uid();
const numBrowsers = mp.browsers.length; const numBrowsers = mp.browsers.length;