add eventEmitter to dockersock class
This commit is contained in:
parent
bfda5177a6
commit
4a90510ff4
@ -118,6 +118,27 @@ export class Dockersock {
|
||||
|
||||
});
|
||||
};
|
||||
getChangeEmitter(){
|
||||
class EventEmitter extends plugins.events.EventEmitter {};
|
||||
let emitterInstance = new EventEmitter();
|
||||
let requestStream = plugins.request.get(this.sockPath + "/events");
|
||||
requestStream.on("response",(response) => {
|
||||
if(response.statusCode == 200){
|
||||
plugins.beautylog.ok("request returned status 200, so we are good!");
|
||||
} else {
|
||||
plugins.beautylog.error("request returned error: " + response.statusCode);
|
||||
}
|
||||
});
|
||||
requestStream.on("data",(data:Buffer) => {
|
||||
let status = JSON.parse(data.toString()).status;
|
||||
plugins.beautylog.logReduced(status);
|
||||
emitterInstance.emit("change",data);
|
||||
});
|
||||
requestStream.on("end",()=> {
|
||||
|
||||
});
|
||||
return emitterInstance;
|
||||
}
|
||||
request(methodArg:string,routeArg:string,queryArg:string = "", dataArg = {}){
|
||||
let done = plugins.q.defer();
|
||||
let jsonArg:string = JSON.stringify(dataArg);
|
||||
|
@ -1,4 +1,6 @@
|
||||
import "typings-global";
|
||||
export import beautylog = require("beautylog");
|
||||
export import events = require("events");
|
||||
export let q = require("q");
|
||||
export let request = require("request");
|
||||
export let request = require("request");
|
||||
eventEmitter.
|
Loading…
Reference in New Issue
Block a user