ludo.remote.Broadcaster

ludo.remote.Broadcaster
ludo.remoteBroadcaster.withResource('Person').withService('read').on('success', function(){
// Do something
});


new ludo.remote.Broadcaster()

Singleton class responsible for broadcasting messages from remote requests.
Instance of this class is available in ludo.remoteBroadcaster.

The broadcaster can fire four events:
start, success, failure and serverError. The example below show you how
to add listeners to these events.

Source:

Methods


addResourceEvent(eventType, resource, fn)

Listen to events from remote requests. EventType is either
success, failure or serverError. resource is a name of resource
specified in the request.

Parameters:
Name Type Description
eventType String
resource String
fn function
Source:
Examples
ludo.remoteBroadcaster.addEvent('failure', 'Person', function(response){
            this.getBody().html( response.message');
        }.bind(this));
     The event payload is an object in this format:
     
{
             "code": 200,
             "message": "A message",
             "resource": "Which resource",
             "service": "Which service"
         }

addResourceEvent(eventType, resource, services, fn)

Listen to remote events from a specific service only.

Parameters:
Name Type Description
eventType String
resource String
services Array
fn function
Source:
Examples
ludo.remoteBroadcaster.addEvent('failure', 'Person', ['save'], function(response){
            this.getBody().html( response.message');
        }.bind(this));
     The event payload is an object in this format:
     
{
             "code": 200,
             "message": "A message",
             "resource": "Which resource",
             "service": "Which service"
         }

on(events, fn) → {remote.Broadcaster}

Chained method for adding broadcaster events.

Parameters:
Name Type Description
events String | Array
fn function
Source:
Returns:
Type
remote.Broadcaster
Example
ludo.remoteBroadcaster.withResource('Person').withService('read').on('success', function(){
	 		alert('Save success');
	 	}).on('start', function(){ alert('About to save') });
     Example with array:

        ludo.remoteBroadcaster.withResource('Person').withService('read').on('success', function(){
	 		alert('Save success');
	 	}).on(['start','success'], function(){ alert('Remote event') });

setDefaultMessage(message, eventType, resource, service)

Specify default response messages for resource service

Parameters:
Name Type Description
message String
eventType String
resource String
service String
Source:
Example
ludo.remoteBroadcaster.setDefaultMessage('You have registered successfully', 'success', 'User', 'register');

withResource(resource) → {remote.Broadcaster}

Chained method for adding broadcaster events.

Parameters:
Name Type Description
resource String
Source:
Returns:
Type
remote.Broadcaster
Example
ludo.remoteBroadcaster.withResource('Person').withService('save').on('success', function(){
	 		alert('Save success');
	 	});

withResourceService(resourceAndService) → {remote.Broadcaster}

Chained method for adding broadcaster events.

Parameters:
Name Type Description
resourceAndService String
Source:
Returns:
Type
remote.Broadcaster
Example
ludo.remoteBroadcaster.withResourceService('Person/save').on('success', function(){
	 		alert('Save success');
	 	});

withService(service) → {remote.Broadcaster}

Chained method for adding broadcaster events.

Parameters:
Name Type Description
service String
Source:
Returns:
Type
remote.Broadcaster
Example
ludo.remoteBroadcaster.withResource('Person').withService('read').
            withService('save').on('success', function(){
	 		alert('Save success');
	 	});