pl-fe: remove rumble-specific autoplay handling

Signed-off-by: mkljczk <git@mkljczk.pl>
This commit is contained in:
mkljczk
2024-12-14 22:47:23 +01:00
parent 716a393ac6
commit 78792ccc89
2 changed files with 9 additions and 35 deletions

View File

@ -1,31 +1,15 @@
import { addAutoPlay } from './media';
describe('addAutoPlay()', () => {
describe('when the provider is Rumble', () => {
it('adds the correct query parameters to the src', () => {
const html = '<iframe src="https://rumble.com/embed/123456/" width="1920" height="1080" frameborder="0" title="Video upload for 1" allowfullscreen=""></iframe>';
expect(addAutoPlay(html)).toEqual('<iframe src="https://rumble.com/embed/123456/?pub=7a20&amp;autoplay=2" width="1920" height="1080" frameborder="0" title="Video upload for 1" allowfullscreen=""></iframe>');
});
describe('when the iframe src already has params', () => {
it('adds the correct query parameters to the src', () => {
const html = '<iframe src="https://rumble.com/embed/123456/?foo=bar" width="1920" height="1080" frameborder="0" title="Video upload for 1" allowfullscreen=""></iframe>';
expect(addAutoPlay(html)).toEqual('<iframe src="https://rumble.com/embed/123456/?foo=bar&amp;pub=7a20&amp;autoplay=2" width="1920" height="1080" frameborder="0" title="Video upload for 1" allowfullscreen=""></iframe>');
});
});
it('adds the correct query parameters to the src', () => {
const html = '<iframe src="https://youtube.com/embed/123456/" width="1920" height="1080" frameborder="0" title="Video upload for 1" allowfullscreen=""></iframe>';
expect(addAutoPlay(html)).toEqual('<iframe src="https://youtube.com/embed/123456/?autoplay=1&amp;auto_play=1" width="1920" height="1080" frameborder="0" title="Video upload for 1" allowfullscreen=""></iframe>');
});
describe('when the provider is not Rumble', () => {
describe('when the iframe src already has params', () => {
it('adds the correct query parameters to the src', () => {
const html = '<iframe src="https://youtube.com/embed/123456/" width="1920" height="1080" frameborder="0" title="Video upload for 1" allowfullscreen=""></iframe>';
expect(addAutoPlay(html)).toEqual('<iframe src="https://youtube.com/embed/123456/?autoplay=1&amp;auto_play=1" width="1920" height="1080" frameborder="0" title="Video upload for 1" allowfullscreen=""></iframe>');
});
describe('when the iframe src already has params', () => {
it('adds the correct query parameters to the src', () => {
const html = '<iframe src="https://youtube.com/embed/123456?foo=bar" width="1920" height="1080" frameborder="0" title="Video upload for 1" allowfullscreen=""></iframe>';
expect(addAutoPlay(html)).toEqual('<iframe src="https://youtube.com/embed/123456?foo=bar&amp;autoplay=1&amp;auto_play=1" width="1920" height="1080" frameborder="0" title="Video upload for 1" allowfullscreen=""></iframe>');
});
const html = '<iframe src="https://youtube.com/embed/123456?foo=bar" width="1920" height="1080" frameborder="0" title="Video upload for 1" allowfullscreen=""></iframe>';
expect(addAutoPlay(html)).toEqual('<iframe src="https://youtube.com/embed/123456?foo=bar&amp;autoplay=1&amp;auto_play=1" width="1920" height="1080" frameborder="0" title="Video upload for 1" allowfullscreen=""></iframe>');
});
});
});

View File

@ -53,10 +53,6 @@ const getVideoDuration = (file: File): Promise<number> => {
const domParser = new DOMParser();
enum VideoProviders {
RUMBLE = 'rumble.com'
}
/** Try adding autoplay to an iframe embed for platforms such as YouTube. */
const addAutoPlay = (html: string): string => {
try {
@ -65,16 +61,10 @@ const addAutoPlay = (html: string): string => {
if (iframe) {
const url = new URL(iframe.src);
const provider = new URL(iframe.src).host;
if (provider === VideoProviders.RUMBLE) {
url.searchParams.append('pub', '7a20');
url.searchParams.append('autoplay', '2');
} else {
url.searchParams.append('autoplay', '1');
url.searchParams.append('auto_play', '1');
iframe.allow = 'autoplay';
}
url.searchParams.append('autoplay', '1');
url.searchParams.append('auto_play', '1');
iframe.allow = 'autoplay';
iframe.src = url.toString();