Skip to content

Commit

Permalink
tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
tailuge committed Dec 28, 2024
1 parent f4c3bfa commit f84c0d7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/network/client/nchanmessagerelay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import { MessageRelay } from "./messagerelay"
export class NchanMessageRelay<T> implements MessageRelay<T> {
private readonly websockets: Map<string, WebSocket> = new Map()

constructor(private readonly baseURL: string) {}
constructor(
private readonly baseURL: string = "https://billiards-network.onrender.com"
) {}

subscribe(channel: string, callback: (message: T) => void): void {
const url = `${this.baseURL}/subscribe/${channel}`
const ws = new WebSocket(url)

console.log("Subscribed to ", url)
ws.onmessage = (event) => {
try {
const message = JSON.parse(event.data) as T
Expand Down
6 changes: 4 additions & 2 deletions test/server/messagerelay.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { expect } from "chai"
import { InMemoryMessageRelay } from "../mocks/inmemorymessagerelay"
import { MessageRelay } from "../../src/network/client/messagerelay"
import { BreakEvent } from "../../src/events/breakevent"
import { GameEvent } from "../../src/events/gameevent"

const jestConsole = console

Expand All @@ -13,11 +15,11 @@ afterEach(() => {
})

describe("MessageRelay", () => {
const relay: MessageRelay<string> = new InMemoryMessageRelay<string>()
const relay: MessageRelay<GameEvent> = new InMemoryMessageRelay<GameEvent>()

it("validate subscriber receives published message", (done) => {
const channel = "test"
const message = "hello"
const message = new BreakEvent()
relay.subscribe(channel, (msg) => {
expect(msg).to.equal(message)
done()
Expand Down

0 comments on commit f84c0d7

Please sign in to comment.