2015-07-01 16:38:01 +00:00
( function ( ) {
2017-05-20 23:50:00 +00:00
var CUSTOM _EMBED _WARNING , CustomEmbedPlayer , DEFAULT _ERROR , DailymotionPlayer , EmbedPlayer , FilePlayer , GoogleDrivePlayer , GoogleDriveYouTubePlayer , HLSPlayer , ImgurPlayer , LivestreamPlayer , Player , RTMPPlayer , SmashcastPlayer , SoundCloudPlayer , TYPE _MAP , TwitchPlayer , UstreamPlayer , VideoJSPlayer , VimeoPlayer , YouTubePlayer , codecToMimeType , genParam , sortSources ,
2015-07-01 16:38:01 +00:00
extend = function ( child , parent ) { for ( var key in parent ) { if ( hasProp . call ( parent , key ) ) child [ key ] = parent [ key ] ; } function ctor ( ) { this . constructor = child ; } ctor . prototype = parent . prototype ; child . prototype = new ctor ( ) ; child . _ _super _ _ = parent . prototype ; return child ; } ,
hasProp = { } . hasOwnProperty ;
window . Player = Player = ( function ( ) {
function Player ( data ) {
if ( ! ( this instanceof Player ) ) {
return new Player ( data ) ;
}
this . setMediaProperties ( data ) ;
this . paused = false ;
}
2013-08-06 15:42:20 +00:00
2015-07-01 16:38:01 +00:00
Player . prototype . load = function ( data ) {
return this . setMediaProperties ( data ) ;
2013-08-06 15:42:20 +00:00
} ;
2015-07-01 16:38:01 +00:00
Player . prototype . setMediaProperties = function ( data ) {
this . mediaId = data . id ;
this . mediaType = data . type ;
return this . mediaLength = data . seconds ;
2013-08-06 15:42:20 +00:00
} ;
2015-07-01 16:38:01 +00:00
Player . prototype . play = function ( ) {
return this . paused = false ;
2013-08-06 15:42:20 +00:00
} ;
2015-07-01 16:38:01 +00:00
Player . prototype . pause = function ( ) {
return this . paused = true ;
2013-08-06 15:42:20 +00:00
} ;
2015-07-01 16:38:01 +00:00
Player . prototype . seekTo = function ( time ) { } ;
2014-02-03 02:04:50 +00:00
2015-07-01 16:38:01 +00:00
Player . prototype . setVolume = function ( volume ) { } ;
2014-02-03 02:04:50 +00:00
2015-07-01 16:38:01 +00:00
Player . prototype . getTime = function ( cb ) {
return cb ( 0 ) ;
2014-02-03 02:04:50 +00:00
} ;
2015-07-01 16:38:01 +00:00
Player . prototype . isPaused = function ( cb ) {
return cb ( this . paused ) ;
2014-02-03 02:04:50 +00:00
} ;
2013-08-04 16:16:19 +00:00
2015-07-01 16:38:01 +00:00
Player . prototype . getVolume = function ( cb ) {
return cb ( VOLUME ) ;
} ;
2013-08-04 16:16:19 +00:00
2016-03-03 03:31:29 +00:00
Player . prototype . destroy = function ( ) { } ;
2015-07-01 16:38:01 +00:00
return Player ;
2013-08-04 16:16:19 +00:00
2015-07-01 16:38:01 +00:00
} ) ( ) ;
2013-08-04 16:16:19 +00:00
2015-07-01 16:38:01 +00:00
window . VimeoPlayer = VimeoPlayer = ( function ( superClass ) {
extend ( VimeoPlayer , superClass ) ;
2013-08-04 16:16:19 +00:00
2015-07-01 16:38:01 +00:00
function VimeoPlayer ( data ) {
if ( ! ( this instanceof VimeoPlayer ) ) {
return new VimeoPlayer ( data ) ;
}
this . load ( data ) ;
}
2014-02-03 02:04:50 +00:00
2015-07-01 16:38:01 +00:00
VimeoPlayer . prototype . load = function ( data ) {
this . setMediaProperties ( data ) ;
return waitUntilDefined ( window , '$f' , ( function ( _this ) {
return function ( ) {
var video ;
video = $ ( '<iframe/>' ) ;
removeOld ( video ) ;
video . attr ( {
src : "https://player.vimeo.com/video/" + data . id + "?api=1&player_id=ytapiplayer" ,
webkitallowfullscreen : true ,
mozallowfullscreen : true ,
allowfullscreen : true
} ) ;
if ( USEROPTS . wmode _transparent ) {
video . attr ( 'wmode' , 'transparent' ) ;
}
return $f ( video [ 0 ] ) . addEvent ( 'ready' , function ( ) {
_this . vimeo = $f ( video [ 0 ] ) ;
_this . play ( ) ;
_this . vimeo . addEvent ( 'finish' , function ( ) {
if ( CLIENT . leader ) {
return socket . emit ( 'playNext' ) ;
}
2013-08-05 04:19:10 +00:00
} ) ;
2015-07-01 16:38:01 +00:00
_this . vimeo . addEvent ( 'pause' , function ( ) {
_this . paused = true ;
if ( CLIENT . leader ) {
return sendVideoUpdate ( ) ;
}
} ) ;
_this . vimeo . addEvent ( 'play' , function ( ) {
_this . paused = false ;
if ( CLIENT . leader ) {
return sendVideoUpdate ( ) ;
}
} ) ;
return _this . setVolume ( VOLUME ) ;
} ) ;
} ;
} ) ( this ) ) ;
2013-08-05 04:19:10 +00:00
} ;
2013-06-11 15:29:21 +00:00
2015-07-01 16:38:01 +00:00
VimeoPlayer . prototype . play = function ( ) {
this . paused = false ;
if ( this . vimeo ) {
return this . vimeo . api ( 'play' ) ;
}
2013-08-05 04:19:10 +00:00
} ;
2013-06-11 15:29:21 +00:00
2015-07-01 16:38:01 +00:00
VimeoPlayer . prototype . pause = function ( ) {
this . paused = true ;
if ( this . vimeo ) {
return this . vimeo . api ( 'pause' ) ;
}
2013-08-05 04:19:10 +00:00
} ;
2013-06-11 15:29:21 +00:00
2015-07-01 16:38:01 +00:00
VimeoPlayer . prototype . seekTo = function ( time ) {
if ( this . vimeo ) {
return this . vimeo . api ( 'seekTo' , time ) ;
}
2013-08-05 04:19:10 +00:00
} ;
2013-07-12 20:34:55 +00:00
2015-07-01 16:38:01 +00:00
VimeoPlayer . prototype . setVolume = function ( volume ) {
if ( this . vimeo ) {
return this . vimeo . api ( 'setVolume' , volume ) ;
}
2013-08-05 04:19:10 +00:00
} ;
2014-02-03 02:04:50 +00:00
2015-07-01 16:38:01 +00:00
VimeoPlayer . prototype . getTime = function ( cb ) {
if ( this . vimeo ) {
return this . vimeo . api ( 'getCurrentTime' , function ( time ) {
return cb ( parseFloat ( time ) ) ;
} ) ;
} else {
return cb ( 0 ) ;
}
2014-02-03 02:04:50 +00:00
} ;
2015-07-01 16:38:01 +00:00
VimeoPlayer . prototype . getVolume = function ( cb ) {
if ( this . vimeo ) {
return this . vimeo . api ( 'getVolume' , cb ) ;
} else {
return cb ( VOLUME ) ;
}
2014-02-03 02:04:50 +00:00
} ;
2015-07-01 16:38:01 +00:00
return VimeoPlayer ;
2013-06-11 15:29:21 +00:00
2015-07-01 16:38:01 +00:00
} ) ( Player ) ;
2014-05-16 05:36:33 +00:00
2015-07-01 16:38:01 +00:00
window . YouTubePlayer = YouTubePlayer = ( function ( superClass ) {
extend ( YouTubePlayer , superClass ) ;
2014-05-16 05:36:33 +00:00
2015-07-01 16:38:01 +00:00
function YouTubePlayer ( data ) {
if ( ! ( this instanceof YouTubePlayer ) ) {
return new YouTubePlayer ( data ) ;
}
this . setMediaProperties ( data ) ;
this . qualityRaceCondition = true ;
this . pauseSeekRaceCondition = false ;
waitUntilDefined ( window , 'YT' , ( function ( _this ) {
return function ( ) {
return waitUntilDefined ( YT , 'Player' , function ( ) {
var wmode ;
removeOld ( ) ;
wmode = USEROPTS . wmode _transparent ? 'transparent' : 'opaque' ;
return _this . yt = new YT . Player ( 'ytapiplayer' , {
videoId : data . id ,
playerVars : {
autohide : 1 ,
autoplay : 1 ,
controls : 1 ,
iv _load _policy : 3 ,
rel : 0 ,
wmode : wmode
} ,
events : {
onReady : _this . onReady . bind ( _this ) ,
onStateChange : _this . onStateChange . bind ( _this )
}
2013-07-28 14:49:12 +00:00
} ) ;
2015-07-01 16:38:01 +00:00
} ) ;
} ;
} ) ( this ) ) ;
}
2013-07-28 14:49:12 +00:00
2015-07-01 16:38:01 +00:00
YouTubePlayer . prototype . load = function ( data ) {
this . setMediaProperties ( data ) ;
if ( this . yt && this . yt . ready ) {
this . yt . loadVideoById ( data . id , data . currentTime ) ;
this . qualityRaceCondition = true ;
if ( USEROPTS . default _quality ) {
return this . setQuality ( USEROPTS . default _quality ) ;
}
} else {
return console . error ( 'WTF? YouTubePlayer::load() called but yt is not ready' ) ;
}
} ;
2013-07-28 14:49:12 +00:00
2015-07-01 16:38:01 +00:00
YouTubePlayer . prototype . onReady = function ( ) {
this . yt . ready = true ;
return this . setVolume ( VOLUME ) ;
} ;
2013-06-11 15:29:21 +00:00
2015-07-01 16:38:01 +00:00
YouTubePlayer . prototype . onStateChange = function ( ev ) {
if ( this . qualityRaceCondition ) {
this . qualityRaceCondition = false ;
if ( USEROPTS . default _quality ) {
this . setQuality ( USEROPTS . default _quality ) ;
}
}
if ( ev . data === YT . PlayerState . PLAYING && this . pauseSeekRaceCondition ) {
this . pause ( ) ;
this . pauseSeekRaceCondition = false ;
}
if ( ( ev . data === YT . PlayerState . PAUSED && ! this . paused ) || ( ev . data === YT . PlayerState . PLAYING && this . paused ) ) {
this . paused = ev . data === YT . PlayerState . PAUSED ;
if ( CLIENT . leader ) {
sendVideoUpdate ( ) ;
2014-02-03 02:04:50 +00:00
}
2015-07-01 16:38:01 +00:00
}
if ( ev . data === YT . PlayerState . ENDED && CLIENT . leader ) {
return socket . emit ( 'playNext' ) ;
}
2013-08-05 04:19:10 +00:00
} ;
2013-06-11 15:29:21 +00:00
2015-07-01 16:38:01 +00:00
YouTubePlayer . prototype . play = function ( ) {
this . paused = false ;
if ( this . yt && this . yt . ready ) {
return this . yt . playVideo ( ) ;
}
2013-08-05 04:19:10 +00:00
} ;
2013-06-11 15:29:21 +00:00
2015-07-01 16:38:01 +00:00
YouTubePlayer . prototype . pause = function ( ) {
this . paused = true ;
if ( this . yt && this . yt . ready ) {
return this . yt . pauseVideo ( ) ;
}
2013-08-05 04:19:10 +00:00
} ;
2013-06-11 15:29:21 +00:00
2015-07-01 16:38:01 +00:00
YouTubePlayer . prototype . seekTo = function ( time ) {
if ( this . yt && this . yt . ready ) {
return this . yt . seekTo ( time , true ) ;
}
2013-08-05 04:19:10 +00:00
} ;
2013-06-11 15:29:21 +00:00
2015-07-01 16:38:01 +00:00
YouTubePlayer . prototype . setVolume = function ( volume ) {
if ( this . yt && this . yt . ready ) {
if ( volume > 0 ) {
this . yt . unMute ( ) ;
}
return this . yt . setVolume ( volume * 100 ) ;
}
2013-08-05 04:19:10 +00:00
} ;
2014-02-03 02:04:50 +00:00
2015-07-01 16:38:01 +00:00
YouTubePlayer . prototype . setQuality = function ( quality ) {
var ytQuality ;
if ( ! this . yt || ! this . yt . ready ) {
return ;
}
ytQuality = ( function ( ) {
switch ( String ( quality ) ) {
case '240' :
return 'small' ;
case '360' :
return 'medium' ;
case '480' :
return 'large' ;
case '720' :
return 'hd720' ;
case '1080' :
return 'hd1080' ;
case 'best' :
return 'highres' ;
default :
return 'auto' ;
2014-02-03 02:04:50 +00:00
}
2015-07-01 16:38:01 +00:00
} ) ( ) ;
if ( ytQuality !== 'auto' ) {
return this . yt . setPlaybackQuality ( ytQuality ) ;
}
2014-02-03 02:04:50 +00:00
} ;
2015-07-01 16:38:01 +00:00
YouTubePlayer . prototype . getTime = function ( cb ) {
if ( this . yt && this . yt . ready ) {
return cb ( this . yt . getCurrentTime ( ) ) ;
} else {
return cb ( 0 ) ;
}
} ;
YouTubePlayer . prototype . getVolume = function ( cb ) {
if ( this . yt && this . yt . ready ) {
if ( this . yt . isMuted ( ) ) {
return cb ( 0 ) ;
} else {
return cb ( this . yt . getVolume ( ) / 100 ) ;
2014-02-03 02:04:50 +00:00
}
2015-07-01 16:38:01 +00:00
} else {
return cb ( VOLUME ) ;
}
2014-02-03 02:04:50 +00:00
} ;
2013-08-07 18:25:08 +00:00
2015-07-01 16:38:01 +00:00
return YouTubePlayer ;
2013-06-11 15:29:21 +00:00
2015-07-01 16:38:01 +00:00
} ) ( Player ) ;
2013-06-11 15:29:21 +00:00
2015-07-01 16:38:01 +00:00
window . DailymotionPlayer = DailymotionPlayer = ( function ( superClass ) {
extend ( DailymotionPlayer , superClass ) ;
2013-06-11 15:29:21 +00:00
2015-07-01 16:38:01 +00:00
function DailymotionPlayer ( data ) {
if ( ! ( this instanceof DailymotionPlayer ) ) {
return new DailymotionPlayer ( data ) ;
}
this . setMediaProperties ( data ) ;
this . initialVolumeSet = false ;
waitUntilDefined ( window , 'DM' , ( function ( _this ) {
return function ( ) {
var params , quality ;
removeOld ( ) ;
params = {
autoplay : 1 ,
wmode : USEROPTS . wmode _transparent ? 'transparent' : 'opaque' ,
logo : 0
} ;
quality = _this . mapQuality ( USEROPTS . default _quality ) ;
if ( quality !== 'auto' ) {
params . quality = quality ;
}
_this . dm = DM . player ( 'ytapiplayer' , {
video : data . id ,
width : parseInt ( VWIDTH , 10 ) ,
height : parseInt ( VHEIGHT , 10 ) ,
params : params
} ) ;
return _this . dm . addEventListener ( 'apiready' , function ( ) {
_this . dm . ready = true ;
_this . dm . addEventListener ( 'ended' , function ( ) {
if ( CLIENT . leader ) {
return socket . emit ( 'playNext' ) ;
}
2014-02-03 02:04:50 +00:00
} ) ;
2015-07-01 16:38:01 +00:00
_this . dm . addEventListener ( 'pause' , function ( ) {
_this . paused = true ;
if ( CLIENT . leader ) {
return sendVideoUpdate ( ) ;
}
2013-08-05 04:19:10 +00:00
} ) ;
2015-07-01 16:38:01 +00:00
return _this . dm . addEventListener ( 'playing' , function ( ) {
_this . paused = false ;
if ( CLIENT . leader ) {
sendVideoUpdate ( ) ;
}
if ( ! _this . initialVolumeSet ) {
_this . setVolume ( VOLUME ) ;
return _this . initialVolumeSet = true ;
}
} ) ;
} ) ;
} ;
} ) ( this ) ) ;
}
2013-06-11 15:29:21 +00:00
2015-07-01 16:38:01 +00:00
DailymotionPlayer . prototype . load = function ( data ) {
this . setMediaProperties ( data ) ;
if ( this . dm && this . dm . ready ) {
this . dm . load ( data . id ) ;
return this . dm . seek ( data . currentTime ) ;
} else {
return console . error ( 'WTF? DailymotionPlayer::load() called but dm is not ready' ) ;
}
2013-08-05 04:19:10 +00:00
} ;
2013-06-11 15:29:21 +00:00
2015-07-01 16:38:01 +00:00
DailymotionPlayer . prototype . pause = function ( ) {
if ( this . dm && this . dm . ready ) {
this . paused = true ;
return this . dm . pause ( ) ;
}
2013-08-05 04:19:10 +00:00
} ;
2013-06-11 15:29:21 +00:00
2015-07-01 16:38:01 +00:00
DailymotionPlayer . prototype . play = function ( ) {
if ( this . dm && this . dm . ready ) {
this . paused = false ;
return this . dm . play ( ) ;
}
2013-08-05 04:19:10 +00:00
} ;
2013-06-11 15:29:21 +00:00
2015-07-01 16:38:01 +00:00
DailymotionPlayer . prototype . seekTo = function ( time ) {
if ( this . dm && this . dm . ready ) {
return this . dm . seek ( time ) ;
}
2013-08-05 04:19:10 +00:00
} ;
2013-06-11 15:29:21 +00:00
2015-07-01 16:38:01 +00:00
DailymotionPlayer . prototype . setVolume = function ( volume ) {
if ( this . dm && this . dm . ready ) {
return this . dm . setVolume ( volume ) ;
}
2013-08-05 04:19:10 +00:00
} ;
2014-02-03 02:04:50 +00:00
2015-07-01 16:38:01 +00:00
DailymotionPlayer . prototype . getTime = function ( cb ) {
if ( this . dm && this . dm . ready ) {
return cb ( this . dm . currentTime ) ;
} else {
return cb ( 0 ) ;
}
2014-02-03 02:04:50 +00:00
} ;
2015-07-01 16:38:01 +00:00
DailymotionPlayer . prototype . getVolume = function ( cb ) {
var volume ;
if ( this . dm && this . dm . ready ) {
if ( this . dm . muted ) {
return cb ( 0 ) ;
} else {
volume = this . dm . volume ;
if ( volume > 1 ) {
volume /= 100 ;
}
return cb ( volume ) ;
}
} else {
return cb ( VOLUME ) ;
}
2013-08-06 02:46:56 +00:00
} ;
2013-06-11 15:29:21 +00:00
2015-07-01 16:38:01 +00:00
DailymotionPlayer . prototype . mapQuality = function ( quality ) {
switch ( String ( quality ) ) {
case '240' :
case '480' :
case '720' :
case '1080' :
return String ( quality ) ;
case '360' :
return '380' ;
case 'best' :
return '1080' ;
default :
return 'auto' ;
}
2013-08-06 02:46:56 +00:00
} ;
2013-06-11 15:29:21 +00:00
2015-07-01 16:38:01 +00:00
return DailymotionPlayer ;
2013-06-11 15:29:21 +00:00
2015-07-01 16:38:01 +00:00
} ) ( Player ) ;
2013-06-11 15:29:21 +00:00
2015-07-01 16:38:01 +00:00
sortSources = function ( sources ) {
2015-07-26 19:28:43 +00:00
var flv , flvOrder , idx , j , len , nonflv , pref , qualities , quality , qualityOrder , sourceOrder ;
2015-07-01 16:38:01 +00:00
if ( ! sources ) {
console . error ( 'sortSources() called with null source list' ) ;
return [ ] ;
}
2017-07-11 04:38:27 +00:00
qualities = [ '2160' , '1440' , '1080' , '720' , '540' , '480' , '360' , '240' ] ;
2015-07-01 16:38:01 +00:00
pref = String ( USEROPTS . default _quality ) ;
2015-10-01 01:26:23 +00:00
if ( USEROPTS . default _quality === 'best' ) {
2017-07-11 04:38:27 +00:00
pref = '2160' ;
2015-10-01 01:26:23 +00:00
}
2015-07-01 16:38:01 +00:00
idx = qualities . indexOf ( pref ) ;
if ( idx < 0 ) {
2015-08-04 02:02:56 +00:00
idx = 2 ;
2015-07-01 16:38:01 +00:00
}
2015-08-04 02:02:56 +00:00
qualityOrder = qualities . slice ( idx ) . concat ( qualities . slice ( 0 , idx ) . reverse ( ) ) ;
2015-07-01 16:38:01 +00:00
sourceOrder = [ ] ;
flvOrder = [ ] ;
2015-07-26 19:28:43 +00:00
for ( j = 0 , len = qualityOrder . length ; j < len ; j ++ ) {
quality = qualityOrder [ j ] ;
2015-07-01 16:38:01 +00:00
if ( quality in sources ) {
flv = [ ] ;
nonflv = [ ] ;
sources [ quality ] . forEach ( function ( source ) {
source . quality = quality ;
2015-07-03 18:24:21 +00:00
if ( source . contentType === 'video/flv' ) {
2015-07-01 16:38:01 +00:00
return flv . push ( source ) ;
} else {
return nonflv . push ( source ) ;
}
} ) ;
sourceOrder = sourceOrder . concat ( nonflv ) ;
flvOrder = flvOrder . concat ( flv ) ;
}
}
return sourceOrder . concat ( flvOrder ) . map ( function ( source ) {
return {
2015-07-03 18:24:21 +00:00
type : source . contentType ,
2015-07-01 16:38:01 +00:00
src : source . link ,
quality : source . quality
} ;
2014-02-24 05:27:07 +00:00
} ) ;
2015-07-01 16:38:01 +00:00
} ;
2013-08-06 02:46:56 +00:00
2015-07-01 16:38:01 +00:00
waitUntilDefined ( window , 'videojs' , ( function ( _this ) {
return function ( ) {
return videojs . options . flash . swf = '/video-js.swf' ;
2013-08-06 02:46:56 +00:00
} ;
2015-07-01 16:38:01 +00:00
} ) ( this ) ) ;
window . VideoJSPlayer = VideoJSPlayer = ( function ( superClass ) {
extend ( VideoJSPlayer , superClass ) ;
function VideoJSPlayer ( data ) {
if ( ! ( this instanceof VideoJSPlayer ) ) {
return new VideoJSPlayer ( data ) ;
}
2016-08-20 17:59:20 +00:00
this . load ( data ) ;
2015-07-03 18:24:21 +00:00
}
VideoJSPlayer . prototype . loadPlayer = function ( data ) {
return waitUntilDefined ( window , 'videojs' , ( function ( _this ) {
2015-07-01 16:38:01 +00:00
return function ( ) {
2016-08-12 04:07:06 +00:00
var video ;
2015-07-01 16:38:01 +00:00
video = $ ( '<video/>' ) . addClass ( 'video-js vjs-default-skin embed-responsive-item' ) . attr ( {
width : '100%' ,
height : '100%'
} ) ;
removeOld ( video ) ;
2016-08-12 04:07:06 +00:00
_this . sources = sortSources ( data . meta . direct ) ;
if ( _this . sources . length === 0 ) {
2015-07-01 16:38:01 +00:00
console . error ( 'VideoJSPlayer::constructor(): data.meta.direct has no sources!' ) ;
_this . mediaType = null ;
return ;
}
2016-08-12 04:07:06 +00:00
_this . sourceIdx = 0 ;
_this . sources . forEach ( function ( source ) {
2015-07-01 16:38:01 +00:00
return $ ( '<source/>' ) . attr ( {
src : source . src ,
type : source . type ,
2017-07-01 23:50:30 +00:00
res : source . quality ,
label : source . quality + "p " + ( source . type . split ( '/' ) [ 1 ] )
2015-07-01 16:38:01 +00:00
} ) . appendTo ( video ) ;
} ) ;
2015-07-25 08:19:32 +00:00
if ( data . meta . gdrive _subtitles ) {
data . meta . gdrive _subtitles . available . forEach ( function ( subt ) {
2015-07-26 19:28:43 +00:00
var label ;
label = subt . lang _original ;
if ( subt . name ) {
label += " (" + subt . name + ")" ;
}
2015-07-25 08:19:32 +00:00
return $ ( '<track/>' ) . attr ( {
src : "/gdvtt/" + data . id + "/" + subt . lang + "/" + subt . name + ".vtt?vid=" + data . meta . gdrive _subtitles . vid ,
kind : 'subtitles' ,
srclang : subt . lang ,
2015-07-26 19:28:43 +00:00
label : label
2015-07-25 08:19:32 +00:00
} ) . appendTo ( video ) ;
} ) ;
}
2017-08-09 03:35:17 +00:00
if ( data . meta . textTracks ) {
data . meta . textTracks . forEach ( function ( track ) {
var label ;
label = track . name ;
return $ ( '<track/>' ) . attr ( {
src : track . url ,
kind : 'subtitles' ,
type : track . type ,
label : label
} ) . appendTo ( video ) ;
} ) ;
}
2015-07-01 16:38:01 +00:00
_this . player = videojs ( video [ 0 ] , {
autoplay : true ,
2017-07-01 23:50:30 +00:00
controls : true ,
plugins : {
videoJsResolutionSwitcher : {
"default" : _this . sources [ 0 ] . quality
}
}
2015-07-01 16:38:01 +00:00
} ) ;
return _this . player . ready ( function ( ) {
2016-08-12 04:07:06 +00:00
_this . player . on ( 'error' , function ( ) {
var err ;
err = _this . player . error ( ) ;
if ( err && err . code === 4 ) {
console . error ( 'Caught error, trying next source' ) ;
_this . sourceIdx ++ ;
if ( _this . sourceIdx < _this . sources . length ) {
return _this . player . src ( _this . sources [ _this . sourceIdx ] ) ;
} else {
2016-08-24 04:50:18 +00:00
console . error ( 'Out of sources, video will not play' ) ;
if ( _this . mediaType === 'gd' && ! window . hasDriveUserscript ) {
return window . promptToInstallDriveUserscript ( ) ;
}
2016-08-12 04:07:06 +00:00
}
}
} ) ;
2015-07-05 20:50:34 +00:00
_this . setVolume ( VOLUME ) ;
2015-07-01 16:38:01 +00:00
_this . player . on ( 'ended' , function ( ) {
if ( CLIENT . leader ) {
return socket . emit ( 'playNext' ) ;
}
} ) ;
_this . player . on ( 'pause' , function ( ) {
_this . paused = true ;
if ( CLIENT . leader ) {
return sendVideoUpdate ( ) ;
}
} ) ;
2015-07-02 06:59:21 +00:00
_this . player . on ( 'play' , function ( ) {
2015-07-01 16:38:01 +00:00
_this . paused = false ;
if ( CLIENT . leader ) {
return sendVideoUpdate ( ) ;
}
} ) ;
2015-07-26 19:28:43 +00:00
_this . player . on ( 'seeked' , function ( ) {
2015-07-02 06:59:21 +00:00
return $ ( '.vjs-waiting' ) . removeClass ( 'vjs-waiting' ) ;
} ) ;
2015-07-26 20:29:06 +00:00
return setTimeout ( function ( ) {
return $ ( '#ytapiplayer .vjs-subtitles-button .vjs-menu-item' ) . each ( function ( i , elem ) {
2016-08-12 03:04:51 +00:00
var textNode ;
textNode = elem . childNodes [ 0 ] ;
if ( textNode . textContent === localStorage . lastSubtitle ) {
2015-07-26 20:29:06 +00:00
elem . click ( ) ;
2015-07-26 19:28:43 +00:00
}
2015-07-26 20:29:06 +00:00
return elem . onclick = function ( ) {
2016-08-12 03:04:51 +00:00
if ( elem . attributes [ 'aria-checked' ] . value === 'true' ) {
return localStorage . lastSubtitle = textNode . textContent ;
2015-07-26 20:29:06 +00:00
}
} ;
} ) ;
} , 1 ) ;
2015-07-01 16:38:01 +00:00
} ) ;
2013-06-11 15:29:21 +00:00
} ;
2015-07-01 16:38:01 +00:00
} ) ( this ) ) ;
2015-07-03 18:24:21 +00:00
} ;
2015-07-01 16:38:01 +00:00
VideoJSPlayer . prototype . load = function ( data ) {
this . setMediaProperties ( data ) ;
2016-03-03 03:31:29 +00:00
this . destroy ( ) ;
2015-07-03 18:24:21 +00:00
return this . loadPlayer ( data ) ;
2013-08-06 02:46:56 +00:00
} ;
2013-06-11 15:29:21 +00:00
2015-07-01 16:38:01 +00:00
VideoJSPlayer . prototype . play = function ( ) {
this . paused = false ;
if ( this . player && this . player . readyState ( ) > 0 ) {
return this . player . play ( ) ;
}
2013-08-06 02:46:56 +00:00
} ;
2013-06-11 15:29:21 +00:00
2015-07-01 16:38:01 +00:00
VideoJSPlayer . prototype . pause = function ( ) {
this . paused = true ;
if ( this . player && this . player . readyState ( ) > 0 ) {
return this . player . pause ( ) ;
}
} ;
2013-06-11 15:29:21 +00:00
2015-07-01 16:38:01 +00:00
VideoJSPlayer . prototype . seekTo = function ( time ) {
if ( this . player && this . player . readyState ( ) > 0 ) {
return this . player . currentTime ( time ) ;
}
} ;
2013-07-12 20:34:55 +00:00
2015-07-01 16:38:01 +00:00
VideoJSPlayer . prototype . setVolume = function ( volume ) {
2015-07-05 20:50:34 +00:00
if ( this . player ) {
2015-07-01 16:38:01 +00:00
return this . player . volume ( volume ) ;
}
} ;
2013-06-11 15:29:21 +00:00
2015-07-01 16:38:01 +00:00
VideoJSPlayer . prototype . getTime = function ( cb ) {
if ( this . player && this . player . readyState ( ) > 0 ) {
return cb ( this . player . currentTime ( ) ) ;
} else {
return cb ( 0 ) ;
}
} ;
2014-02-03 02:04:50 +00:00
2015-07-01 16:38:01 +00:00
VideoJSPlayer . prototype . getVolume = function ( cb ) {
if ( this . player && this . player . readyState ( ) > 0 ) {
if ( this . player . muted ( ) ) {
return cb ( 0 ) ;
} else {
return cb ( this . player . volume ( ) ) ;
}
} else {
return cb ( VOLUME ) ;
}
2014-02-03 02:04:50 +00:00
} ;
2016-03-03 03:31:29 +00:00
VideoJSPlayer . prototype . destroy = function ( ) {
removeOld ( ) ;
if ( this . player ) {
return this . player . dispose ( ) ;
}
} ;
2015-07-01 16:38:01 +00:00
return VideoJSPlayer ;
2014-02-03 02:04:50 +00:00
2015-07-01 16:38:01 +00:00
} ) ( Player ) ;
2013-06-11 15:29:21 +00:00
2016-08-16 04:00:56 +00:00
window . GoogleDrivePlayer = GoogleDrivePlayer = ( function ( superClass ) {
extend ( GoogleDrivePlayer , superClass ) ;
function GoogleDrivePlayer ( data ) {
if ( ! ( this instanceof GoogleDrivePlayer ) ) {
return new GoogleDrivePlayer ( data ) ;
}
GoogleDrivePlayer . _ _super _ _ . constructor . call ( this , data ) ;
}
2016-08-20 17:59:20 +00:00
GoogleDrivePlayer . prototype . load = function ( data ) {
2017-03-04 07:39:38 +00:00
if ( ! window . hasDriveUserscript ) {
2016-10-08 17:33:18 +00:00
window . promptToInstallDriveUserscript ( ) ;
} else if ( window . hasDriveUserscript ) {
window . maybePromptToUpgradeUserscript ( ) ;
}
2016-08-20 17:59:20 +00:00
if ( typeof window . getGoogleDriveMetadata === 'function' ) {
2016-10-08 17:33:18 +00:00
return setTimeout ( ( function ( _this ) {
return function ( ) {
return backoffRetry ( function ( cb ) {
return window . getGoogleDriveMetadata ( data . id , cb ) ;
} , function ( error , metadata ) {
var alertBox ;
if ( error ) {
console . error ( error ) ;
alertBox = window . document . createElement ( 'div' ) ;
alertBox . className = 'alert alert-danger' ;
alertBox . textContent = error ;
return document . getElementById ( 'ytapiplayer' ) . appendChild ( alertBox ) ;
} else {
data . meta . direct = metadata . videoMap ;
return GoogleDrivePlayer . _ _super _ _ . load . call ( _this , data ) ;
}
} , {
maxTries : 3 ,
delay : 1000 ,
factor : 1.2 ,
jitter : 500
} ) ;
2016-08-20 17:59:20 +00:00
} ;
2016-10-08 17:33:18 +00:00
} ) ( this ) , Math . random ( ) * 1000 ) ;
2016-08-20 17:59:20 +00:00
}
} ;
2016-08-16 04:00:56 +00:00
return GoogleDrivePlayer ;
} ) ( VideoJSPlayer ) ;
2015-07-03 18:24:21 +00:00
codecToMimeType = function ( codec ) {
switch ( codec ) {
case 'mov/h264' :
return 'video/mp4' ;
case 'flv/h264' :
return 'video/flv' ;
case 'matroska/vp8' :
case 'matroska/vp9' :
return 'video/webm' ;
case 'ogg/theora' :
return 'video/ogg' ;
case 'mp3' :
return 'audio/mp3' ;
case 'vorbis' :
2016-02-10 03:44:07 +00:00
return 'audio/ogg' ;
2016-12-18 03:53:17 +00:00
case 'aac' :
return 'audio/aac' ;
2015-07-03 18:24:21 +00:00
default :
return 'video/flv' ;
2015-07-01 16:38:01 +00:00
}
} ;
window . FilePlayer = FilePlayer = ( function ( superClass ) {
extend ( FilePlayer , superClass ) ;
function FilePlayer ( data ) {
if ( ! ( this instanceof FilePlayer ) ) {
return new FilePlayer ( data ) ;
}
data . meta . direct = {
480 : [
{
2015-07-03 18:24:21 +00:00
contentType : codecToMimeType ( data . meta . codec ) ,
2015-07-01 16:38:01 +00:00
link : data . id
}
]
} ;
FilePlayer . _ _super _ _ . constructor . call ( this , data ) ;
2014-02-03 02:04:50 +00:00
}
2014-11-14 02:24:05 +00:00
2015-07-01 16:38:01 +00:00
FilePlayer . prototype . load = function ( data ) {
data . meta . direct = {
480 : [
{
2015-07-03 18:24:21 +00:00
contentType : codecToMimeType ( data . meta . codec ) ,
2015-07-01 16:38:01 +00:00
link : data . id
}
]
} ;
return FilePlayer . _ _super _ _ . load . call ( this , data ) ;
2013-08-06 02:55:11 +00:00
} ;
2013-06-11 15:29:21 +00:00
2015-07-01 16:38:01 +00:00
return FilePlayer ;
} ) ( VideoJSPlayer ) ;
window . SoundCloudPlayer = SoundCloudPlayer = ( function ( superClass ) {
extend ( SoundCloudPlayer , superClass ) ;
function SoundCloudPlayer ( data ) {
if ( ! ( this instanceof SoundCloudPlayer ) ) {
return new SoundCloudPlayer ( data ) ;
}
this . setMediaProperties ( data ) ;
waitUntilDefined ( window , 'SC' , ( function ( _this ) {
return function ( ) {
2016-03-24 05:45:54 +00:00
var sliderHolder , soundUrl , volumeSlider , widget ;
2015-07-01 16:38:01 +00:00
removeOld ( ) ;
if ( data . meta . scuri ) {
soundUrl = data . meta . scuri ;
} else {
soundUrl = data . id ;
}
widget = $ ( '<iframe/>' ) . appendTo ( $ ( '#ytapiplayer' ) ) ;
widget . attr ( {
id : 'scplayer' ,
src : "https://w.soundcloud.com/player/?url=" + soundUrl
} ) ;
2016-03-24 05:45:54 +00:00
sliderHolder = $ ( '<div/>' ) . attr ( 'id' , 'soundcloud-volume-holder' ) . insertAfter ( widget ) ;
$ ( '<span/>' ) . attr ( 'id' , 'soundcloud-volume-label' ) . addClass ( 'label label-default' ) . text ( 'Volume' ) . appendTo ( sliderHolder ) ;
volumeSlider = $ ( '<div/>' ) . attr ( 'id' , 'soundcloud-volume' ) . appendTo ( sliderHolder ) . slider ( {
2015-07-01 16:38:01 +00:00
range : 'min' ,
value : VOLUME * 100 ,
stop : function ( event , ui ) {
return _this . setVolume ( ui . value / 100 ) ;
}
} ) ;
_this . soundcloud = SC . Widget ( widget [ 0 ] ) ;
return _this . soundcloud . bind ( SC . Widget . Events . READY , function ( ) {
_this . soundcloud . ready = true ;
_this . setVolume ( VOLUME ) ;
_this . play ( ) ;
_this . soundcloud . bind ( SC . Widget . Events . PAUSE , function ( ) {
_this . paused = true ;
if ( CLIENT . leader ) {
return sendVideoUpdate ( ) ;
}
} ) ;
_this . soundcloud . bind ( SC . Widget . Events . PLAY , function ( ) {
_this . paused = false ;
if ( CLIENT . leader ) {
return sendVideoUpdate ( ) ;
}
} ) ;
return _this . soundcloud . bind ( SC . Widget . Events . FINISH , function ( ) {
if ( CLIENT . leader ) {
return socket . emit ( 'playNext' ) ;
}
} ) ;
} ) ;
} ;
} ) ( this ) ) ;
}
SoundCloudPlayer . prototype . load = function ( data ) {
var soundUrl ;
this . setMediaProperties ( data ) ;
if ( this . soundcloud && this . soundcloud . ready ) {
if ( data . meta . scuri ) {
soundUrl = data . meta . scuri ;
2014-11-14 02:24:05 +00:00
} else {
2015-07-01 16:38:01 +00:00
soundUrl = data . id ;
2014-11-14 02:24:05 +00:00
}
2016-03-26 18:25:04 +00:00
this . soundcloud . load ( soundUrl , {
2015-07-01 16:38:01 +00:00
auto _play : true
} ) ;
2016-03-26 18:25:04 +00:00
return this . soundcloud . bind ( SC . Widget . Events . READY , ( function ( _this ) {
return function ( ) {
return _this . setVolume ( VOLUME ) ;
} ;
} ) ( this ) ) ;
2015-07-01 16:38:01 +00:00
} else {
return console . error ( 'SoundCloudPlayer::load() called but soundcloud is not ready' ) ;
}
2013-08-06 02:46:56 +00:00
} ;
2013-06-11 15:29:21 +00:00
2015-07-01 16:38:01 +00:00
SoundCloudPlayer . prototype . play = function ( ) {
this . paused = false ;
if ( this . soundcloud && this . soundcloud . ready ) {
return this . soundcloud . play ( ) ;
}
2013-08-06 02:46:56 +00:00
} ;
2015-07-01 16:38:01 +00:00
SoundCloudPlayer . prototype . pause = function ( ) {
this . paused = true ;
if ( this . soundcloud && this . soundcloud . ready ) {
return this . soundcloud . pause ( ) ;
}
2013-08-06 02:46:56 +00:00
} ;
2013-07-12 20:34:55 +00:00
2015-07-01 16:38:01 +00:00
SoundCloudPlayer . prototype . seekTo = function ( time ) {
if ( this . soundcloud && this . soundcloud . ready ) {
return this . soundcloud . seekTo ( time * 1000 ) ;
}
2013-08-06 02:46:56 +00:00
} ;
2013-06-11 15:29:21 +00:00
2015-07-01 16:38:01 +00:00
SoundCloudPlayer . prototype . setVolume = function ( volume ) {
if ( this . soundcloud && this . soundcloud . ready ) {
2017-07-11 04:38:27 +00:00
return this . soundcloud . setVolume ( volume * 100 ) ;
2015-07-01 16:38:01 +00:00
}
2013-08-06 02:46:56 +00:00
} ;
2014-02-03 02:04:50 +00:00
2015-07-01 16:38:01 +00:00
SoundCloudPlayer . prototype . getTime = function ( cb ) {
if ( this . soundcloud && this . soundcloud . ready ) {
return this . soundcloud . getPosition ( function ( time ) {
return cb ( time / 1000 ) ;
} ) ;
} else {
return cb ( 0 ) ;
}
2014-02-03 02:04:50 +00:00
} ;
2015-07-01 16:38:01 +00:00
SoundCloudPlayer . prototype . getVolume = function ( cb ) {
if ( this . soundcloud && this . soundcloud . ready ) {
2017-08-08 04:08:04 +00:00
return this . soundcloud . getVolume ( function ( vol ) {
return cb ( vol / 100 ) ;
} ) ;
2015-07-01 16:38:01 +00:00
} else {
return cb ( VOLUME ) ;
}
2014-02-03 02:04:50 +00:00
} ;
2015-07-01 16:38:01 +00:00
return SoundCloudPlayer ;
2013-06-11 15:29:21 +00:00
2015-07-01 16:38:01 +00:00
} ) ( Player ) ;
2013-06-11 15:29:21 +00:00
2017-01-10 07:47:11 +00:00
DEFAULT _ERROR = 'You are currently connected via HTTPS but the embedded content uses non-secure plain HTTP. Your browser therefore blocks it from loading due to mixed content policy. To fix this, embed the video using a secure link if available (https://...), or find another source for the content.' ;
2013-06-11 15:29:21 +00:00
2015-07-01 16:38:01 +00:00
genParam = function ( name , value ) {
return $ ( '<param/>' ) . attr ( {
name : name ,
value : value
} ) ;
} ;
2014-02-03 02:04:50 +00:00
2015-07-01 16:38:01 +00:00
window . EmbedPlayer = EmbedPlayer = ( function ( superClass ) {
extend ( EmbedPlayer , superClass ) ;
2013-06-11 15:29:21 +00:00
2015-07-01 16:38:01 +00:00
function EmbedPlayer ( data ) {
if ( ! ( this instanceof EmbedPlayer ) ) {
return new EmbedPlayer ( data ) ;
}
this . load ( data ) ;
}
2014-12-11 05:56:17 +00:00
2015-07-01 16:38:01 +00:00
EmbedPlayer . prototype . load = function ( data ) {
var embed ;
this . setMediaProperties ( data ) ;
embed = data . meta . embed ;
if ( embed == null ) {
console . error ( 'EmbedPlayer::load(): missing meta.embed' ) ;
return ;
}
if ( embed . tag === 'object' ) {
this . player = this . loadObject ( embed ) ;
} else {
this . player = this . loadIframe ( embed ) ;
}
return removeOld ( this . player ) ;
} ;
2014-12-11 05:56:17 +00:00
2015-07-01 16:38:01 +00:00
EmbedPlayer . prototype . loadObject = function ( embed ) {
var key , object , ref , value ;
object = $ ( '<object/>' ) . attr ( {
type : 'application/x-shockwave-flash' ,
2015-09-17 03:20:51 +00:00
data : embed . src ,
wmode : 'opaque'
2015-07-01 16:38:01 +00:00
} ) ;
genParam ( 'allowfullscreen' , 'true' ) . appendTo ( object ) ;
genParam ( 'allowscriptaccess' , 'always' ) . appendTo ( object ) ;
ref = embed . params ;
for ( key in ref ) {
value = ref [ key ] ;
genParam ( key , value ) . appendTo ( object ) ;
}
return object ;
} ;
2014-12-11 05:56:17 +00:00
2015-07-01 16:38:01 +00:00
EmbedPlayer . prototype . loadIframe = function ( embed ) {
var alert , error , iframe ;
if ( embed . src . indexOf ( 'http:' ) === 0 && location . protocol === 'https:' ) {
if ( this . _ _proto _ _ . mixedContentError != null ) {
error = this . _ _proto _ _ . mixedContentError ;
} else {
error = DEFAULT _ERROR ;
2014-12-11 05:56:17 +00:00
}
2015-07-01 16:38:01 +00:00
alert = makeAlert ( 'Mixed Content Error' , error , 'alert-danger' ) . removeClass ( 'col-md-12' ) ;
alert . find ( '.close' ) . remove ( ) ;
return alert ;
} else {
iframe = $ ( '<iframe/>' ) . attr ( {
src : embed . src ,
2016-02-22 05:04:35 +00:00
frameborder : '0' ,
allowfullscreen : '1'
2015-07-01 16:38:01 +00:00
} ) ;
return iframe ;
}
2013-08-06 02:46:56 +00:00
} ;
2013-08-03 15:12:53 +00:00
2015-07-01 16:38:01 +00:00
return EmbedPlayer ;
2013-08-03 15:12:53 +00:00
2015-07-01 16:38:01 +00:00
} ) ( Player ) ;
2013-08-03 15:12:53 +00:00
2015-07-05 21:04:21 +00:00
window . TwitchPlayer = TwitchPlayer = ( function ( superClass ) {
extend ( TwitchPlayer , superClass ) ;
function TwitchPlayer ( data ) {
if ( ! ( this instanceof TwitchPlayer ) ) {
return new TwitchPlayer ( data ) ;
}
2016-08-25 03:21:49 +00:00
this . setMediaProperties ( data ) ;
waitUntilDefined ( window , 'Twitch' , ( function ( _this ) {
return function ( ) {
return waitUntilDefined ( Twitch , 'Player' , function ( ) {
return _this . init ( data ) ;
} ) ;
} ;
} ) ( this ) ) ;
2015-07-05 21:04:21 +00:00
}
2016-08-25 03:21:49 +00:00
TwitchPlayer . prototype . init = function ( data ) {
var options ;
removeOld ( ) ;
2016-09-05 01:53:38 +00:00
if ( data . type === 'tv' ) {
options = {
video : data . id
} ;
} else {
options = {
channel : data . id
} ;
}
2016-08-25 03:21:49 +00:00
this . twitch = new Twitch . Player ( 'ytapiplayer' , options ) ;
return this . twitch . addEventListener ( Twitch . Player . READY , ( function ( _this ) {
return function ( ) {
_this . setVolume ( VOLUME ) ;
_this . twitch . setQuality ( _this . mapQuality ( USEROPTS . default _quality ) ) ;
_this . twitch . addEventListener ( Twitch . Player . PLAY , function ( ) {
2016-09-05 01:53:38 +00:00
_this . paused = false ;
2016-08-25 03:21:49 +00:00
if ( CLIENT . leader ) {
return sendVideoUpdate ( ) ;
}
} ) ;
_this . twitch . addEventListener ( Twitch . Player . PAUSE , function ( ) {
2016-09-05 01:53:38 +00:00
_this . paused = true ;
2016-08-25 03:21:49 +00:00
if ( CLIENT . leader ) {
return sendVideoUpdate ( ) ;
}
} ) ;
return _this . twitch . addEventListener ( Twitch . Player . ENDED , function ( ) {
if ( CLIENT . leader ) {
return socket . emit ( 'playNext' ) ;
}
} ) ;
} ;
} ) ( this ) ) ;
} ;
2015-07-05 21:04:21 +00:00
TwitchPlayer . prototype . load = function ( data ) {
2016-10-08 02:55:41 +00:00
var error ;
2016-08-25 03:21:49 +00:00
this . setMediaProperties ( data ) ;
try {
2016-09-05 01:53:38 +00:00
if ( data . type === 'tv' ) {
return this . twitch . setVideo ( data . id ) ;
} else {
return this . twitch . setChannel ( data . id ) ;
}
2016-08-25 03:21:49 +00:00
} catch ( error1 ) {
error = error1 ;
return console . error ( error ) ;
}
} ;
TwitchPlayer . prototype . pause = function ( ) {
2016-10-08 02:55:41 +00:00
var error ;
2016-08-25 03:21:49 +00:00
try {
2016-09-05 01:53:38 +00:00
this . twitch . pause ( ) ;
return this . paused = true ;
2016-08-25 03:21:49 +00:00
} catch ( error1 ) {
error = error1 ;
return console . error ( error ) ;
}
} ;
TwitchPlayer . prototype . play = function ( ) {
2016-10-08 02:55:41 +00:00
var error ;
2016-08-25 03:21:49 +00:00
try {
2016-09-05 01:53:38 +00:00
this . twitch . play ( ) ;
return this . paused = false ;
2016-08-25 03:21:49 +00:00
} catch ( error1 ) {
error = error1 ;
return console . error ( error ) ;
}
} ;
TwitchPlayer . prototype . seekTo = function ( time ) {
2016-10-08 02:55:41 +00:00
var error ;
2016-08-25 03:21:49 +00:00
try {
return this . twitch . seek ( time ) ;
} catch ( error1 ) {
error = error1 ;
return console . error ( error ) ;
}
} ;
TwitchPlayer . prototype . getTime = function ( cb ) {
2016-10-08 02:55:41 +00:00
var error ;
2016-08-25 03:21:49 +00:00
try {
2016-09-05 01:53:38 +00:00
return cb ( this . twitch . getCurrentTime ( ) ) ;
2016-08-25 03:21:49 +00:00
} catch ( error1 ) {
error = error1 ;
return console . error ( error ) ;
}
} ;
TwitchPlayer . prototype . setVolume = function ( volume ) {
2016-10-08 02:55:41 +00:00
var error ;
2016-08-25 03:21:49 +00:00
try {
this . twitch . setVolume ( volume ) ;
if ( volume > 0 ) {
return this . twitch . setMuted ( false ) ;
2015-07-05 21:04:21 +00:00
}
2016-08-25 03:21:49 +00:00
} catch ( error1 ) {
error = error1 ;
return console . error ( error ) ;
}
} ;
TwitchPlayer . prototype . getVolume = function ( cb ) {
2016-10-08 02:55:41 +00:00
var error ;
2016-08-25 03:21:49 +00:00
try {
if ( this . twitch . isPaused ( ) ) {
return cb ( 0 ) ;
} else {
return cb ( this . twitch . getVolume ( ) ) ;
}
} catch ( error1 ) {
error = error1 ;
return console . error ( error ) ;
}
} ;
TwitchPlayer . prototype . mapQuality = function ( quality ) {
switch ( String ( quality ) ) {
case '1080' :
return 'chunked' ;
case '720' :
return 'high' ;
case '480' :
return 'medium' ;
case '360' :
return 'low' ;
case '240' :
return 'mobile' ;
case 'best' :
return 'chunked' ;
default :
return '' ;
}
2015-07-05 21:04:21 +00:00
} ;
return TwitchPlayer ;
2016-08-25 03:21:49 +00:00
} ) ( Player ) ;
2015-07-05 21:04:21 +00:00
2015-07-05 21:00:59 +00:00
window . LivestreamPlayer = LivestreamPlayer = ( function ( superClass ) {
extend ( LivestreamPlayer , superClass ) ;
function LivestreamPlayer ( data ) {
if ( ! ( this instanceof LivestreamPlayer ) ) {
return new LivestreamPlayer ( data ) ;
}
this . load ( data ) ;
}
LivestreamPlayer . prototype . load = function ( data ) {
if ( LIVESTREAM _CHROMELESS ) {
data . meta . embed = {
src : 'https://cdn.livestream.com/chromelessPlayer/v20/playerapi.swf' ,
tag : 'object' ,
params : {
flashvars : "channel=" + data . id
}
} ;
} else {
data . meta . embed = {
src : "https://cdn.livestream.com/embed/" + data . id + "?layout=4&color=0x000000&iconColorOver=0xe7e7e7&iconColor=0xcccccc" ,
tag : 'iframe'
} ;
}
return LivestreamPlayer . _ _super _ _ . load . call ( this , data ) ;
} ;
return LivestreamPlayer ;
} ) ( EmbedPlayer ) ;
2015-07-01 16:38:01 +00:00
CUSTOM _EMBED _WARNING = 'This channel is embedding custom content from %link%. Since this content is not trusted, you must click "Embed" below to allow the content to be embedded.<hr>' ;
2013-08-03 15:12:53 +00:00
2015-07-01 16:38:01 +00:00
window . CustomEmbedPlayer = CustomEmbedPlayer = ( function ( superClass ) {
extend ( CustomEmbedPlayer , superClass ) ;
2013-08-06 02:46:56 +00:00
2015-07-01 16:38:01 +00:00
function CustomEmbedPlayer ( data ) {
if ( ! ( this instanceof CustomEmbedPlayer ) ) {
return new CustomEmbedPlayer ( data ) ;
}
this . load ( data ) ;
}
2014-02-03 02:04:50 +00:00
2015-07-01 16:38:01 +00:00
CustomEmbedPlayer . prototype . load = function ( data ) {
var alert , embedSrc , link ;
if ( data . meta . embed == null ) {
console . error ( 'CustomEmbedPlayer::load(): missing meta.embed' ) ;
return ;
}
embedSrc = data . meta . embed . src ;
link = "<a href=\"" + embedSrc + "\" target=\"_blank\"><strong>" + embedSrc + "</strong></a>" ;
alert = makeAlert ( 'Untrusted Content' , CUSTOM _EMBED _WARNING . replace ( '%link%' , link ) , 'alert-warning' ) . removeClass ( 'col-md-12' ) ;
$ ( '<button/>' ) . addClass ( 'btn btn-default' ) . text ( 'Embed' ) . click ( ( function ( _this ) {
return function ( ) {
return CustomEmbedPlayer . _ _super _ _ . load . call ( _this , data ) ;
} ;
} ) ( this ) ) . appendTo ( alert . find ( '.alert' ) ) ;
return removeOld ( alert ) ;
} ;
2014-02-03 02:04:50 +00:00
2015-07-01 16:38:01 +00:00
return CustomEmbedPlayer ;
2014-02-03 02:04:50 +00:00
2015-07-01 16:38:01 +00:00
} ) ( EmbedPlayer ) ;
2013-08-03 15:12:53 +00:00
2015-07-01 16:38:01 +00:00
window . RTMPPlayer = RTMPPlayer = ( function ( superClass ) {
extend ( RTMPPlayer , superClass ) ;
2014-02-03 02:04:50 +00:00
2015-07-01 16:38:01 +00:00
function RTMPPlayer ( data ) {
if ( ! ( this instanceof RTMPPlayer ) ) {
return new RTMPPlayer ( data ) ;
}
2016-03-03 03:18:33 +00:00
this . setupMeta ( data ) ;
RTMPPlayer . _ _super _ _ . constructor . call ( this , data ) ;
}
RTMPPlayer . prototype . load = function ( data ) {
this . setupMeta ( data ) ;
return RTMPPlayer . _ _super _ _ . load . call ( this , data ) ;
} ;
RTMPPlayer . prototype . setupMeta = function ( data ) {
return data . meta . direct = {
2015-11-09 03:51:17 +00:00
480 : [
{
2017-07-16 03:17:13 +00:00
link : data . id ,
2017-07-24 00:55:25 +00:00
contentType : 'rtmp/flv'
2015-11-09 03:51:17 +00:00
}
]
2015-07-01 16:38:01 +00:00
} ;
2016-03-03 03:18:33 +00:00
} ;
2014-02-03 02:04:50 +00:00
2015-07-01 16:38:01 +00:00
return RTMPPlayer ;
2014-02-03 02:04:50 +00:00
2015-11-09 03:51:17 +00:00
} ) ( VideoJSPlayer ) ;
2014-02-03 02:04:50 +00:00
2017-05-20 23:50:00 +00:00
window . SmashcastPlayer = SmashcastPlayer = ( function ( superClass ) {
extend ( SmashcastPlayer , superClass ) ;
2014-02-03 02:04:50 +00:00
2017-05-20 23:50:00 +00:00
function SmashcastPlayer ( data ) {
if ( ! ( this instanceof SmashcastPlayer ) ) {
return new SmashcastPlayer ( data ) ;
2015-07-01 16:38:01 +00:00
}
this . load ( data ) ;
2014-06-01 17:54:53 +00:00
}
2015-01-23 05:21:31 +00:00
2017-05-20 23:50:00 +00:00
SmashcastPlayer . prototype . load = function ( data ) {
2015-07-01 16:38:01 +00:00
data . meta . embed = {
2017-05-20 23:50:00 +00:00
src : "https://www.smashcast.tv/embed/" + data . id ,
2015-07-01 16:38:01 +00:00
tag : 'iframe'
} ;
2017-05-20 23:50:00 +00:00
return SmashcastPlayer . _ _super _ _ . load . call ( this , data ) ;
2015-01-23 05:21:31 +00:00
} ;
2017-05-20 23:50:00 +00:00
return SmashcastPlayer ;
2015-01-23 05:21:31 +00:00
2015-07-01 16:38:01 +00:00
} ) ( EmbedPlayer ) ;
2015-01-23 05:21:31 +00:00
2015-07-01 16:38:01 +00:00
window . UstreamPlayer = UstreamPlayer = ( function ( superClass ) {
extend ( UstreamPlayer , superClass ) ;
2015-01-23 05:21:31 +00:00
2015-07-01 16:38:01 +00:00
function UstreamPlayer ( data ) {
if ( ! ( this instanceof UstreamPlayer ) ) {
return new UstreamPlayer ( data ) ;
}
this . load ( data ) ;
}
2015-01-23 05:21:31 +00:00
2015-07-01 16:38:01 +00:00
UstreamPlayer . prototype . load = function ( data ) {
data . meta . embed = {
tag : 'iframe' ,
2017-03-03 02:47:47 +00:00
src : "/ustream_bypass/embed/" + data . id + "?html5ui&autoplay=1"
2015-07-01 16:38:01 +00:00
} ;
return UstreamPlayer . _ _super _ _ . load . call ( this , data ) ;
} ;
2015-01-23 05:21:31 +00:00
2015-07-01 16:38:01 +00:00
return UstreamPlayer ;
2015-01-23 05:21:31 +00:00
2015-07-01 16:38:01 +00:00
} ) ( EmbedPlayer ) ;
2015-01-23 05:21:31 +00:00
2015-07-01 16:38:01 +00:00
window . ImgurPlayer = ImgurPlayer = ( function ( superClass ) {
extend ( ImgurPlayer , superClass ) ;
2013-09-22 04:54:29 +00:00
2015-07-01 16:38:01 +00:00
function ImgurPlayer ( data ) {
if ( ! ( this instanceof ImgurPlayer ) ) {
return new ImgurPlayer ( data ) ;
}
this . load ( data ) ;
2013-09-22 04:54:29 +00:00
}
2014-02-03 02:04:50 +00:00
2015-07-01 16:38:01 +00:00
ImgurPlayer . prototype . load = function ( data ) {
data . meta . embed = {
tag : 'iframe' ,
src : "https://imgur.com/a/" + data . id + "/embed"
} ;
return ImgurPlayer . _ _super _ _ . load . call ( this , data ) ;
} ;
2013-08-06 02:46:56 +00:00
2015-07-01 16:38:01 +00:00
return ImgurPlayer ;
} ) ( EmbedPlayer ) ;
2015-09-16 06:32:01 +00:00
window . GoogleDriveYouTubePlayer = GoogleDriveYouTubePlayer = ( function ( superClass ) {
extend ( GoogleDriveYouTubePlayer , superClass ) ;
function GoogleDriveYouTubePlayer ( data ) {
if ( ! ( this instanceof GoogleDriveYouTubePlayer ) ) {
return new GoogleDriveYouTubePlayer ( data ) ;
}
this . setMediaProperties ( data ) ;
this . init ( data ) ;
}
GoogleDriveYouTubePlayer . prototype . init = function ( data ) {
var embed ;
2016-08-24 04:50:18 +00:00
window . promptToInstallDriveUserscript ( ) ;
2015-09-16 06:32:01 +00:00
embed = $ ( '<embed />' ) . attr ( {
type : 'application/x-shockwave-flash' ,
2015-09-16 07:04:34 +00:00
src : "https://www.youtube.com/get_player?docid=" + data . id + "&ps=docs&partnerid=30&enablejsapi=1&cc_load_policy=1&auth_timeout=86400000000" ,
2015-09-16 06:32:01 +00:00
flashvars : 'autoplay=1&playerapiid=uniquePlayerId' ,
wmode : 'opaque' ,
allowscriptaccess : 'always'
} ) ;
removeOld ( embed ) ;
return window . onYouTubePlayerReady = ( function ( _this ) {
return function ( ) {
if ( PLAYER !== _this ) {
return ;
}
_this . yt = embed [ 0 ] ;
window . gdriveStateChange = _this . onStateChange . bind ( _this ) ;
_this . yt . addEventListener ( 'onStateChange' , 'gdriveStateChange' ) ;
return _this . onReady ( ) ;
} ;
} ) ( this ) ;
} ;
GoogleDriveYouTubePlayer . prototype . load = function ( data ) {
2015-12-22 01:23:48 +00:00
this . yt = null ;
2015-09-16 06:32:01 +00:00
this . setMediaProperties ( data ) ;
return this . init ( data ) ;
} ;
GoogleDriveYouTubePlayer . prototype . onReady = function ( ) {
this . yt . ready = true ;
this . setVolume ( VOLUME ) ;
return this . setQuality ( USEROPTS . default _quality ) ;
} ;
GoogleDriveYouTubePlayer . prototype . onStateChange = function ( ev ) {
if ( PLAYER !== this ) {
return ;
}
if ( ( ev === YT . PlayerState . PAUSED && ! this . paused ) || ( ev === YT . PlayerState . PLAYING && this . paused ) ) {
this . paused = ev === YT . PlayerState . PAUSED ;
if ( CLIENT . leader ) {
sendVideoUpdate ( ) ;
}
}
if ( ev === YT . PlayerState . ENDED && CLIENT . leader ) {
return socket . emit ( 'playNext' ) ;
}
} ;
GoogleDriveYouTubePlayer . prototype . play = function ( ) {
this . paused = false ;
if ( this . yt && this . yt . ready ) {
return this . yt . playVideo ( ) ;
}
} ;
GoogleDriveYouTubePlayer . prototype . pause = function ( ) {
this . paused = true ;
if ( this . yt && this . yt . ready ) {
return this . yt . pauseVideo ( ) ;
}
} ;
GoogleDriveYouTubePlayer . prototype . seekTo = function ( time ) {
if ( this . yt && this . yt . ready ) {
return this . yt . seekTo ( time , true ) ;
}
} ;
GoogleDriveYouTubePlayer . prototype . setVolume = function ( volume ) {
if ( this . yt && this . yt . ready ) {
if ( volume > 0 ) {
this . yt . unMute ( ) ;
}
return this . yt . setVolume ( volume * 100 ) ;
}
} ;
GoogleDriveYouTubePlayer . prototype . setQuality = function ( quality ) {
var ytQuality ;
if ( ! this . yt || ! this . yt . ready ) {
return ;
}
ytQuality = ( function ( ) {
switch ( String ( quality ) ) {
case '240' :
return 'small' ;
case '360' :
return 'medium' ;
case '480' :
return 'large' ;
case '720' :
return 'hd720' ;
case '1080' :
return 'hd1080' ;
case 'best' :
return 'highres' ;
default :
return 'auto' ;
}
} ) ( ) ;
if ( ytQuality !== 'auto' ) {
return this . yt . setPlaybackQuality ( ytQuality ) ;
}
} ;
GoogleDriveYouTubePlayer . prototype . getTime = function ( cb ) {
if ( this . yt && this . yt . ready ) {
return cb ( this . yt . getCurrentTime ( ) ) ;
} else {
return cb ( 0 ) ;
}
} ;
GoogleDriveYouTubePlayer . prototype . getVolume = function ( cb ) {
if ( this . yt && this . yt . ready ) {
if ( this . yt . isMuted ( ) ) {
return cb ( 0 ) ;
} else {
return cb ( this . yt . getVolume ( ) / 100 ) ;
}
} else {
return cb ( VOLUME ) ;
}
} ;
return GoogleDriveYouTubePlayer ;
} ) ( Player ) ;
2016-08-24 04:50:18 +00:00
window . promptToInstallDriveUserscript = function ( ) {
var alertBox , closeButton , infoLink ;
if ( document . getElementById ( 'prompt-install-drive-userscript' ) ) {
return ;
}
alertBox = document . createElement ( 'div' ) ;
alertBox . id = 'prompt-install-drive-userscript' ;
alertBox . className = 'alert alert-info' ;
2017-03-04 07:39:38 +00:00
alertBox . innerHTML = "Due to continual breaking changes making it increasingly difficult to\nmaintain Google Drive support, Google Drive now requires installing\na userscript in order to play the video." ;
2016-08-24 04:50:18 +00:00
alertBox . appendChild ( document . createElement ( 'br' ) ) ;
infoLink = document . createElement ( 'a' ) ;
infoLink . className = 'btn btn-info' ;
infoLink . href = '/google_drive_userscript' ;
infoLink . textContent = 'Click here for details' ;
infoLink . target = '_blank' ;
alertBox . appendChild ( infoLink ) ;
closeButton = document . createElement ( 'button' ) ;
closeButton . className = 'close pull-right' ;
closeButton . innerHTML = '×' ;
closeButton . onclick = function ( ) {
return alertBox . parentNode . removeChild ( alertBox ) ;
} ;
alertBox . insertBefore ( closeButton , alertBox . firstChild ) ;
2017-03-04 07:39:38 +00:00
return removeOld ( $ ( '<div/>' ) . append ( alertBox ) ) ;
2016-08-24 04:50:18 +00:00
} ;
2016-08-07 04:14:52 +00:00
window . HLSPlayer = HLSPlayer = ( function ( superClass ) {
extend ( HLSPlayer , superClass ) ;
function HLSPlayer ( data ) {
if ( ! ( this instanceof HLSPlayer ) ) {
return new HLSPlayer ( data ) ;
}
this . setupMeta ( data ) ;
HLSPlayer . _ _super _ _ . constructor . call ( this , data ) ;
}
HLSPlayer . prototype . load = function ( data ) {
this . setupMeta ( data ) ;
return HLSPlayer . _ _super _ _ . load . call ( this , data ) ;
} ;
HLSPlayer . prototype . setupMeta = function ( data ) {
return data . meta . direct = {
480 : [
{
link : data . id ,
contentType : 'application/x-mpegURL'
}
]
} ;
} ;
return HLSPlayer ;
} ) ( VideoJSPlayer ) ;
2015-07-01 16:38:01 +00:00
TYPE _MAP = {
yt : YouTubePlayer ,
vi : VimeoPlayer ,
dm : DailymotionPlayer ,
2016-08-16 04:00:56 +00:00
gd : GoogleDrivePlayer ,
2015-07-01 16:38:01 +00:00
gp : VideoJSPlayer ,
fi : FilePlayer ,
jw : FilePlayer ,
sc : SoundCloudPlayer ,
li : LivestreamPlayer ,
tw : TwitchPlayer ,
2016-09-05 01:53:38 +00:00
tv : TwitchPlayer ,
2015-07-01 16:38:01 +00:00
cu : CustomEmbedPlayer ,
rt : RTMPPlayer ,
2017-05-20 23:50:00 +00:00
hb : SmashcastPlayer ,
2015-07-01 16:38:01 +00:00
us : UstreamPlayer ,
2016-06-26 00:09:48 +00:00
im : ImgurPlayer ,
2016-08-07 04:14:52 +00:00
vm : VideoJSPlayer ,
2016-08-10 05:41:55 +00:00
hl : HLSPlayer ,
2017-05-27 18:49:27 +00:00
sb : VideoJSPlayer ,
2017-08-09 03:35:17 +00:00
tc : VideoJSPlayer ,
cm : VideoJSPlayer
2015-07-01 16:38:01 +00:00
} ;
window . loadMediaPlayer = function ( data ) {
2016-10-08 02:55:41 +00:00
var e , error ;
2016-03-03 03:31:29 +00:00
try {
if ( window . PLAYER ) {
window . PLAYER . destroy ( ) ;
}
} catch ( error1 ) {
error = error1 ;
console . error ( error ) ;
}
2015-09-16 06:32:01 +00:00
if ( data . meta . direct && data . type !== 'gd' ) {
2015-07-05 20:50:34 +00:00
try {
return window . PLAYER = new VideoJSPlayer ( data ) ;
2016-10-08 02:55:41 +00:00
} catch ( error1 ) {
e = error1 ;
2015-07-05 20:50:34 +00:00
return console . error ( e ) ;
}
2016-08-12 03:04:51 +00:00
} else if ( data . type in TYPE _MAP ) {
try {
return window . PLAYER = TYPE _MAP [ data . type ] ( data ) ;
2016-10-08 02:55:41 +00:00
} catch ( error1 ) {
e = error1 ;
2016-08-12 03:04:51 +00:00
return console . error ( e ) ;
}
2013-06-11 15:29:21 +00:00
}
2015-07-01 16:38:01 +00:00
} ;
2013-08-06 02:46:56 +00:00
2015-07-01 16:38:01 +00:00
window . handleMediaUpdate = function ( data ) {
var PLAYER , waiting ;
PLAYER = window . PLAYER ;
if ( typeof PLAYER . mediaLength === 'number' && PLAYER . mediaLength > 0 && data . currentTime > PLAYER . mediaLength ) {
return ;
}
waiting = data . currentTime < 0 ;
if ( data . id && data . id !== PLAYER . mediaId ) {
if ( data . currentTime < 0 ) {
data . currentTime = 0 ;
}
PLAYER . load ( data ) ;
PLAYER . play ( ) ;
}
if ( waiting ) {
PLAYER . seekTo ( 0 ) ;
if ( PLAYER instanceof YouTubePlayer ) {
PLAYER . pauseSeekRaceCondition = true ;
} else {
PLAYER . pause ( ) ;
}
return ;
} else if ( PLAYER instanceof YouTubePlayer ) {
PLAYER . pauseSeekRaceCondition = false ;
}
if ( CLIENT . leader || ! USEROPTS . synch ) {
return ;
}
if ( data . paused && ! PLAYER . paused ) {
PLAYER . seekTo ( data . currentTime ) ;
PLAYER . pause ( ) ;
2015-07-05 20:29:06 +00:00
} else if ( PLAYER . paused && ! data . paused ) {
2015-07-01 16:38:01 +00:00
PLAYER . play ( ) ;
}
return PLAYER . getTime ( function ( seconds ) {
var accuracy , diff , time ;
time = data . currentTime ;
diff = ( time - seconds ) || time ;
accuracy = USEROPTS . sync _accuracy ;
if ( PLAYER instanceof DailymotionPlayer ) {
accuracy = Math . max ( accuracy , 5 ) ;
}
if ( diff > accuracy ) {
return PLAYER . seekTo ( time ) ;
} else if ( diff < - accuracy ) {
if ( ! ( PLAYER instanceof DailymotionPlayer ) ) {
time += 1 ;
2013-06-11 15:29:21 +00:00
}
2015-07-01 16:38:01 +00:00
return PLAYER . seekTo ( time ) ;
}
2013-08-06 02:46:56 +00:00
} ) ;
2015-07-01 16:38:01 +00:00
} ;
window . removeOld = function ( replace ) {
var old ;
2016-03-24 05:45:54 +00:00
$ ( '#soundcloud-volume-holder' ) . remove ( ) ;
2015-07-01 16:38:01 +00:00
if ( replace == null ) {
replace = $ ( '<div/>' ) . addClass ( 'embed-responsive-item' ) ;
2013-08-06 03:25:16 +00:00
}
2015-07-01 16:38:01 +00:00
old = $ ( '#ytapiplayer' ) ;
replace . insertBefore ( old ) ;
old . remove ( ) ;
replace . attr ( 'id' , 'ytapiplayer' ) ;
return replace ;
} ;
} ) . call ( this ) ;