Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added noAutoSubscribeDataChannels configuration which prevents … #663

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions cmd/signal/grpc/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,16 @@ func (s *SFUServer) Signal(sig rtc.RTC_SignalServer) error {
noautosub = val == "true"
}

noautosubdc := false
if val, found := payload.Join.Config["NoAutoSubscribeDataChannels"]; found {
noautosubdc = val == "true"
}

cfg := sfu.JoinConfig{
NoPublish: nopub,
NoSubscribe: nosub,
NoAutoSubscribe: noautosub,
NoPublish: nopub,
NoSubscribe: nosub,
NoAutoSubscribe: noautosub,
NoAutoSubscribeDataChannels: noautosubdc,
}

err = peer.Join(sid, uid, cfg)
Expand Down
5 changes: 5 additions & 0 deletions pkg/sfu/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ type JoinConfig struct {
// to customize the subscrbe stream combination as needed.
// this parameter depends on NoSubscribe=false.
NoAutoSubscribe bool
// If true the peer will not automatically subscribe all data channels,
// The peer can subscribe data channels by creating locally.
// this parameter depends on NoSubscribe=false.
NoAutoSubscribeDataChannels bool
}

// SessionProvider provides the SessionLocal to the sfu.Peer
Expand Down Expand Up @@ -111,6 +115,7 @@ func (p *PeerLocal) Join(sid, uid string, config ...JoinConfig) error {
}

p.subscriber.noAutoSubscribe = conf.NoAutoSubscribe
p.subscriber.noAutoSubscribeDataChannels = conf.NoAutoSubscribeDataChannels

p.subscriber.OnNegotiationNeeded(func() {
p.Lock()
Expand Down
11 changes: 8 additions & 3 deletions pkg/sfu/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ func (s *SessionLocal) AddDatachannel(owner string, dc *webrtc.DataChannel) {
label := dc.Label()

s.mu.Lock()
peerOwner := s.peers[owner]
peerOwner.Subscriber().RegisterDatachannel(label, dc)

for _, lbl := range s.fanOutDCs {
if label == lbl {
dc.OnMessage(func(msg webrtc.DataChannelMessage) {
Expand All @@ -169,18 +172,16 @@ func (s *SessionLocal) AddDatachannel(owner string, dc *webrtc.DataChannel) {
}
}
s.fanOutDCs = append(s.fanOutDCs, label)
peerOwner := s.peers[owner]
s.mu.Unlock()
peers := s.Peers()
peerOwner.Subscriber().RegisterDatachannel(label, dc)

dc.OnMessage(func(msg webrtc.DataChannelMessage) {
s.FanOutMessage(owner, label, msg)
})

for _, p := range peers {
peer := p
if peer.ID() == owner || peer.Subscriber() == nil {
if peer.ID() == owner || peer.Subscriber() == nil || peer.Subscriber().noAutoSubscribeDataChannels {
continue
}
ndc, err := peer.Subscriber().AddDataChannel(label)
Expand Down Expand Up @@ -251,6 +252,10 @@ func (s *SessionLocal) Subscribe(peer Peer) {

// Subscribe to fan out data channels
for _, label := range fdc {
if peer.Subscriber().noAutoSubscribeDataChannels {
continue
}

dc, err := peer.Subscriber().AddDataChannel(label)
if err != nil {
Logger.Error(err, "error adding datachannel")
Expand Down
16 changes: 9 additions & 7 deletions pkg/sfu/subscriber.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ type Subscriber struct {
negotiate func()
closeOnce sync.Once

noAutoSubscribe bool
noAutoSubscribe bool
noAutoSubscribeDataChannels bool
}

// NewSubscriber creates a new Subscriber
Expand All @@ -46,12 +47,13 @@ func NewSubscriber(id string, cfg WebRTCTransportConfig) (*Subscriber, error) {
}

s := &Subscriber{
id: id,
me: me,
pc: pc,
tracks: make(map[string][]*DownTrack),
channels: make(map[string]*webrtc.DataChannel),
noAutoSubscribe: false,
id: id,
me: me,
pc: pc,
tracks: make(map[string][]*DownTrack),
channels: make(map[string]*webrtc.DataChannel),
noAutoSubscribe: false,
noAutoSubscribeDataChannels: false,
}

pc.OnICEConnectionStateChange(func(connectionState webrtc.ICEConnectionState) {
Expand Down