server Class Ape.pipe

Summary

pipe object (Communication line)
File
<./src/Ape_Server/modules/libape-spidermonkey.c>

pipe Class Detail

Ape.pipe ()
Pipe constructor.

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.

File:
<./src/Ape_Server/modules/libape-spidermonkey.c>
Returns:
Examples
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();
	}
}
See:

Summary

Own
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.

<static> {void} Ape.pipe. delProperty (name)

Delete a public property from a pipe.

The property 'pubid' cannot be removed.

Parameters:
{string} name The name of the property to unset
Returns:
{void}
Example
pipe.delProperty('user_id');
See:

<static> {void} Ape.pipe. destroy ()

Destroy a custom pipe.
Returns:
{void}
Example
pipe.destroy();
See:

<static> {Ape.channel} Ape.pipe. getParent ()

Get the channel object of a pipe.
Returns:
Example
var channel = Ape.getChannelByPubid(pubid);
var pipe = channel.getParent();
See:

<static> {void} Ape.pipe. sendRaw (name, data, options)

Send a custom RAW on a pipe.

The Ape server has some pre-registered CMD where automatically RAWs are returned upon. See Ape.registerCmd for details.

Parameters:
{string} name The RAW name
{object} data An object that will be JSON encoded and send outh with the RAW
{object} options Optional
{pipe} options.from Optional An user pipe or a custom pipe that will be added in the from field, if an user pipe, the raw will not be sent to this user.
{user|subuser} options.restrict Optional A user (if sending to a channel), or a subuser (if sending to n user) which will not receive the raw.
Returns:
{void}
Examples
//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"});
});
See:

<static> {void} Ape.pipe. sendResponse (name, data)

Send a response to a command.

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.

Parameters:
{string} name The RAW name
{object} data An object that will be JSON encoded and send out with the RAW
Returns:
{void}
Example
Ape.registerCmd("foocmd", true, function(params, info) {
	info.sendResponse('custom_raw', {'foo':'bar'});
});
See:

<static> {void} Ape.pipe. setProperty (key, value)

Set a public property on a pipe.
Parameters:
{string} key The name of the property to set
{mixed} value The value to set
Returns:
{void}
Examples
var userObj = {'name': 'john', 'age': 30};
pipe.setProperty('user', userObj);
pipe.setProperty('foo', 'bar');
See:

<static> {object} Ape.pipe. toObject ()

Get a pipe object.
Returns:
{object}
Example
Ape.registerCmd("foocmd", true, function(params, info) {
	var obj = Ape.getPipe(params.pubid).toObject();
});
See:

Summary

Own
Attributes Name Description
<static>   Ape.pipe. onSend () Trigger a event if something is send on a pipe.

<static> Ape.pipe. onSend ()

Trigger a event if something is send on a pipe.
See: