diff --git a/internal/capture/manager.go b/internal/capture/manager.go index 51d95425..40570d73 100644 --- a/internal/capture/manager.go +++ b/internal/capture/manager.go @@ -168,8 +168,9 @@ func (manager *CaptureManagerCtx) Audio() types.StreamManager { return manager.audio } -func (manager *CaptureManagerCtx) Video(videoID string) types.StreamManager { - return manager.videos[videoID] +func (manager *CaptureManagerCtx) Video(videoID string) (types.StreamManager, bool) { + video, ok := manager.videos[videoID] + return video, ok } func (manager *CaptureManagerCtx) VideoIDs() []string { diff --git a/internal/types/capture.go b/internal/types/capture.go index 575e52b6..ead74036 100644 --- a/internal/types/capture.go +++ b/internal/types/capture.go @@ -37,7 +37,7 @@ type CaptureManager interface { Broadcast() BroadcastManager Screencast() ScreencastManager Audio() StreamManager - Video(videoID string) StreamManager + Video(videoID string) (StreamManager, bool) VideoIDs() []string StartStream() diff --git a/internal/webrtc/manager.go b/internal/webrtc/manager.go index c854048c..0b59c9cd 100644 --- a/internal/webrtc/manager.go +++ b/internal/webrtc/manager.go @@ -57,7 +57,11 @@ func (manager *WebRTCManagerCtx) Start() { videoIDs := manager.capture.VideoIDs() manager.videoTracks = map[string]*webrtc.TrackLocalStaticSample{} for _, videoID := range videoIDs { - video := manager.capture.Video(videoID) + video, ok := manager.capture.Video(videoID) + if !ok { + manager.logger.Warn().Str("videoID", videoID).Msg("video stream not found, skipping") + continue + } track, err := webrtc.NewTrackLocalStaticSample(video.Codec().Capability, "video", "stream") if err != nil { @@ -218,7 +222,12 @@ func (manager *WebRTCManagerCtx) mediaEngine() (*webrtc.MediaEngine, error) { engine := &webrtc.MediaEngine{} // all videos must have the same codec - videoCodec := manager.capture.Video(manager.defaultVideoID).Codec() + video, ok := manager.capture.Video(manager.defaultVideoID) + if !ok { + return nil, fmt.Errorf("default video track not found") + } + + videoCodec := video.Codec() if err := videoCodec.Register(engine); err != nil { return nil, err }