diff --git a/package.json b/package.json index 95d1ea0..573a0a9 100644 --- a/package.json +++ b/package.json @@ -16,10 +16,10 @@ "node": "> 4.0.0" }, "dependencies": { - "websocket": "1.0.23" + "sockjs-client": "1.1.1" }, "optionalDependencies": { - "sockjs-client": "1.1.1", + "websocket": "1.0.23", "githubhook": "1.6.1", "pem": "1.8.3", "readline-sync": "1.3.0" diff --git a/src/app.js b/src/app.js index bccb200..e5ad594 100644 --- a/src/app.js +++ b/src/app.js @@ -114,7 +114,15 @@ class ChatBotApp { /* Create the bot */ let ShowdownBot = null; - if (this.config.websocketLibrary === 'sockjs') { + if (this.config.websocketLibrary === 'websocket') { + try { + require('websocket'); + } catch (e) { + console.log('Installing dependencies... (websocket)'); + require('child_process').spawnSync('sh', ['-c', 'npm install websocket'], {stdio: 'inherit'}); + } + ShowdownBot = require(Path.resolve(__dirname, 'lib/showdown-ws.js')).Bot; + } else { try { require('sockjs-client'); } catch (e) { @@ -122,8 +130,6 @@ class ChatBotApp { require('child_process').spawnSync('sh', ['-c', 'npm install sockjs-client'], {stdio: 'inherit'}); } ShowdownBot = require(Path.resolve(__dirname, 'lib/showdown-sockjs.js')).Bot; - } else { - ShowdownBot = require(Path.resolve(__dirname, 'lib/showdown.js')).Bot; } this.bot = new ShowdownBot(this.config.bot.server, diff --git a/src/lib/showdown.js b/src/lib/showdown-ws.js similarity index 100% rename from src/lib/showdown.js rename to src/lib/showdown-ws.js