Improved debugging output
parent
eb13a4911d
commit
f71c50fe91
|
@ -22,7 +22,7 @@ module.exports = (io, filename='demo.txt') => {
|
||||||
sendLoc(0)
|
sendLoc(0)
|
||||||
} else {
|
} else {
|
||||||
let loc = lines[ln].split(' ')
|
let loc = lines[ln].split(' ')
|
||||||
debug(`Sending demo location: ${loc[1]}, ${loc[2]}`)
|
//debug(`Sending demo location: ${loc[1]}, ${loc[2]}`)
|
||||||
io.to('demo').emit('get', {
|
io.to('demo').emit('get', {
|
||||||
tim: new Date(),
|
tim: new Date(),
|
||||||
lat: loc[1],
|
lat: loc[1],
|
||||||
|
|
|
@ -36,14 +36,14 @@ module.exports = {
|
||||||
|
|
||||||
// Ensure authentication
|
// Ensure authentication
|
||||||
ensureAuth: (req, res, next) => {
|
ensureAuth: (req, res, next) => {
|
||||||
debug(`ensureAuth(${req.url}, ${res.status}, ${next})`)
|
debug(`ensureAuth(${req.url})`)
|
||||||
if (req.isAuthenticated()) return next()
|
if (req.isAuthenticated()) return next()
|
||||||
else res.redirect('/login')
|
else res.redirect('/login')
|
||||||
},
|
},
|
||||||
|
|
||||||
// Ensure administrator
|
// Ensure administrator
|
||||||
ensureAdmin: (req, res, next) => {
|
ensureAdmin: (req, res, next) => {
|
||||||
debug(`ensureAdmin(${req.url}, ${res.status}, ${next})`)
|
debug(`ensureAdmin(${req.url})`)
|
||||||
if (req.isAuthenticated() && req.user.isAdmin) return next()
|
if (req.isAuthenticated() && req.user.isAdmin) return next()
|
||||||
else {
|
else {
|
||||||
let err = new Error("Unauthorized")
|
let err = new Error("Unauthorized")
|
||||||
|
|
|
@ -27,11 +27,11 @@ module.exports = {
|
||||||
|
|
||||||
init: (io) => {
|
init: (io) => {
|
||||||
io.on('connection', (socket) => {
|
io.on('connection', (socket) => {
|
||||||
debug(`${socket.id} connected.`)
|
debug(`${socket.ip} connected.`)
|
||||||
|
|
||||||
// Set a few variables
|
// Set a few variables
|
||||||
// socket.ip = socket.client.request.headers['x-real-ip'];
|
socket.ip = socket.client.request.headers['x-real-ip'];
|
||||||
// socket.ua = socket.client.request.headers['user-agent'];
|
socket.ua = socket.client.request.headers['user-agent'];
|
||||||
|
|
||||||
// Log and errors
|
// Log and errors
|
||||||
socket.on('log', (text) => {
|
socket.on('log', (text) => {
|
||||||
|
@ -41,9 +41,9 @@ module.exports = {
|
||||||
|
|
||||||
// This socket can set location (app)
|
// This socket can set location (app)
|
||||||
socket.on('can-set', (userId) => {
|
socket.on('can-set', (userId) => {
|
||||||
debug(`${socket.id} can set updates for ${userId}.`)
|
debug(`${socket.ip} can set updates for ${userId}.`)
|
||||||
socket.join(userId, () => {
|
socket.join(userId, () => {
|
||||||
debug(`${socket.id} joined ${userId}`)
|
debug(`${socket.ip} joined ${userId} with ${socket.ua}`)
|
||||||
})
|
})
|
||||||
checkForUsers(io, userId)
|
checkForUsers(io, userId)
|
||||||
})
|
})
|
||||||
|
@ -51,16 +51,16 @@ module.exports = {
|
||||||
// This socket can receive location (map)
|
// This socket can receive location (map)
|
||||||
socket.on('can-get', (userId) => {
|
socket.on('can-get', (userId) => {
|
||||||
socket.gets = userId
|
socket.gets = userId
|
||||||
debug(`${socket.id} can get updates for ${userId}.`)
|
debug(`${socket.ip} can get updates for ${userId}.`)
|
||||||
socket.join(userId, () => {
|
socket.join(userId, () => {
|
||||||
debug(`${socket.id} joined ${userId}`)
|
debug(`${socket.ip} joined ${userId}`)
|
||||||
socket.to(userId).emit('activate', 'true')
|
socket.to(userId).emit('activate', 'true')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
// Set location
|
// Set location
|
||||||
socket.on('set', async (loc) => {
|
socket.on('set', async (loc) => {
|
||||||
debug(`${socket.id} set location for ${loc.usr}`)
|
debug(`${socket.ip} set location for ${loc.usr}`)
|
||||||
debug(`Location was set to: ${JSON.stringify(loc)}`)
|
debug(`Location was set to: ${JSON.stringify(loc)}`)
|
||||||
|
|
||||||
// Get android timestamp or use server timestamp
|
// Get android timestamp or use server timestamp
|
||||||
|
@ -123,11 +123,11 @@ module.exports = {
|
||||||
|
|
||||||
// Shutdown (check for remaining clients)
|
// Shutdown (check for remaining clients)
|
||||||
socket.on('disconnect', (reason) => {
|
socket.on('disconnect', (reason) => {
|
||||||
debug(`${socket.id} disconnected because of a ${reason}.`)
|
debug(`${socket.ip} disconnected ${socket.ua} because of a ${reason}.`)
|
||||||
|
|
||||||
// Check if client was receiving updates
|
// Check if client was receiving updates
|
||||||
if (socket.gets) {
|
if (socket.gets) {
|
||||||
debug(`${socket.id} left ${socket.gets}`)
|
debug(`${socket.ip} left ${socket.gets}`)
|
||||||
checkForUsers(io, socket.gets)
|
checkForUsers(io, socket.gets)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue