From 4a90510ff4b30e0132c03afe6cb2f571f80999c0 Mon Sep 17 00:00:00 2001 From: Phil Kunz Date: Mon, 11 Jul 2016 21:55:10 +0200 Subject: [PATCH] add eventEmitter to dockersock class --- ts/dockersock.classes.dockersock.ts | 21 +++++++++++++++++++++ ts/dockersock.plugins.ts | 4 +++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/ts/dockersock.classes.dockersock.ts b/ts/dockersock.classes.dockersock.ts index c6dd442..969be75 100644 --- a/ts/dockersock.classes.dockersock.ts +++ b/ts/dockersock.classes.dockersock.ts @@ -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); diff --git a/ts/dockersock.plugins.ts b/ts/dockersock.plugins.ts index ea322a9..a38787c 100644 --- a/ts/dockersock.plugins.ts +++ b/ts/dockersock.plugins.ts @@ -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"); \ No newline at end of file +export let request = require("request"); +eventEmitter. \ No newline at end of file