Skip to content

Instantly share code, notes, and snippets.

@jwcounts
Last active April 16, 2024 19:39
Show Gist options
  • Save jwcounts/6f70d0bb4015fbd06a64d7faa18823b1 to your computer and use it in GitHub Desktop.
Save jwcounts/6f70d0bb4015fbd06a64d7faa18823b1 to your computer and use it in GitHub Desktop.
PBS GA LivePlayer Parent Message
const inIframe = () => {
try {
return window.self !== window.top;
} catch (e) {
return true;
}
}
window.addEventListener('DOMContentLoaded', (event) => {
if ( inIframe() ) {
console.log( 'loading in iframe' );
let channelTitle = window.livePlayerContextBridge.feed_name;
let channelId = window.livePlayerContextBridge.feed_cid;
window.parent.postMessage({'message': 'iframeload', 'payload': {'channelTitle':channelTitle,'channelId':channelId}, 'sender': 'pbslls'},'*');
let channelSelect = document.querySelectorAll('select.multi-livestream-overlay__channel-select');
Array.from(channelSelect).forEach( (cs) => {
cs.addEventListener('change', function() {
let channelTitle = this.options[this.selectedIndex].text;
let channelId = this.value;
window.parent.postMessage({'message': 'channelChange','payload': {'channelTitle':channelTitle,'channelId':channelId}, 'sender': 'pbslls'},'*');
});
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment