nano javascript WebSocket client SDK
nano.init(params, callback);
Examples
nano.init({
host: host,
port: port,
user: {},
handshakeCallback : function(){}
}, function() {
console.log('success');
});
nano.request(route, msg, callback);
Examples
nano.request(route, {
rid: rid
}, function(data) {
console.log(dta);
});
nano.notify(route, params);
nano.on(route, callback);
Examples
nano.on('onChat', function(data) {
addMessage(data.from, data.target, data.msg);
$("#chatHistory").show();
});
nano.disconnect();
<!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>