We want to make a chat application where user inputs some text and then other users see that. Ext.Ajax.request is the function being called to send data to the server via Ajax.
This is the code in Sencha Architect 3:
var panel = button.up();
var input = panel.getComponent("inputField");
console.debug("Message: " + input.getValue());
Ext.Ajax.request({
url: '/Chat/chatMain/send',
params: {
message: input.getValue()
},
success: function(response){
console.log("Message successfully send.");
},
failure: function(response){
console.log("ERROR!");
console.log('server-side failure with status code ' + response.status);
}
});
Chat Controller in Grails:
class ChatMainController {
def send(){
//code for sending data back to client
//params.message contains message from browser it should be broadcast
//with server-side events
//event('sms', data) // will trigger registered browsers on 'sms' topic
}
}
Below example will receive server-send events which will be send from grails application:
var source = new EventSource('/Chat/chatMain/receive');
source.addEventListener('sms', showSms, false);
source.onmessage = function (event) {
// a message without a type was fired
showSms(event);
};
function showSms(e){
console.log(e.data);
}
We found grails plugins atmosphere and events push but the examples only show websockets not server-side event. We don't know how to broadcast text from grails server with use of events push plugin. Can anybody help?