Skip to content

Commit

Permalink
feat: sub new peers to existing chans (#320)
Browse files Browse the repository at this point in the history
* feat: sub to chans

* updates

* negotiate
  • Loading branch information
tarrencev authored Nov 27, 2020
1 parent 50f6f5e commit 2bddf67
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions pkg/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ func (s *Session) AddDatachannel(owner string, dc *webrtc.DataChannel) {
dc.OnMessage(func(msg webrtc.DataChannelMessage) {
s.onMessage(pid, label, msg)
})

p.subscriber.negotiate()
}
}

Expand Down Expand Up @@ -123,6 +125,7 @@ func (s *Session) Publish(router Router, rr *receiverRouter) {
func (s *Session) Subscribe(peer *Peer) {
s.mu.RLock()
defer s.mu.RUnlock()
subdChans := false
for pid, p := range s.peers {
if pid == peer.id {
continue
Expand All @@ -132,6 +135,25 @@ func (s *Session) Subscribe(peer *Peer) {
log.Errorf("Subscribing to router err: %v", err)
continue
}

if !subdChans {
for _, dc := range p.subscriber.channels {
label := dc.Label()
new, err := peer.subscriber.AddDataChannel(label)

if err != nil {
log.Errorf("error adding datachannel: %s", err)
continue
}

new.OnMessage(func(msg webrtc.DataChannelMessage) {
s.onMessage(peer.id, label, msg)
})
}
subdChans = true

peer.subscriber.negotiate()
}
}
}

Expand Down

0 comments on commit 2bddf67

Please sign in to comment.