onCmd
(since )
Intercept a command sent on a pipe.
Description
string
onCmd
(
string type, string fn )
Execute a function when a command is sent on pipe and pass to the function the arguments sent to APE server.
Parameters
type
Name of the command (e.g : 'send');
fn
Callback function to execute
- args - (object, optional) An object containing all data sent to the server.
- pipe - (object, optional) If the request is made on a pipe (e.g : you sent data to a channel) the second argument will be a pipe object.
Examples
//ape var is a reference to APE instance
//Add an event when a new pipe is created
ape.addEvent('pipeCreate', function(type, pipe, options) {
//Test if the pipe is a "multi pipe" with name test1
if (type == 'multi' && pipe.name == 'test1') {
//Add an event when a message is received on the pipe test1
pipe.onCmd('send', function(data, pipe) {
console.log('Sending data on pipe pipe', pipe.name, ' message : ', data.msg);
});
}
//When a new pipe is created, send hello world
pipe.send('Hello world');
});
//Join channel test1 and test2
ape.join(['test1', 'test2']);
User notes
# No comment
Post a note
CollaborAPE to our wiki !
Find the information you need on the APE Official Wiki : Install, Server, JSF, Help...
