Shuo/client/js/client.js

61 lines
805 B
JavaScript
Raw Normal View History

2014-03-04 17:22:06 +00:00
/**
2014-03-04 21:50:43 +00:00
* The Client class.
2014-03-04 17:22:06 +00:00
*
* @public
*/
function Client() {
/**
2014-03-04 21:50:43 +00:00
* Self reference.
2014-03-04 17:22:06 +00:00
*
* @private
*/
var self = this;
2014-03-04 21:50:43 +00:00
/**
* List of networks.
*
* @type {Array<Network>}
* @public
*/
this.networks = [];
2014-03-04 17:22:06 +00:00
/**
* The active socket.
*
2014-03-04 21:50:43 +00:00
* @type {Socket}
* @public
*/
this.socket;
/**
* Connect to the server via WebSockets and start listening
* to events sent by the server.
*
* @param {String} host
* @public
2014-03-04 17:22:06 +00:00
*/
2014-03-04 21:50:43 +00:00
this.connect = function(host) {
this.socket = io.connect(host)
.on("init", function(networks) { self.networks = networks; })
.on("event", this.handleEvent);
};
2014-03-04 17:22:06 +00:00
/**
2014-03-04 21:50:43 +00:00
* Handle events sent by the server.
2014-03-04 17:22:06 +00:00
*
2014-03-04 21:50:43 +00:00
* @param {Event} event
2014-03-04 17:22:06 +00:00
* @public
*/
2014-03-04 21:50:43 +00:00
this.handleEvent = function(event) {
2014-03-04 17:22:06 +00:00
// Debug
2014-03-04 21:50:43 +00:00
console.log(event);
2014-03-04 17:22:06 +00:00
};
};