Files
go-webrtc-net/types.go

63 lines
1.3 KiB
Go
Raw Normal View History

2025-02-06 22:50:09 -05:00
package webrtc
import (
"context"
"errors"
"net"
"sync"
"time"
"github.com/pion/webrtc/v3"
)
var (
ErrConnectionClosed = errors.New("connection closed")
ErrInvalidAddress = errors.New("invalid address")
)
2025-02-07 15:25:50 -05:00
// RTCConn implements net.Conn over WebRTC
type RTCConn struct {
2025-02-06 22:50:09 -05:00
dc *webrtc.DataChannel
pc *webrtc.PeerConnection
localAddr net.Addr
remoteAddr net.Addr
mu sync.RWMutex
closed bool
readChan chan []byte
ctx context.Context
cancel context.CancelFunc
}
2025-02-07 15:25:50 -05:00
// RTCPacketConn implements net.PacketConn over WebRTC
type RTCPacketConn struct {
2025-02-06 22:50:09 -05:00
pc *webrtc.PeerConnection
dc *webrtc.DataChannel
localAddr net.Addr
mu sync.RWMutex
closed bool
readChan chan packet
ctx context.Context
cancel context.CancelFunc
readDeadline chan time.Time
writeDeadline chan time.Time
}
2025-02-07 15:25:50 -05:00
// RTCListener implements net.Listener over WebRTC
type RTCListener struct {
2025-02-06 22:50:09 -05:00
underlying net.Listener
config *webrtc.Configuration
mu sync.RWMutex
closed bool
acceptChan chan net.Conn
ctx context.Context
cancel context.CancelFunc
}
// packet represents a UDP-like packet
type packet struct {
data []byte
addr net.Addr
}
var STUN_SERVER_URLS = []string{"stun:stun.l.google.com:19302"}