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:
+19
-6
@@ -48,11 +48,12 @@ type RTCClient struct {
|
||||
localParticipant *livekit.ParticipantInfo
|
||||
remoteParticipants map[string]*livekit.ParticipantInfo
|
||||
|
||||
reliableDC *webrtc.DataChannel
|
||||
reliableDCSub *webrtc.DataChannel
|
||||
lossyDC *webrtc.DataChannel
|
||||
lossyDCSub *webrtc.DataChannel
|
||||
publisherConnected utils.AtomicFlag
|
||||
reliableDC *webrtc.DataChannel
|
||||
reliableDCSub *webrtc.DataChannel
|
||||
lossyDC *webrtc.DataChannel
|
||||
lossyDCSub *webrtc.DataChannel
|
||||
publisherConnected utils.AtomicFlag
|
||||
publisherNegotiated utils.AtomicFlag
|
||||
|
||||
// tracks waiting to be acked, cid => trackInfo
|
||||
pendingPublishedTracks map[string]*livekit.TrackInfo
|
||||
@@ -84,6 +85,7 @@ var (
|
||||
|
||||
type Options struct {
|
||||
AutoSubscribe bool
|
||||
Publish string
|
||||
}
|
||||
|
||||
func NewWebSocketConn(host, token string, opts *Options) (*websocket.Conn, error) {
|
||||
@@ -96,7 +98,8 @@ func NewWebSocketConn(host, token string, opts *Options) (*websocket.Conn, error
|
||||
|
||||
connectUrl := u.String()
|
||||
if opts != nil {
|
||||
connectUrl = fmt.Sprintf("%s&auto_subscribe=%t", connectUrl, opts.AutoSubscribe)
|
||||
connectUrl = fmt.Sprintf("%s&auto_subscribe=%t&publish=%s",
|
||||
connectUrl, opts.AutoSubscribe, opts.Publish)
|
||||
}
|
||||
conn, _, err := websocket.DefaultDialer.Dial(connectUrl, requestHeader)
|
||||
return conn, err
|
||||
@@ -224,8 +227,13 @@ func NewRTCClient(conn *websocket.Conn) (*RTCClient, error) {
|
||||
c.publisher.PeerConnection().OnICEConnectionStateChange(func(state webrtc.ICEConnectionState) {
|
||||
logger.Infow("publisher ICE state changed", "state", state.String(),
|
||||
"participant", c.localParticipant.Identity)
|
||||
|
||||
if state == webrtc.ICEConnectionStateConnected {
|
||||
c.publisherConnected.TrySet(true)
|
||||
// check if publisher triggered negotiate (!subscriberPrimary)
|
||||
if c.publisherNegotiated.Get() {
|
||||
c.iceConnected.TrySet(true)
|
||||
}
|
||||
} else {
|
||||
c.publisherConnected.TrySet(false)
|
||||
}
|
||||
@@ -265,6 +273,11 @@ func (c *RTCClient) Run() error {
|
||||
c.remoteParticipants[p.Sid] = p
|
||||
}
|
||||
c.lock.Unlock()
|
||||
// if publish only, negotiate
|
||||
if !msg.Join.SubscriberPrimary {
|
||||
c.publisherNegotiated.TrySet(true)
|
||||
c.publisher.Negotiate()
|
||||
}
|
||||
|
||||
logger.Infow("join accepted, awaiting offer", "participant", msg.Join.Participant.Identity)
|
||||
case *livekit.SignalResponse_Answer:
|
||||
|
||||
Reference in New Issue
Block a user