Skip to content

Commit c2ab0af

Browse files
committed
add socket.io and handle reception on client
1 parent 274fe19 commit c2ab0af

File tree

4 files changed

+11
-2
lines changed

4 files changed

+11
-2
lines changed

index.js

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ var path = require('path');
33
var http = require('http');
44
var app = express();
55
var server = http.Server(app);
6+
var io = require('socket.io')(server);
67
var port = process.env.PORT || 3000;
78

89
app.use(express.static(path.join(__dirname, 'public')));

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
"name": "NodeKC-October-2014",
33
"version": "0.0.1",
44
"engines": {
5-
"node" : "0.10.x"
5+
"node": "0.10.x"
66
},
77
"dependencies": {
8-
"express": "~4.2.0"
8+
"express": "~4.2.0",
9+
"socket.io": "^1.1.0"
910
},
1011
"author": "Joe Longstreet",
1112
"license": "MIT"

public/sup.html

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<h1 id='sup'>sup?</h1>
1212
</div>
1313
<audio id='clip' src='/sup.mp3' />
14+
<script src='/socket.io/socket.io.js'></script>
1415
<script src='/sup.js'></script>
1516
</body>
1617
</html>

public/sup.js

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
var socket = io();
12
var $background = document.getElementById('container');
23
var $sup = document.getElementById('sup');
34
var $audio = document.getElementById('clip');
@@ -25,3 +26,8 @@ var highlight = function(){
2526
var playSound = function(){
2627
$audio.play();
2728
};
29+
30+
socket.on('sup', function(){
31+
highlight();
32+
playSound();
33+
});

0 commit comments

Comments
 (0)