The Gallery is deprecated. No new Gallery components may be submitted, and modifying existing components is disabled. For more information please read the Gallery Deprecation blog post. This is a static snapshot of the Gallery for archive purposes.
See 2 more by this user. Created: 08/16/11
Project: YUI 3
License: YUI BSD
YUI Version: 3.4.1 PR1
Free for use.
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','');
});
});
});
All code on this site is licensed under the BSD License unless stated otherwise.