mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-07-01 13:04:52 +02:00
Merge pull request #2454 from mikiher/socket-authority-close
Add SocketAuthority.close()
This commit is contained in:
commit
fbbceddba8
2 changed files with 20 additions and 2 deletions
|
@ -284,7 +284,7 @@ class Server {
|
||||||
await this.stop()
|
await this.stop()
|
||||||
Logger.info('Server stopped. Exiting.')
|
Logger.info('Server stopped. Exiting.')
|
||||||
} else {
|
} else {
|
||||||
Logger.info('SIGINT (Ctrl+C) received again. Exiting immediately.')
|
Logger.info('SIGINT (Ctrl+C) received again. Exiting immediately.')
|
||||||
}
|
}
|
||||||
process.exit(0)
|
process.exit(0)
|
||||||
})
|
})
|
||||||
|
@ -395,13 +395,17 @@ class Server {
|
||||||
res.sendStatus(200)
|
res.sendStatus(200)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gracefully stop server
|
||||||
|
* Stops watcher and socket server
|
||||||
|
*/
|
||||||
async stop() {
|
async stop() {
|
||||||
Logger.info('=== Stopping Server ===')
|
Logger.info('=== Stopping Server ===')
|
||||||
await this.watcher.close()
|
await this.watcher.close()
|
||||||
Logger.info('Watcher Closed')
|
Logger.info('Watcher Closed')
|
||||||
|
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
this.server.close((err) => {
|
SocketAuthority.close((err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
Logger.error('Failed to close server', err)
|
Logger.error('Failed to close server', err)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -73,6 +73,20 @@ class SocketAuthority {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Closes the Socket.IO server and disconnect all clients
|
||||||
|
*
|
||||||
|
* @param {Function} callback
|
||||||
|
*/
|
||||||
|
close(callback) {
|
||||||
|
Logger.info('[SocketAuthority] Shutting down')
|
||||||
|
// This will close all open socket connections, and also close the underlying http server
|
||||||
|
if (this.io)
|
||||||
|
this.io.close(callback)
|
||||||
|
else
|
||||||
|
callback()
|
||||||
|
}
|
||||||
|
|
||||||
initialize(Server) {
|
initialize(Server) {
|
||||||
this.Server = Server
|
this.Server = Server
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue