From 9f6731c51646bcfba4cc79d89a180e3081edb743 Mon Sep 17 00:00:00 2001 From: Simerus Mahesh <63352151+SimerusM@users.noreply.github.com> Date: Wed, 28 Aug 2024 21:36:28 -0400 Subject: [PATCH] backend debugger + vid/aud toggle --- api-server/webrtc.py | 11 +++++++++++ client/src/pages/MeetingPage.js | 30 +++++++++++++++++++++++++++--- client/src/services/chatHandler.js | 4 ---- client/src/services/rtcHandler.js | 7 +++++++ 4 files changed, 45 insertions(+), 7 deletions(-) diff --git a/api-server/webrtc.py b/api-server/webrtc.py index e00c988..dc98f54 100644 --- a/api-server/webrtc.py +++ b/api-server/webrtc.py @@ -1,7 +1,18 @@ from flask import request from flask_socketio import emit +class DebugTools: + @staticmethod + def log_transport(self): + ''' + Dev Function to log the transport method used in the WebSocket connection. + ''' + transport = request.args.get('transport', 'unknown') + self.log_message('DEBUG', f'Connection transport: {transport}') + + def setup_webrtc(app, socketio, session_storage, log_message): + @socketio.on('offer') def handle_offer(data): to_sid = session_storage[data['meeting_id']]['users'][data['to']] diff --git a/client/src/pages/MeetingPage.js b/client/src/pages/MeetingPage.js index 6b0d39b..6ba0abc 100644 --- a/client/src/pages/MeetingPage.js +++ b/client/src/pages/MeetingPage.js @@ -58,8 +58,33 @@ const MeetingPage = () => { } }, []); - const toggleMute = () => setIsMuted(!isMuted); - const toggleVideo = () => setIsVideoOff(!isVideoOff); + const toggleMute = () => { + setIsMuted(prevState => { + const newMutedState = !prevState; + // Mute or unmute the audio track in the local stream + if (rtcHandler.current && rtcHandler.current.localStream) { + rtcHandler.current.localStream.getAudioTracks().forEach(track => { + console.log(track); + track.enabled = !newMutedState; + }); + } + return newMutedState; + }); + }; + + const toggleVideo = () => { + setIsVideoOff(prevState => { + const newVideoState = !prevState; + // Turn on or off the video track in the local stream + if (rtcHandler.current && rtcHandler.current.localStream) { + rtcHandler.current.localStream.getVideoTracks().forEach(track => { + console.log(track); + track.enabled = !newVideoState; + }); + } + return newVideoState; + }); + }; const sendMessage = (e) => { e.preventDefault(); @@ -76,7 +101,6 @@ const MeetingPage = () => { }; if (!username || !rtcHandler.current) { - // wait for username and rtcHandler return null; } diff --git a/client/src/services/chatHandler.js b/client/src/services/chatHandler.js index 31eae60..7d8757e 100644 --- a/client/src/services/chatHandler.js +++ b/client/src/services/chatHandler.js @@ -35,10 +35,6 @@ class ChatHandler { sendMessage(text) { this.socket.emit('chat_message', { meeting_id: this.meeting_id, text: text, sender: this.username }); } - - setChatHistoryListener(listener) { - this.setChatHistory = listener; - } } export default ChatHandler; diff --git a/client/src/services/rtcHandler.js b/client/src/services/rtcHandler.js index a021325..9517795 100644 --- a/client/src/services/rtcHandler.js +++ b/client/src/services/rtcHandler.js @@ -31,6 +31,13 @@ class RTCHandler { try { this.localStream = await navigator.mediaDevices.getUserMedia({ video: true, audio: true }); this.hasMediaDevices = true; + + // Log out details of the localStream + console.log("Local Stream:", this.localStream); + + this.localStream.getTracks().forEach(track => { + console.log(`Track kind: ${track.kind}, Track ID: ${track.id}, Track enabled: ${track.enabled}`); + }); } catch (err) { console.warn('No media devices found or access denied:', err); toast.error('No media devices found or access denied. Continuing without video/audio.');