-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
62 lines (47 loc) · 1.41 KB
/
app.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
// app.js
var express = require('express');
var app = express();
var server = require('http').createServer(app);
var io = require('socket.io')(server);
app.use(express.static(__dirname + '/'));
app.get('/', function(req, res,next) {
res.sendFile(__dirname + '/index.html');
});
// app.js
var roomno = 1;
io.on('connection', function(client) {
//client.join("room-"+roomno);
console.log('Client connected...');
//client.join('some room');
console.log('yoyoyo')
client.on('yo', function(data) {
client.emit('broad', data);
client.broadcast.emit('broad',data);
//console.log(data)
});
client.on('join', function(data) {
//scene.add()
console.log(data);
client.on('say to someone', (id, msg) => {
client.to(id).emit('broad', msg);
});
client.on('messages', function(data) {
var options = {
text:data,
size: 0.4,
color: (Math.random() * 0xffffff),
position:[randomInRange(0,10)-5,randomInRange(0,10)-5,randomInRange(0,10)-5],
rotation:[randomInRange(0,2)-1,randomInRange(0,2)-1,randomInRange(0,2)-1],
}
client.emit('broad', options);
client.broadcast.emit('broad',options);
//console.log(data)
});
});
client.broadcast.emit('broad','poop');
});
server.listen(4515);
io.to('some room').emit('some event');
function randomInRange(min, max) {
return Math.random() < 0.5 ? ((1-Math.random()) * (max-min) + min) : (Math.random() * (max-min) + min);
}