Awesome
nano-egret-client
nano javascript WebSocket client SDK for egret engine.
Integret to egret engine
Change egret project file egretProperties.json
and add nano
client sdk reference to modules, likes below:
{
"native": {
"path_ignore": []
},
"publish": {
"web": 0,
"native": 1,
"path": "bin-release"
},
"egret_version": "5.0.7",
"template": {},
"eui": {
"exmlRoot": [
"resource/eui_skins"
],
"themes": [
"resource/default.thm.json"
],
"exmlPublishPolicy": "content"
},
"modules": [
{
"name": "egret"
},
{
"name": "res"
},
{
"name": "eui"
},
{
"name": "tween"
},
{
"name": "promise",
"path": "./promise"
},
{
"name": "nano",
"path": "path/to/nano"
}
]
}
Usage
public static connectServer(host:string, port:number):void {
nano.init({
host:host,
port:port,
reconnect: true,
}, this.onConnected);
}
private static onConnected() {
console.log("connect to nano")
// do something
}
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();