Polyv Help Center

Help Center

Page Events

Updated: 2023-09-19 11:51:07

Purpose

When embedding the live streaming backend into another page via iframe, you can listen for new page opening events, allowing the parent page to control them.

Currently, events are only received when opening the live streaming monitoring page.

Details

Setup Steps

  1. When embedding the live streaming backend via iframe, you need to include ?isBrowser=false, for example:
https://console.polyv.net/live/index.html?isBrowser=false#/channel

Note: ?isBrowser=false must be placed before the hash value in the URL.

  1. In the live streaming backend, set the parent page domain that uses the iframe to embed the backend as a secure domain. Only after configuring the secure domain will the corresponding event be received when opening the live streaming monitoring page.
  2. Listen for events on the parent page:
window.addEventListener(
  "message",
  (event) => {
    // 通过 event.data 可以获取到事件数据,event.data 中包含两个属性:
    // 1. event.data.source 事件数据来源,值为 'polyv-live-admin' 时表示来自保利威直播后台
    // 2. event.data.url 需要打开新页面的 URL
    
    // 先判断数据来源是否符合预期
    if (event.data.source === 'polyv-live-admin') {
      // 打开页面(或进行其他处理)
      window.open(event.data.url);
    }
  },
  false,
);
联系客服,在线咨询