trying to send through transceiver and still trying to fiddle

This commit is contained in:
talksik
2022-04-28 09:35:07 -05:00
parent 44ee03c9e5
commit 3a5a1b8fbd
2 changed files with 66 additions and 23 deletions
+18 -10
View File
@@ -31,20 +31,26 @@ async function handleJoin(req: Request, res: Response) {
],
});
// now that remote is set
// allow this peer connection for this specific line to get tracks for this line already
try {
linesStreams[lineId]?.forEach((stream: any) => {
stream.getTracks().forEach((track: any) => {
console.log(`have tracks in this line`, track, stream);
peer.addTrack(track, stream);
});
});
} catch (e) {
console.log(`hacking around small problem with adding track`, e);
}
// allow this peer connection to receive other peoples' streams
peer.ontrack = (e: any) => handleStreams(e, peer, lineId);
// allow this peer connection for this specific line to get tracks for this line already
linesStreams[lineId]?.forEach((stream: any) => {
stream.getTracks().forEach((track: any) => {
console.log(`have tracks in this line`, track, stream);
peer.addTrack(track, stream);
});
});
// create connection between server and client who hit this endpoint
const desc = new webrtc.RTCSessionDescription(sdp);
await peer.setRemoteDescription(desc);
const answer = await peer.createAnswer();
await peer.setLocalDescription(answer);
@@ -68,11 +74,13 @@ async function handleJoin(req: Request, res: Response) {
function handleStreams(e: any, peer: any, lineId: string) {
// if the room/line exists already, then add to the list of streams
if (lineId in linesStreams) {
const newStreamsForLine = [...(linesStreams[lineId] ?? []), ...e.streams];
const newStreamsForLine = [...(linesStreams[lineId] ?? []), e.streams[0]];
linesStreams[lineId] = newStreamsForLine;
} else {
// create a new list of streams
linesStreams[lineId] = [...e.streams];
linesStreams[lineId] = [e.streams[0]];
}
console.log(linesStreams);
}