lint fix minor problems.

This commit is contained in:
Miroslav Šedivý 2021-10-07 21:41:19 +02:00
parent e45bd7098f
commit d5c0c62675
2 changed files with 18 additions and 20 deletions

View File

@ -118,8 +118,7 @@ func (manager *WebRTCManagerCtx) CreatePeer(session types.Session, videoID strin
return nil, err return nil, err
} }
audioTrack.AddToConnection(connection) if err := audioTrack.AddToConnection(connection); err != nil {
if err != nil {
return nil, err return nil, err
} }
@ -130,8 +129,7 @@ func (manager *WebRTCManagerCtx) CreatePeer(session types.Session, videoID strin
return nil, err return nil, err
} }
videoTrack.AddToConnection(connection) if err := videoTrack.AddToConnection(connection); err != nil {
if err != nil {
return nil, err return nil, err
} }
@ -157,6 +155,20 @@ func (manager *WebRTCManagerCtx) CreatePeer(session types.Session, videoID strin
iceTrickle: manager.config.ICETrickle, iceTrickle: manager.config.ICETrickle,
} }
connection.OnConnectionStateChange(func(state webrtc.PeerConnectionState) {
switch state {
case webrtc.PeerConnectionStateConnected:
session.SetWebRTCConnected(peer, true)
case webrtc.PeerConnectionStateDisconnected,
webrtc.PeerConnectionStateFailed:
connection.Close()
case webrtc.PeerConnectionStateClosed:
session.SetWebRTCConnected(peer, false)
videoTrack.RemoveStream()
audioTrack.RemoveStream()
}
})
cursorImage := func(entry *cursor.ImageEntry) { cursorImage := func(entry *cursor.ImageEntry) {
if err := peer.SendCursorImage(entry.Cursor, entry.Image); err != nil { if err := peer.SendCursorImage(entry.Cursor, entry.Image); err != nil {
logger.Err(err).Msg("could not send cursor image") logger.Err(err).Msg("could not send cursor image")
@ -173,20 +185,6 @@ func (manager *WebRTCManagerCtx) CreatePeer(session types.Session, videoID strin
} }
} }
connection.OnConnectionStateChange(func(state webrtc.PeerConnectionState) {
switch state {
case webrtc.PeerConnectionStateConnected:
session.SetWebRTCConnected(peer, true)
case webrtc.PeerConnectionStateDisconnected,
webrtc.PeerConnectionStateFailed:
connection.Close()
case webrtc.PeerConnectionStateClosed:
session.SetWebRTCConnected(peer, false)
videoTrack.RemoveStream()
audioTrack.RemoveStream()
}
})
dataChannel.OnOpen(func() { dataChannel.OnOpen(func() {
manager.curImage.AddListener(&cursorImage) manager.curImage.AddListener(&cursorImage)
manager.curPosition.AddListener(&cursorPosition) manager.curPosition.AddListener(&cursorPosition)
@ -214,7 +212,7 @@ func (manager *WebRTCManagerCtx) CreatePeer(session types.Session, videoID strin
return return
} }
if err = manager.handle(message.Data, session); err != nil { if err := manager.handle(message.Data, session); err != nil {
logger.Err(err).Msg("data handle failed") logger.Err(err).Msg("data handle failed")
} }
}) })

View File

@ -69,7 +69,7 @@ func (peer *PeerStreamTrack) RemoveStream() {
defer peer.streamMu.Unlock() defer peer.streamMu.Unlock()
if peer.stream != nil { if peer.stream != nil {
peer.stream.RemoveListener(&peer.listener) _ = peer.stream.RemoveListener(&peer.listener)
peer.stream = nil peer.stream = nil
} }
} }