MCPcopy
hub / github.com/ampproject/amphtml / onMessage

Function onMessage

ads/google/ima/ima-video.js:1375–1449  ·  view source on GitHub ↗

* Handles messages from the top window. * @param {!Object} global * @param {!Event} event

(global, event)

Source from the content-addressed store, hash-verified

1373 * @param {!Event} event
1374 */
1375function onMessage(global, event) {
1376 const eventData = getData(event);
1377 if (!eventData) {
1378 return;
1379 }
1380 const msg = isObject(eventData) ? eventData : tryParseJson(eventData);
1381 if (!msg) {
1382 return; // We only process valid JSON.
1383 }
1384 if (!msg['event'] || !msg['func']) {
1385 return;
1386 }
1387 switch (msg['func']) {
1388 case 'play':
1389 if (adsActive || playbackStarted) {
1390 playVideo();
1391 } else {
1392 // Auto-play support
1393 onOverlayButtonInteract(global);
1394 }
1395 break;
1396 case 'pause':
1397 pauseVideo();
1398 break;
1399 case 'mute':
1400 muteVideo();
1401 break;
1402 case 'unmute':
1403 unmuteVideo();
1404 break;
1405 case 'hideControls':
1406 if (!adsActive) {
1407 hideControls();
1408 }
1409 break;
1410 case 'showControls':
1411 if (!adsActive) {
1412 showControls();
1413 }
1414 break;
1415 case 'resize':
1416 const args = msg['args'];
1417 if (args && args.width && args.height) {
1418 if (adsActive && !fullscreen) {
1419 adsManager.resize(
1420 args.width,
1421 args.height,
1422 global.google.ima.ViewMode.NORMAL
1423 );
1424 } else {
1425 adsManagerWidthOnLoad = args.width;
1426 adsManagerHeightOnLoad = args.height;
1427 }
1428 }
1429 break;
1430 case 'onFirstScroll':
1431 case 'onAdRequestDelayTimeout':
1432 if (!adsRequested && imaLoadAllowed) {

Callers 1

attachFunction · 0.50

Calls 14

getDataFunction · 0.90
isObjectFunction · 0.90
tryParseJsonFunction · 0.90
playVideoFunction · 0.85
onOverlayButtonInteractFunction · 0.85
pauseVideoFunction · 0.85
muteVideoFunction · 0.85
unmuteVideoFunction · 0.85
hideControlsFunction · 0.85
showControlsFunction · 0.85
enterFullscreenFunction · 0.85
exitFullscreenFunction · 0.85

Tested by

no test coverage detected