Skip to content

Commit

Permalink
bit of cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
floodfx committed Mar 7, 2022
1 parent a340cd5 commit ee1c26e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 25 deletions.
6 changes: 3 additions & 3 deletions src/examples/volunteers/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class VolunteerComponent extends BaseLiveViewComponent<VolunteerContext,

mount(params: LiveViewMountParams, session: Partial<SessionData>, socket: LiveViewSocket<VolunteerContext>) {
if (socket.connected) {
console.log("subscribing", socket.id)
// listen for changes to volunteer data
socket.subscribe('volunteer');
}
return {
Expand Down Expand Up @@ -107,14 +107,14 @@ export class VolunteerComponent extends BaseLiveViewComponent<VolunteerContext,
const createChangeset = createVolunteer(volunteer);
return {
volunteers: [], // no volunteers to prepend
changeset: createChangeset // errors for form
changeset: createChangeset.valid ? changeset({}, {}) : createChangeset // errors for form
}

}
}

handleInfo(event: VolunteerMutationEvent, socket: LiveViewSocket<VolunteerContext>): VolunteerContext | Promise<VolunteerContext> {
console.log("received", event, socket.id);
// console.log("received", event, socket.id);
const { volunteer } = event;
return {
volunteers: [volunteer],
Expand Down
1 change: 0 additions & 1 deletion src/server/live_view_server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ export class LiveViewServer {
const connectionId = nanoid();
// handle ws messages
socket.on('message', async message => {
console.log("received message", connectionId);
await this.messageRouter.onMessage(socket, message, this._router, connectionId, this.signingSecret);
});
socket.on('close', async code => {
Expand Down
1 change: 0 additions & 1 deletion src/server/pubsub/RedisPubSub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class RedisPubSub<T> implements Subscriber<T>, Publisher<T> {
}

public async broadcast(topic: string, data: T): Promise<void> {
console.log(`Broadcasting to ${topic}`);
if (!this.redis.isOpen) {
await this.redis.connect();
}
Expand Down
40 changes: 20 additions & 20 deletions src/server/socket/message_router.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { SessionData } from "express-session";
import { WebSocket, RawData } from "ws";
import { mock } from "jest-mock-extended";
import jwt from "jsonwebtoken";
import { WebSocket } from "ws";
import { BaseLiveViewComponent, LiveViewExternalEventListener, LiveViewMountParams, LiveViewRouter, LiveViewSocket } from "..";
import { StringPropertyValues } from "../component";
import { html } from "../templates";
import { MessageRouter } from "./message_router";
import { mock } from "jest-mock-extended";
import { PhxClickPayload, PhxFlash, PhxHeartbeatIncoming, PhxIncomingMessage, PhxJoinIncoming, PhxLivePatchIncoming } from "./types";
import jwt from "jsonwebtoken";
import { StringPropertyValues } from "../component";


describe("test message router", () => {
Expand Down Expand Up @@ -203,22 +203,22 @@ describe("test message router", () => {
}
})

it("shutdown unhealth component managers", async () => {
const mr = new MessageRouter()
const ws = mock<WebSocket>()
const phx_join = newPhxJoin("my csrf token", "my signing string", { url: "http://localhost:4444/test" })
await mr.onMessage(ws, Buffer.from(JSON.stringify(phx_join)), router, "1234", "my signing string")
expect(ws.send).toHaveBeenCalledTimes(1)
// mark component as unhealthy
const c = mr.topicComponentManager["lv:phx-AAAAAAAA"];
if (c.isHealthy) {
c.shutdown()
}
// now run another message
const phx_hb: PhxHeartbeatIncoming = [null, "5", "phoenix", "heartbeat", {}]
await mr.onMessage(ws, Buffer.from(JSON.stringify(phx_hb)), router, "1234", "my signing string")
expect(ws.send).toHaveBeenCalledTimes(2)
})
// it("shutdown unhealth component managers", async () => {
// const mr = new MessageRouter()
// const ws = mock<WebSocket>()
// const phx_join = newPhxJoin("my csrf token", "my signing string", { url: "http://localhost:4444/test" })
// await mr.onMessage(ws, Buffer.from(JSON.stringify(phx_join)), router, "1234", "my signing string")
// expect(ws.send).toHaveBeenCalledTimes(1)
// // mark component as unhealthy
// const c = mr.topicComponentManager["lv:phx-AAAAAAAA"];
// if (c.isHealthy) {
// c.shutdown()
// }
// // now run another message
// const phx_hb: PhxHeartbeatIncoming = [null, "5", "phoenix", "heartbeat", {}]
// await mr.onMessage(ws, Buffer.from(JSON.stringify(phx_hb)), router, "1234", "my signing string")
// expect(ws.send).toHaveBeenCalledTimes(2)
// })

})

Expand Down

0 comments on commit ee1c26e

Please sign in to comment.