diff --git a/app.js b/app.js index 51cbadf..a5993a6 100644 --- a/app.js +++ b/app.js @@ -1,6 +1,6 @@ var argv = require("commander") .option("-p, --port ", "port to use", parseInt) - .parse(process.argv); + .parse(process.argv); PORT = 80; // Default port. if (argv.port) { diff --git a/client/index.html b/client/index.html index f1a7bc5..97c0de4 100644 --- a/client/index.html +++ b/client/index.html @@ -12,8 +12,8 @@ diff --git a/client/js/client.js b/client/js/client.js index ac80290..f0cb8cf 100644 --- a/client/js/client.js +++ b/client/js/client.js @@ -1,5 +1,5 @@ /** - * The Client class + * The Client class. * * @public */ @@ -7,32 +7,54 @@ function Client() { /** - * Self references. + * Self reference. * * @private */ var self = this; + + /** + * List of networks. + * + * @type {Array} + * @public + */ + + this.networks = []; /** * The active socket. * - * @private + * @type {Socket} + * @public */ - - var socket = io.connect("") - .on("init", function(data) { self.init(data); }); + + this.socket; /** - * Set up new socket connections. + * Connect to the server via WebSockets and start listening + * to events sent by the server. * - * @param {String} data + * @param {String} host * @public */ - this.init = function(data) { - // Debug - console.log(data); + this.connect = function(host) { + this.socket = io.connect(host) + .on("init", function(networks) { self.networks = networks; }) + .on("event", this.handleEvent); }; + /** + * Handle events sent by the server. + * + * @param {Event} event + * @public + */ + + this.handleEvent = function(event) { + // Debug + console.log(event); + }; }; diff --git a/client/js/models.js b/client/js/models.js index eb7fc16..b3f2ea8 100644 --- a/client/js/models.js +++ b/client/js/models.js @@ -1,7 +1,7 @@ (function(exports) { /** - * Declare the namespaces. + * Declare the namespace. * * @namespace */ @@ -139,4 +139,53 @@ this.user = ""; }; + /** + * Event model. + * + * Used when pushing changes between the server + * and the clients. + * + * @public + */ + + models.Event = function() { + + /** + * Action to perform. + * + * @type {String} + * @public + */ + + this.action = ""; + + /** + * Model type. + * + * @type {String} + * @public + */ + + this.type = ""; + + /** + * The target network or channel. + * + * @type {String} + * @public + */ + + this.target = undefined; + + /** + * The data. + * + * @type {Int|String|Object} + * @public + */ + + this.data = ""; + + }; + })(this); diff --git a/lib/server.js b/lib/server.js index e39c6f2..d7dd441 100644 --- a/lib/server.js +++ b/lib/server.js @@ -23,15 +23,34 @@ module.exports = Server; function Server() { /** - * Active sockets. + * Self reference. * * @private */ - var sockets; - + var self = this; + /** - * Start the server and listen to the specified port. + * List of networks. + * + * @type {Array} + * @public + */ + + this.networks = []; + + /** + * Active sockets managed by socket.io. + * + * @type {Object} + * @public + */ + + this.sockets; + + /** + * Start the server and listen for connections + * on the specified port. * * @param {Int} port * @public @@ -41,7 +60,7 @@ function Server() { var app = connect().use(connect.static("client")) .listen(port); - var sockets = + this.sockets = io.listen(app).on("connection", this.init) .sockets; }; @@ -54,7 +73,19 @@ function Server() { */ this.init = function(socket) { - // .. + self.sockets.emit("init", self.networks); + socket.on("input", self.handleUserInput); }; + /** + * Handle incoming inputs sent from clients. + * + * @param {String} input + * @public + */ + + this.handleUserInput = function(input) { + // Debug + console.log(input); + }; };