Skip to content

Commit

Permalink
feat: simulcast api changes
Browse files Browse the repository at this point in the history
  • Loading branch information
raviteja83 authored Nov 25, 2022
2 parents 4af0efe + 217fbcf commit a4d3be6
Show file tree
Hide file tree
Showing 99 changed files with 1,492 additions and 862 deletions.
4 changes: 2 additions & 2 deletions apps/100ms-custom-app/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions apps/100ms-web/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions apps/100ms-web/src/common/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export const APP_DATA = {
rtmpStarted: "rtmpStarted",
recordingStarted: "recordingStarted",
embedConfig: "embedConfig",
pinnedTrackId: "pinnedTrackId",
};
export const UI_SETTINGS = {
isAudioOnly: "isAudioOnly",
Expand Down
6 changes: 6 additions & 0 deletions apps/100ms-web/src/components/AppData/useUISettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useCallback } from "react";
import {
selectAppData,
selectAppDataByPath,
selectTrackByID,
useHMSActions,
useHMSStore,
useHMSVanillaStore,
Expand Down Expand Up @@ -76,6 +77,11 @@ export const useUrlToEmbed = () => {
return useHMSStore(selectAppData(APP_DATA.embedConfig))?.url;
};

export const usePinnedTrack = () => {
const pinnedTrackId = useHMSStore(selectAppData(APP_DATA.pinnedTrackId));
return useHMSStore(selectTrackByID(pinnedTrackId));
};

export const useSubscribedNotifications = notificationKey => {
const notificationPreference = useHMSStore(
selectAppDataByPath(APP_DATA.subscribedNotifications, notificationKey)
Expand Down
8 changes: 0 additions & 8 deletions apps/100ms-web/src/components/Chat/ChatDotIcon.jsx

This file was deleted.

7 changes: 6 additions & 1 deletion apps/100ms-web/src/components/Chat/ChatSelector.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,14 @@ import {
Tooltip,
} from "@100mslive/react-ui";
import { ParticipantSearch } from "../Header/ParticipantList";
import { ChatDotIcon } from "./ChatDotIcon";
import { useFilteredRoles } from "../../common/hooks";

const ChatDotIcon = () => {
return (
<Box css={{ size: "$6", bg: "$brandDefault", mx: "$2", r: "$round" }} />
);
};

const SelectorItem = ({ value, active, onClick, unreadCount }) => {
return (
<Dropdown.Item
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ const Wrapper = styled("div", {
position: "absolute",
bottom: "$2",
left: "$2",
zIndex: 10,
backgroundColor: "$backgroundDark",
borderRadius: "$1",
zIndex: 1,
"& p,span": {
p: "$2 $3",
},
Expand Down
110 changes: 70 additions & 40 deletions apps/100ms-web/src/components/StatsForNerds.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useEffect, useMemo, useRef, useState } from "react";
import {
selectHMSStats,
selectLocalPeerID,
selectPeersMap,
selectTracksMap,
useHMSStatsStore,
Expand Down Expand Up @@ -30,7 +31,7 @@ export const StatsForNerds = ({ onOpenChange }) => {
],
[tracksWithLabels]
);
const [selectedStat, setSelectedStat] = useState("local-peer");
const [selectedStat, setSelectedStat] = useState(statsOptions[0]);
const [showStatsOnTiles, setShowStatsOnTiles] = useSetUiSettings(
UI_SETTINGS.showStatsOnTiles
);
Expand All @@ -40,8 +41,8 @@ export const StatsForNerds = ({ onOpenChange }) => {

useEffect(() => {
if (
selectedStat !== "local-peer" &&
!tracksWithLabels.find(track => track.id === selectedStat)
selectedStat.id !== "local-peer" &&
!tracksWithLabels.find(track => track.id === selectedStat.id)
) {
setSelectedStat("local-peer");
}
Expand Down Expand Up @@ -94,10 +95,7 @@ export const StatsForNerds = ({ onOpenChange }) => {
onOpenChange={setOpen}
>
<DialogDropdownTrigger
title={
statsOptions.find(({ id }) => id === selectedStat)?.label ||
"Select Stats"
}
title={selectedStat.label || "Select Stats"}
css={{ mt: "$4" }}
titleCSS={{ mx: 0 }}
open={open}
Expand All @@ -109,34 +107,39 @@ export const StatsForNerds = ({ onOpenChange }) => {
sideOffset={8}
css={{ w: ref.current?.clientWidth, zIndex: 1000 }}
>
{statsOptions.map(option => (
<Dropdown.Item
key={option.id}
onClick={() => {
setSelectedStat(option.id);
}}
css={{
px: "$9",
bg:
option.id === selectedStat ? selectionBg : undefined,
c:
option.id === selectedStat
? "$white"
: "$textPrimary",
}}
>
{option.label}
</Dropdown.Item>
))}
{statsOptions.map(option => {
const isSelected =
option.id === selectedStat.id &&
option.layer === selectedStat.layer;
return (
<Dropdown.Item
key={option.label}
onClick={() => {
setSelectedStat(option);
}}
css={{
px: "$9",
bg: isSelected ? selectionBg : undefined,
c: isSelected ? "$white" : "$textPrimary",
}}
>
{option.label}
</Dropdown.Item>
);
})}
</Dropdown.Content>
</Dropdown.Portal>
</Dropdown.Root>
</Flex>
{/* Stats */}
{selectedStat === "local-peer" ? (
{selectedStat.id === "local-peer" ? (
<LocalPeerStats />
) : (
<TrackStats trackID={selectedStat} />
<TrackStats
trackID={selectedStat.id}
layer={selectedStat.layer}
local={selectedStat.local}
/>
)}
</Dialog.Content>
</Dialog.Portal>
Expand All @@ -147,16 +150,33 @@ export const StatsForNerds = ({ onOpenChange }) => {
const useTracksWithLabel = () => {
const tracksMap = useHMSStore(selectTracksMap);
const peersMap = useHMSStore(selectPeersMap);
const localPeerID = useHMSStore(selectLocalPeerID);
const tracksWithLabels = useMemo(
() =>
Object.values(tracksMap).map(track => {
Object.values(tracksMap).reduce((res, track) => {
const peerName = peersMap[track.peerId]?.name;
return {
const isLocalTrack = track.peerId === localPeerID;
if (isLocalTrack && track.layerDefinitions?.length) {
res = res.concat(
track.layerDefinitions.map(({ layer }) => {
return {
id: track.id,
layer,
local: true,
label: `${peerName} ${track.source} ${track.type} - ${layer}`,
};
})
);
return res;
}
res.push({
id: track.id,
local: isLocalTrack,
label: `${peerName} ${track.source} ${track.type}`,
};
}),
[tracksMap, peersMap]
});
return res;
}, []),
[tracksMap, peersMap, localPeerID]
);
return tracksWithLabels;
};
Expand All @@ -170,8 +190,11 @@ const LocalPeerStats = () => {

return (
<Flex css={{ flexWrap: "wrap", gap: "$10" }}>
<StatsRow label="Packets Lost" value={stats.subscribe?.packetsLost} />
<StatsRow label="Jitter" value={stats.subscribe?.jitter} />
<StatsRow
label="Packets Lost"
value={stats.subscribe?.packetsLost || "-"}
/>
<StatsRow label="Jitter" value={stats.subscribe?.jitter || "-"} />
<StatsRow
label="Publish Bitrate"
value={formatBytes(stats.publish?.bitrate, "b/s")}
Expand All @@ -192,8 +215,13 @@ const LocalPeerStats = () => {
);
};

const TrackStats = ({ trackID }) => {
const stats = useHMSStatsStore(selectHMSStats.trackStatsByID(trackID));
const TrackStats = ({ trackID, layer, local }) => {
const selector = layer
? selectHMSStats.localVideoTrackStatsByLayer(layer)(trackID)
: local
? selectHMSStats.localAudioTrackStatsByID(trackID)
: selectHMSStats.trackStatsByID(trackID);
const stats = useHMSStatsStore(selector);
if (!stats) {
return null;
}
Expand All @@ -204,7 +232,7 @@ const TrackStats = ({ trackID }) => {
<StatsRow label="Type" value={stats.type + " " + stats.kind} />
<StatsRow label="Bitrate" value={formatBytes(stats.bitrate, "b/s")} />
<StatsRow label="Packets Lost" value={stats.packetsLost || "-"} />
<StatsRow label="Jitter" value={stats.jitter || "-"} />
<StatsRow label="Jitter" value={stats.jitter?.toFixed(3) || "-"} />
<StatsRow
label={inbound ? "Bytes Received" : "Bytes Sent"}
value={formatBytes(inbound ? stats.bytesReceived : stats.bytesSent)}
Expand All @@ -218,13 +246,14 @@ const TrackStats = ({ trackID }) => {
value={stats.qualityLimitationReason || "-"}
/>
)}
{stats.rid && <StatsRow label="Rid" value={stats.rid} />}
</>
)}
</Flex>
);
};

const StatsRow = ({ label, value }) => (
const StatsRow = React.memo(({ label, value }) => (
<Box css={{ bg: "$surfaceLight", w: "calc(50% - $6)", p: "$8", r: "$3" }}>
<Text
variant="overline"
Expand All @@ -243,9 +272,10 @@ const StatsRow = ({ label, value }) => (
{value}
</Text>
</Box>
);
));

const formatBytes = (bytes, unit = "B", decimals = 2) => {
if (bytes === undefined) return "-";
if (bytes === 0) return "0 " + unit;

const k = 1024;
Expand Down
Loading

0 comments on commit a4d3be6

Please sign in to comment.