mirror of
https://github.com/unitoftime/rtcnet.git
synced 2025-09-26 20:31:17 +08:00
Add ability to get local and remote addresses
This commit is contained in:
13
conn.go
13
conn.go
@@ -21,11 +21,16 @@ type Conn struct {
|
||||
|
||||
closeOnce sync.Once
|
||||
closed atomic.Bool
|
||||
|
||||
localAddr, remoteAddr net.Addr
|
||||
}
|
||||
func newConn(peer *webrtc.PeerConnection) *Conn {
|
||||
func newConn(peer *webrtc.PeerConnection, localAddr, remoteAddr net.Addr) *Conn {
|
||||
c := &Conn{
|
||||
peerConn: peer,
|
||||
errorChan: make(chan error, 16), //TODO! - Sizing
|
||||
|
||||
localAddr: localAddr,
|
||||
remoteAddr: remoteAddr,
|
||||
}
|
||||
return c
|
||||
}
|
||||
@@ -88,13 +93,11 @@ func (c *Conn) Close() error {
|
||||
}
|
||||
|
||||
func (c *Conn) LocalAddr() net.Addr {
|
||||
//TODO: implement
|
||||
return nil
|
||||
return c.localAddr
|
||||
}
|
||||
|
||||
func (c *Conn) RemoteAddr() net.Addr {
|
||||
//TODO: implement
|
||||
return nil
|
||||
return c.remoteAddr
|
||||
}
|
||||
|
||||
func (c *Conn) SetDeadline(t time.Time) error {
|
||||
|
2
dial.go
2
dial.go
@@ -51,7 +51,7 @@ func Dial(address string, tlsConfig *tls.Config, ordered bool, iceServers []stri
|
||||
return nil, err
|
||||
}
|
||||
|
||||
conn := newConn(peerConnection)
|
||||
conn := newConn(peerConnection, wSock.LocalAddr(), wSock.RemoteAddr())
|
||||
connFinish := make(chan bool)
|
||||
peerConnection.OnICECandidate(func(c *webrtc.ICECandidate) {
|
||||
logger.Trace().Msg("Dial: peerConnection.OnICECandidate")
|
||||
|
14
listener.go
14
listener.go
@@ -87,6 +87,9 @@ func (l *Listener) Addr() net.Addr {
|
||||
func (l *Listener) attemptWebRtcNegotiation(wsConn net.Conn) {
|
||||
defer trace("finished attemptWebRtcNegotiation")
|
||||
|
||||
localAddr := wsConn.LocalAddr()
|
||||
remoteAddr := wsConn.RemoteAddr()
|
||||
|
||||
api := getSettingsEngineApi()
|
||||
|
||||
var candidatesMux sync.Mutex
|
||||
@@ -121,6 +124,15 @@ func (l *Listener) attemptWebRtcNegotiation(wsConn net.Conn) {
|
||||
return // Do nothing because the ice candidate was nil for some reason
|
||||
}
|
||||
|
||||
// logger.Trace().
|
||||
// Str("Address", c.Address).
|
||||
// Str("Protocol", c.Protocol.String()).
|
||||
// Uint16("Port", c.Port).
|
||||
// Str("CandidateType", c.Typ.String()).
|
||||
// Str("RelatedAddress", c.RelatedAddress).
|
||||
// Uint16("RelatedPort", c.RelatedPort).
|
||||
// Msg("rtcnet: peerConnection.OnICECandidate")
|
||||
|
||||
candidatesMux.Lock()
|
||||
defer candidatesMux.Unlock()
|
||||
|
||||
@@ -167,7 +179,7 @@ func (l *Listener) attemptWebRtcNegotiation(wsConn net.Conn) {
|
||||
|
||||
// Register data channel creation handling
|
||||
peerConnection.OnDataChannel(func(d *webrtc.DataChannel) {
|
||||
conn := newConn(peerConnection)
|
||||
conn := newConn(peerConnection, localAddr, remoteAddr)
|
||||
conn.dataChannel = d
|
||||
|
||||
// Register channel opening handling
|
||||
|
Reference in New Issue
Block a user