-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
68 lines (35 loc) · 1.35 KB
/
Copy pathapp.js
File metadata and controls
68 lines (35 loc) · 1.35 KB
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
63
64
65
66
67
68
const Kahoot = require("kahoot.js-republished");
const NameGenerator = require('nodejs-randomnames');
const app = require('express')();
const server = require('http').Server(app);
const io = require('socket.io')(server);
var client = []
server.listen(3000);
// WARNING: app.listen(80) will NOT work here!
app.get('/', function (req, res) {
res.sendFile(__dirname + '/public/index.html');
});
io.on('connection', function (socket) {
console.log('connect')
socket.on('kahoot', function(data){
var amount = data.amount;
var gamePin = data.pin;
console.log(amount);
for(var i=0; i<amount; i++){
client[i] = new Kahoot;
}
for(var i=0; i<amount; i++){
client[i].join(gamePin ,NameGenerator.getRandomName());
}
console.log("joined")
client[0].on("questionStart", function(question){
for(var i=0; i<client.length-1; i++){
client[i].answerQuestion(0)
}
console.log("Answering");
});
client[0].on("quizEnd", () => {
console.log("The quiz has ended.");
});
})
});