forwarder: handle reconnect gracefully
This commit is contained in:
parent
d1b3f5057a
commit
acea0007ae
15
forwarder.js
15
forwarder.js
|
@ -6,11 +6,26 @@ module.exports = class Forwarder {
|
|||
this.mappingM2I = mappingM2I;
|
||||
}
|
||||
|
||||
joinIRCRooms() {
|
||||
console.log("Joining IRC Rooms...");
|
||||
for (const room of Object.keys(this.mappingI2M)) {
|
||||
this.clientIRC.say("ChanServ", "INVITE " + room);
|
||||
this.clientIRC.join(room);
|
||||
}
|
||||
}
|
||||
|
||||
start() {
|
||||
this.joinIRCRooms();
|
||||
console.log("Starting relay");
|
||||
this.clientIRC.on("registered", this.onReconnect.bind(this));
|
||||
this.clientIRC.on("message", this.onIRCMessage.bind(this));
|
||||
}
|
||||
|
||||
onReconnect() {
|
||||
console.log("IRC client reconnected");
|
||||
this.joinIRCRooms();
|
||||
}
|
||||
|
||||
onIRCMessage(event) {
|
||||
if (!event.target) {
|
||||
// Not something we care about
|
||||
|
|
8
index.js
8
index.js
|
@ -8,7 +8,6 @@ function main() {
|
|||
console.log("Logging into IRC...");
|
||||
connectIrc(config, (clientIRC) => {
|
||||
console.log("Successfully logged into IRC!");
|
||||
joinIRCRooms(clientIRC, Object.keys(mappingI2M));
|
||||
console.log("Logging into matrix...");
|
||||
connectMatrix(config, (clientMatrix) => {
|
||||
console.log("Successfully logged into Matrix!");
|
||||
|
@ -33,13 +32,6 @@ function connectIrc(config, callback) {
|
|||
client.once('registered', () => { callback(client) });
|
||||
}
|
||||
|
||||
function joinIRCRooms(client, rooms) {
|
||||
for (const room of rooms) {
|
||||
client.say("ChanServ", "INVITE " + room);
|
||||
client.join(room);
|
||||
}
|
||||
}
|
||||
|
||||
function connectMatrix(config, callback) {
|
||||
let client = matrix.createClient(config.matrix);
|
||||
let myCallback = (state) => {
|
||||
|
|
Loading…
Reference in New Issue