playing audio track, distortion but it seems normal looking at gmeet
This commit is contained in:
@@ -1,4 +1,8 @@
|
|||||||
import { FiActivity, FiSun } from "react-icons/fi";
|
import { FiActivity, FiSun } from "react-icons/fi";
|
||||||
|
import {
|
||||||
|
ServerResponseChannels,
|
||||||
|
SomeoneUntunedFromLineResponse,
|
||||||
|
} from "@nirvana/core/sockets/channels";
|
||||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||||
|
|
||||||
import { $selectedLineId } from "../../../controller/recoil";
|
import { $selectedLineId } from "../../../controller/recoil";
|
||||||
@@ -154,7 +158,7 @@ export default function LineRow({
|
|||||||
{isUserTunedIn && (
|
{isUserTunedIn && (
|
||||||
<StreamRoom
|
<StreamRoom
|
||||||
currentBroadcasters={masterLineData.currentBroadcastersUserIds}
|
currentBroadcasters={masterLineData.currentBroadcastersUserIds}
|
||||||
initialTunedInUserIds={masterLineData.tunedInMemberIds}
|
tunedInUsers={masterLineData.tunedInMemberIds}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
@@ -162,10 +166,10 @@ export default function LineRow({
|
|||||||
}
|
}
|
||||||
|
|
||||||
function StreamRoom({
|
function StreamRoom({
|
||||||
initialTunedInUserIds,
|
tunedInUsers,
|
||||||
currentBroadcasters,
|
currentBroadcasters,
|
||||||
}: {
|
}: {
|
||||||
initialTunedInUserIds?: string[];
|
tunedInUsers?: string[];
|
||||||
currentBroadcasters?: string[];
|
currentBroadcasters?: string[];
|
||||||
}) {
|
}) {
|
||||||
// ?could move this up the tree and pass it down? or set it in the header?
|
// ?could move this up the tree and pass it down? or set it in the header?
|
||||||
@@ -176,18 +180,44 @@ function StreamRoom({
|
|||||||
// local peer map of userIds to peers
|
// local peer map of userIds to peers
|
||||||
const [userPeers, setUserPeers] = useState<{ [userId: string]: Peer }>({});
|
const [userPeers, setUserPeers] = useState<{ [userId: string]: Peer }>({});
|
||||||
|
|
||||||
|
// ws listen to events of user disconnecting and such or rely on tunedin members prop
|
||||||
|
const { $ws } = useLineDataProvider();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
navigator.mediaDevices
|
navigator.mediaDevices
|
||||||
.getUserMedia({ video: false, audio: true })
|
.getUserMedia({
|
||||||
|
video: false,
|
||||||
|
audio: {
|
||||||
|
echoCancellation: true,
|
||||||
|
autoGainControl: true,
|
||||||
|
},
|
||||||
|
})
|
||||||
.then((userStream) => {
|
.then((userStream) => {
|
||||||
setLocalStream(userStream);
|
setLocalStream(userStream);
|
||||||
|
|
||||||
if (userStreamTagRef?.current)
|
// if (userStreamTagRef?.current)
|
||||||
userStreamTagRef.current.srcObject = userStream;
|
// userStreamTagRef.current.srcObject = userStream;
|
||||||
|
|
||||||
|
// alternative to dom element
|
||||||
// const audio = new Audio();
|
// const audio = new Audio();
|
||||||
// audio.autoplay = true;
|
// audio.autoplay = true;
|
||||||
// audio.srcObject = userStream;
|
// audio.srcObject = userStream;
|
||||||
|
|
||||||
|
// test distortion to go away on disabling audio
|
||||||
|
setTimeout(() => {
|
||||||
|
console.log("stopping audio stream ");
|
||||||
|
|
||||||
|
userStream.getTracks().forEach((track) => {
|
||||||
|
track.enabled = !track.enabled;
|
||||||
|
|
||||||
|
track.stop();
|
||||||
|
});
|
||||||
|
}, 2000);
|
||||||
|
|
||||||
|
// take the initial list of tunedInUsers
|
||||||
|
// create local peer objects for them
|
||||||
|
// notify all of them individually
|
||||||
|
//
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
@@ -196,8 +226,20 @@ function StreamRoom({
|
|||||||
"Make sure that you have permissions enabled and microphone connected"
|
"Make sure that you have permissions enabled and microphone connected"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$ws.on(
|
||||||
|
ServerResponseChannels.SOMEONE_UNTUNED_FROM_LINE,
|
||||||
|
(res: SomeoneUntunedFromLineResponse) => {
|
||||||
|
// take the relevant userId
|
||||||
|
res.userId;
|
||||||
|
}
|
||||||
|
);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
console.log("change in tuned in users in the streaming room!!!");
|
||||||
|
}, [tunedInUsers]);
|
||||||
|
|
||||||
// we only loop through peers that are associated to user Ids which exist in the currentBroadcasters array
|
// we only loop through peers that are associated to user Ids which exist in the currentBroadcasters array
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -234,19 +276,15 @@ function PeerStreamRenderer({
|
|||||||
|
|
||||||
if (streamRef?.current) streamRef.current.srcObject = remotePeerStream;
|
if (streamRef?.current) streamRef.current.srcObject = remotePeerStream;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return () => peer.destroy();
|
||||||
}, [streamRef]);
|
}, [streamRef]);
|
||||||
|
|
||||||
// when someone is broadcasting, we enable their stream
|
// when someone is broadcasting, we enable their stream
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<video
|
<audio muted={!isBroadcasting} autoPlay ref={streamRef} />
|
||||||
muted={!isBroadcasting}
|
|
||||||
autoPlay
|
|
||||||
ref={streamRef}
|
|
||||||
height={"400"}
|
|
||||||
width={"500"}
|
|
||||||
/>
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user