Skip to content
Open
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
9 changes: 9 additions & 0 deletions packages/sdk/src/realtime/media-channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import mitt, { type Emitter } from "mitt";

import { createConsoleLogger, type Logger } from "../utils/logger";
import { REALTIME_CONFIG } from "./config-realtime";
import { attachRoomInstrumentation } from "./observability/network-instrumentation";
import type { RealtimeObservability } from "./observability/realtime-observability";

export type VideoCodec = "h264" | "vp8" | "vp9" | "av1";
Expand Down Expand Up @@ -57,6 +58,7 @@ export class MediaChannel {
private remoteStream: MediaStream | null = null;
private events: Emitter<MediaChannelEvents> = mitt();
private readonly logger: Logger;
private detachInstrumentation: (() => void) | null = null;

constructor(private readonly config: MediaChannelConfig) {
this.logger = config.logger ?? createConsoleLogger("warn");
Expand Down Expand Up @@ -105,6 +107,9 @@ export class MediaChannel {
await room.connect(opts.url, opts.token);
this.config.observability?.endPhase("webrtc-handshake", { success: true });
this.config.observability?.setLiveKitRoom(room);
if (this.config.observability) {
this.detachInstrumentation = attachRoomInstrumentation(room, this.config.observability);
}
}

async publishLocalTracks(): Promise<void> {
Expand All @@ -118,6 +123,10 @@ export class MediaChannel {
const room = this.room;
this.room = null;
this.remoteStream = null;
if (this.detachInstrumentation) {
this.detachInstrumentation();
this.detachInstrumentation = null;
}
this.config.observability?.setLiveKitRoom(null);
if (room) {
room.disconnect().catch(() => {});
Expand Down
Loading
Loading