mirror of
https://github.com/pion/webrtc.git
synced 2025-10-30 18:26:36 +08:00
listen on correct port
we need to listen on the local port of the STUN client, not the remote one as those might be different
This commit is contained in:
committed by
Sean DuBois
parent
e3269e606f
commit
8ed90c4fb0
@@ -3,6 +3,8 @@ package webrtc
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
"net"
|
||||||
|
"net/url"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -131,8 +133,8 @@ func (r *RTCPeerConnection) CreateAnswer() error {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, url := range server.URLs {
|
for _, iceURL := range server.URLs {
|
||||||
proto, host, err := protocolAndHost(url)
|
proto, host, err := protocolAndHost(iceURL)
|
||||||
// TODO if one of the URLs does not work we should just ignore it.
|
// TODO if one of the URLs does not work we should just ignore it.
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -142,6 +144,9 @@ func (r *RTCPeerConnection) CreateAnswer() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
u, _ := url.Parse(client.LocalAddr().String())
|
||||||
|
_, localPort, _ := net.SplitHostPort(u.Host)
|
||||||
|
|
||||||
resp, err := client.Request()
|
resp, err := client.Request()
|
||||||
if err := client.Close(); err != nil {
|
if err := client.Close(); err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -157,11 +162,11 @@ func (r *RTCPeerConnection) CreateAnswer() error {
|
|||||||
if err := addr.Unpack(resp, attr); err != nil {
|
if err := addr.Unpack(resp, attr); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
port, err := network.NewPort(fmt.Sprintf("0.0.0.0:%d", addr.Port), []byte(r.icePwd), r.tlscfg, r.generateChannel, r.iceStateChange)
|
port, err := network.NewPort(fmt.Sprintf("0.0.0.0:%s", localPort), []byte(r.icePwd), r.tlscfg, r.generateChannel, r.iceStateChange)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
candidates = append(candidates, fmt.Sprintf("candidate:%scandidate %d %s %d %s %d typ srflx", proto, id+1, proto, basePriority, addr.IP.String(), addr.Port))
|
candidates = append(candidates, fmt.Sprintf("candidate:%scandidate %d %s %d %s %s typ srflx", proto, id+1, proto, basePriority, addr.IP.String(), localPort))
|
||||||
basePriority = basePriority + 1
|
basePriority = basePriority + 1
|
||||||
r.ports = append(r.ports, port)
|
r.ports = append(r.ports, port)
|
||||||
id++
|
id++
|
||||||
|
|||||||
Reference in New Issue
Block a user