From d5c0c62675c1ce006c21b3ba99fed3ac65a7b3cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Thu, 7 Oct 2021 21:41:19 +0200 Subject: [PATCH] lint fix minor problems. --- internal/webrtc/manager.go | 36 ++++++++++++++---------------- internal/webrtc/peerstreamtrack.go | 2 +- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/internal/webrtc/manager.go b/internal/webrtc/manager.go index f410bb4a..f71726f6 100644 --- a/internal/webrtc/manager.go +++ b/internal/webrtc/manager.go @@ -118,8 +118,7 @@ func (manager *WebRTCManagerCtx) CreatePeer(session types.Session, videoID strin return nil, err } - audioTrack.AddToConnection(connection) - if err != nil { + if err := audioTrack.AddToConnection(connection); err != nil { return nil, err } @@ -130,8 +129,7 @@ func (manager *WebRTCManagerCtx) CreatePeer(session types.Session, videoID strin return nil, err } - videoTrack.AddToConnection(connection) - if err != nil { + if err := videoTrack.AddToConnection(connection); err != nil { return nil, err } @@ -157,6 +155,20 @@ func (manager *WebRTCManagerCtx) CreatePeer(session types.Session, videoID strin 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) { if err := peer.SendCursorImage(entry.Cursor, entry.Image); err != nil { 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() { manager.curImage.AddListener(&cursorImage) manager.curPosition.AddListener(&cursorPosition) @@ -214,7 +212,7 @@ func (manager *WebRTCManagerCtx) CreatePeer(session types.Session, videoID strin 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") } }) diff --git a/internal/webrtc/peerstreamtrack.go b/internal/webrtc/peerstreamtrack.go index c6c882a5..2e3251e6 100644 --- a/internal/webrtc/peerstreamtrack.go +++ b/internal/webrtc/peerstreamtrack.go @@ -69,7 +69,7 @@ func (peer *PeerStreamTrack) RemoveStream() { defer peer.streamMu.Unlock() if peer.stream != nil { - peer.stream.RemoveListener(&peer.listener) + _ = peer.stream.RemoveListener(&peer.listener) peer.stream = nil } }