Added socket.io

This commit is contained in:
Mattias Erming 2014-03-04 09:22:06 -08:00
parent e65c9130c0
commit 9cdcfdefd2
4 changed files with 91 additions and 4 deletions

View File

@ -1 +1,17 @@
Hello, world.
<!doctype html>
<html>
<head></head>
<body>
Hello, world.
<script src="/socket.io/socket.io.js"></script>
<script src="/js/client.js"></script>
<script>
// Run the client.
new Client();
</script>
</body>
</html>

38
client/js/client.js Normal file
View File

@ -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);
};
};

View File

@ -3,6 +3,7 @@
*/
var connect = require("connect");
var io = require("socket.io");
/**
* Export module.
@ -19,12 +20,38 @@ module.exports = Server;
function Server() {
/**
* Start the server.
* Active sockets.
*
* @private
*/
var sockets;
/**
* 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.");
};
};

View File

@ -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"
}
}