1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-04 10:19:24 +02:00
This commit is contained in:
Daniel Neto 2025-01-10 19:06:09 -03:00
parent dededfbe31
commit fc1b1627cc

View file

@ -50,8 +50,22 @@ function stopWebcamLive(rtmpURL) {
// Send media chunks with the associated streamKey
function sendStreamToServer(stream) {
try {
if (!window.MediaRecorder) {
console.error('MediaRecorder API is not supported on this device.');
avideoToastError('MediaRecorder API is not supported on this device.');
return;
}
const mediaRecorder = new MediaRecorder(stream);
const options = {
mimeType: 'video/webm; codecs=vp8,opus' // Check for Safari compatibility
};
try {
const mediaRecorder = new MediaRecorder(stream, options);
console.log('MediaRecorder initialized with options:', options);
} catch (error) {
avideoTpastErrpr(`Failed to initialize MediaRecorder with options:${error}`);
}
mediaRecorder.ondataavailable = (event) => {
if (event.data.size > 0) {
@ -142,7 +156,15 @@ async function startWebRTC({ videoDeviceId = null, audioDeviceId = null, useScre
// Start or update the media stream
const newStream = useScreen
? await navigator.mediaDevices.getDisplayMedia(constraints)
: await navigator.mediaDevices.getUserMedia(constraints);
: await navigator.mediaDevices.getUserMedia(constraints)
.then((stream) => {
console.log('Media stream obtained:', stream);
sendStreamToServer(stream);
})
.catch((error) => {
avideoToastError(`Error accessing media devices: ${error}`);
console.error('Error accessing media devices:', error);
});
// Stop existing tracks before replacing them
if (localStream) {