Code to initialize object:
var ms = new $('#msgchat').jqh5ajx({ msg_link:server_url, clbk_fnc:'setchatdtls' });
where server_url is the server url to call, and setchatdtls is the callback function.
Code to send data using websocket:
// use this condition to make sure it is using websocket connection
if(typeof ms.mcevs != 'undefined' && ms.mcevs != null && typeof ms.chattype != 'undefined' && ms.chattype != null && ms.chattype == 'ws') {
ms.send('text');
}
Code to close websocket connection:
// use this condition to make sure it is using websocket connection
if(typeof ms.mcevs != 'undefined' && ms.mcevs != null && typeof ms.chattype != 'undefined' && ms.chattype != null && ms.chattype == 'ws') {
ms.close();
}
For handling web-sockets, can use any php web-socket server library like:
1) Ratchet PHP Web-Sockets library (http://socketo.me/)
OR
2) https://github.com/Devristo/phpws
|