From bf5b622b1a609ad615cacaa55d16f70de29f772f Mon Sep 17 00:00:00 2001 From: giongto35 Date: Sat, 6 Jun 2020 04:29:16 +0800 Subject: [PATCH] Fix high CPU due to nonstop loop (#191) --- pkg/webrtc/webrtc.go | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/pkg/webrtc/webrtc.go b/pkg/webrtc/webrtc.go index 877c3505..f933c768 100644 --- a/pkg/webrtc/webrtc.go +++ b/pkg/webrtc/webrtc.go @@ -198,21 +198,22 @@ func (w *WebRTC) StartClient(isMobile bool, iceCB OnIceCallback) (string, error) }) w.connection.OnTrack(func(remoteTrack *webrtc.Track, receiver *webrtc.RTPReceiver) { - rtpBuf := make([]byte, 1400) + //NOTE: High CPU due to constantly for loop. Turn it off first, Fix it later. + //rtpBuf := make([]byte, 1400) - log.Println("Received Voice from Client") - for { - if w.RoomID == "" { - // skip sending voice when game is not running - continue - } + //log.Println("Received Voice from Client") + //for { + //if w.RoomID == "" { + //// skip sending voice when game is not running + //continue + //} - i, err := remoteTrack.Read(rtpBuf) - // TODO: can receive track but the voice doesn't work - if err == nil { - w.VoiceInChannel <- rtpBuf[:i] - } - } + //i, err := remoteTrack.Read(rtpBuf) + //// TODO: can receive track but the voice doesn't work + //if err == nil { + //w.VoiceInChannel <- rtpBuf[:i] + //} + //} })