ExtJS Websocket Chat Application -
im setting mvc application extjs 4.2 has chat support client. i'm using extjs websocket , followed tutorial https://market.sencha.com/extensions/ext-ux-websocket seem work broadcast message connected client on different browsers. here codes:
this.ws = ext.create('ext.ux.websocket', { url : 'ws://localhost:6966', autoreconnect : true, autoreconnectinterval : 1000, keepunsentmessages : true, listeners : { open : function(ws) { ws.send('notify', { 'message' : 'connected server!', 'id' : '123456' }); }, message : function(ws, data) { var data = ext.decode(data); console.log(data) }, close : function(ws) { var panel = ext.getcmp('panel' + ws.url); if ((panel != null) || (panel != undefined)) { panel.destroy(); } } } }); this.ws.on('notify', function(data) { ext.get('chat-history').dom.innerhtml += '> ' + data.msg + '<br/>'; }); ext.ux.websocketmanager.register(this.ws);
and use send/broadcast messages:
var data = { id : '123456', msg : 'sample message' }; ext.ux.websocketmanager.broadcast('notify', data);
you try out this link.
you need nodejs , npm.
then, install every dependencies:
$ npm install
open websocket each port want:
$ node demo/server.js 9001 9002 9003
then connect client using code posted.
Comments
Post a Comment