A pipe is an object that is kind of a connector through wich RAWs are sent.
Each user an channel has got an associated pipe.
Pipes created manually (custom pipes) are a little different from user and channel pipes. A manually created pipe is just usefull to receive "SEND" commands from clients (Proxy pipes are working this way). See example for more details.
var mypipe = new Ape.pipe();
//Custom pipe //We create a new custom pipe var pipe = new Ape.pipe(); //Custom pipe is created with an unique pubid Ape.log('Custom pipe pubid: ' + pipe.getProperty('pubid')); //We listen "SEND" commands received on this pipe pipe.onSend = function(user, params) { Ape.log('Received data from pipe: ' + params.msg); if(params.destroy) { pipe.destroy(); } }
Methods Attributes | Methods Name | Methods Description |
---|---|---|
<static> | Ape.pipe. delProperty (name) | Delete a public property from a pipe. |
<static> | Ape.pipe. destroy () | Destroy a custom pipe. |
<static> | Ape.pipe. getParent () | Get the channel object of a pipe. |
<static> | Ape.pipe. sendRaw (name, data, options) | Send a custom RAW on a pipe. |
<static> | Ape.pipe. sendResponse (name, data) | Send a response to a command. |
<static> | Ape.pipe. setProperty (key, value) | Set a public property on a pipe. |
<static> | Ape.pipe. toObject () | Get a pipe object. |
The property 'pubid' cannot be removed.
pipe.delProperty('user_id');
pipe.destroy();
var channel = Ape.getChannelByPubid(pubid); var pipe = channel.getParent();
The Ape server has some pre-registered CMD where automatically RAWs are returned upon. See Ape.registerCmd for details.
//Basic pipe.sendRaw("CUSTOM_RAW", {"foo":"bar"}); //This will send this raw: {"time":"1255281320","raw":"CUSTOM_RAW","data":{"foo":"bar"}}
//Send a raw to an user Ape.registerCmd("foocmd", true, function(params, info) { Ape.log("The user ip : ("+infos.ip+"), foo : " + params.foo); info.user.pipe.sendRaw("CUSTOM_RAW", {"foo":"bar"}); });
//Send a raw to a pipe Ape.registerCmd("foocmd", true, function(params, info) { Ape.log("The user ip : ("+info.ip+"), foo : " + params.foo); Ape.getPipe(params.pubid).sendRaw("CUSTOM_RAW", {"foo":"bar"}); });
You can send a response in registerHookCmd and registerCmd. This is useful if you want to assign a callback to a command in client-side.
When calling sendResponse method, the RAW sent to the user has the challenge 'chl' set to the value that came in the request to facilitate a callback. Other methods of sending a response includes pipe.sendRaw however server doesn't set the 'chl' automatically for them.
Ape.registerCmd("foocmd", true, function(params, info) { info.sendResponse('custom_raw', {'foo':'bar'}); });
var userObj = {'name': 'john', 'age': 30}; pipe.setProperty('user', userObj);
pipe.setProperty('foo', 'bar');
Ape.registerCmd("foocmd", true, function(params, info) { var obj = Ape.getPipe(params.pubid).toObject(); });