Skip to content

Commit d5b0e8d

Browse files
committed
tune media panel
1 parent 0d18393 commit d5b0e8d

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

src/api/const.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ export const MEDIA_ELEMENT_EVENTS = [
4949
];
5050

5151
export const MEDIA_ELEMENT_PROPS = [
52-
'src',
52+
'poster',
5353
'currentSrc',
54+
'src',
5455
'srcObject',
5556
'error',
5657
'preload',
@@ -66,14 +67,13 @@ export const MEDIA_ELEMENT_PROPS = [
6667
'ended',
6768
'autoplay',
6869
'loop',
70+
'defaultMuted',
6971
'muted',
7072
'volume',
71-
'preservesPitch',
72-
'defaultMuted',
7373
'crossOrigin',
7474
'defaultPlaybackRate',
7575
'playbackRate',
76-
'mediaGroup',
76+
'preservesPitch',
7777
'controls',
7878
'audioTracks',
7979
'videoTracks',
@@ -84,7 +84,6 @@ export const MEDIA_ELEMENT_PROPS = [
8484
'height',
8585
'videoWidth',
8686
'videoHeight',
87-
'poster',
8887
];
8988
// https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/networkState
9089
export const NETWORK_STATE = [

src/api/mediaMonitor.ts

+9-5
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,12 @@ export function collectMediaMetrics(
6767
rv.collection = mediaCollection.map((v) => {
6868
// refresh props metrics
6969
for (const prop of MEDIA_ELEMENT_PROPS) {
70-
v.metrics.props[prop] = formatPropValue(
71-
prop,
72-
v.el[prop as keyof HTMLMediaElement]
73-
);
70+
if (prop in v.el) {
71+
v.metrics.props[prop] = formatPropValue(
72+
prop,
73+
v.el[prop as keyof HTMLMediaElement]
74+
);
75+
}
7476
}
7577
return v.metrics;
7678
});
@@ -86,6 +88,8 @@ function formatPropValue(prop: string, value: unknown): any {
8688
rv = `${value} - ${NETWORK_STATE[value as number]}`;
8789
} else if ('readyState' === prop) {
8890
rv = `${value} - ${READY_STATE[value as number]}`;
91+
} else if ('srcObject' === prop) {
92+
rv = value ? `${value}` : value;
8993
} else if (value instanceof TimeRanges) {
9094
rv = [];
9195

@@ -95,7 +99,7 @@ function formatPropValue(prop: string, value: unknown): any {
9599

96100
rv = rv.join('');
97101
} else if (value instanceof TextTrackList) {
98-
rv = `[${value.length}]`;
102+
rv = value.length;
99103
} else if (value instanceof MediaError) {
100104
rv = `${value.code}/${value.message}`;
101105
}

src/view/components/MediaMetrics.svelte

+7-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,13 @@
2424
<table class="w-full">
2525
<caption class="bc-invert ta-l">Properties</caption>
2626
{#each Object.entries(metrics.props) as [label, value] (label)}
27-
<tr class:isPassive={null === value} class:isActive={true === value}>
27+
<tr
28+
class:isPassive={null === value ||
29+
false === value ||
30+
'' === value ||
31+
0 === value}
32+
class:isActive={true === value}
33+
>
2834
<td class="item-label">{label}</td>
2935
<td class="item-value">
3036
{#if ['networkState', 'readyState'].includes(label)}

0 commit comments

Comments
 (0)