client Namespace APE.Pipe

Summary

File
<./src/Ape_Jsf/Source/Pipe/Pipe.js>

Pipe Namespace Detail

APE.Pipe
Variable containing pipe options

This variable contains the options of a pipe (name, properties, casttype, pubid).

The options var passed to pipeCreate event contains the same data as the pipe var.

File:
<./src/Ape_Jsf/Source/Pipe/Pipe.js>
See:

Summary

Own
Attributes Type Name Description
<static>   APE.Pipe request

<static> APE.Pipe request

See:
APE.request

Summary

Own
Methods Attributes Methods Name Methods Description
<static>   APE.Pipe. addEvent (eventName, fn, internal) Intercept an event.
<static>   APE.Pipe. fireEvent (eventName, args, delay) Fire a event manually on a pipe.
<static>   APE.Pipe. fireGlobalEvent (eventName, args, delay) Executes all events of the specified type present on in this pipe and in the core

When an event is fired on the core, it's also fired on the APE Client (as client and core share the same events).

<static>   APE.Pipe. getPubid () Return the pubid of the pipe
<static>   APE.Pipe. send (params) Shortcut to Send a message to the APE server on this pipe

<static> {APE} APE.Pipe. addEvent (eventName, fn, internal)

Intercept an event.
Parameters:
{string} eventName Event if it is send an a pipe
{function} fn The function that will be executed upon this named event
{boolean} internal Optional Flag to hide the function
Returns:
{APE}
Example
//ape var is a reference to APE instance
//myPipe var is a reference to a pipe object
//In this example this core will never be called as the event is only fired on the pipe
ape.addEvent('testEvent', function() {
		console.log('Event received on core');
});
myPipe.addEvent('testEvent', function() {
	console.log('Event received on pipe');
});
//Fire the event only on the pipe
myPipe.fireEvent('testEvent');
See:

<static> {APE} APE.Pipe. fireEvent (eventName, args, delay)

Fire a event manually on a pipe.

Executes all events of the specified type present on in only this pipe.

Parameters:
{string} eventName Event to launch.
{Array|object} args The arguments for the appropiate event callbacks
{integer} delay Optional Delay in ms before the event should be fired
Returns:
{APE}
Example
//ape var is a reference to APE instance
//myPipe var is a reference to a pipe object
//In this example this core will never be called as the event is only fired on the pipe
ape.addEvent('testEvent', function() {
		console.log('Event received on core');
	});
	myPipe.addEvent('testEvent', function() {
		console.log('Event received on pipe');
});
//Fire the event only on the pipe
myPipe.fireEvent('testEvent');
See:

<static> {APE} APE.Pipe. fireGlobalEvent (eventName, args, delay)

Executes all events of the specified type present on in this pipe and in the core

When an event is fired on the core, it's also fired on the APE Client (as client and core share the same events).

Parameters:
{string} eventName Event to launch.
{Array|object} args The arguments for the appropiate event callbacks
{integer} delay Optional Delay in ms before the event should be fired
Returns:
{APE}
Example
//ape var is a reference to APE instance
//myPipe var is a reference to a pipe object
//client var is a reference to a client instance
//Intercept event on pipe
myPipe.addEvent('testEvent', function() {
		console.log('event received on pipe');
});
//Intercept event on core
ape.addEvent('testEvent', function() {
		console.log('event received on core');
});
//Fire the event "testEvent" on the Pipe & Core
myPipe.fireGlobalEvent('testEvent', ['args1', 'args2']);
See:

<static> {string} APE.Pipe. getPubid ()

Return the pubid of the pipe
Returns:
{string} The pubid of this pipe
Example
//ape var is a reference to APE instance
	- ape.addEvent('pipeCreate', function(type, pipe, options) {
	var pubid = pipe.getPubid();
	//pipes is hash indexed by pubid containings all pipes
	var thePipe = ape.pipes.get(pubid);
	//thePipe is the same var than the var pipe passed in arguments
});

<static> APE.Pipe. send (params)

Shortcut to Send a message to the APE server on this pipe
Parameters:
{object} params Optional The message content
Example
//ape var is a reference to APE instance
//Join channel testChannel
ape.join('testChannel');
ape.addEvent('pipeCreate', function(type, pipe, options) {
	//Send "Hello world" on the pipe
	pipe.send('Hello world');
	//pipe.send is a shorcut for :
 	pipe.request.send({'msg':'Hellow world'});
});
See:
APE.Request.send
APE.Request.Stack.send
APE.Request.CycledStack.send

Summary

Own
Attributes Name Description
<static>   APE.Pipe. onCmd (commandName, fn, internal) Intercept an server command (CMD) on a pipe.
<static>   APE.Pipe. onRaw (rawName, fn, internal) Intercept an server raw (RAW) on a pipe.

<static> {APE} APE.Pipe. onCmd (commandName, fn, internal)

Intercept an server command (CMD) on a pipe.

Execute a function when a command is sent and pass to the function the arguments sent to APE server.

File:
<./src/Ape_Jsf/Source/Core/Events.js>
Parameters:
{string} commandName The name of the command (e.g. 'connect', 'send');
{function} fn The function to execute upon sending such a command to the server
{object} fn.args Optional An object containing all data that was send to the server
{object} fn.pipe 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.
{boolean} internal Optional Flag to hide the function
Returns:
{APE}
Example
//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']);
See:
APE.onCmd
APE.onError
APE.onRaw
APE.Pipe.onRaw

<static> {APE} APE.Pipe. onRaw (rawName, fn, internal)

Intercept an server raw (RAW) on a pipe.

Execute a function when a raw is received and pass to the function the data received from the server.

If the received raw is related to a pipe (e.g : you receive data from a channel) the second arguments will be a pipe object.

If you send custom raw and you want to intercept those on the pipe you need to add a pipe arguments to data your are sending. (see examples for more information).

File:
<./src/Ape_Jsf/Source/Core/Events.js>
Parameters:
{string} rawName The name of the raw (e.g. 'login', 'data');
{function} fn The function to execute upon sending such a command to the server
{object} fn.args Optional An object containing all data that was send to the server
{object} fn.pipe 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.
{boolean} internal Optional Flag to hide the function
Returns:
{APE}
Examples
//client side code
/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.onRaw('data', function(data, pipe) {
				console.log('data received on 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']);
// server side code
var chan = APE.getChannelByName('demoChannel');
chan.pipe.sendRaw('testRaw', {'foo': 'bar', 'pipe': chan.pipe.toObject()});
//Client side code (pipe is a pipe object)
pipe.onRaw('testRaw', function(data, pipe) {
		console.log('testRaw received on pipe');
	});
See:
APE.onRaw
APE.onError
APE.onCmd
APE.Pipe.onCmd