Skip to content

Commit

Permalink
fix: [#1557] Adds missing setter for the HTMLMediaElement.srcObject p…
Browse files Browse the repository at this point in the history
…roperty (#1560)

* fix: [#1557] TypeError: Cannot set property srcObject had only a getter

* chore: [#1557] Adds validation for if object is of type MediaStream

---------

Co-authored-by: David Ortner <[email protected]>
  • Loading branch information
ewesemann and capricorn86 authored Nov 6, 2024
1 parent b949718 commit 32f7510
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,20 @@ export default class HTMLMediaElement extends HTMLElement {
return this[PropertySymbol.srcObject];
}

/**
* Sets src object.
*
* @param srcObject SrcObject.
*/
public set srcObject(srcObject: MediaStream | null) {
if (srcObject !== null && !(srcObject instanceof MediaStream)) {
throw new this[PropertySymbol.window].TypeError(
`Failed to set the 'srcObject' property on 'HTMLMediaElement': The provided value is not of type 'MediaStream'.`
);
}
this[PropertySymbol.srcObject] = srcObject;
}

/**
* Returns text track list.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,30 @@ describe('HTMLMediaElement', () => {
});
});

describe('set srcObject()', () => {
it('Sets a MediaStream object', () => {
const srcObject = new window.MediaStream();
element.srcObject = srcObject;
expect(element.srcObject).toBe(srcObject);
});

it('Allows to be set to null', () => {
element.srcObject = new window.MediaStream();
element.srcObject = null;
expect(element.srcObject).toBeNull();
});

it('Throws an error if the value is not a MediaStream object', () => {
expect(() => {
element.srcObject = <MediaStream>{};
}).toThrowError(
new TypeError(
`Failed to set the 'srcObject' property on 'HTMLMediaElement': The provided value is not of type 'MediaStream'.`
)
);
});
});

describe('get textTracks()', () => {
it('Returns an empty TextTrackList object by default.', () => {
expect(element.textTracks.length).toBe(0);
Expand Down

0 comments on commit 32f7510

Please sign in to comment.