From 248c200a748d95cd6519465316f50dda3c4a0781 Mon Sep 17 00:00:00 2001 From: Calvin Montgomery Date: Mon, 22 Jun 2020 19:39:00 -0700 Subject: [PATCH] Implement twitch changes for #874 --- NEWS.md | 17 +++++++++++++++++ package.json | 2 +- player/twitch.coffee | 30 ++++++++++++++++++++++++++---- player/twitchclip.coffee | 11 ++++++++++- 4 files changed, 54 insertions(+), 6 deletions(-) diff --git a/NEWS.md b/NEWS.md index e15e0e90..86e64265 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,20 @@ +2020-06-22 +========== + +Twitch has [updated their embed +player](https://discuss.dev.twitch.tv/t/twitch-embedded-player-migration-timeline-update/25588), +which adds new requirements for embedding Twitch: + + 1. The origin website must be served over HTTPS + 2. The origin website must be served over the default port (i.e., the hostname + cannot include a port; https://example.com:8443 won't work) + +Additionally, third-party cookies must be enabled for whatever internal +subdomains Twitch is using. + +CyTube now sets the parameters expected by Twitch, and displays an error message +if it detects (1) or (2) above are not met. + 2020-02-15 ========== diff --git a/package.json b/package.json index 42ccece8..4bb5337c 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Calvin Montgomery", "name": "CyTube", "description": "Online media synchronizer and chat", - "version": "3.70.4", + "version": "3.70.5", "repository": { "url": "http://github.com/calzoneman/sync" }, diff --git a/player/twitch.coffee b/player/twitch.coffee index e95ef2af..4348036f 100644 --- a/player/twitch.coffee +++ b/player/twitch.coffee @@ -1,3 +1,10 @@ +window.TWITCH_PARAMS_ERROR = 'The Twitch embed player now uses parameters which only +work if the following requirements are met: (1) The embedding website uses +HTTPS; (2) The embedding website uses the default port (443) and is accessed +via https://example.com instead of https://example.com:port. I have no +control over this -- see this Twitch post +for details' + window.TwitchPlayer = class TwitchPlayer extends Player constructor: (data) -> if not (this instanceof TwitchPlayer) @@ -12,14 +19,29 @@ window.TwitchPlayer = class TwitchPlayer extends Player init: (data) -> removeOld() + + if location.hostname != location.host or location.protocol != 'https:' + alert = makeAlert( + 'Twitch API Parameters', + window.TWITCH_PARAMS_ERROR, + 'alert-danger' + ).removeClass('col-md-12') + removeOld(alert) + @twitch = null + return + + options = + parent: [location.hostname] + width: $('#ytapiplayer').width() + height: $('#ytapiplayer').height() + if data.type is 'tv' # VOD - options = - video: data.id + options.video = data.id else # Livestream - options = - channel: data.id + options.channel = data.id + @twitch = new Twitch.Player('ytapiplayer', options) @twitch.addEventListener(Twitch.Player.READY, => @setVolume(VOLUME) diff --git a/player/twitchclip.coffee b/player/twitchclip.coffee index d87c2a3d..8a4beef0 100644 --- a/player/twitchclip.coffee +++ b/player/twitchclip.coffee @@ -6,7 +6,16 @@ window.TwitchClipPlayer = class TwitchClipPlayer extends EmbedPlayer @load(data) load: (data) -> + if location.hostname != location.host or location.protocol != 'https:' + alert = makeAlert( + 'Twitch API Parameters', + window.TWITCH_PARAMS_ERROR, + 'alert-danger' + ).removeClass('col-md-12') + removeOld(alert) + return + data.meta.embed = tag: 'iframe' - src: "https://clips.twitch.tv/embed?clip=#{data.id}" + src: "https://clips.twitch.tv/embed?clip=#{data.id}&parent=#{location.host}" super(data)