Skip to content

Commit 215423e

Browse files
committed
add abstract high level api
1 parent 8eb7729 commit 215423e

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

client-web/src/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@ import { ClientCore } from "./lib";
66
maxDownstreams: 1,
77
});
88

9+
const videos: Record<string, HTMLVideoElement> = {};
910
client.$state.listen((v) => console.log(v));
1011
client.$participants.listen((newValue, _, changed) => {
11-
// assign this to a video element
12-
console.log(changed);
12+
const video = videos[changed] || document.createElement("video");
13+
const participant = newValue[changed].get();
14+
client.subscribe(video, participant);
15+
videos[changed] = video;
1316
});
1417
await client.connect("default", `alice-${Math.round(Math.random() * 100)}`);
1518

client-web/src/lib/core.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,4 +337,10 @@ export class ClientCore {
337337
this.#videoSender.sender.replaceTrack(null);
338338
this.#audioSender.sender.replaceTrack(null);
339339
}
340+
341+
// TODO: remove browser specific
342+
subscribe(video: HTMLVideoElement, participant: ParticipantMeta) {
343+
video.srcObject = participant.stream;
344+
video.autoplay = true;
345+
}
340346
}

0 commit comments

Comments
 (0)