Skip to content

Commit e706e4c

Browse files
committed
fix tests. refactor findIFrame util
1 parent 84df165 commit e706e4c

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

src/lib/embed.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*/
44

55
import Player from '../player';
6-
import { isVimeoUrl, getVimeoUrl, getOembedDomain, isVimeoEmbed, getIFrameFromMessageEvent } from './functions';
6+
import { isVimeoUrl, getVimeoUrl, getOembedDomain, isVimeoEmbed, findIframeBySourceWindow } from './functions';
77
import { parseMessageData } from './postmessage';
88

99
const oEmbedParameters = [
@@ -224,7 +224,7 @@ export function resizeEmbeds(parent = document) {
224224
return;
225225
}
226226

227-
const senderIFrame = getIFrameFromMessageEvent(event, parent);
227+
const senderIFrame = event.source ? findIframeBySourceWindow(event.source, parent) : null;
228228

229229
if (senderIFrame) {
230230
// Change padding-bottom of the enclosing div to accommodate
@@ -260,7 +260,7 @@ export function initAppendVideoMetadata(parent = document) {
260260
return;
261261
}
262262

263-
const senderIFrame = getIFrameFromMessageEvent(event, parent);
263+
const senderIFrame = event.source ? findIframeBySourceWindow(event.source, parent) : null;
264264

265265
// Initiate appendVideoMetadata if iframe is a Vimeo embed
266266
if (senderIFrame && isVimeoEmbed(senderIFrame.src)) {
@@ -301,7 +301,7 @@ export function checkUrlTimeParam(parent = document) {
301301
return;
302302
}
303303

304-
const senderIFrame = getIFrameFromMessageEvent(event, parent);
304+
const senderIFrame = event.source ? findIframeBySourceWindow(event.source, parent) : null;
305305

306306
if (senderIFrame && isVimeoEmbed(senderIFrame.src)) {
307307
const player = new Player(senderIFrame);
@@ -350,7 +350,7 @@ export function updateDRMEmbeds() {
350350
return;
351351
}
352352

353-
const senderIFrame = getIFrameFromMessageEvent(event);
353+
const senderIFrame = event.source ? findIframeBySourceWindow(event.source) : null;
354354

355355
if (!senderIFrame) {
356356
return;

src/lib/functions.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export function getOembedDomain(url) {
8787
}
8888
}
8989

90-
return 'vimeo.dev';
90+
return 'vimeo.com';
9191
}
9292

9393
/**
@@ -153,22 +153,21 @@ export const logSurveyLink = () => {
153153
};
154154

155155
/**
156-
* Find the iframe element that contains the source window from a message event
156+
* Find the iframe element that contains a specific source window
157157
*
158-
* @param {MessageEvent} event The message event
158+
* @param {Window} sourceWindow The source window to find the iframe for
159159
* @param {Document} [doc=document] The document to search within
160160
* @return {HTMLIFrameElement|null} The iframe element if found, otherwise null
161161
*/
162-
export function getIFrameFromMessageEvent(event, doc = document) {
163-
if (!event || !event.source) {
162+
export function findIframeBySourceWindow(sourceWindow, doc = document) {
163+
if (!sourceWindow || !doc || typeof doc.querySelectorAll !== 'function') {
164164
return null;
165165
}
166166

167-
const sourceWindow = event.source;
168167
const iframes = doc.querySelectorAll('iframe');
169168

170169
for (let i = 0; i < iframes.length; i++) {
171-
if (iframes[i].contentWindow === sourceWindow) {
170+
if (iframes[i] && iframes[i].contentWindow === sourceWindow) {
172171
return iframes[i];
173172
}
174173
}

0 commit comments

Comments
 (0)