From afa2940e0461925ea6ef01a87e5e25eb9e3e10ee Mon Sep 17 00:00:00 2001 From: LiYuqing Date: Tue, 21 Jun 2022 21:42:45 +0800 Subject: [PATCH] Add base64 RawURLEncoding --- engine/turn.go | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/engine/turn.go b/engine/turn.go index 52be074..9926b09 100644 --- a/engine/turn.go +++ b/engine/turn.go @@ -9,9 +9,10 @@ import ( ) type NTS struct { - URLs string `json:"urls"` - Credential string `json:"credential"` - Username string `json:"username"` + URLs string `json:"urls"` + Credential string `json:"credential"` + CredentialBase64 string `json:"credential_base64"` + Username string `json:"username"` } func turn(conf *Configuration, uid string) ([]*NTS, error) { @@ -21,17 +22,21 @@ func turn(conf *Configuration, uid string) ([]*NTS, error) { if _, err := mac.Write([]byte(username)); err != nil { return nil, err } - credential := base64.StdEncoding.EncodeToString(mac.Sum(nil)) + credentialBuf := mac.Sum(nil) + credential := base64.StdEncoding.EncodeToString(credentialBuf) + credentialBase64 := base64.RawURLEncoding.EncodeToString(credentialBuf) url := conf.Turn.Host ownUDP := &NTS{ - URLs: url + "?transport=udp", - Username: username, - Credential: credential, + URLs: url + "?transport=udp", + Username: username, + Credential: credential, + CredentialBase64: credentialBase64, } ownTCP := &NTS{ - URLs: url + "?transport=tcp", - Username: username, - Credential: credential, + URLs: url + "?transport=tcp", + Username: username, + Credential: credential, + CredentialBase64: credentialBase64, } return []*NTS{ownUDP, ownTCP}, nil }