shutdown hoook
This commit is contained in:
parent
e36bce5a86
commit
3ba8fb6706
@ -1,6 +1,7 @@
|
||||
module.exports = {
|
||||
"remotes": [{
|
||||
"debug": true,
|
||||
"debug": false,
|
||||
"announce_channel": false,
|
||||
"name": "IRC",
|
||||
"type": "irc",
|
||||
"host": "irc.libera.chat",
|
||||
@ -11,7 +12,8 @@ module.exports = {
|
||||
"main": "pandorabox-test"
|
||||
}
|
||||
},{
|
||||
"debug": true,
|
||||
"debug": false,
|
||||
"announce_channel": false,
|
||||
"name": "Discord",
|
||||
"type": "discord",
|
||||
"token": process.env.BEERCHAT_DISCORD_TEST_TOKEN,
|
||||
|
@ -2,7 +2,7 @@ const app = require("../app");
|
||||
const events = require("../events");
|
||||
|
||||
// mod -> web
|
||||
app.post('/reconnect', function(req, res){
|
||||
events.emit("reconnect", {});
|
||||
app.post('/shutdown', function(req, res){
|
||||
events.emit("shutdown", {});
|
||||
res.end();
|
||||
});
|
@ -24,7 +24,7 @@ module.exports = class {
|
||||
Object.keys(remote.channels).forEach(ingame_name => {
|
||||
const discord_channel_name = remote.channels[ingame_name];
|
||||
const channel = this.client.channels.cache.find(ch => ch.name === discord_channel_name);
|
||||
if (channel) {
|
||||
if (channel && remote.announce_channel) {
|
||||
channel.send(`beerchat_proxy connected! ingame-channel: ${ingame_name}`);
|
||||
}
|
||||
});
|
||||
|
@ -29,11 +29,13 @@ module.exports = class {
|
||||
this.client.on('registered', () => {
|
||||
let delay = 5000;
|
||||
Object.keys(remote.channels).forEach(ingame_name => {
|
||||
setTimeout(function(){
|
||||
setTimeout(() => {
|
||||
const irc_name = remote.channels[ingame_name];
|
||||
var channel = this.client.channel("#" + irc_name);
|
||||
channel.join();
|
||||
if (remote.announce_channel) {
|
||||
channel.say(`beerchat_proxy connected! ingame-channel: ${ingame_name}`);
|
||||
}
|
||||
channels[ingame_name] = channel;
|
||||
}, delay);
|
||||
delay += 2000;
|
||||
|
19
src/index.js
19
src/index.js
@ -8,7 +8,7 @@ enableWs(app);
|
||||
require("./api/rx");
|
||||
require("./api/tx");
|
||||
require("./api/ws");
|
||||
require("./api/reconnect");
|
||||
require("./api/shutdown");
|
||||
|
||||
const cfg = require("./config");
|
||||
const events = require("./events");
|
||||
@ -19,19 +19,26 @@ const handlers = {
|
||||
discord: require("./handler/discord")
|
||||
};
|
||||
|
||||
const instances = [];
|
||||
cfg.remotes.forEach(remote => {
|
||||
const Handler = handlers[remote.type];
|
||||
const instance = new Handler();
|
||||
|
||||
console.log(`Setting up remote: ${remote.name} with type: ${remote.type}`);
|
||||
instance.init(remote, events);
|
||||
});
|
||||
|
||||
events.on("reconnect", function(){
|
||||
//TODO
|
||||
instances.push(instance);
|
||||
});
|
||||
|
||||
console.log("Starting message router");
|
||||
router(cfg, events);
|
||||
|
||||
app.listen(8080, () => console.log('Listening on http://127.0.0.1:8080'));
|
||||
const server = app.listen(8080, () => console.log('Listening on http://127.0.0.1:8080'));
|
||||
|
||||
events.on("shutdown", function(){
|
||||
// close http server
|
||||
server.close();
|
||||
// close clients
|
||||
instances.forEach(i => i.destroy());
|
||||
// forcibly quit
|
||||
process.exit(0);
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user