commit
73201094b7
2 changed files with 42 additions and 9 deletions
|
|
@ -296,6 +296,14 @@ const throwOnInvalidToken = async token => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getGun = () => {
|
||||||
|
return gun
|
||||||
|
}
|
||||||
|
|
||||||
|
const getUser = () => {
|
||||||
|
return user
|
||||||
|
}
|
||||||
|
|
||||||
class Mediator {
|
class Mediator {
|
||||||
/**
|
/**
|
||||||
* @param {Readonly<SimpleSocket>} socket
|
* @param {Readonly<SimpleSocket>} socket
|
||||||
|
|
@ -336,6 +344,34 @@ class Mediator {
|
||||||
this.socket.on(Event.ON_SEED_BACKUP, this.onSeedBackup)
|
this.socket.on(Event.ON_SEED_BACKUP, this.onSeedBackup)
|
||||||
|
|
||||||
this.socket.on(IS_GUN_AUTH, this.isGunAuth)
|
this.socket.on(IS_GUN_AUTH, this.isGunAuth)
|
||||||
|
|
||||||
|
this.socket.on('SET_LAST_SEEN_APP', async body => {
|
||||||
|
try {
|
||||||
|
await throwOnInvalidToken(body.token)
|
||||||
|
await new Promise((res, rej) => {
|
||||||
|
getUser()
|
||||||
|
.get('lastSeenApp')
|
||||||
|
.put(Date.now(), ack => {
|
||||||
|
if (ack.err) {
|
||||||
|
rej(new Error(ack.err))
|
||||||
|
} else {
|
||||||
|
res()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
this.socket.emit('SET_LAST_SEEN_APP', {
|
||||||
|
ok: true,
|
||||||
|
msg: null,
|
||||||
|
origBody: body
|
||||||
|
})
|
||||||
|
} catch (e) {
|
||||||
|
this.socket.emit('SET_LAST_SEEN_APP', {
|
||||||
|
ok: false,
|
||||||
|
msg: e.message,
|
||||||
|
origBody: body
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @param {SimpleSocket} socket */
|
/** @param {SimpleSocket} socket */
|
||||||
|
|
@ -1136,14 +1172,6 @@ const createMediator = socket => {
|
||||||
return new Mediator(socket)
|
return new Mediator(socket)
|
||||||
}
|
}
|
||||||
|
|
||||||
const getGun = () => {
|
|
||||||
return gun
|
|
||||||
}
|
|
||||||
|
|
||||||
const getUser = () => {
|
|
||||||
return user
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
authenticate,
|
authenticate,
|
||||||
logoff,
|
logoff,
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,12 @@ const { Buffer } = require('buffer')
|
||||||
const APIKeyPair = new Map()
|
const APIKeyPair = new Map()
|
||||||
const authorizedDevices = new Map()
|
const authorizedDevices = new Map()
|
||||||
|
|
||||||
const nonEncryptedEvents = ['ping', 'disconnect', 'IS_GUN_AUTH']
|
const nonEncryptedEvents = [
|
||||||
|
'ping',
|
||||||
|
'disconnect',
|
||||||
|
'IS_GUN_AUTH',
|
||||||
|
'SET_LAST_SEEN_APP'
|
||||||
|
]
|
||||||
|
|
||||||
const Encryption = {
|
const Encryption = {
|
||||||
isNonEncrypted: event => nonEncryptedEvents.includes(event),
|
isNonEncrypted: event => nonEncryptedEvents.includes(event),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue