@@ -92,29 +92,38 @@ func (h *hub) ClientInfo(details bool) (clientCount int, sessions map[string]*Da
9292}
9393
9494func (h * hub ) CreateTurnData (sender Sender , session * Session ) * DataTurn {
95- // Create turn data credentials for shared secret auth with TURN
96- // server. See http://tools.ietf.org/html/draft-uberti-behave-turn-rest-00
97- // and https://code.google.com/p/rfc5766-turn-server/ REST API auth
98- // and set shared secret in TURN server with static-auth-secret.
99- if len (h .turnSecret ) == 0 {
100- return & DataTurn {}
95+ if len (h .turnSecret ) > 0 {
96+ // Create turn data credentials for shared secret auth with TURN
97+ // server. See http://tools.ietf.org/html/draft-uberti-behave-turn-rest-00
98+ // and https://code.google.com/p/rfc5766-turn-server/ REST API auth
99+ // and set shared secret in TURN server with static-auth-secret.
100+ id := session .Id
101+ bar := sha256 .New ()
102+ bar .Write ([]byte (id ))
103+ id = base64 .StdEncoding .EncodeToString (bar .Sum (nil ))
104+ foo := hmac .New (sha1 .New , h .turnSecret )
105+ expiration := int32 (time .Now ().Unix ()) + turnTTL
106+ user := fmt .Sprintf ("%d:%s" , expiration , id )
107+ foo .Write ([]byte (user ))
108+ password := base64 .StdEncoding .EncodeToString (foo .Sum (nil ))
109+
110+ return & DataTurn {
111+ Username : user ,
112+ Password : password ,
113+ Ttl : turnTTL ,
114+ Urls : h .config .TurnURIs ,
115+ }
101116 }
102- id := session .Id
103- bar := sha256 .New ()
104- bar .Write ([]byte (id ))
105- id = base64 .StdEncoding .EncodeToString (bar .Sum (nil ))
106- foo := hmac .New (sha1 .New , h .turnSecret )
107- expiration := int32 (time .Now ().Unix ()) + turnTTL
108- user := fmt .Sprintf ("%d:%s" , expiration , id )
109- foo .Write ([]byte (user ))
110- password := base64 .StdEncoding .EncodeToString (foo .Sum (nil ))
111117
112- return & DataTurn {
113- Username : user ,
114- Password : password ,
115- Ttl : turnTTL ,
116- Urls : h .config .TurnURIs ,
118+ if h .config .TurnUsername != "" && h .config .TurnPassword != "" {
119+ return & DataTurn {
120+ Username : h .config .TurnUsername ,
121+ Password : h .config .TurnPassword ,
122+ Urls : h .config .TurnURIs ,
123+ }
117124 }
125+
126+ return & DataTurn {}
118127}
119128
120129func (h * hub ) GetSession (id string ) (session * Session , ok bool ) {
0 commit comments