var Media = function(data) { this.id = data.id; this.type = data.type; switch(this.type) { case "yt": this.initYouTube(); break; case "vi": this.initVimeo(); break; case "dm": this.initDailymotion(); break; case "sc": this.initSoundcloud(); break; case "li": this.initLivestream(); break; case "tw": this.initTwitch(); break; case "rt": this.initRTMP(); break; default: break; } } Media.prototype.initYouTube = function() { this.removeOld(); this.player = new YT.Player("ytapiplayer", { height: VHEIGHT, width: VWIDTH, videoId: this.id, playerVars: { "autoplay": 1, "controls": 1, }, events: { onPlayerReady: function() { socket.emit("playerReady"); }, onStateChange: function(ev) { if(LEADER && ev.data == YT.PlayerState.ENDED) { socket.emit("playNext"); } } } }); $("#ytapiplayer").css("border", "none"); this.load = function(data) { if(this.player.loadVideoById) { this.player.loadVideoById(data.id, data.currentTime); this.id = data.id; } } this.pause = function() { this.player.pauseVideo(); } this.play = function() { this.player.playVideo(); } this.getTime = function(callback) { callback(this.player.getCurrentTime()); } this.seek = function(time) { this.player.seekTo(time, true); } } Media.prototype.initVimeo = function() { var iframe = $("