Skip to content

Commit

Permalink
Code refactoring for #1448
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed Nov 11, 2024
1 parent fde04bd commit 9ee8174
Showing 1 changed file with 4 additions and 18 deletions.
22 changes: 4 additions & 18 deletions internal/streams/add_consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,45 +130,31 @@ func formatError(consMedias, prodMedias []*core.Media, prodErrors []error) error

// 2. Return "codecs not matched"
if prodMedias != nil {
var prod, cons map[string]string = make(map[string]string), make(map[string]string)
var prod, cons string

for _, media := range prodMedias {
if media.Direction == core.DirectionRecvonly {
for _, codec := range media.Codecs {
if _, ok := prod[codec.Name]; !ok {
prod[media.Kind] = ""
}
prod[media.Kind] = appendString(prod[media.Kind], codec.PrintName())
prod = appendString(prod, media.Kind+":"+codec.PrintName())
}
}
}

for _, media := range consMedias {
if media.Direction == core.DirectionSendonly {
for _, codec := range media.Codecs {
if _, ok := cons[codec.Name]; !ok {
cons[media.Kind] = ""
}
cons[media.Kind] = appendString(cons[media.Kind], codec.PrintName())
cons = appendString(cons, media.Kind+":"+codec.PrintName())
}
}
}

return errors.New("streams: codecs not matched: " + mapToString(prod) + " => " + mapToString(cons))
return errors.New("streams: codecs not matched: " + prod + " => " + cons)
}

// 3. Return unknown error
return errors.New("streams: unknown error")
}

func mapToString(m map[string]string) string {
var s string
for k, v := range m {
s = appendString(s, "("+k+": "+v+")")
}
return s
}

func appendString(s, elem string) string {
if strings.Contains(s, elem) {
return s
Expand Down

0 comments on commit 9ee8174

Please sign in to comment.