Skip to content

Commit

Permalink
Merge pull request #41 from EkoLabs/overriding-host-param
Browse files Browse the repository at this point in the history
Added the ability to override the URL's host via options.
  • Loading branch information
ShlomiAmichay authored Mar 22, 2022
2 parents a5dbf54 + 73d93eb commit 3922cc8
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/lib/ekoEmbed/EkoEmbedDeliveryBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ class EkoEmbedDeliveryBase {
};
}

getDeliveryUrl(embedParams, options) {
const host = options.host ? `${options.host}` : `${options.env || ''}embed.eko.com`;
return `https://${host}${this.embedpath}?${stringifyQueryParams(embedParams)}`;
}

load(id, options) {
let embedParams = {
Expand Down Expand Up @@ -53,7 +57,7 @@ class EkoEmbedDeliveryBase {
// Finally, let's set the iframe's src to begin loading the project
this.iframe.setAttribute(
'src',
`https://${options.env || ''}embed.eko.com${this.embedpath}?${stringifyQueryParams(embedParams)}`
this.getDeliveryUrl(embedParams, options)
);
}

Expand All @@ -70,6 +74,7 @@ class EkoEmbedDeliveryBase {

this.iframe.contentWindow.postMessage(action, '*');
}

on(eventName, callback) {
this.eventEmitter.on(eventName, callback);
}
Expand Down
45 changes: 45 additions & 0 deletions test/integration/ekoDelivery/EkoEmbedDeliveryBase.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/* eslint-disable no-undef */
/* eslint-disable new-cap */
/* eslint-disable no-magic-numbers */
const puppeteer = require('puppeteer');
const testingInstanceId = '42rvvp6tpn';

let browser;
beforeAll(async() => {
browser = await puppeteer.launch({
headless: true,
args: ['--disable-features=site-per-process']
});
}, 10000);

afterAll(async() => {
await browser.close();
}, 15000);

jest.setTimeout(999999);

describe('ekoPlayer.load()', () => {
it(`ekoPlayer.load(id, { host: 'directembed.eko.com' }))
check host override `, async() => {
const page = await browser.newPage();
await page.goto(`file://${__dirname}/../app.html`);

await page.evaluate((instanceId) => {
let ekoPlayer = new EkoPlayer('#ekoPlayerEl', '3.0');
ekoPlayer.load(instanceId, {
iframeAttributes: { id: 'testFrame' },
host: 'directembed.eko.com'
});
}, testingInstanceId);

// Check host
const host = await page.evaluate(() => {
const iframeSrc = document.querySelector('iframe').getAttribute('src');
const iframeURL = new URL(iframeSrc);
return iframeURL.host;
});

expect(host).toBeDefined();
expect(host).toEqual('directembed.eko.com');
});
});
2 changes: 1 addition & 1 deletion test/integration/ekoDelivery/v3.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/* eslint-disable new-cap */
/* eslint-disable no-magic-numbers */
const puppeteer = require('puppeteer');
const testingInstanceId = 'IlA4fs022o';
const testingInstanceId = '42rvvp6tpn';

let browser;
beforeAll(async() => {
Expand Down

0 comments on commit 3922cc8

Please sign in to comment.