#Pomelo javascript websocket client
The javascript websocket client library for Pomelo.
Since there are two kind connectors in pomelo 0.3, socket.io and socket(websocket), we provide two javascript clients for different usage. websocket client is optimized for data transfer size, the package is compressedin high rate. It's suitable for HTML5 online game, especially mobile platform.
socket.io client is excellent for browser compatibility, the package is in json. It's suitable for online realtime application on browser, like chat, on which browser compatiblity is an important issue.
The apis are almost the same in both clients, except websocket client need a handshake callback for protocol data. Both clients use bower package manager for building.
##Usage
pomelo.init(params, callback);
params object are
example:
pomelo.init({
host: host,
port: port,
user: {},
handshakeCallback : function(){}
}, function() {
console.log('success');
});
user field is user define json content
handshakeCallback field is handshake callback function
pomelo.request(route, msg, callback);
example:
pomelo.request(route, {
rid: rid
}, function(data) {
console.log(dta);
});
pomelo.notify(route, params);
pomelo.on(route, callback);
example:
pomelo.on('onChat', function(data) {
addMessage(data.from, data.target, data.msg);
$("#chatHistory").show();
});
pomelo.disconnect();