Improved debugging output

master
Keith Irwin 2018-08-13 19:34:58 +00:00
parent eb13a4911d
commit f71c50fe91
No known key found for this signature in database
GPG Key ID: 378933C743E2BBC0
3 changed files with 13 additions and 13 deletions

View File

@ -22,7 +22,7 @@ module.exports = (io, filename='demo.txt') => {
sendLoc(0)
} else {
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', {
tim: new Date(),
lat: loc[1],

View File

@ -36,14 +36,14 @@ module.exports = {
// Ensure authentication
ensureAuth: (req, res, next) => {
debug(`ensureAuth(${req.url}, ${res.status}, ${next})`)
debug(`ensureAuth(${req.url})`)
if (req.isAuthenticated()) return next()
else res.redirect('/login')
},
// Ensure administrator
ensureAdmin: (req, res, next) => {
debug(`ensureAdmin(${req.url}, ${res.status}, ${next})`)
debug(`ensureAdmin(${req.url})`)
if (req.isAuthenticated() && req.user.isAdmin) return next()
else {
let err = new Error("Unauthorized")

View File

@ -27,11 +27,11 @@ module.exports = {
init: (io) => {
io.on('connection', (socket) => {
debug(`${socket.id} connected.`)
debug(`${socket.ip} connected.`)
// Set a few variables
// socket.ip = socket.client.request.headers['x-real-ip'];
// socket.ua = socket.client.request.headers['user-agent'];
socket.ip = socket.client.request.headers['x-real-ip'];
socket.ua = socket.client.request.headers['user-agent'];
// Log and errors
socket.on('log', (text) => {
@ -41,9 +41,9 @@ module.exports = {
// This socket can set location (app)
socket.on('can-set', (userId) => {
debug(`${socket.id} can set updates for ${userId}.`)
debug(`${socket.ip} can set updates for ${userId}.`)
socket.join(userId, () => {
debug(`${socket.id} joined ${userId}`)
debug(`${socket.ip} joined ${userId} with ${socket.ua}`)
})
checkForUsers(io, userId)
})
@ -51,16 +51,16 @@ module.exports = {
// This socket can receive location (map)
socket.on('can-get', (userId) => {
socket.gets = userId
debug(`${socket.id} can get updates for ${userId}.`)
debug(`${socket.ip} can get updates for ${userId}.`)
socket.join(userId, () => {
debug(`${socket.id} joined ${userId}`)
debug(`${socket.ip} joined ${userId}`)
socket.to(userId).emit('activate', 'true')
})
})
// Set location
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)}`)
// Get android timestamp or use server timestamp
@ -123,11 +123,11 @@ module.exports = {
// Shutdown (check for remaining clients)
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
if (socket.gets) {
debug(`${socket.id} left ${socket.gets}`)
debug(`${socket.ip} left ${socket.gets}`)
checkForUsers(io, socket.gets)
}
})