nano javascript WebSocket client SDK for 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"
}
]
}
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
}
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();