MCPcopy Index your code
hub / github.com/livekit/livekit / TestClientConnectDuplicate

Function TestClientConnectDuplicate

test/singlenode_test.go:89–160  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

87}
88
89func TestClientConnectDuplicate(t *testing.T) {
90 if testing.Short() {
91 t.SkipNow()
92 return
93 }
94
95 _, finish := setupSingleNodeTest("TestClientConnectDuplicate")
96 defer finish()
97
98 for _, testRTCServicePath := range testRTCServicePaths {
99 t.Run(fmt.Sprintf("testRTCServicePath=%s", testRTCServicePath.String()), func(t *testing.T) {
100 grant := &auth.VideoGrant{RoomJoin: true, Room: testRoom}
101 grant.SetCanPublish(true)
102 grant.SetCanSubscribe(true)
103 token := joinTokenWithGrant("c1", grant)
104 c1 := createRTCClientWithToken(token, defaultServerPort, testRTCServicePath, nil)
105
106 // publish 2 tracks
107 t1, err := c1.AddStaticTrack("audio/opus", "audio", "webcam")
108 require.NoError(t, err)
109 defer t1.Stop()
110 t2, err := c1.AddStaticTrack("video/vp8", "video", "webcam")
111 require.NoError(t, err)
112 defer t2.Stop()
113
114 c2 := createRTCClient("c2", defaultServerPort, testRTCServicePath, nil)
115 waitUntilConnected(t, c1, c2)
116
117 opts := &testclient.Options{
118 Publish: "duplicate_connection",
119 }
120 testutils.WithTimeout(t, func() string {
121 if len(c2.SubscribedTracks()) == 0 {
122 return "c2 didn't subscribe to anything"
123 }
124 // should have received two tracks
125 if len(c2.SubscribedTracks()[c1.ID()]) != 2 {
126 return "c2 didn't subscribe to both tracks from c1"
127 }
128
129 // participant ID can be appended with '#..' . but should contain orig id as prefix
130 tr1 := c2.SubscribedTracks()[c1.ID()][0]
131 participantId1, _ := rtc.UnpackStreamID(tr1.StreamID())
132 require.Equal(t, c1.ID(), participantId1)
133 tr2 := c2.SubscribedTracks()[c1.ID()][1]
134 participantId2, _ := rtc.UnpackStreamID(tr2.StreamID())
135 require.Equal(t, c1.ID(), participantId2)
136 return ""
137 })
138
139 c1Dup := createRTCClientWithToken(token, defaultServerPort, testRTCServicePath, opts)
140
141 waitUntilConnected(t, c1Dup)
142
143 t3, err := c1Dup.AddStaticTrack("video/vp8", "video", "webcam")
144 require.NoError(t, err)
145 defer t3.Stop()
146

Callers

nothing calls this directly

Calls 14

WithTimeoutFunction · 0.92
UnpackStreamIDFunction · 0.92
setupSingleNodeTestFunction · 0.85
joinTokenWithGrantFunction · 0.85
createRTCClientWithTokenFunction · 0.85
createRTCClientFunction · 0.85
waitUntilConnectedFunction · 0.85
AddStaticTrackMethod · 0.80
SubscribedTracksMethod · 0.80
StopMethod · 0.65
IDMethod · 0.65
StreamIDMethod · 0.65

Tested by

no test coverage detected