This repository has been archived by the owner on Feb 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
io.js
62 lines (58 loc) · 1.52 KB
/
io.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
* io.js
*
* Description:
* file for WebSocket
*
* Author:
* sota1235
*/
var socket = require('socket.io');
module.exports = function(server) {
var io = socket.listen(server);
io.on('connection', function(socket) {
console.log('a user connected');
// send comment
socket.on('comment', function(msg) {
console.log('comment: ' + msg);
io.emit('comment', msg);
});
// send vote for choices of quiz
socket.on('vote', function(msg) {
console.log('vote: ' + msg);
io.emit('vote', msg);
});
// display quiz
socket.on('open', function(id, text) {
console.log('open: ' + id);
io.emit('open', id);
io.emit('question-open', text); // index page
});
// answer check (count vote)
socket.on('answerCheck', function(msg) {
console.log('answer check!');
io.emit('answerCheck');
});
// show answer
socket.on('openAnswer', function(msg) {
console.log('open answer: ' + (msg + 1));
io.emit('openAnswer', msg);
});
// hide quiz
socket.on('finish', function(msg) {
console.log('finish quiz');
io.emit('finish');
io.emit('question-finish'); // index page
});
// quiz timer finish
socket.on('timerFinish', function(msg) {
console.log('exit time limit of quiz');
io.emit('timerFinish');
});
// publish image events
socket.on('imageEvent', function(msg) {
console.log('send image event: ' + JSON.stringify(msg));
io.emit('imageEvent', msg);
});
});
};