From 90cd3741e4cd16daf2609859da13fb4a176f8d8e Mon Sep 17 00:00:00 2001 From: ian ramzy Date: Wed, 25 Mar 2020 02:02:06 -0400 Subject: [PATCH] pause video, fixed routing, cleanup --- public/chat.html | 1 + public/chat.js | 66 ++++++++++++++++++++++++++++++++---------------- server.js | 2 +- 3 files changed, 46 insertions(+), 23 deletions(-) diff --git a/public/chat.html b/public/chat.html index e1b4789..31a71b1 100644 --- a/public/chat.html +++ b/public/chat.html @@ -22,6 +22,7 @@ Back Fullscreen Mute + Pause Share Screen diff --git a/public/chat.js b/public/chat.js index c1378e9..baa3bc5 100644 --- a/public/chat.js +++ b/public/chat.js @@ -1,18 +1,29 @@ if (window.location.pathname === "/") { - // Generate random room name if needed - var adjectives = ["small", "big", "large", "smelly", "new", "happy", "shiny", "old", "clean", "nice", "bad", "cool", - "hot", "cold", "warm", "hungry", "slow", "fast", "red", "white", "black", "blue", "green"]; - var nouns = ["dog", "bat", "wrench", "apple", "pear", "ghost", "cat", "wolf", "squid", "goat", "snail", "hat", - "sock", "plum", "bear", "snake", "turtle", "horse", "spoon", "fork", "spider", "tree", "chair", "table", - "couch", "towel"]; - var adjective = adjectives[Math.floor(Math.random() * adjectives.length)]; - var noun = nouns[Math.floor(Math.random() * nouns.length)]; - noun = noun.charAt(0).toUpperCase() + noun.substring(1); - adjective = adjective.charAt(0).toUpperCase() + adjective.substring(1); - window.location.href = window.location.href + adjective + noun; + window.location.href = "/landing/newroom"; } const roomHash = window.location.pathname; + +var isWebRTCSupported = + navigator.getUserMedia || + navigator.webkitGetUserMedia || + navigator.mozGetUserMedia || + navigator.msGetUserMedia || + window.RTCPeerConnection; + +// try { +// window.RTCPeerConnection.peerConnection.addStream +// } catch (e) { +// alert("Your browser doesn't support Neon Chat. Please use Chrome or Firefox."); +// window.location.href = "/landing"; +// } + +if (!isWebRTCSupported) { + alert("Your browser doesn't support Neon Chat. Please use Chrome or Firefox."); + window.location.href = "/landing"; +} + + function logIt(message, error) { // console.log(message); // Add to logs on page @@ -47,7 +58,9 @@ var VideoChat = { VideoChat.onMediaStream(stream); }) .catch(error => { - VideoChat.noMediaStream(error); + console.log(error); + logIt('No media stream for us.'); + alert("Please check your webcam browser privacy settings.") }); }, @@ -58,7 +71,9 @@ var VideoChat = { VideoChat.onMediaStream(stream); }) .catch(error => { - VideoChat.noMediaStream(error); + console.log(error); + logIt('No media stream for us.'); + alert("Please check your screen sharing browser privacy settings.") }); }, @@ -77,15 +92,10 @@ var VideoChat = { VideoChat.socket.on('willInitiateCall', () => VideoChat.willInitiateCall = true); }, - // There's not much to do in this demo if there is no media stream. So let's just stop. - noMediaStream: function () { - logIt('No media stream for us.'); - }, chatRoomFull: function () { alert("Chat room is full. Check to make sure you don't have multiple open tabs, or try with a new room link"); - // VideoChat.socket.disconnect() - // todo handle this better + window.location.href = "/landing/newroom"; }, // When we are ready to call, enable the Call button. @@ -125,8 +135,7 @@ var VideoChat = { }; }, - // When the peerConnection generates an ice candidate, send it over the socket - // to the peer. + // When the peerConnection generates an ice candidate, send it over the socket to the peer. onIceCandidate: function (event) { console.log("onIceCandidate"); if (event.candidate) { @@ -262,6 +271,20 @@ function muteMicrophone() { } } +function pauseVideo() { + var muted = !VideoChat.localStream.getAudioTracks()[0].enabled; + var videoPaused = !VideoChat.localStream.getVideoTracks()[0].enabled; + VideoChat.localStream.getAudioTracks()[0].enabled = muted; + VideoChat.localStream.getVideoTracks()[0].enabled = videoPaused; + var pausedButton = document.getElementById("videoPauseButton"); + if (!muted) { + pausedButton.innerText = "Unpause" + } else { + pausedButton.innerText = "Pause" + } + +} + var timedelay = 1; @@ -279,5 +302,4 @@ $(document).mousemove(function () { clearInterval(_delay); _delay = setInterval(delayCheck, 500); }); -// page loads starts delay timer _delay = setInterval(delayCheck, 500); diff --git a/server.js b/server.js index 6e90d86..368facf 100644 --- a/server.js +++ b/server.js @@ -16,7 +16,7 @@ app.get('/landing/newroom', function (req, res) { }); app.get('/landing', function (req, res) { - res.sendFile(path.join(public, 'landing/landing2.html')); + res.sendFile(path.join(public, 'landing/landing.html')); }); app.get('/newroom', function (req, res) {