remote.Broadcaster Class
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.
Item Index
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.
Example:
ludo.remoteBroadcaster.addEvent('failure', 'Person', function(response){ this.getBody().set('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.
Example:
ludo.remoteBroadcaster.addEvent('failure', 'Person', ['save'], function(response){ this.getBody().set('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
Chained method for adding broadcaster events.
Returns:
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
Example:
ludo.remoteBroadcaster.setDefaultMessage('You have registered successfully', 'success', 'User', 'register');
withResource
-
resource
Chained method for adding broadcaster events.
Parameters:
-
resource
String
Returns:
Example:
ludo.remoteBroadcaster.withResource('Person').withService('save').on('success', function(){
alert('Save success');
});
withResourceService
-
resourceAndService
Chained method for adding broadcaster events.
Parameters:
-
resourceAndService
String
Returns:
Example:
ludo.remoteBroadcaster.withResourceService('Person/save').on('success', function(){ alert('Save success'); });
withService
-
service
Chained method for adding broadcaster events.
Parameters:
-
service
String
Returns:
Example:
ludo.remoteBroadcaster.withResource('Person').withService('read').
withService('save').on('success', function(){
alert('Save success');
});