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 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.webrtcConnected = connected
session.manager.emmiter.Emit("state_changed", session) session.manager.emmiter.Emit("state_changed", session)

View File

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

View File

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