From 0ba869f0ebd84eaabe6b4e232d6f85ab8c0ff39c Mon Sep 17 00:00:00 2001 From: brunosimon Date: Sun, 24 Dec 2017 13:25:10 +0100 Subject: [PATCH] :bug: Server > Fix alert --- lib/chat.js | 12 ++++-------- lib/index.js | 1 + lib/project.js | 3 ++- lib/watcher.js | 13 +++++++++++++ 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/lib/chat.js b/lib/chat.js index 790f653..302e302 100644 --- a/lib/chat.js +++ b/lib/chat.js @@ -1,7 +1,5 @@ const ids = require('./ids.js') const robotNames = require('./assets/data/robot-names.json') -const nodeNotifier = require('node-notifier') -const path = require('path') const HTMLEntities = require('html-entities') class Chat @@ -10,6 +8,8 @@ class Chat { this.config = _config this.slug = _options.slug + this.watcherSocket = _options.watcherSocket + this.users = {} this.messages = [] this.availableRobotNames = this.shuffle(robotNames.slice()) @@ -100,12 +100,8 @@ class Chat // On alert socket.on('alert', () => { - nodeNotifier.notify({ - title: 'Keppler', - message: 'Alert!', - icon: path.join(__dirname, 'assets/images/notification-icon-200x200.png'), - wait: true - }) + // Transfer to the watcher socket + this.watcherSocket.emit('alert') // Debug if(this.config.debug >= 1) diff --git a/lib/index.js b/lib/index.js index dad2933..38ec0b3 100644 --- a/lib/index.js +++ b/lib/index.js @@ -218,6 +218,7 @@ class App // Start project socket.on('start_project', (data) => { + data.watcherSocket = socket // Add watcher socket project = this.projects.createProject(data) this.site.createProjectRoute(project) diff --git a/lib/project.js b/lib/project.js index 4af1656..0206b7f 100644 --- a/lib/project.js +++ b/lib/project.js @@ -13,6 +13,7 @@ class Project { this.config = _config this.path = _options.path + this.watcherSocket = _options.watcherSocket this.setName(_options.name) this.setSocket() @@ -20,7 +21,7 @@ class Project this.excludeRegex = new RegExp(_options.excludeRegex) this.zipNeedsUpdate = true this.files = new Files(this.config, { projectSocket: this.projectSocket }) - this.chat = new Chat(this.config, { slug: this.slug }) + this.chat = new Chat(this.config, { slug: this.slug, watcherSocket: this.watcherSocket }) this.date = new Date() // Add test contents diff --git a/lib/watcher.js b/lib/watcher.js index a5791c4..c545f71 100644 --- a/lib/watcher.js +++ b/lib/watcher.js @@ -4,6 +4,8 @@ const fs = require('fs') const mime = require('mime') const socketIoClient = require('socket.io-client') const opener = require('opener') +const nodeNotifier = require('node-notifier') +const path = require('path') /** * Watcher class @@ -64,6 +66,17 @@ class Watcher opener(url) } }) + + // Alert event + this.socket.on('alert', () => + { + nodeNotifier.notify({ + title: 'Keppler', + message: 'Alert!', + icon: path.join(__dirname, 'assets/images/notification-icon-200x200.png'), + wait: true + }) + }) } setExcludeRegex()