Allow participants to create new connection for publishing new tracks (#224)

* Allow participants to create new connection for publishing new tracks

new param 'publish=<name>' enables publishing new connection with publish
only grants. Also, identity is appended with '#<name>'

* Add integration test to duplicate publish only connection

Signed-off-by: shishir gowda <shishir@livekit.io>

* Reuse token in test and set subscribeGrant to false on publish param

Signed-off-by: shishir gowda <shishir@livekit.io>

* create auth token with grants

Signed-off-by: shishir gowda <shishir@livekit.io>

* Signal ice on negotiate in test client

Signed-off-by: shishir gowda <shishir@livekit.io>

* Update pkg/service/rtcservice.go

Co-authored-by: David Zhao <david@davidzhao.com>

Co-authored-by: David Zhao <david@davidzhao.com>
This commit is contained in:
shishirng
2021-12-07 16:23:16 -05:00
committed by GitHub
co-authored by David Zhao
parent 5dc0a43b29
commit 461f29c097
4 changed files with 136 additions and 6 deletions
+78
View File
@@ -6,6 +6,8 @@ import (
"testing"
"time"
"github.com/livekit/protocol/auth"
"github.com/livekit/livekit-server/pkg/rtc"
"github.com/pion/webrtc/v3"
"github.com/stretchr/testify/require"
@@ -33,6 +35,82 @@ func TestClientCouldConnect(t *testing.T) {
})
}
func TestClientConnectDuplicate(t *testing.T) {
if testing.Short() {
t.SkipNow()
return
}
_, finish := setupSingleNodeTest("TestClientCouldConnect", testRoom)
defer finish()
grant := &auth.VideoGrant{RoomJoin: true, Room: testRoom}
grant.SetCanPublish(true)
grant.SetCanSubscribe(true)
token := joinTokenWithGrant("c1", grant)
c1 := createRTCClientWithToken(token, defaultServerPort, nil)
// publish 2 tracks
t1, err := c1.AddStaticTrack("audio/opus", "audio", "webcam")
require.NoError(t, err)
defer t1.Stop()
t2, err := c1.AddStaticTrack("video/vp8", "video", "webcam")
require.NoError(t, err)
defer t2.Stop()
c2 := createRTCClient("c2", defaultServerPort, nil)
waitUntilConnected(t, c1, c2)
opts := &testclient.Options{
Publish: "duplicate_connection",
}
success := testutils.WithTimeout(t, "c2 should receive two tracks", func() bool {
if len(c2.SubscribedTracks()) == 0 {
return false
}
// should have received three tracks
if len(c2.SubscribedTracks()[c1.ID()]) != 2 {
return false
}
//participant ID can be appended with '#..' . but should contain orig id as prefix
tr1 := c2.SubscribedTracks()[c1.ID()][0]
participantId1, _ := rtc.UnpackStreamID(tr1.StreamID())
require.Equal(t, c1.ID(), participantId1)
tr2 := c2.SubscribedTracks()[c1.ID()][1]
participantId2, _ := rtc.UnpackStreamID(tr2.StreamID())
require.Equal(t, c1.ID(), participantId2)
return true
})
if !success {
t.FailNow()
}
c1Dup := createRTCClientWithToken(token, defaultServerPort, opts)
waitUntilConnected(t, c1Dup)
t3, err := c1Dup.AddStaticTrack("video/vp8", "video", "webcam")
require.NoError(t, err)
defer t3.Stop()
success = testutils.WithTimeout(t, "c2 should receive third tracks", func() bool {
if len(c2.SubscribedTracks()[c1Dup.ID()]) != 1 {
return false
}
tr3 := c2.SubscribedTracks()[c1Dup.ID()][0]
participantId3, _ := rtc.UnpackStreamID(tr3.StreamID())
require.Contains(t, c1Dup.ID(), participantId3)
return true
})
if !success {
t.FailNow()
}
}
func TestSinglePublisher(t *testing.T) {
if testing.Short() {
t.SkipNow()