alejandro soto gonzalez![]()
With this module you only have to define the callback methods to show the messages that are being pulled from the server side, PHP in this case, or the configuration to publish messages to the live channel. However you will have to modify the max_execution_time variable in the PHP configuration (php.ini) to create a messages pool in your server. Is an alternative to develop rich applications with YUI 3 and to synchronize the browsers in order to have more responsive RIAs in real time.
As you can see, you only have to define the events in order to get the messages published by other clients or the event to know if a message was successfully sent.
YUI().use('gallery-live-messaging', function(Y) {
function successEvent(event){
//inject messages in the markup
var ul = Y.one('#list ul');
ul.set('innerHTML', ul.get('innerHTML') + '<li>' + event.result.data + '</li>' )
}
function messageSentEvent(event){
//message successfully sent
}
function messageSentErrorEvent(event){
alert(event.message);
}
/* DOM READY TRIGGER */
Y.on('domready', function() {
//configuration to publish messages
var externalPublisherCfg = {
channel : 'default',
//dispatcher url
url : 'back-end/dispatcher.php',
//events
success : messageSentEvent,
error : function(){},
complete : function(){} ,
method : 'GET',
//infinite timeout
timeout : 0 // 0 to infinite timeout
};
//configuration to subscribe to messages
var externalSubscriberCfg = {
channel : 'default',
//dispatcher url
url : 'back-end/dispatcher.php',
//events
success : successEvent,
error : function(event){},
complete : function(event){},
method : 'GET',
//infinite timeout
timeout : 0 // 0 to infinite timeout
};
//initializes the messaging object
var msgObject = new Y.messagingObject();
msgObject.publishToChannel(externalPublisherCfg);
msgObject.subscribeToChannel(externalSubscriberCfg);
msgObject.connect();
Y.one('#boton').on('click',function(e){
e.preventDefault();
msgObject.send(Y.one('#texto').get('value'));
Y.one('#texto').set('value','');
});
});
});
© 2006-2013 Yahoo! Inc. All rights reserved.
All code on this site is licensed under the BSD License unless stated otherwise.
About This Site · Security Contact Info