diff --git a/src/config_new.ts b/src/config_new.ts index 63aa3d6..7630f01 100644 --- a/src/config_new.ts +++ b/src/config_new.ts @@ -3,6 +3,7 @@ const config = { { type: "vehicle-position", source: "gtfs", + emitName: "vehicles-on-route", subscribePath: "subscribe-route", unsubscribePath: "unsubscribe-route", loggingEventName: "route", @@ -14,6 +15,7 @@ const config = { { type: "arrivals", source: "gtfs", + emitName: "arrivals", subscribePath: "subscribe-arrivals", unsubscribePath: "unsubscribe-arrivals", loggingEventName: "arrivals", diff --git a/src/gtfs/interval.ts b/src/gtfs/interval.ts index ae0a83e..043368d 100644 --- a/src/gtfs/interval.ts +++ b/src/gtfs/interval.ts @@ -1,7 +1,7 @@ class Interval { #callback: () => void; - #interval: NodeJS.Timeout; + #interval: NodeJS.Timer; #seconds: number; diff --git a/src/index.ts b/src/index.ts index 39d70cd..cdf9cb9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -26,6 +26,7 @@ StaticGTFS.updateGTFS().then(() => { config.providers.forEach((provider) => { const realtimeProvider = getRealtimeFactory(provider); const manager = new Manager( + provider.emitName, realtimeProvider, provider.loggingEventName ); diff --git a/src/spec/ws-managers/manager.spec.ts b/src/spec/ws-managers/manager.spec.ts index 8ad1631..afb23ae 100644 --- a/src/spec/ws-managers/manager.spec.ts +++ b/src/spec/ws-managers/manager.spec.ts @@ -19,7 +19,7 @@ describe("websocket connection manager", () => { socket = new MockedSocket(); provider = new MockProvider(); - manager = new Manager(provider); + manager = new Manager("event-name", provider); }); afterEach(() => { @@ -53,7 +53,7 @@ describe("websocket connection manager", () => { describe("data emitting", () => { context("provider hasn't emitted data", () => { it("emits on publish", (done) => { - socket.on("data", (data: EmittedData) => { + socket.on("event-name", (data: EmittedData) => { try { expect(data.data).to.deep.equal(emittedData[0][stopId]); expect(data.k).to.equal(stopId); @@ -75,7 +75,7 @@ describe("websocket connection manager", () => { }); it("emits data on connect", (done) => { - socket.on("data", (data: EmittedData) => { + socket.on("event-name", (data: EmittedData) => { try { expect(data.data).to.deep.equal(emittedData[0][stopId]); expect(data.k).to.equal(stopId); diff --git a/src/ws-managers/manager.ts b/src/ws-managers/manager.ts index d0c2db3..c91ea34 100644 --- a/src/ws-managers/manager.ts +++ b/src/ws-managers/manager.ts @@ -14,12 +14,19 @@ class Manager { */ data: T; + eventName: string; provider: RealtimeProvider; + #interval: NodeJS.Timer; #loggingEventType; #ignoreCount: number; - constructor(realtimeProvider: RealtimeProvider, loggingEventType = "") { + constructor( + eventName: string, + realtimeProvider: RealtimeProvider, + loggingEventType = "" + ) { + this.eventName = eventName; this.provider = realtimeProvider; this.#loggingEventType = loggingEventType; this.#ignoreCount = 0; @@ -122,7 +129,7 @@ class Manager { */ #emit(subscriber: { socket: UserSocket; key: string }) { if (!this.data) return; - subscriber.socket.emit("data", { + subscriber.socket.emit(this.eventName, { data: this.data[subscriber.key], k: subscriber.key, });