Skip to content

Commit

Permalink
[mirotalkbro] - #10 add message popup if can't get stream
Browse files Browse the repository at this point in the history
  • Loading branch information
miroslavpejic85 committed Jan 20, 2025
1 parent 231ccf5 commit 646ec37
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 37 deletions.
2 changes: 1 addition & 1 deletion app/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @license For open source under AGPL-3.0
* @license For private project or commercial purposes contact us at: [email protected]
* @author Miroslav Pejic - [email protected]
* @version 1.1.15
* @version 1.1.16
*/

require('dotenv').config();
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mirotalkbro",
"version": "1.1.15",
"version": "1.1.16",
"description": "P2P WebRTC audio, video and screen live broadcast",
"main": "app/server.js",
"scripts": {
Expand Down
74 changes: 39 additions & 35 deletions public/js/broadcast.js
Original file line number Diff line number Diff line change
Expand Up @@ -1023,48 +1023,52 @@ videoSelect.onchange = getStream;
getStream().then(getDevices).then(gotDevices);

function getStream() {
videoOff.style.visibility = 'hidden';

videoQualitySelect.selectedIndex = localStorage.videoQualitySelectedIndex
? localStorage.videoQualitySelectedIndex
: 0;
videoFpsSelect.selectedIndex = localStorage.videoFpsSelectedIndex ? localStorage.videoFpsSelectedIndex : 0;
videoBtn.style.color = getMode === 'dark' ? 'white' : 'black';
try {
videoOff.style.visibility = 'hidden';

videoQualitySelect.selectedIndex = localStorage.videoQualitySelectedIndex
? localStorage.videoQualitySelectedIndex
: 0;
videoFpsSelect.selectedIndex = localStorage.videoFpsSelectedIndex ? localStorage.videoFpsSelectedIndex : 0;
videoBtn.style.color = getMode === 'dark' ? 'white' : 'black';

const audioSource = audioSelect.value;
const videoSource = videoSelect.value;

const screenConstraints = { audio: true, video: true };
const cameraConstraints = {
audio: { deviceId: audioSource ? { exact: audioSource } : undefined },
video: { deviceId: videoSource ? { exact: videoSource } : undefined },
};
const constraints = screenShareEnabled ? screenConstraints : cameraConstraints;

if (screenShareEnabled) {
stopVideoTrack(broadcastStream);

video.classList.remove('mirror');
isVideoMirrored = false;
return navigator.mediaDevices
.getDisplayMedia(constraints)
.then(gotScreenStream)
.then(applyVideoConstraints)
.catch(handleError);
}

const audioSource = audioSelect.value;
const videoSource = videoSelect.value;
if (isDesktopDevice && !isVideoMirrored) {
video.className = 'mirror';
isVideoMirrored = true;
}

const screenConstraints = { audio: true, video: true };
const cameraConstraints = {
audio: { deviceId: audioSource ? { exact: audioSource } : undefined },
video: { deviceId: videoSource ? { exact: videoSource } : undefined },
};
const constraints = screenShareEnabled ? screenConstraints : cameraConstraints;
stopTracks(broadcastStream);

if (screenShareEnabled) {
stopVideoTrack(broadcastStream);

video.classList.remove('mirror');
isVideoMirrored = false;
return navigator.mediaDevices
.getDisplayMedia(constraints)
.then(gotScreenStream)
.getUserMedia(constraints)
.then(gotStream)
.then(applyVideoConstraints)
.catch(handleError);
} catch (error) {
handleError("Can't get stream, make sure you are in a secure TLS context (HTTPS) and try again");
}

if (isDesktopDevice && !isVideoMirrored) {
video.className = 'mirror';
isVideoMirrored = true;
}

stopTracks(broadcastStream);

return navigator.mediaDevices
.getUserMedia(constraints)
.then(gotStream)
.then(applyVideoConstraints)
.catch(handleError);
}

function gotStream(stream) {
Expand Down

0 comments on commit 646ec37

Please sign in to comment.