MCPcopy
hub / github.com/livekit/livekit / TestSinglePublisher

Function TestSinglePublisher

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

Source from the content-addressed store, hash-verified

160}
161
162func TestSinglePublisher(t *testing.T) {
163 if testing.Short() {
164 t.SkipNow()
165 return
166 }
167
168 s, finish := setupSingleNodeTest("TestSinglePublisher")
169 defer finish()
170
171 for _, testRTCServicePath := range testRTCServicePaths {
172 t.Run(fmt.Sprintf("testRTCServicePath=%s", testRTCServicePath.String()), func(t *testing.T) {
173 c1 := createRTCClient("c1", defaultServerPort, testRTCServicePath, nil)
174 c2 := createRTCClient("c2", defaultServerPort, testRTCServicePath, nil)
175 waitUntilConnected(t, c1, c2)
176
177 // publish an audio and video track and ensure clients receive it ok
178 t1, err := c1.AddStaticTrack("audio/OPUS", "audio", "webcamaudio")
179 require.NoError(t, err)
180 defer t1.Stop()
181 t2, err := c1.AddStaticTrack("video/vp8", "video", "webcamvideo")
182 require.NoError(t, err)
183 defer t2.Stop()
184
185 testutils.WithTimeout(t, func() string {
186 if len(c2.SubscribedTracks()) == 0 {
187 return "c2 was not subscribed to anything"
188 }
189 // should have received two tracks
190 if len(c2.SubscribedTracks()[c1.ID()]) != 2 {
191 return "c2 didn't subscribe to both tracks from c1"
192 }
193
194 tr1 := c2.SubscribedTracks()[c1.ID()][0]
195 participantId, _ := rtc.UnpackStreamID(tr1.StreamID())
196 require.Equal(t, c1.ID(), participantId)
197 return ""
198 })
199 // ensure mime type is received
200 remoteC1 := c2.GetRemoteParticipant(c1.ID())
201 audioTrack := funk.Find(remoteC1.Tracks, func(ti *livekit.TrackInfo) bool {
202 return ti.Name == "webcamaudio"
203 }).(*livekit.TrackInfo)
204 require.Equal(t, "audio/opus", audioTrack.MimeType)
205
206 // a new client joins and should get the initial stream
207 c3 := createRTCClient("c3", defaultServerPort, testRTCServicePath, nil)
208
209 // ensure that new client that has joined also received tracks
210 waitUntilConnected(t, c3)
211 testutils.WithTimeout(t, func() string {
212 if len(c3.SubscribedTracks()) == 0 {
213 return "c3 didn't subscribe to anything"
214 }
215 // should have received two tracks
216 if len(c3.SubscribedTracks()[c1.ID()]) != 2 {
217 return "c3 didn't subscribe to tracks from c1"
218 }
219 return ""

Callers

nothing calls this directly

Calls 15

WithTimeoutFunction · 0.92
UnpackStreamIDFunction · 0.92
setupSingleNodeTestFunction · 0.85
createRTCClientFunction · 0.85
waitUntilConnectedFunction · 0.85
AddStaticTrackMethod · 0.80
SubscribedTracksMethod · 0.80
GetRemoteParticipantMethod · 0.80
RoomManagerMethod · 0.80
StopMethod · 0.65
IDMethod · 0.65
StreamIDMethod · 0.65

Tested by

no test coverage detected