mirror of
https://github.com/nioc/xmpp-bot.git
synced 2024-11-10 03:56:48 +01:00
30 lines
813 B
JavaScript
30 lines
813 B
JavaScript
/**
|
|
* Close handler
|
|
*
|
|
* Disconnect bot from XMPP server before app closes
|
|
*
|
|
* @file This files defines the closing handler
|
|
* @author nioc
|
|
* @since 1.0.0
|
|
* @license AGPL-3.0+
|
|
*/
|
|
|
|
module.exports = (logger, xmpp) => {
|
|
let nodeCleanup = require('node-cleanup')
|
|
nodeCleanup(function (exitCode, signal) {
|
|
logger.warn(`Received ${exitCode}/${signal} (application is closing), disconnect from XMPP server`)
|
|
try {
|
|
xmpp.close()
|
|
.then(() => {
|
|
logger.debug('Connection successfully closed')
|
|
})
|
|
.catch((error) => {
|
|
logger.error('Error during XMPP disconnection', error)
|
|
})
|
|
} catch (error) {
|
|
logger.error('Error during XMPP disconnection: ' + error.message)
|
|
}
|
|
logger.debug('Synchronize logs file')
|
|
logger.shutdown()
|
|
})
|
|
}
|