http polling events

This commit is contained in:
Daniel Lugo 2020-02-21 12:47:25 -04:00
parent 922dad78b7
commit 4ca1e7ffe3

View file

@ -1562,6 +1562,99 @@ module.exports = async (
}); });
}); });
const GunEvent = require('../services/gunDB/event-constants')
const Events = require('../services/gunDB/contact-api/events')
app.get(`/api/gun/${GunEvent.ON_RECEIVED_REQUESTS}`, (_, res) => {
try {
// spinup
Events.onSimplerReceivedRequests(() => {})()
const data = Events.getCurrentReceivedReqs()
res.json({
data,
})
} catch (err) {
res.status(500).json({
errorMessage: (typeof err === 'object' && err.message) || 'Unknown error'
})
}
})
app.get(`/api/gun/${GunEvent.ON_SENT_REQUESTS}`, (_, res) => {
try {
// spinup
Events.onSimplerSentRequests(() => {})()
const data = Events.getCurrentSentReqs()
res.json({
data,
})
} catch (err) {
res.status(500).json({
errorMessage: (typeof err === 'object' && err.message) || 'Unknown error'
})
}
})
app.get(`/api/gun/${GunEvent.ON_CHATS}`, (_, res) => {
try {
// spinup
Events.onChats(() => {})()
const data = Events.getChats()
res.json({
data
})
} catch (err) {
res.status(500).json({
errorMessage: (typeof err === 'object' && err.message) || 'Unknown error'
})
}
})
app.get(`/api/gun/${GunEvent.ON_AVATAR}`, (_, res) => {
try {
// spinup
Events.onAvatar(() => {})()
const data = Events.getAvatar()
res.json({
data
})
} catch (err) {
res.status(500).json({
errorMessage: (typeof err === 'object' && err.message) || 'Unknown error'
})
}
})
app.get(`/api/gun/${GunEvent.ON_DISPLAY_NAME}`, (_, res) => {
try {
// spinup
Events.onDisplayName(() => {})()
const data = Events.getDisplayName()
res.json({
data
})
} catch (err) {
res.status(500).json({
errorMessage: (typeof err === 'object' && err.message) || 'Unknown error'
})
}
})
app.get(`/api/gun/${GunEvent.ON_HANDSHAKE_ADDRESS}`, (_, res) => {
try {
// spinup
Events.onCurrentHandshakeAddress(() => {})()
const data = Events.getHandshakeAddress()
res.json({
data
})
} catch (err) {
res.status(500).json({
errorMessage: (typeof err === 'object' && err.message) || 'Unknown error'
})
}
})
/** /**
* Return app so that it can be used by express. * Return app so that it can be used by express.
*/ */