catch socket connection error

This commit is contained in:
Evert Prants 2022-08-25 21:32:41 +03:00
parent b1b3be5e22
commit 836faee834
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
2 changed files with 16 additions and 10 deletions

View File

@ -2,7 +2,7 @@
"main": "plugin.js", "main": "plugin.js",
"name": "syncplay", "name": "syncplay",
"description": "Syncplay Service for Squeebot 3", "description": "Syncplay Service for Squeebot 3",
"version": "1.0.2", "version": "1.0.3",
"tags": ["service", "syncplay"], "tags": ["service", "syncplay"],
"dependencies": ["control?"], "dependencies": ["control?"],
"npmDependencies": [] "npmDependencies": []

View File

@ -196,16 +196,22 @@ class SyncplayProtocol extends Protocol {
password = crypto.createHash('md5').update(password).digest('hex'); password = crypto.createHash('md5').update(password).digest('hex');
} }
this.socket = net.connect(opts, () => { try {
this.write({ this.socket = net.connect(opts, () => {
Hello: { this.write({
username: this.config.syncplay.name, Hello: {
password, username: this.config.syncplay.name,
room: { name: this.config.syncplay.room }, password,
version: PROTOCOL_VERSION room: { name: this.config.syncplay.room },
} version: PROTOCOL_VERSION
}
});
}); });
}); } catch(err: any) {
this.emit('error', err);
this.stop(true);
return;
}
let buffer: any = ''; let buffer: any = '';
this.socket.on('data', (chunk) => { this.socket.on('data', (chunk) => {