From 97464928cb8a10276a2f83a4ed8f4d3a754c809f Mon Sep 17 00:00:00 2001 From: Saul van der Walt Date: Tue, 26 May 2015 09:33:15 +0200 Subject: [PATCH 1/7] Same Example in pure JavaScript Just removed the Jquery bits and replaced it with native JS code , the example works fine --- index.html | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/index.html b/index.html index 5f2767e98..d22927842 100644 --- a/index.html +++ b/index.html @@ -1,7 +1,8 @@ - - Socket.IO chat + + + Node Realtime Experiment - - + +
- - + From d21bd57167ee90e383514e0b8c41df800976b640 Mon Sep 17 00:00:00 2001 From: Saul van der Walt Date: Tue, 26 May 2015 09:37:32 +0200 Subject: [PATCH 2/7] modernized and added a few feutures now logs on client disconnect , serves static files in public folder (possible extension to allow emoticons and other shared resources) changed the way it sets and listens on port now more modern --- index.js | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index a322dca0f..d73c9b8c0 100644 --- a/index.js +++ b/index.js @@ -2,16 +2,25 @@ var app = require('express')(); var http = require('http').Server(app); var io = require('socket.io')(http); -app.get('/', function(req, res){ - res.sendFile(__dirname + '/index.html'); +app.set('port', (process.env.PORT || 3000)); + +app.get('/', function (req,res) { + res.sendFile(__dirname + '/index.html'); }); +app.use('/public', express.static(__dirname + '/public')); + io.on('connection', function(socket){ - socket.on('chat message', function(msg){ - io.emit('chat message', msg); - }); + console.log("Someone Connected"); + socket.on('chat message', function(msg){ + io.emit('chat message', msg); + }); +}); + +socket.on('disconnect', function(msg) { + console.log("Someone Disconnected"); }); -http.listen(3000, function(){ - console.log('listening on *:3000'); +http.listen(app.get('port'), function(){ + console.log('Server Started : listening on *:3000'); }); From 91732a33b39c2a38af66fd94060aa0aa1007dc62 Mon Sep 17 00:00:00 2001 From: Saul van der Walt Date: Tue, 26 May 2015 09:39:05 +0200 Subject: [PATCH 3/7] updated dependencies to use newer versions --- package.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 46f75814b..7e1b3ddae 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,9 @@ { - "name": "socket-chat-example", + "name": "socket-chat-example-updated", "version": "0.0.1", - "description": "my first socket.io app", + "description": "cool realtime chat socket.io app", "dependencies": { - "express": "4.10.2", - "socket.io": "1.2.0" + "express": "^4.12.4", + "socket.io": "^1.3.5" } } From 79fbe242079f5fdbe9091d9b45326ec1157fb68d Mon Sep 17 00:00:00 2001 From: Saul van der Walt Date: Tue, 26 May 2015 09:40:52 +0200 Subject: [PATCH 4/7] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c18a098c0..c81d92743 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # chat-example -This is the source code for a very simple chat example used for +This is an updated version of source code for a very simple chat example used for the [Getting Started](http://socket.io/get-started/chat/) guide of the Socket.IO website. -Please refer to it to learn how to run this application. +This version does not use Jquery it's plain JavaScript and the Index.js is a bit more modern From d56db08aa3af67b44d2fe5860e0aad500d31ab0c Mon Sep 17 00:00:00 2001 From: Saul van der Walt Date: Tue, 26 May 2015 09:49:30 +0200 Subject: [PATCH 5/7] Update index.js --- index.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/index.js b/index.js index d73c9b8c0..757257a8b 100644 --- a/index.js +++ b/index.js @@ -8,8 +8,6 @@ app.get('/', function (req,res) { res.sendFile(__dirname + '/index.html'); }); -app.use('/public', express.static(__dirname + '/public')); - io.on('connection', function(socket){ console.log("Someone Connected"); socket.on('chat message', function(msg){ @@ -17,7 +15,7 @@ io.on('connection', function(socket){ }); }); -socket.on('disconnect', function(msg) { +io.on('disconnect', function(msg) { console.log("Someone Disconnected"); }); From 77082fbae71787b926969108a83370a3a1ebfc87 Mon Sep 17 00:00:00 2001 From: Saul van der Walt Date: Tue, 26 May 2015 10:06:54 +0200 Subject: [PATCH 6/7] Update index.js --- index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 757257a8b..2f89ef4b0 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,5 @@ -var app = require('express')(); +var express = require('express'); +var app = express(); var http = require('http').Server(app); var io = require('socket.io')(http); @@ -8,6 +9,8 @@ app.get('/', function (req,res) { res.sendFile(__dirname + '/index.html'); }); +app.use("/assets", express.static(__dirname + '/assets')); + io.on('connection', function(socket){ console.log("Someone Connected"); socket.on('chat message', function(msg){ From aa1c9ea630e620edb3c87212821d528b66d7da7e Mon Sep 17 00:00:00 2001 From: Saul van der Walt Date: Tue, 26 May 2015 10:58:36 +0200 Subject: [PATCH 7/7] Update index.js --- index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 2f89ef4b0..0e0e5bada 100644 --- a/index.js +++ b/index.js @@ -5,12 +5,12 @@ var io = require('socket.io')(http); app.set('port', (process.env.PORT || 3000)); +app.use("/", express.static(__dirname + '/public')); + app.get('/', function (req,res) { - res.sendFile(__dirname + '/index.html'); + res.sendFile(__dirname + '/public/index.html'); }); -app.use("/assets", express.static(__dirname + '/assets')); - io.on('connection', function(socket){ console.log("Someone Connected"); socket.on('chat message', function(msg){