Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement permissive STUN URL parsing
The parser included in the ice package strictly adheres to RFC 7064, however, this can be problematic when attempting to use ICE server URLs that were automatically generated by a third party. Twilio, for example, has been seen to send the following in its list of ICE servers: stun:global.stun.twilio.com:3478?transport=udp which would require user intervention to sanitise before passing to Pion. This patch side-steps this aspect of ice.ParseURL by pre-stripping any queries that may be present so that we can allow URLs of this form.
- Loading branch information
Showing
4 changed files
with
46 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package webrtc | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/pion/ice" | ||
) | ||
|
||
// getICEServers side-steps the strict parsing mode of the ice package | ||
// (as defined in https://tools.ietf.org/html/rfc7064) by stripping any | ||
// erroneous queries from "stun(s):" URLs before parsing. | ||
func (c Configuration) getICEServers() (*[]*ice.URL, error) { | ||
var iceServers []*ice.URL | ||
for _, server := range c.ICEServers { | ||
for _, rawURL := range server.URLs { | ||
if strings.HasPrefix(rawURL, "stun") { | ||
// strip the query from "stun(s):" if present | ||
parts := strings.Split(rawURL, "?") | ||
rawURL = parts[0] | ||
} | ||
url, err := ice.ParseURL(rawURL) | ||
if err != nil { | ||
return nil, err | ||
} | ||
iceServers = append(iceServers, url) | ||
} | ||
} | ||
return &iceServers, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters