ICE servers as URIs with auth.

This commit is contained in:
Miroslav Šedivý 2021-03-15 16:34:13 +01:00
parent 0824c24bf6
commit a1be9002f7

View File

@ -3,6 +3,7 @@ package webrtc
import (
"fmt"
"io"
"net/url"
"strings"
"sync"
"time"
@ -423,6 +424,35 @@ func (manager *WebRTCManagerCtx) apiConfiguration() *webrtc.Configuration {
}
}
ICEServers := []webrtc.ICEServer{}
for _, server := range manager.config.ICEServers {
u, err := url.Parse(server)
// if it is not valid URL, just pass it down
if err != nil {
ICEServers = append(ICEServers, webrtc.ICEServer{
URLs: []string{server},
})
continue
}
var pwdInt interface{}
pwd, ok := u.User.Password()
if ok {
pwdInt = pwd
} else {
pwdInt = false
}
ICEServers = append(ICEServers, webrtc.ICEServer{
URLs: []string{
u.Scheme + ":" + u.Host + u.Path + "?" + u.RawQuery,
},
Username: u.User.Username(),
Credential: pwdInt,
})
}
return &webrtc.Configuration{
ICEServers: []webrtc.ICEServer{
{