Files
piik/native/sender/internal/remote/peer_test.go
T

78 lines
2.5 KiB
Go

package remote
import (
"testing"
"github.com/pion/webrtc/v4"
)
func TestSelectedRouteTreatsARemoteRelayCandidateAsTURN(t *testing.T) {
report := webrtc.StatsReport{
"local": webrtc.ICECandidateStats{
ID: "local",
Protocol: "udp",
CandidateType: webrtc.ICECandidateTypeHost,
},
"remote": webrtc.ICECandidateStats{
ID: "remote",
Protocol: "udp",
CandidateType: webrtc.ICECandidateTypeRelay,
},
}
pair := webrtc.ICECandidatePairStats{LocalCandidateID: "local", RemoteCandidateID: "remote"}
if route := selectedRoute(report, pair); route != "turn-unknown" {
t.Fatalf("selected route = %q, want turn-unknown", route)
}
}
func TestSelectedRouteUsesOnlyTheLocalRelayProtocol(t *testing.T) {
report := webrtc.StatsReport{
"local": webrtc.ICECandidateStats{
ID: "local", Protocol: "udp", CandidateType: webrtc.ICECandidateTypeRelay,
},
"remote": webrtc.ICECandidateStats{
ID: "remote", Protocol: "udp", CandidateType: webrtc.ICECandidateTypeHost,
},
}
pair := webrtc.ICECandidatePairStats{LocalCandidateID: "local", RemoteCandidateID: "remote"}
if route := selectedRoute(report, pair); route != "turn-unknown" {
t.Fatalf("selected route without local relayProtocol = %q", route)
}
local := report["local"].(webrtc.ICECandidateStats)
local.RelayProtocol = "tcp"
report["local"] = local
if route := selectedRoute(report, pair); route != "turn-tcp" {
t.Fatalf("selected route with local relayProtocol = %q", route)
}
}
func TestSelectedRouteRequiresBothCandidatesBeforeClaimingDirect(t *testing.T) {
report := webrtc.StatsReport{
"local": webrtc.ICECandidateStats{
ID: "local",
Protocol: "udp",
CandidateType: webrtc.ICECandidateTypeHost,
},
}
pair := webrtc.ICECandidatePairStats{LocalCandidateID: "local", RemoteCandidateID: "missing"}
if route := selectedRoute(report, pair); route != "unknown" {
t.Fatalf("selected route = %q, want unknown", route)
}
}
func TestPeerAnswerFailureIsSanitized(t *testing.T) {
connection, err := webrtc.NewPeerConnection(webrtc.Configuration{})
if err != nil {
t.Fatal(err)
}
defer connection.Close()
viewer := &peer{connection: connection, connectionID: "connection-1"}
err = viewer.acceptSignal(inboundSignalPayload{
Kind: "description", ConnectionID: "connection-1",
Description: &sessionDescription{Type: "answer", SDP: "private-sdp-marker"},
})
if err == nil || err.Error() != "apply viewer answer failed" {
t.Fatalf("answer error = %q", err)
}
}