Additional outputs tweaks + fix track constraints (#28)

* code

* add code

* add code
This commit is contained in:
Freddy Boulton
2024-12-03 15:32:43 -05:00
committed by GitHub
parent 65d0ba023f
commit c85c117576
10 changed files with 91 additions and 53 deletions

View File

@@ -31,6 +31,7 @@
export let i18n: I18nFormatter;
export let time_limit: number | null = null;
export let track_constraints: MediaTrackConstraints = {};
export let rtp_params: RTCRtpParameters = {} as RTCRtpParameters;
export let on_change_cb: (mg: "tick" | "change") => void;
let options_open = false;
@@ -143,7 +144,7 @@
}
if (stream == null) return;
start(stream, pc, mode === "send" ? null: audio_player, server.offer, _webrtc_id, "audio", on_change_cb).then((connection) => {
start(stream, pc, mode === "send" ? null: audio_player, server.offer, _webrtc_id, "audio", on_change_cb, rtp_params).then((connection) => {
pc = connection;
}).catch(() => {
console.info("catching")

View File

@@ -23,6 +23,7 @@
export let track_constraints: MediaTrackConstraints = {};
export let mode: "send" | "send-receive";
export let on_change_cb: (msg: "change" | "tick") => void;
export let rtp_params: RTCRtpParameters = {} as RTCRtpParameters;
const dispatch = createEventDispatcher<{
change: FileData | null;
@@ -53,6 +54,7 @@
{time_limit}
{track_constraints}
{mode}
{rtp_params}
{on_change_cb}
on:error
on:start_recording

View File

@@ -27,8 +27,7 @@
export let on_change_cb: (msg: "tick" | "change") => void;
export let mode: "send-receive" | "send";
const _webrtc_id = Math.random().toString(36).substring(2);
console.log("mode", mode);
export let rtp_params: RTCRtpParameters = {} as RTCRtpParameters;
export const modify_stream: (state: "open" | "closed" | "waiting") => void = (
state: "open" | "closed" | "waiting"
@@ -82,7 +81,7 @@
async function access_webcam(): Promise<void> {
try {
get_video_stream(include_audio, video_source)
get_video_stream(include_audio, video_source, null, track_constraints)
.then(async (local_stream) => {
webcam_accessed = true;
available_video_devices = await get_devices();
@@ -144,7 +143,7 @@
)
stream_state = "waiting"
webrtc_id = Math.random().toString(36).substring(2);
start(stream, pc, mode === "send" ? null: video_source, server.offer, webrtc_id, "video", on_change_cb).then((connection) => {
start(stream, pc, mode === "send" ? null: video_source, server.offer, webrtc_id, "video", on_change_cb, rtp_params).then((connection) => {
pc = connection;
}).catch(() => {
console.info("catching")

View File

@@ -52,6 +52,7 @@ export async function start(
webrtc_id,
modality: "video" | "audio" = "video",
on_change_cb: (msg: "change" | "tick") => void = () => {},
rtp_params = {},
) {
pc = createPeerConnection(pc, node);
const data_channel = pc.createDataChannel("text");
@@ -70,9 +71,13 @@ export async function start(
};
if (stream) {
stream.getTracks().forEach((track) => {
stream.getTracks().forEach(async (track) => {
console.debug("Track stream callback", track);
pc.addTrack(track, stream);
const sender = pc.addTrack(track, stream);
const params = sender.getParameters();
const updated_params = { ...params, ...rtp_params };
await sender.setParameters(updated_params)
console.debug("sender params", sender.getParameters());
});
} else {
console.debug("Creating transceiver!");