From 9cdcfdefd26c09b93a405a197643ce3382e5f1e0 Mon Sep 17 00:00:00 2001 From: Mattias Erming Date: Tue, 4 Mar 2014 09:22:06 -0800 Subject: [PATCH] Added socket.io --- client/index.html | 18 +++++++++++++++++- client/js/client.js | 38 ++++++++++++++++++++++++++++++++++++++ lib/server.js | 31 +++++++++++++++++++++++++++++-- package.json | 8 +++++++- 4 files changed, 91 insertions(+), 4 deletions(-) create mode 100644 client/js/client.js diff --git a/client/index.html b/client/index.html index f75ba05f..9330d289 100644 --- a/client/index.html +++ b/client/index.html @@ -1 +1,17 @@ -Hello, world. + + + + + + Hello, world. + + + + + + + + diff --git a/client/js/client.js b/client/js/client.js new file mode 100644 index 00000000..7b09481e --- /dev/null +++ b/client/js/client.js @@ -0,0 +1,38 @@ +/** + * The Client class + * + * @public + */ + +function Client() { + + /** + * Self references. + * + * @private + */ + + var self = this; + + /** + * The active socket. + * + * @private + */ + + var socket = io.connect("") + .on("init", function(data) { self.init(data); }); + + /** + * Setup new socket connections. + * + * @param {String} data + * @public + */ + + this.init = function(data) { + // Debug + console.log(data); + }; + +}; diff --git a/lib/server.js b/lib/server.js index 640f55da..51ca72ed 100644 --- a/lib/server.js +++ b/lib/server.js @@ -3,6 +3,7 @@ */ var connect = require("connect"); +var io = require("socket.io"); /** * Export module. @@ -17,14 +18,40 @@ module.exports = Server; */ function Server() { + + /** + * Active sockets. + * + * @private + */ + + var sockets; /** - * Start the server. + * Start the server and listen to the specified port. * + * @param {Number} port * @public */ this.listen = function(port) { - connect().use(connect.static("client")).listen(port); + var app = connect().use(connect.static("client")) + .listen(port); + + var sockets = + io.listen(app).on("connection", this.init) + .sockets; }; + + /** + * Initiate new socket connections. + * + * @param {Socket} socket + * @public + */ + + this.init = function(socket) { + socket.emit("init", "Hello, world."); + }; + }; diff --git a/package.json b/package.json index d4f93a33..5c5807eb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,12 @@ { + "author": { + "name": "Mattias Erming", + "email": "mattias@mattiaserming.com" + }, + "description": "A web-based client/server IRC chat", "dependencies": { + "commander": "2.1.0", "connect": "2.13.0", - "commander": "2.1.0" + "socket.io": "0.9.16" } }