Skip to content

Commit

Permalink
go and manually put together TURN TLS for twilio (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
danjenkins authored Apr 29, 2024
1 parent 2fdfdb3 commit 6d96c95
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions adapters/twilio/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,6 @@ type TwilioResponse struct {
func (d *Driver) GetIceServers() (iceServers []webrtc.ICEServer, err error) {
client := &http.Client{}

if err != nil {
log.WithFields(log.Fields{
"error": err,
}).Error("Error forming http request URL")
return nil, err
}
req, err := http.NewRequest("POST", d.Config.RequestUrl, nil)
req.SetBasicAuth(d.Config.HttpUsername, d.Config.HttpPassword)

Expand Down Expand Up @@ -79,6 +73,8 @@ func (d *Driver) GetIceServers() (iceServers []webrtc.ICEServer, err error) {
responseServers := TwilioResponse{}
json.Unmarshal([]byte(responseData), &responseServers)

tempTurnHost := ""

for _, r := range responseServers.IceServers {

info, err := stun.ParseURI(r.URL)
Expand All @@ -91,6 +87,10 @@ func (d *Driver) GetIceServers() (iceServers []webrtc.ICEServer, err error) {
continue
}

if (info.Scheme == stun.SchemeTypeTURN) {
tempTurnHost = info.Host
}

s := webrtc.ICEServer{
URLs: []string{r.URL},
}
Expand All @@ -104,5 +104,21 @@ func (d *Driver) GetIceServers() (iceServers []webrtc.ICEServer, err error) {
iceServers = append(iceServers, s)
}



//apparently if you go and make a tls turn uri it will work
s := webrtc.ICEServer{
URLs: []string{"turns:" + tempTurnHost + ":5349?transport=tcp"},
}

if responseServers.Username != "" {
s.Username = responseServers.Username
}
if responseServers.Password != "" {
s.Credential = responseServers.Password
}

iceServers = append(iceServers, s)

return iceServers, nil
}

0 comments on commit 6d96c95

Please sign in to comment.