Skip to content

Commit

Permalink
Revert "remove emitName from ws manager"
Browse files Browse the repository at this point in the history
This reverts commit cc064a5.
  • Loading branch information
patrickdemers6 committed Oct 9, 2023
1 parent cc064a5 commit 48d0dc6
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/config_new.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const config = {
{
type: "vehicle-position",
source: "gtfs",
emitName: "vehicles-on-route",
subscribePath: "subscribe-route",
unsubscribePath: "unsubscribe-route",
loggingEventName: "route",
Expand All @@ -14,6 +15,7 @@ const config = {
{
type: "arrivals",
source: "gtfs",
emitName: "arrivals",
subscribePath: "subscribe-arrivals",
unsubscribePath: "unsubscribe-arrivals",
loggingEventName: "arrivals",
Expand Down
2 changes: 1 addition & 1 deletion src/gtfs/interval.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class Interval {
#callback: () => void;

#interval: NodeJS.Timeout;
#interval: NodeJS.Timer;

#seconds: number;

Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ StaticGTFS.updateGTFS().then(() => {
config.providers.forEach((provider) => {
const realtimeProvider = getRealtimeFactory(provider);
const manager = new Manager<unknown>(
provider.emitName,
realtimeProvider,
provider.loggingEventName
);
Expand Down
6 changes: 3 additions & 3 deletions src/spec/ws-managers/manager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down Expand Up @@ -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<ArrivalsByStopID>) => {
socket.on("event-name", (data: EmittedData<ArrivalsByStopID>) => {
try {
expect(data.data).to.deep.equal(emittedData[0][stopId]);
expect(data.k).to.equal(stopId);
Expand All @@ -75,7 +75,7 @@ describe("websocket connection manager", () => {
});

it("emits data on connect", (done) => {
socket.on("data", (data: EmittedData<ArrivalsByStopID>) => {
socket.on("event-name", (data: EmittedData<ArrivalsByStopID>) => {
try {
expect(data.data).to.deep.equal(emittedData[0][stopId]);
expect(data.k).to.equal(stopId);
Expand Down
11 changes: 9 additions & 2 deletions src/ws-managers/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,19 @@ class Manager<T> {
*/
data: T;

eventName: string;
provider: RealtimeProvider<T>;
#interval: NodeJS.Timer;
#loggingEventType;

#ignoreCount: number;

constructor(realtimeProvider: RealtimeProvider<T>, loggingEventType = "") {
constructor(
eventName: string,
realtimeProvider: RealtimeProvider<T>,
loggingEventType = ""
) {
this.eventName = eventName;
this.provider = realtimeProvider;
this.#loggingEventType = loggingEventType;
this.#ignoreCount = 0;
Expand Down Expand Up @@ -122,7 +129,7 @@ class Manager<T> {
*/
#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,
});
Expand Down

0 comments on commit 48d0dc6

Please sign in to comment.