Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FCE 756 enable unit test and remove validators #165

Merged
merged 5 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/node.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ jobs:
- name: Build 📦
run: yarn build

- name: Test 🧑‍🔬
run: yarn test:unit

- name: Check formatting 🎨
run: yarn format:check

Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/react-client/docker-compose-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: "3"

services:
fishjam:
image: "ghcr.io/fishjam-cloud/fishjam:0.8.0"
image: "ghcr.io/fishjam-cloud/fishjam:0.9.0"
container_name: fishjam
restart: on-failure
healthcheck:
Expand Down
99 changes: 15 additions & 84 deletions e2e-tests/ts-client/app/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,67 +24,31 @@ export type TrackMetadata = {
goodTrack: string;
};

function endpointMetadataParser(a: unknown): EndpointMetadata {
if (
typeof a !== "object" ||
a === null ||
!("goodStuff" in a) ||
typeof a.goodStuff !== "string"
)
throw "Invalid metadata!!!";
return { goodStuff: a.goodStuff };
}

function trackMetadataParser(a: unknown): TrackMetadata {
if (
typeof a !== "object" ||
a === null ||
!("goodTrack" in a) ||
typeof a.goodTrack !== "string"
)
throw "Invalid track metadata!!!";
return { goodTrack: a.goodTrack };
}

class RemoteStore {
cache: Record<
string,
[
Record<string, Endpoint<EndpointMetadata, TrackMetadata>>,
Record<string, TrackContext<EndpointMetadata, TrackMetadata>>,
]
[Record<string, Endpoint>, Record<string, TrackContext>]
> = {};
invalidateCache: boolean = false;

constructor(
private webrtc: WebRTCEndpoint<EndpointMetadata, TrackMetadata>,
) {}
constructor(private webrtc: WebRTCEndpoint) {}

subscribe(callback: () => void) {
const cb = () => {
this.invalidateCache = true;
callback();
};

const trackCb: TrackContextEvents<
EndpointMetadata,
TrackMetadata
>["encodingChanged"] = () => cb();
const trackCb: TrackContextEvents["encodingChanged"] = () => cb();

const trackAddedCb: WebRTCEndpointEvents<
EndpointMetadata,
TrackMetadata
>["trackAdded"] = (context) => {
const trackAddedCb: WebRTCEndpointEvents["trackAdded"] = (context) => {
context.on("encodingChanged", () => trackCb);
context.on("voiceActivityChanged", () => trackCb);

callback();
};

const removeCb: WebRTCEndpointEvents<
EndpointMetadata,
TrackMetadata
>["trackRemoved"] = (context) => {
const removeCb: WebRTCEndpointEvents["trackRemoved"] = (context) => {
context.removeListener("encodingChanged", () => trackCb);
context.removeListener("voiceActivityChanged", () => trackCb);

Expand Down Expand Up @@ -127,10 +91,7 @@ class RemoteStore {
// Assign a random client ID to make it easier to distinguish their messages
const clientId = Math.floor(Math.random() * 100);

const webrtc = new WebRTCEndpoint({
endpointMetadataParser,
trackMetadataParser,
});
const webrtc = new WebRTCEndpoint();
(window as typeof window & { webrtc: WebRTCEndpoint }).webrtc = webrtc;
const remoteTracksStore = new RemoteStore(webrtc);

Expand Down Expand Up @@ -289,14 +250,7 @@ export function App() {
<MockComponent webrtc={webrtc} />
<div style={{ width: "100%" }}>
{Object.values(remoteTracks).map(
({
stream,
trackId,
endpoint,
metadata,
rawMetadata,
metadataParsingError,
}) => (
({ stream, trackId, endpoint, metadata }) => (
<div
key={trackId}
data-endpoint-id={endpoint.id}
Expand All @@ -305,16 +259,6 @@ export function App() {
<div>Endpoint id: {endpoint.id}</div>
Metadata:{" "}
<code className="metadata">{JSON.stringify(metadata)}</code>
<br />
Raw:{" "}
<code className="raw-metadata">
{JSON.stringify(rawMetadata)}
</code>
<br />
Error:{" "}
<code className="metadata-parsing-error">
{metadataParsingError}
</code>
<div style={{ display: "flex", flexDirection: "column" }}>
<VideoPlayerWithDetector
id={endpoint.id}
Expand Down Expand Up @@ -342,27 +286,14 @@ export function App() {
<hr />
<div id="endpoints-container">
Endpoints:
{Object.values(remoteEndpoints).map(
({ id, metadata, rawMetadata, metadataParsingError }) => (
<details key={id} open>
<summary>{id}</summary>
metadata:{" "}
<code id={`metadata-${id}`}>
{JSON.stringify(metadata.peer)}
</code>
<br />
raw metadata:{" "}
<code id={`raw-metadata-${id}`}>
{JSON.stringify(rawMetadata.peer)}
</code>
<br />
metadata parsing error:{" "}
<code id={`metadata-parsing-error-${id}`}>
{metadataParsingError?.toString?.() ?? metadataParsingError}
</code>
</details>
),
)}
{Object.values(remoteEndpoints).map(({ id, metadata }) => (
<details key={id} open>
<summary>{id}</summary>
metadata:{" "}
<code id={`metadata-${id}`}>{JSON.stringify(metadata)}</code>
<br />
</details>
))}
</div>
</div>
</div>
Expand Down
3 changes: 1 addition & 2 deletions e2e-tests/ts-client/app/src/MockComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { createStream } from "./mocks";
import { VideoPlayer } from "./VideoPlayer";
import { useRef, useState } from "react";
import type { EndpointMetadata, TrackMetadata } from "./App";
import type {
BandwidthLimit,
SimulcastConfig,
Expand All @@ -22,7 +21,7 @@ export const heartMock = createStream("🫀", "white", "low", 24);
export const heart2Mock = createStream("💝", "#FF0000", "low", 24);

type Props = {
webrtc: WebRTCEndpoint<EndpointMetadata, TrackMetadata>;
webrtc: WebRTCEndpoint;
};

export const MockComponent = ({ webrtc }: Props) => {
Expand Down
15 changes: 6 additions & 9 deletions e2e-tests/ts-client/app/src/MuteTrackTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { brain2Mock, heart2Mock } from "./MockComponent";
import { useEffect, useState } from "react";
import { VideoPlayer } from "./VideoPlayer";
import type { WebRTCEndpointEvents } from "@fishjam-cloud/ts-client/webrtc";
import type { EndpointMetadata, TrackMetadata } from "./App";

type Props = {
webrtc: WebRTCEndpoint;
Expand All @@ -15,19 +14,17 @@ export const MuteTrackTest = ({ webrtc }: Props) => {
const [trackId, setTrackId] = useState<string | null>(null);

useEffect(() => {
const localTrackAdded: WebRTCEndpointEvents<
EndpointMetadata,
TrackMetadata
>["localTrackAdded"] = (event) => {
const localTrackAdded: WebRTCEndpointEvents["localTrackAdded"] = (
event,
) => {
setCurrentStream(event.stream);
setCurrentTrack(event.track);
setTrackId(event.trackId);
};

const localTrackReplaced: WebRTCEndpointEvents<
EndpointMetadata,
TrackMetadata
>["localTrackReplaced"] = (event) => {
const localTrackReplaced: WebRTCEndpointEvents["localTrackReplaced"] = (
event,
) => {
setCurrentTrack(event.track);
};

Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/ts-client/docker-compose-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: '3'

services:
fishjam:
image: "ghcr.io/fishjam-cloud/fishjam:0.8.0"
image: "ghcr.io/fishjam-cloud/fishjam:0.9.0"
container_name: fishjam
restart: on-failure
healthcheck:
Expand Down
Loading
Loading