forked from Dharmik3/tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
99 lines (76 loc) · 2.57 KB
/
Copy pathapp.js
File metadata and controls
99 lines (76 loc) · 2.57 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// const express = require('express');
// const app = express();
// const http = require('http');
// const socketio = require('socket.io');
// const ejs = require('ejs');
// const path = require('path');
// const server = http.createServer(app);
// const io = socketio(server)
// app.set('view engine', "ejs")
// app.use(express.static(path.join(__dirname, 'public')))
// io.on('connection', (socket) => {
// socket.on("send-location", (data) => {
// console.log(data)
// io.emit('receive-location', { id: socket.id, ...data })
// })
// socket.on('disconnect', () => {
// io.emit('user-disconnected', socket.id)
// })
// console.log('connected')
// })
// app.get('/', (req, res) => {
// res.render('index')
// })
// server.listen(3002)
// const express = require('express');
// const app = express();
// const http = require('http');
// const socketio = require('socket.io');
// const ejs = require('ejs');
// const path = require('path');
// const server = http.createServer(app);
// const io = socketio(server)
// // app.set('view engine', "ejs")
// app.use(express.static(path.join(__dirname, 'public')))
// io.on('connection', (socket) => {
// console.log('User connected:', socket.id)
// socket.on("send-location", (data) => {
// console.log(`Location received from ${socket.id}:`, data)
// io.emit('receive-location', { id: socket.id, ...data })
// })
// socket.on('disconnect', () => {
// console.log('User disconnected:', socket.id)
// io.emit('user-disconnected', socket.id)
// })
// })
// app.get('/', (req, res) => {
// res.render('index')
// })
// server.listen(3002, () => {
// console.log('Server running on port 3002')
// })
const express = require('express');
const http = require('http');
const socketio = require('socket.io');
const path = require('path');
const app = express();
const server = http.createServer(app);
const io = socketio(server);
app.use(express.static(path.join(__dirname, 'public')));
io.on('connection', (socket) => {
console.log('User connected:', socket.id);
socket.on("send-location", (data) => {
console.log(`Location received from ${socket.id}:`, data);
io.emit('receive-location', { id: socket.id, ...data });
});
socket.on('disconnect', () => {
console.log('User disconnected:', socket.id);
io.emit('user-disconnected', socket.id);
});
socket.on('error', (err) => {
console.log(socket.id, { err })
})
});
server.listen(3002, () => {
console.log('Server running on port 3002');
});