1 window.TWITCH_PARAMS_ERROR = 'The Twitch embed player now uses parameters which only
2 work if the following requirements are met: (1) The embedding website uses
3 HTTPS; (2) The embedding website uses the default port (443) and is accessed
4 via https://example.com instead of https://example.com:port. I have no
5 control over this -- see <a href="https://discuss.dev.twitch.tv/t/twitch-embedded-player-migration-timeline-update/25588" rel="noopener noreferrer" target="_blank">this Twitch post</a>
8 window.TwitchPlayer = class TwitchPlayer extends Player
10 if not (this instanceof TwitchPlayer)
11 return new TwitchPlayer(data)
13 @setMediaProperties(data)
14 waitUntilDefined(window, 'Twitch', =>
15 waitUntilDefined(Twitch, 'Player', =>
23 if location.hostname != location.host or location.protocol != 'https:'
25 'Twitch API Parameters',
26 window.TWITCH_PARAMS_ERROR,
28 ).removeClass('col-md-12')
34 parent: [location.hostname]
35 width: $('#ytapiplayer').width()
36 height: $('#ytapiplayer').height()
40 options.video = data.id
43 options.channel = data.id
45 @twitch = new Twitch.Player('ytapiplayer', options)
46 @twitch.addEventListener(Twitch.Player.READY, =>
48 @twitch.setQuality(@mapQuality(USEROPTS.default_quality))
49 @twitch.addEventListener(Twitch.Player.PLAY, =>
54 @twitch.addEventListener(Twitch.Player.PAUSE, =>
59 @twitch.addEventListener(Twitch.Player.ENDED, =>
61 socket.emit('playNext')
66 @setMediaProperties(data)
70 @twitch.setVideo(data.id)
73 @twitch.setChannel(data.id)
99 cb(@twitch.getCurrentTime())
103 setVolume: (volume) ->
105 @twitch.setVolume(volume)
107 @twitch.setMuted(false)
113 if @twitch.isPaused()
116 cb(@twitch.getVolume())
120 mapQuality: (quality) ->
121 switch String(quality)
122 when '1080' then 'chunked'
123 when '720' then 'high'
124 when '480' then 'medium'
125 when '360' then 'low'
126 when '240' then 'mobile'
127 when 'best' then 'chunked'