Skip to content

Commit

Permalink
enhancement: Activity stream updated even when no one is listening
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorybesson committed Mar 31, 2017
1 parent a1fdc41 commit d6fb3ee
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/cli/core/manager/Manager.js
Expand Up @@ -68,8 +68,14 @@ class Manager {
template: new events.EventEmitter(0),
structure: new events.EventEmitter(0),
reference: new events.EventEmitter(0),
activity: new events.EventEmitter(0),
}

this.events.activity.on('activity', function(data) {
this.addActivity(data)
this.events.activity.emit("activity-stream", data)
}.bind(this));

// watch template folder
try {
fse.accessSync(this._pathTemplate, fse.F_OK)
Expand Down
2 changes: 1 addition & 1 deletion src/server/routes/operations/post/submit.js
Expand Up @@ -36,7 +36,7 @@ var route = function(req, res, next){
if(res.user && res.user.username){
username = res.user.username
}
res.app.emit("activity-stream", {operation: operation.workflow, post: operation.postUrl, user: username})
Manager.instance.events.activity.emit("activity", {operation: operation.workflow, post: operation.postUrl, user: username})
res.set('Content-Type', 'application/json')
res.send(JSON.stringify(result))
},
Expand Down
3 changes: 1 addition & 2 deletions src/server/routes/rest/activity-stream.js
Expand Up @@ -4,7 +4,6 @@ import {
} from '../../../cli'

var eventOnActivity = function(data) {
Manager.instance.addActivity(data)
var activities = Manager.instance.getActivities()
this.write('data: {\n')
var i = 0
Expand Down Expand Up @@ -34,7 +33,7 @@ var route = function(req, res) {
})

let evt = eventOnActivity.bind(res)
res.app.on("activity-stream", evt)
Manager.instance.events.activity.on("activity-stream", evt)

if (!req.headers['last-event-id']) {
var activities = Manager.instance.getActivities()
Expand Down

0 comments on commit d6fb3ee

Please sign in to comment.