Add new CEF --> Server communication
This commit is contained in:
parent
a7bbc8032b
commit
d748eb892b
48
src/index.js
48
src/index.js
@ -35,7 +35,7 @@ const processEvent = (...args) => {
|
|||||||
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,
|
||||||
environment: data.env
|
environment: data.fenv || data.env
|
||||||
};
|
};
|
||||||
if(environment === "server") info.player = args[0];
|
if(environment === "server") info.player = args[0];
|
||||||
const promise = callProcedure(data.name, data.args, info);
|
const promise = callProcedure(data.name, data.args, info);
|
||||||
@ -142,13 +142,7 @@ rpc.unregister = (name) => {
|
|||||||
*/
|
*/
|
||||||
rpc.call = (name, args) => callProcedure(name, args, { environment });
|
rpc.call = (name, args) => callProcedure(name, args, { environment });
|
||||||
|
|
||||||
/**
|
function callServer(name, args, extraData){
|
||||||
* Calls a remote procedure registered on the server.
|
|
||||||
* @param {string} name - The name of the registered procedure.
|
|
||||||
* @param args - Any parameters for the procedure.
|
|
||||||
* @returns {Promise} - The result from the procedure.
|
|
||||||
*/
|
|
||||||
rpc.callServer = (name, args) => {
|
|
||||||
switch(environment){
|
switch(environment){
|
||||||
case "server": {
|
case "server": {
|
||||||
return rpc.call(name, args);
|
return rpc.call(name, args);
|
||||||
@ -165,28 +159,25 @@ rpc.callServer = (name, args) => {
|
|||||||
id,
|
id,
|
||||||
name,
|
name,
|
||||||
env: environment,
|
env: environment,
|
||||||
args
|
args,
|
||||||
|
...extraData
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
case "cef": {
|
case "cef": {
|
||||||
/*const id = util.uid();
|
return rpc.callClient('__rpc:callServer', [name, args]);
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
pending[id] = {
|
|
||||||
resolve,
|
|
||||||
reject
|
|
||||||
};
|
|
||||||
mp.trigger(PROCESS_EVENT, util.stringifyData({
|
|
||||||
req: 1,
|
|
||||||
id,
|
|
||||||
name,
|
|
||||||
env: environment,
|
|
||||||
args,
|
|
||||||
thru: 1
|
|
||||||
}));
|
|
||||||
});*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calls a remote procedure registered on the server.
|
||||||
|
* @param {string} name - The name of the registered procedure.
|
||||||
|
* @param args - Any parameters for the procedure.
|
||||||
|
* @returns {Promise} - The result from the procedure.
|
||||||
|
*/
|
||||||
|
rpc.callServer = (name, args) => {
|
||||||
|
return callServer(name, args, {});
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -301,4 +292,13 @@ rpc.callBrowser = async (name, args) => {
|
|||||||
return Promise.reject('PROCEDURE_NOT_FOUND');
|
return Promise.reject('PROCEDURE_NOT_FOUND');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// set up internal pass-through events
|
||||||
|
if(environment === "client"){
|
||||||
|
rpc.register('__rpc:callServer', ([name, args], info) => {
|
||||||
|
return callServer(name, args, {
|
||||||
|
fenv: info.environment
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = rpc;
|
module.exports = rpc;
|
Reference in New Issue
Block a user