From eeec8a90e8b44f722bdb1788635c163ff9a2aabd Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Mon, 24 Jan 2022 20:41:20 -0800 Subject: [PATCH] common: RTCAVSource usage --- common/src/wrtc-ffmpeg-source.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/common/src/wrtc-ffmpeg-source.ts b/common/src/wrtc-ffmpeg-source.ts index 7ebfa28dd..063f2c3d7 100644 --- a/common/src/wrtc-ffmpeg-source.ts +++ b/common/src/wrtc-ffmpeg-source.ts @@ -1,4 +1,4 @@ -import { RTCAVMessage, FFMpegInput, MediaManager, MediaStreamOptions} from "@scrypted/sdk/types"; +import { RTCAVSource, RTCAVMessage, FFMpegInput, MediaManager, MediaStreamOptions} from "@scrypted/sdk/types"; import { listenZeroSingleClient } from "./listen-cluster"; import { RTCPeerConnection, RTCRtpCodecParameters } from "werift"; import dgram from 'dgram'; @@ -40,7 +40,7 @@ export function getRTCMediaStreamOptions(id: string, name: string): MediaStreamO }; } -export async function createRTCPeerConnectionSource(id: string, name: string, console: Console, mediaManager: MediaManager, sendOffer: (offer: RTCAVMessage) => Promise): Promise<{ +export async function createRTCPeerConnectionSource(avsource: RTCAVSource, id: string, name: string, console: Console, sendOffer: (offer: RTCAVMessage) => Promise): Promise<{ ffmpegInput: FFMpegInput, peerConnection: RTCPeerConnection, }> { @@ -83,7 +83,10 @@ export async function createRTCPeerConnectionSource(id: string, name: string, co let gotAudio = false; let gotVideo = false; - const audioTransceiver = pc.addTransceiver("audio", { direction: "recvonly" }); + if (avsource.datachannel) + pc.createDataChannel(avsource.datachannel.label, avsource.datachannel.dict); + + const audioTransceiver = pc.addTransceiver("audio", avsource.audio as any); audioTransceiver.onTrack.subscribe((track) => { audioTransceiver.sender.replaceTrack(track); track.onReceiveRtp.subscribe((rtp) => { @@ -95,7 +98,7 @@ export async function createRTCPeerConnectionSource(id: string, name: string, co }); }); - const videoTransceiver = pc.addTransceiver("video", { direction: "recvonly" }); + const videoTransceiver = pc.addTransceiver("video", avsource.video as any); videoTransceiver.onTrack.subscribe((track) => { videoTransceiver.sender.replaceTrack(track); track.onReceiveRtp.subscribe((rtp) => { @@ -110,8 +113,6 @@ export async function createRTCPeerConnectionSource(id: string, name: string, co }); }); - pc.createDataChannel('dataSendChannel', { id: 1 }); - let offer = await pc.createOffer(); await pc.setLocalDescription(offer);