Skip to content

Commit

Permalink
fix: Dont subscribe on ice state (#308)
Browse files Browse the repository at this point in the history
  • Loading branch information
OrlandoCo authored Nov 17, 2020
1 parent 45f0aff commit 6176d4e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 17 deletions.
2 changes: 2 additions & 0 deletions pkg/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ func (p *Peer) Join(sid string, sdp webrtc.SessionDescription) (*webrtc.SessionD
}
})

p.session.Subscribe(p)

p.subscriber.OnICECandidate(func(c *webrtc.ICECandidate) {
log.Debugf("on ice candidate called")
if c == nil {
Expand Down
6 changes: 0 additions & 6 deletions pkg/publisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ type Publisher struct {
onICEConnectionStateChangeHandler func(webrtc.ICEConnectionState)

closeOnce sync.Once
subOnce sync.Once
}

// NewPublisher creates a new Publisher
Expand Down Expand Up @@ -54,11 +53,6 @@ func NewPublisher(session *Session, id string, me MediaEngine, cfg WebRTCTranspo
pc.OnICEConnectionStateChange(func(connectionState webrtc.ICEConnectionState) {
log.Debugf("ice connection state: %s", connectionState)
switch connectionState {
case webrtc.ICEConnectionStateConnected:
p.subOnce.Do(func() {
// Subscribe to existing peers
p.session.Subscribe(p.id)
})
case webrtc.ICEConnectionStateFailed:
fallthrough
case webrtc.ICEConnectionStateClosed:
Expand Down
20 changes: 9 additions & 11 deletions pkg/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,17 @@ func (s *Session) Publish(router Router, rr *receiverRouter) {
}

// Subscribe will create a Sender for every other Receiver in the session
func (s *Session) Subscribe(id string) {
func (s *Session) Subscribe(peer *Peer) {
s.mu.RLock()
defer s.mu.RUnlock()
if peer, ok := s.peers[id]; ok {
for pid, p := range s.peers {
if pid == id {
continue
}
err := p.publisher.GetRouter().AddSender(peer.subscriber, nil)
if err != nil {
log.Errorf("Subscribing to router err: %v", err)
continue
}
for pid, p := range s.peers {
if pid == peer.id {
continue
}
err := p.publisher.GetRouter().AddSender(peer.subscriber, nil)
if err != nil {
log.Errorf("Subscribing to router err: %v", err)
continue
}
}
}
Expand Down

0 comments on commit 6176d4e

Please sign in to comment.