From 2bddf67ea9b80a6a9f73c083d607711c2b5f043c Mon Sep 17 00:00:00 2001 From: Tarrence van As Date: Fri, 27 Nov 2020 12:23:55 -0500 Subject: [PATCH] feat: sub new peers to existing chans (#320) * feat: sub to chans * updates * negotiate --- pkg/session.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/pkg/session.go b/pkg/session.go index c7c60dbbb..a755b9134 100644 --- a/pkg/session.go +++ b/pkg/session.go @@ -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() } } @@ -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 @@ -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() + } } }