From 3eb419d980fcbfe7cdec067850b309be6649835a Mon Sep 17 00:00:00 2001 From: Alex Hamlin Date: Wed, 4 Sep 2024 18:02:21 -0700 Subject: [PATCH] Use errors.Join to simplify codec registration --- internal/api/webrtc.go | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/internal/api/webrtc.go b/internal/api/webrtc.go index c6c3b80..fa8c0d2 100644 --- a/internal/api/webrtc.go +++ b/internal/api/webrtc.go @@ -3,6 +3,7 @@ package api import ( "context" "encoding/json" + "errors" "log" "net/http" "sync" @@ -27,20 +28,15 @@ func init() { ) var me webrtc.MediaEngine - - videoParameters := webrtc.RTPCodecParameters{ - PayloadType: videoPayloadType, - RTPCodecCapability: tuner.VideoCodecCapability, - } - if err := me.RegisterCodec(videoParameters, webrtc.RTPCodecTypeVideo); err != nil { - panic(err) - } - - audioParameters := webrtc.RTPCodecParameters{ - PayloadType: audioPayloadType, - RTPCodecCapability: tuner.AudioCodecCapability, - } - if err := me.RegisterCodec(audioParameters, webrtc.RTPCodecTypeAudio); err != nil { + err := errors.Join( + me.RegisterCodec( + webrtc.RTPCodecParameters{PayloadType: videoPayloadType, RTPCodecCapability: tuner.VideoCodecCapability}, + webrtc.RTPCodecTypeVideo), + me.RegisterCodec( + webrtc.RTPCodecParameters{PayloadType: audioPayloadType, RTPCodecCapability: tuner.AudioCodecCapability}, + webrtc.RTPCodecTypeAudio), + ) + if err != nil { panic(err) }