Skip to content

kwaziidev/pomelo-jsclient-websocket-bower

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

#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

connect to the server

  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

send request to server with callback

  pomelo.request(route, msg, callback);

example:

	pomelo.request(route, {
		rid: rid
	}, function(data) {  
    console.log(dta);	
	});

send request to server without callback

  pomelo.notify(route, params);

receive message from server

  pomelo.on(route, callback); 

example:

	pomelo.on('onChat', function(data) {
		addMessage(data.from, data.target, data.msg);
		$("#chatHistory").show();
	});

disconnect from server

pomelo.disconnect();

About

pomelo client for websocket

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published