Skip to content

nano-ecosystem/nano-websocket-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

nano-websocket-client

nano javascript WebSocket client SDK

API

Connect to server

nano.init(params, callback);

Examples

nano.init({
    host: host,
    port: port,
	user: {},
	handshakeCallback : function(){}
}, function() {
	console.log('success');
});

Send request to server with callback

nano.request(route, msg, callback);

Examples

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

Send request to server without callback

nano.notify(route, params);

Receive message from server

nano.on(route, callback); 

Examples

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

Disconnect from server

nano.disconnect();

Usage

<!DOCTYPE html/>
<html>
<head>
	<title>nano WebSocket Test Page</title>
</head>
<body>
<script src="./protocol.js"></script>
<script src="./nano-websocket-client.js"></script>
<script type="text/javascript">

var nano = window.nano

nano.init({host: "127.0.0.1", port: 3250, log: true}, function(){
	nano.request("gate.Handler.Login", {"name":"chrislonng", "age":10000}, function(data){
		console.log(data);
	});

	nano.request("gate.Handler.Signup", {"name":"Signup chrislonng", "age":10000}, function(data){
		console.log(data);
	});

	nano.on("notify", function(data){
		console.log(data);
	});
});

</script>
</body>
</html>

License

MIT License

About

nano javascript WebSocket client SDK

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published