WebRTC events only for active peer connection.

This commit is contained in:
Miroslav Šedivý 2021-02-14 17:17:06 +01:00
parent 2b693f4e52
commit cd18a22655
3 changed files with 8 additions and 4 deletions

View File

@ -191,7 +191,11 @@ func (session *SessionCtx) SetWebRTCPeer(webrtcPeer types.WebRTCPeer) {
session.webrtcPeer = webrtcPeer
}
func (session *SessionCtx) SetWebRTCConnected(connected bool) {
func (session *SessionCtx) SetWebRTCConnected(webrtcPeer types.WebRTCPeer, connected bool) {
if webrtcPeer != session.webrtcPeer {
return
}
session.webrtcConnected = connected
session.manager.emmiter.Emit("state_changed", session)

View File

@ -56,7 +56,7 @@ type Session interface {
// webrtc
SetWebRTCPeer(webrtcPeer WebRTCPeer)
SetWebRTCConnected(connected bool)
SetWebRTCConnected(webrtcPeer WebRTCPeer, connected bool)
GetWebRTCPeer() WebRTCPeer
}

View File

@ -263,13 +263,13 @@ func (manager *WebRTCManagerCtx) CreatePeer(session types.Session, videoID strin
connection.OnConnectionStateChange(func(state webrtc.PeerConnectionState) {
switch state {
case webrtc.PeerConnectionStateConnected:
session.SetWebRTCConnected(true)
session.SetWebRTCConnected(peer, true)
case webrtc.PeerConnectionStateDisconnected:
fallthrough
case webrtc.PeerConnectionStateFailed:
connection.Close()
case webrtc.PeerConnectionStateClosed:
session.SetWebRTCConnected(false)
session.SetWebRTCConnected(peer, false)
videoStream.RemoveListener(&listener)
// should be stream stopped