pl-fe: remove rumble-specific autoplay handling
Signed-off-by: mkljczk <git@mkljczk.pl>
This commit is contained in:
@ -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&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&pub=7a20&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&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&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&autoplay=1&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&autoplay=1&auto_play=1" width="1920" height="1080" frameborder="0" title="Video upload for 1" allowfullscreen=""></iframe>');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user