add eventEmitter to dockersock class

This commit is contained in:
Phil Kunz 2016-07-11 21:55:10 +02:00
parent bfda5177a6
commit 4a90510ff4
2 changed files with 24 additions and 1 deletions

View File

@ -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);

View File

@ -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.