-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.js
58 lines (41 loc) · 1.08 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
var events = require("events"),
JSuck = require("jsuck");
var DockerEvents = module.exports = function DockerEvents(options) {
events.EventEmitter.call(this, options);
options = options || {};
this.docker = options.docker;
this.running = false;
};
DockerEvents.prototype = Object.create(events.EventEmitter.prototype, {constructor: {value: DockerEvents}});
DockerEvents.prototype.start = function start() {
var self = this;
this.running = true;
this.docker.getEvents(function(err, res) {
if (err) {
return self.emit("error", err);
}
self.res = res;
self.emit("connect");
var parser = new JSuck();
res.pipe(parser);
parser.on("data", function(data) {
self.emit("_message", data);
self.emit(data.status, data);
});
parser.on("end", function() {
self.emit("disconnect");
self.res = null;
if (self.running) {
self.start();
}
});
});
return this;
};
DockerEvents.prototype.stop = function stop() {
this.running = false;
if (this.res) {
this.res.destroy();
}
return this;
};