diff --git a/src/lib/embed.js b/src/lib/embed.js index bd6beeb58..1d99bebd0 100755 --- a/src/lib/embed.js +++ b/src/lib/embed.js @@ -3,7 +3,7 @@ */ import Player from '../player'; -import { isVimeoUrl, isVimeoEmbed, getVimeoUrl } from './functions'; +import { isVimeoUrl, isVimeoEmbed, getVimeoUrl, getOembedDomain } from './functions'; import { parseMessageData } from './postmessage'; const oEmbedParameters = [ @@ -108,7 +108,8 @@ export function getOEmbedData(videoUrl, params = {}, element) { throw new TypeError(`“${videoUrl}” is not a vimeo.com url.`); } - let url = `https://vimeo.com/api/oembed.json?url=${encodeURIComponent(videoUrl)}`; + const domain = getOembedDomain(videoUrl); + let url = `https://${domain}/api/oembed.json?url=${encodeURIComponent(videoUrl)}`; for (const param in params) { if (params.hasOwnProperty(param)) { diff --git a/src/lib/functions.js b/src/lib/functions.js index 354315d31..b3eb08eda 100755 --- a/src/lib/functions.js +++ b/src/lib/functions.js @@ -58,7 +58,7 @@ export function isInteger(value) { * @return {boolean} */ export function isVimeoUrl(url) { - return (/^(https?:)?\/\/((player|www)\.)?vimeo\.com(?=$|\/)/).test(url); + return (/^(https?:)?\/\/((((player|www)\.)?vimeo\.com)|((player\.)?[a-zA-Z0-9-]+\.videoji\.hk))(?=$|\/)/).test(url); } /** @@ -68,10 +68,21 @@ export function isVimeoUrl(url) { * @return {boolean} */ export function isVimeoEmbed(url) { - const expr = /^https:\/\/player\.vimeo\.com\/video\/\d+/; + const expr = /^https:\/\/player\.((vimeo\.com)|([a-zA-Z0-9-]+\.videoji\.hk))\/video\/\d+/; return expr.test(url); } +export function getOembedDomain(url) { + const match = (url || '').match(/^(?:https?:)?(?:\/\/)?([^/?]+)/); + const domain = ((match && match[1]) || '').replace('player.', ''); + + if (domain.endsWith('.videoji.hk')) { + return domain; + } + + return 'vimeo.com'; +} + /** * Get the Vimeo URL from an element. * The element must have either a data-vimeo-id or data-vimeo-url attribute. diff --git a/test/functions-test.js b/test/functions-test.js index 2ee1b50b9..c25ccc748 100755 --- a/test/functions-test.js +++ b/test/functions-test.js @@ -1,6 +1,6 @@ import test from 'ava'; import html from './helpers/html'; -import { getMethodName, isDomElement, isInteger, isVimeoUrl, isVimeoEmbed, getVimeoUrl } from '../src/lib/functions'; +import { getMethodName, isDomElement, isInteger, isVimeoUrl, isVimeoEmbed, getVimeoUrl, getOembedDomain } from '../src/lib/functions'; test('getMethodName properly formats the method name', (t) => { t.true(getMethodName('color', 'get') === 'getColor'); @@ -40,6 +40,11 @@ test('isVimeoUrl identifies *.vimeo.com only', (t) => { t.true(isVimeoUrl('https://www.vimeo.com') === true); t.true(isVimeoUrl('//www.vimeo.com') === true); t.true(isVimeoUrl('http://player.vimeo.com') === true); + t.true(isVimeoUrl('http://player.subdomain.videoji.hk') === true); + t.true(isVimeoUrl('http://player.subdomain.videoji.hk/video/12345') === true); + t.true(isVimeoUrl('http://player.subdomain.videoji.hk/video/12345?h=a1b2c3d4') === true); + t.true(isVimeoUrl('http://subdomain.videoji.hk') === true); + t.true(isVimeoUrl('http://videoji.hk') === false); t.true(isVimeoUrl('//player.vimeo.com') === true); t.true(isVimeoUrl('https://player.vimeo.com') === true); t.true(isVimeoUrl('https://notvimeo.com') === false); @@ -56,9 +61,23 @@ test('isVimeoEmbed identifies Vimeo embeds only', (t) => { t.true(isVimeoEmbed('https://player.vimeo.com/video/76979871?h=8272103f6e') === true); t.true(isVimeoEmbed('https://player.vimeo.com/video/76979871') === true); t.true(isVimeoEmbed('http://player.vimeo.com/video/76979871?h=8272103f6e') === false); + t.true(isVimeoEmbed('http://player.subdomain.videoji.hk/video/76979871?h=8272103f6e') === false); + t.true(isVimeoEmbed('https://player.subdomain.videoji.hk/video/76979871?h=8272103f6e') === true); t.true(isVimeoEmbed('http2://not-vimeo.com/video/76979871') === false); }); +test('getOembedDomain correctly returns a domain from a url', (t) => { + t.true(getOembedDomain('https://player.vimeo.com/video/76979871?h=8272103f6e') === 'vimeo.com'); + t.true(getOembedDomain('https://player.vimeo.com/video/76979871') === 'vimeo.com'); + t.true(getOembedDomain('http://player.vimeo.com/video/76979871?h=8272103f6e') === 'vimeo.com'); + t.true(getOembedDomain('http://player.subdomain.videoji.hk/video/76979871?h=8272103f6e') === 'subdomain.videoji.hk'); + t.true(getOembedDomain('https://player.subdomain.videoji.hk/video/76979871?h=8272103f6e') === 'subdomain.videoji.hk'); + t.true(getOembedDomain('http2://not-vimeo.com/video/76979871') === 'vimeo.com'); + t.true(getOembedDomain(null) === 'vimeo.com'); + t.true(getOembedDomain(undefined) === 'vimeo.com'); + t.true(getOembedDomain('') === 'vimeo.com'); +}); + test('getVimeoUrl correctly returns a url from the embed parameters', (t) => { t.true(getVimeoUrl({ id: 445351154 }) === 'https://vimeo.com/445351154'); t.true(getVimeoUrl({ url: 'http://vimeo.com/445351154' }) === 'https://vimeo.com/445351154');