Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ import {
LiveIndicator,
} from '../LivestreamTopView';
import { IconWrapper, Maximize } from '../../../icons';
import InCallManager from 'react-native-incall-manager';
import {
VolumeOff,
VolumeOn,
PauseIcon,
PlayIcon,
} from '../../../icons/LivestreamControls';
import { useCallStateHooks } from '@stream-io/video-react-bindings';

/**
* Props for the ViewerLivestreamControls component.
Expand Down Expand Up @@ -65,6 +65,9 @@ export const ViewerLivestreamControls = ({
const [showPlayPauseButton, setShowPlayPauseButton] = useState(true);
const playPauseTimeout = useRef<NodeJS.Timeout | null>(null);

const { useDominantSpeaker } = useCallStateHooks();
const dominantSpeaker = useDominantSpeaker();

const hidePlayPauseButtonAfterDelay = useCallback(() => {
if (playPauseTimeout.current) {
clearTimeout(playPauseTimeout.current);
Expand Down Expand Up @@ -104,8 +107,16 @@ export const ViewerLivestreamControls = ({
};

const toggleAudio = () => {
setIsMuted(!isMuted);
InCallManager.setForceSpeakerphoneOn(isMuted);
const audioTrack = dominantSpeaker?.audioStream?.getAudioTracks?.()[0];
const shouldMute = !isMuted;
if (shouldMute) {
// @ts-expect-error - _setVolume is a private method of MediaStreamTrack in rn-webrtc
audioTrack?._setVolume(0);
} else {
// @ts-expect-error -_setVolume is a private method of MediaStreamTrack in rn-webrtc
audioTrack?._setVolume(0.75);
}
setIsMuted(shouldMute);
Comment on lines +110 to +119
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assumes that there is only one presenter. In case there are multiple, the behavior of this code is non-deterministic.
For example:

  • At the moment of mute, A was the dominant speaker
  • At the moment of unmute, B is the dominant speaker

In this case, A will stay forever muted, and B will always be audible.
We need to either:

  • Mute audio on system level
  • Mute all available audio tracks, individually

};

const togglePlayPause = () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import React, { useCallback, useEffect, useState } from 'react';
import { hasScreenShare, SfuModels } from '@stream-io/video-client';
import {
hasScreenShare,
SfuModels,
StreamVideoParticipant,
} from '@stream-io/video-client';
import { useCall, useCallStateHooks } from '@stream-io/video-react-bindings';
import { StyleSheet, View, type ViewStyle } from 'react-native';
import { usePaginatedLayoutSortPreset } from '../../../hooks/usePaginatedLayoutSortPreset';
Expand All @@ -9,6 +13,7 @@ import {
type VideoRendererProps,
} from '../../Participant';
import type { ScreenShareOverlayProps } from '../../utility/ScreenShareOverlay';
import { useTrackDimensions } from '../../../hooks';

/**
* Props for the LivestreamLayout component.
Expand Down Expand Up @@ -56,11 +61,6 @@ export const LivestreamLayout = ({
React.ComponentProps<NonNullable<typeof VideoRenderer>>['objectFit']
>();

// no need to pass object fit for local participant as the dimensions are for remote tracks
const objectFitToBeSet = currentSpeaker?.isLocalParticipant
? undefined
: objectFit;

const onDimensionsChange = useCallback(
(d: SfuModels.VideoDimension | undefined) => {
if (d) {
Expand All @@ -84,48 +84,57 @@ export const LivestreamLayout = ({
livestreamLayout.container,
]}
>
<RemoteVideoTrackDimensionsRenderLessComponent
onDimensionsChange={onDimensionsChange}
/>
{VideoRenderer &&
hasOngoingScreenShare &&
presenter &&
(presenter.isLocalParticipant && ScreenShareOverlay ? (
<ScreenShareOverlay />
) : (
<VideoRenderer trackType="screenShareTrack" participant={presenter} />
<>
<VideoRenderer
trackType="screenShareTrack"
objectFit={objectFit}
participant={presenter}
/>
<VideoTrackDimensionsRenderLessComponent
onDimensionsChange={onDimensionsChange}
participant={presenter}
trackType="screenShareTrack"
/>
</>
))}
{VideoRenderer && !hasOngoingScreenShare && currentSpeaker && (
<VideoRenderer
participant={currentSpeaker}
objectFit={objectFitToBeSet}
trackType="videoTrack"
/>
<>
<VideoRenderer
participant={currentSpeaker}
objectFit={objectFit}
trackType="videoTrack"
/>
<VideoTrackDimensionsRenderLessComponent
onDimensionsChange={onDimensionsChange}
participant={currentSpeaker}
trackType="videoTrack"
/>
</>
)}
</View>
);
};

const RemoteVideoTrackDimensionsRenderLessComponent = ({
const VideoTrackDimensionsRenderLessComponent = ({
onDimensionsChange,
participant,
trackType,
}: {
onDimensionsChange: (d: SfuModels.VideoDimension | undefined) => void;
participant: StreamVideoParticipant;
trackType: 'videoTrack' | 'screenShareTrack';
}) => {
const [dimension, setDimension] = useState<SfuModels.VideoDimension>();
const { useCallStatsReport } = useCallStateHooks();
const statsReport = useCallStatsReport();
const highestFrameHeight = statsReport?.subscriberStats?.highestFrameHeight;
const highestFrameWidth = statsReport?.subscriberStats?.highestFrameWidth;

useEffect(() => {
if (highestFrameHeight && highestFrameWidth) {
setDimension({ height: highestFrameHeight, width: highestFrameWidth });
}
}, [highestFrameHeight, highestFrameWidth]);
const { width, height } = useTrackDimensions(participant, trackType);

useEffect(() => {
onDimensionsChange(dimension);
}, [dimension, onDimensionsChange]);
onDimensionsChange({ width, height });
}, [width, height, onDimensionsChange]);

return null;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,10 @@ export const ViewLiveStreamChildren = ({
params: { callId },
} = route;

const client = useStreamVideoClient();
const call = useSetCall(callId, 'livestream', client);

if (!call) {
return null;
}

/**
* Note: Here we provide the `StreamCall` component again. This is done, so that the call used, is created by the anonymous user.
*/
return (
<StreamCall call={call}>
<LivestreamPlayer callId={callId} callType="livestream" />
</StreamCall>
);
return <LivestreamPlayer callId={callId} callType="livestream" />;
};

export const ViewLiveStreamScreen = ({
Expand Down