From 1219c373fce799f92a6de3e021fd44109bf0795a Mon Sep 17 00:00:00 2001 From: asanrom Date: Tue, 30 Aug 2016 22:59:43 +0200 Subject: [PATCH] Use SockJS as default websocket client library --- package.json | 4 ++-- src/app.js | 12 +++++++++--- src/lib/{showdown.js => showdown-ws.js} | 0 3 files changed, 11 insertions(+), 5 deletions(-) rename src/lib/{showdown.js => showdown-ws.js} (100%) 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