-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathcredentials.go
More file actions
37 lines (33 loc) · 1.43 KB
/
credentials.go
File metadata and controls
37 lines (33 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package nethernet
import "github.com/pion/webrtc/v4"
// Credentials holds the configuration for ICE servers used for gathering local ICE candidates.
type Credentials struct {
ExpirationInSeconds int `json:"ExpirationInSeconds"`
ICEServers []ICEServer `json:"TurnAuthServers"`
}
// ICEServer represents a single ICE server configuration, including its authentication details
// and connection URLs. Each server requires a username and password for authentication.
type ICEServer struct {
Username string `json:"Username"`
Password string `json:"Password"`
URLs []string `json:"Urls"`
}
// gatherOptions transforms the given Credentials and gather policy into a
// [webrtc.ICEGatherOptions] for gathering local ICE candidates with
// [webrtc.ICEGatherer]. If the given credentials are nil or contain no ICE
// servers, only the gather policy is populated.
func gatherOptions(credentials *Credentials, policy webrtc.ICEGatherPolicy) webrtc.ICEGatherOptions {
opts := webrtc.ICEGatherOptions{ICEGatherPolicy: policy}
if credentials != nil && len(credentials.ICEServers) > 0 {
opts.ICEServers = make([]webrtc.ICEServer, len(credentials.ICEServers))
for i, server := range credentials.ICEServers {
opts.ICEServers[i] = webrtc.ICEServer{
Username: server.Username,
Credential: server.Password,
CredentialType: webrtc.ICECredentialTypePassword,
URLs: server.URLs,
}
}
}
return opts
}