removed track resume from videogrid
This commit is contained in:
parent
0ad5553050
commit
60772e0ae0
|
|
@ -2,14 +2,13 @@ import React, { useState, useMemo, useEffect, useRef } from 'react';
|
||||||
import Tile from '@dailyjs/shared/components/Tile';
|
import Tile from '@dailyjs/shared/components/Tile';
|
||||||
import { DEFAULT_ASPECT_RATIO } from '@dailyjs/shared/constants';
|
import { DEFAULT_ASPECT_RATIO } from '@dailyjs/shared/constants';
|
||||||
import { useParticipants } from '@dailyjs/shared/contexts/ParticipantsProvider';
|
import { useParticipants } from '@dailyjs/shared/contexts/ParticipantsProvider';
|
||||||
import { useTracks } from '@dailyjs/shared/contexts/TracksProvider';
|
import usePreferredLayer from '@dailyjs/shared/hooks/usePreferredLayer';
|
||||||
import { useDeepCompareMemo } from 'use-deep-compare';
|
import { useDeepCompareMemo } from 'use-deep-compare';
|
||||||
|
|
||||||
export const VideoGrid = React.memo(
|
export const VideoGrid = React.memo(
|
||||||
() => {
|
() => {
|
||||||
const containerRef = useRef();
|
const containerRef = useRef();
|
||||||
const { allParticipants } = useParticipants();
|
const { allParticipants } = useParticipants();
|
||||||
const { resumeVideoTrack } = useTracks();
|
|
||||||
const [dimensions, setDimensions] = useState({
|
const [dimensions, setDimensions] = useState({
|
||||||
width: 1,
|
width: 1,
|
||||||
height: 1,
|
height: 1,
|
||||||
|
|
@ -91,40 +90,7 @@ export const VideoGrid = React.memo(
|
||||||
[layout, allParticipants]
|
[layout, allParticipants]
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
usePreferredLayer();
|
||||||
* Set bandwidth layer based on amount of visible participants
|
|
||||||
*/
|
|
||||||
useEffect(() => {
|
|
||||||
if (
|
|
||||||
typeof rtcpeers === 'undefined' ||
|
|
||||||
// eslint-disable-next-line no-undef
|
|
||||||
rtcpeers?.getCurrentType() !== 'sfu'
|
|
||||||
)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// eslint-disable-next-line no-undef
|
|
||||||
const sfu = rtcpeers.soup;
|
|
||||||
const count = allParticipants.length;
|
|
||||||
|
|
||||||
allParticipants.forEach(({ id }) => {
|
|
||||||
if (count < 5) {
|
|
||||||
// High quality video for calls with < 5 people per page
|
|
||||||
sfu.setPreferredLayerForTrack(id, 'cam-video', 2);
|
|
||||||
} else if (count < 10) {
|
|
||||||
// Medium quality video for calls with < 10 people per page
|
|
||||||
sfu.setPreferredLayerForTrack(id, 'cam-video', 1);
|
|
||||||
} else {
|
|
||||||
// Low quality video for calls with 10 or more people per page
|
|
||||||
sfu.setPreferredLayerForTrack(id, 'cam-video', 0);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}, [allParticipants]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
allParticipants.forEach(
|
|
||||||
(p) => p.id !== 'local' && resumeVideoTrack(p.id)
|
|
||||||
);
|
|
||||||
}, [allParticipants, resumeVideoTrack]);
|
|
||||||
|
|
||||||
if (!allParticipants.length) {
|
if (!allParticipants.length) {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ export default function Index({
|
||||||
predefinedRoom = '',
|
predefinedRoom = '',
|
||||||
forceFetchToken = false,
|
forceFetchToken = false,
|
||||||
forceOwner = false,
|
forceOwner = false,
|
||||||
|
subscribeToTracksAutomatically = true,
|
||||||
asides,
|
asides,
|
||||||
modals,
|
modals,
|
||||||
customTrayComponent,
|
customTrayComponent,
|
||||||
|
|
@ -111,7 +112,12 @@ export default function Index({
|
||||||
modals={modals}
|
modals={modals}
|
||||||
customTrayComponent={customTrayComponent}
|
customTrayComponent={customTrayComponent}
|
||||||
>
|
>
|
||||||
<CallProvider domain={domain} room={roomName} token={token}>
|
<CallProvider
|
||||||
|
domain={domain}
|
||||||
|
room={roomName}
|
||||||
|
token={token}
|
||||||
|
subscribeToTracksAutomatically={subscribeToTracksAutomatically}
|
||||||
|
>
|
||||||
<ParticipantsProvider>
|
<ParticipantsProvider>
|
||||||
<TracksProvider>
|
<TracksProvider>
|
||||||
<MediaDeviceProvider>
|
<MediaDeviceProvider>
|
||||||
|
|
@ -136,11 +142,11 @@ Index.propTypes = {
|
||||||
customAppComponent: PropTypes.node,
|
customAppComponent: PropTypes.node,
|
||||||
forceFetchToken: PropTypes.bool,
|
forceFetchToken: PropTypes.bool,
|
||||||
forceOwner: PropTypes.bool,
|
forceOwner: PropTypes.bool,
|
||||||
|
subscribeToTracksAutomatically: PropTypes.bool,
|
||||||
};
|
};
|
||||||
|
|
||||||
export async function getStaticProps() {
|
export async function getStaticProps() {
|
||||||
const defaultProps = getDemoProps();
|
const defaultProps = getDemoProps();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
props: defaultProps,
|
props: defaultProps,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ import { useDeepCompareMemo } from 'use-deep-compare';
|
||||||
* - Set user name and join call / request access
|
* - Set user name and join call / request access
|
||||||
*/
|
*/
|
||||||
export const HairCheck = () => {
|
export const HairCheck = () => {
|
||||||
const { callObject } = useCallState();
|
const { callObject, join } = useCallState();
|
||||||
const { localParticipant } = useParticipants();
|
const { localParticipant } = useParticipants();
|
||||||
const { deviceState, camError, micError, isCamMuted, isMicMuted } =
|
const { deviceState, camError, micError, isCamMuted, isMicMuted } =
|
||||||
useMediaDevices();
|
useMediaDevices();
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ export const CallProvider = ({
|
||||||
domain,
|
domain,
|
||||||
room,
|
room,
|
||||||
token = '',
|
token = '',
|
||||||
subscribeToTracksAutomatically = false,
|
subscribeToTracksAutomatically = true,
|
||||||
}) => {
|
}) => {
|
||||||
const [videoQuality, setVideoQuality] = useState(VIDEO_QUALITY_AUTO);
|
const [videoQuality, setVideoQuality] = useState(VIDEO_QUALITY_AUTO);
|
||||||
const [preJoinNonAuthorized, setPreJoinNonAuthorized] = useState(false);
|
const [preJoinNonAuthorized, setPreJoinNonAuthorized] = useState(false);
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,46 @@
|
||||||
|
/* global rtcpeers */
|
||||||
|
|
||||||
|
import { useEffect } from 'react';
|
||||||
|
import { useParticipants } from '../contexts/ParticipantsProvider';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This hook will switch between one of the 3 simulcast layers
|
||||||
|
* depending on the number of participants present on the call
|
||||||
|
* to optimise bandwidth / cpu usage
|
||||||
|
*
|
||||||
|
* Note: the API for this feature is currently work in progress
|
||||||
|
* and not documented. Momentarily we are using an internal
|
||||||
|
* method `setPreferredLayerForTrack` found on the global
|
||||||
|
* `rtcpeers` object.
|
||||||
|
*
|
||||||
|
* Note: this will have no effect when not in SFU mode
|
||||||
|
*/
|
||||||
|
export const usePreferredLayer = () => {
|
||||||
|
const { allParticipants } = useParticipants();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set bandwidth layer based on amount of visible participants
|
||||||
|
*/
|
||||||
|
useEffect(() => {
|
||||||
|
if (typeof rtcpeers === 'undefined' || rtcpeers?.getCurrentType() !== 'sfu')
|
||||||
|
return;
|
||||||
|
|
||||||
|
const sfu = rtcpeers.soup;
|
||||||
|
const count = allParticipants.length;
|
||||||
|
|
||||||
|
allParticipants.forEach(({ id }) => {
|
||||||
|
if (count < 5) {
|
||||||
|
// High quality video for calls with < 5 people per page
|
||||||
|
sfu.setPreferredLayerForTrack(id, 'cam-video', 2);
|
||||||
|
} else if (count < 10) {
|
||||||
|
// Medium quality video for calls with < 10 people per page
|
||||||
|
sfu.setPreferredLayerForTrack(id, 'cam-video', 1);
|
||||||
|
} else {
|
||||||
|
// Low quality video for calls with 10 or more people per page
|
||||||
|
sfu.setPreferredLayerForTrack(id, 'cam-video', 0);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}, [allParticipants]);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default usePreferredLayer;
|
||||||
|
|
@ -5,5 +5,7 @@ export default function getDemoProps() {
|
||||||
isConfigured: !!process.env.DAILY_DOMAIN && !!process.env.DAILY_API_KEY,
|
isConfigured: !!process.env.DAILY_DOMAIN && !!process.env.DAILY_API_KEY,
|
||||||
// Have we predefined a room to use?
|
// Have we predefined a room to use?
|
||||||
predefinedRoom: process.env.DAILY_ROOM || '',
|
predefinedRoom: process.env.DAILY_ROOM || '',
|
||||||
|
// Manual or automatic track subscriptions
|
||||||
|
subscribeToTracksAutomatically: !process.env.MANUAL_TRACK_SUBS,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue