MCPcopy
hub / github.com/livekit/livekit / TestFilteringCandidates

Function TestFilteringCandidates

pkg/rtc/transport_test.go:400–517  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

398}
399
400func TestFilteringCandidates(t *testing.T) {
401 params := TransportParams{
402 Config: &WebRTCConfig{},
403 EnabledPublishCodecs: []*livekit.Codec{
404 {Mime: mime.MimeTypeOpus.String()},
405 {Mime: mime.MimeTypeVP8.String()},
406 {Mime: mime.MimeTypeH264.String()},
407 },
408 Handler: &transportfakes.FakeHandler{},
409 }
410 transport, err := NewPCTransport(params)
411 require.NoError(t, err)
412
413 _, err = transport.pc.CreateDataChannel(ReliableDataChannel, nil)
414 require.NoError(t, err)
415
416 _, err = transport.pc.AddTransceiverFromKind(webrtc.RTPCodecTypeAudio)
417 require.NoError(t, err)
418
419 _, err = transport.pc.AddTransceiverFromKind(webrtc.RTPCodecTypeVideo)
420 require.NoError(t, err)
421
422 offer, err := transport.pc.CreateOffer(nil)
423 require.NoError(t, err)
424
425 offerGatheringComplete := webrtc.GatheringCompletePromise(transport.pc)
426 require.NoError(t, transport.pc.SetLocalDescription(offer))
427 <-offerGatheringComplete
428
429 // should not filter out UDP candidates if TCP is not preferred
430 offer = *transport.pc.LocalDescription()
431 filteredOffer := transport.filterCandidates(offer, false, true)
432 require.EqualValues(t, offer.SDP, filteredOffer.SDP)
433
434 parsed, err := offer.Unmarshal()
435 require.NoError(t, err)
436
437 // add a couple of TCP candidates
438 done := false
439 for _, m := range parsed.MediaDescriptions {
440 for _, a := range m.Attributes {
441 if a.Key == sdp.AttrKeyCandidate {
442 for idx, aa := range m.Attributes {
443 if aa.Key == sdp.AttrKeyEndOfCandidates {
444 modifiedAttributes := make([]sdp.Attribute, idx)
445 copy(modifiedAttributes, m.Attributes[:idx])
446 modifiedAttributes = append(modifiedAttributes, []sdp.Attribute{
447 {
448 Key: sdp.AttrKeyCandidate,
449 Value: "054225987 1 tcp 2124414975 159.203.70.248 7881 typ host tcptype passive",
450 },
451 {
452 Key: sdp.AttrKeyCandidate,
453 Value: "054225987 2 tcp 2124414975 159.203.70.248 7881 typ host tcptype passive",
454 },
455 }...)
456 m.Attributes = append(modifiedAttributes, m.Attributes[idx:]...)
457 done = true

Callers

nothing calls this directly

Calls 9

filterCandidatesMethod · 0.95
SetPreferTCPMethod · 0.95
CloseMethod · 0.95
NewPCTransportFunction · 0.85
CreateDataChannelMethod · 0.80
StringMethod · 0.45
UnmarshalMethod · 0.45
MarshalMethod · 0.45

Tested by

no test coverage detected