1
Fork 0
mirror of https://github.com/jech/galene.git synced 2024-11-23 00:55:58 +01:00

Update group API after description change.

This commit is contained in:
Juliusz Chroboczek 2021-01-04 01:41:34 +01:00
parent 2e752f9460
commit 43ed55a055

View file

@ -246,6 +246,23 @@ func APIFromCodecs(codecs []webrtc.RTPCodecCapability) *webrtc.API {
) )
} }
func APIFromNames(names []string) *webrtc.API {
if len(names) == 0 {
names = []string{"vp8", "opus"}
}
codecs := make([]webrtc.RTPCodecCapability, 0, len(names))
for _, n := range names {
codec, err := codecFromName(n)
if err != nil {
log.Printf("Codec %v: %v", n, err)
continue
}
codecs = append(codecs, codec)
}
return APIFromCodecs(codecs)
}
func Add(name string, desc *description) (*Group, error) { func Add(name string, desc *description) (*Group, error) {
if name == "" || strings.HasSuffix(name, "/") { if name == "" || strings.HasSuffix(name, "/") {
return nil, UserError("illegal group name") return nil, UserError("illegal group name")
@ -269,28 +286,12 @@ func Add(name string, desc *description) (*Group, error) {
} }
} }
names := desc.Codecs
if len(names) == 0 {
names = []string{"vp8", "opus"}
}
codecs := make([]webrtc.RTPCodecCapability, 0, len(names))
for _, n := range names {
codec, err := codecFromName(n)
if err != nil {
log.Printf("Codec %v: %v", n, err)
continue
}
codecs = append(codecs, codec)
}
api := APIFromCodecs(codecs)
g = &Group{ g = &Group{
name: name, name: name,
description: desc, description: desc,
clients: make(map[string]Client), clients: make(map[string]Client),
timestamp: time.Now(), timestamp: time.Now(),
api: api, api: APIFromNames(desc.Codecs),
} }
groups.groups[name] = g groups.groups[name] = g
return g, nil return g, nil
@ -301,6 +302,7 @@ func Add(name string, desc *description) (*Group, error) {
if desc != nil { if desc != nil {
g.description = desc g.description = desc
g.api = APIFromNames(desc.Codecs)
return g, nil return g, nil
} }
@ -316,6 +318,7 @@ func Add(name string, desc *description) (*Group, error) {
return nil, err return nil, err
} }
g.description = desc g.description = desc
g.api = APIFromNames(desc.Codecs)
} else { } else {
g.description.loadTime = time.Now() g.description.loadTime = time.Now()
} }