remove old socket code
This commit is contained in:
parent
3d965fe630
commit
f184f7be94
1 changed files with 13 additions and 49 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
/** @prettier */
|
/** @prettier */
|
||||||
// app/sockets.js
|
// @ts-check
|
||||||
|
|
||||||
const logger = require('winston')
|
const logger = require('winston')
|
||||||
const Encryption = require('../utils/encryptionStore')
|
const Encryption = require('../utils/encryptionStore')
|
||||||
|
|
@ -21,8 +21,6 @@ module.exports = (
|
||||||
/** @type {import('socket.io').Server} */
|
/** @type {import('socket.io').Server} */
|
||||||
io
|
io
|
||||||
) => {
|
) => {
|
||||||
const Mediator = require('../services/gunDB/Mediator/index.js')
|
|
||||||
|
|
||||||
// This should be used for encrypting and emitting your data
|
// This should be used for encrypting and emitting your data
|
||||||
const emitEncryptedEvent = ({ eventName, data, socket }) => {
|
const emitEncryptedEvent = ({ eventName, data, socket }) => {
|
||||||
try {
|
try {
|
||||||
|
|
@ -260,61 +258,27 @@ module.exports = (
|
||||||
|
|
||||||
logger.info('socket.handshake', socket.handshake)
|
logger.info('socket.handshake', socket.handshake)
|
||||||
|
|
||||||
const isOneTimeUseSocket = !!socket.handshake.query.IS_GUN_AUTH
|
|
||||||
const isLNDSocket = !!socket.handshake.query.IS_LND_SOCKET
|
const isLNDSocket = !!socket.handshake.query.IS_LND_SOCKET
|
||||||
const isNotificationsSocket = !!socket.handshake.query
|
const isNotificationsSocket = !!socket.handshake.query
|
||||||
.IS_NOTIFICATIONS_SOCKET
|
.IS_NOTIFICATIONS_SOCKET
|
||||||
|
|
||||||
if (!isLNDSocket) {
|
if (!isLNDSocket) {
|
||||||
/** printing out the client who joined */
|
/** printing out the client who joined */
|
||||||
logger.info('New socket client connected (id=' + socket.id + ').')
|
logger.info('New socket client connected (id=' + socket.id + ').')
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isOneTimeUseSocket) {
|
if (isLNDSocket) {
|
||||||
logger.info('New socket is one time use')
|
const subID = Math.floor(Math.random() * 1000).toString()
|
||||||
socket.on('IS_GUN_AUTH', () => {
|
const isNotifications = isNotificationsSocket ? 'notifications' : ''
|
||||||
try {
|
logger.info('[LND] New LND Socket created:' + isNotifications + subID)
|
||||||
const isGunAuth = Mediator.isAuthenticated()
|
const cancelInvoiceStream = onNewInvoice(socket, subID)
|
||||||
socket.emit('IS_GUN_AUTH', {
|
const cancelTransactionStream = onNewTransaction(socket, subID)
|
||||||
ok: true,
|
const cancelPingStream = onPing(socket, subID)
|
||||||
msg: {
|
|
||||||
isGunAuth
|
|
||||||
},
|
|
||||||
origBody: {}
|
|
||||||
})
|
|
||||||
socket.disconnect()
|
|
||||||
} catch (err) {
|
|
||||||
socket.emit('IS_GUN_AUTH', {
|
|
||||||
ok: false,
|
|
||||||
msg: err.message,
|
|
||||||
origBody: {}
|
|
||||||
})
|
|
||||||
socket.disconnect()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
if (isLNDSocket) {
|
|
||||||
const subID = Math.floor(Math.random() * 1000).toString()
|
|
||||||
const isNotifications = isNotificationsSocket ? 'notifications' : ''
|
|
||||||
logger.info('[LND] New LND Socket created:' + isNotifications + subID)
|
|
||||||
const cancelInvoiceStream = onNewInvoice(socket, subID)
|
|
||||||
const cancelTransactionStream = onNewTransaction(socket, subID)
|
|
||||||
const cancelPingStream = onPing(socket, subID)
|
|
||||||
socket.on('disconnect', () => {
|
|
||||||
logger.info('LND socket disconnected:' + isNotifications + subID)
|
|
||||||
cancelInvoiceStream()
|
|
||||||
cancelTransactionStream()
|
|
||||||
cancelPingStream()
|
|
||||||
})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
logger.info('New socket is NOT one time use')
|
|
||||||
// this is where we create the websocket connection
|
|
||||||
// with the GunDB service.
|
|
||||||
Mediator.createMediator(socket)
|
|
||||||
|
|
||||||
/** listening if client has disconnected */
|
|
||||||
socket.on('disconnect', () => {
|
socket.on('disconnect', () => {
|
||||||
logger.info('client disconnected (id=' + socket.id + ').')
|
logger.info('LND socket disconnected:' + isNotifications + subID)
|
||||||
|
cancelInvoiceStream()
|
||||||
|
cancelTransactionStream()
|
||||||
|
cancelPingStream()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue