Added fixes for player not starting on youtubevideos that has already been played by the client

Fix for userpass not being set correctly
Fix for emit function not being used everywhere it needs to be used
This commit is contained in:
Kasper Rynning-Tønnesen
2018-03-01 13:10:51 +01:00
parent 97e06e3726
commit a6083d3402
3 changed files with 25 additions and 11 deletions

View File

@@ -143,6 +143,7 @@ var Admin = {
}, },
pw: function(msg) { pw: function(msg) {
if(msg == false) return;
w_p = false; w_p = false;
if(adminpass == undefined || adminpass == "") { if(adminpass == undefined || adminpass == "") {
adminpass = Crypt.get_pass(chan.toLowerCase()); adminpass = Crypt.get_pass(chan.toLowerCase());
@@ -354,8 +355,9 @@ var Admin = {
userpass: Crypt.crypt_pass(pass_send), userpass: Crypt.crypt_pass(pass_send),
userpass_changed: userpass_changed userpass_changed: userpass_changed
}; };
if(userpass_changed){
Crypt.set_userpass(chan.toLowerCase(), CryptoJS.SHA256(userpass).toString()); Crypt.set_userpass(chan.toLowerCase(), CryptoJS.SHA256(userpass).toString());
}
emit("conf", configs); emit("conf", configs);
}, },

View File

@@ -74,6 +74,8 @@ var chromecastReady = false;
var find_word = ""; var find_word = "";
var found_array = []; var found_array = [];
var found_array_index = 0; var found_array_index = 0;
var startTime = 0;
var fix_too_far = false;
var guid = ""; var guid = "";
var castSession; var castSession;
var width_timeout; var width_timeout;
@@ -141,9 +143,9 @@ window.zoff = {
} }
if(!Helper.mobilecheck()) { if(!Helper.mobilecheck()) {
$(window).error(function(e){ window.onerror = function(e) {
e.preventDefault(); if(e == "Script error.") return true;
Helper.logs.unshift({log: e.originalEvent.error.stack.toString().replace(/(\r\n|\n|\r)/gm,""), date: new Date()}); Helper.logs.unshift({log: e.toString().replace(/(\r\n|\n|\r)/gm,""), date: new Date()});
$(".contact-form-content").remove(); $(".contact-form-content").remove();
$("#submit-contact-form").remove(); $("#submit-contact-form").remove();
$(".contact-modal-header").text("An error occurred"); $(".contact-modal-header").text("An error occurred");
@@ -159,8 +161,9 @@ if(!Helper.mobilecheck()) {
$("#contact").modal("open"); $("#contact").modal("open");
/*$("#error-report-modal").modal();*/ /*$("#error-report-modal").modal();*/
$("#error-report-code").text(JSON.stringify(Helper.logs, undefined, 4)); $("#error-report-code").text(JSON.stringify(Helper.logs, undefined, 4));
console.error(e.originalEvent.error); //console.error(e.originalEvent.error);
}); return true;
};
} }
$().ready(function(){ $().ready(function(){

View File

@@ -11,6 +11,7 @@ var Player = {
youtube_listener: function(obj) { youtube_listener: function(obj) {
Helper.log(["object", obj]); Helper.log(["object", obj]);
var state; var state;
fix_too_far = false;
if(embed && obj.np) { if(embed && obj.np) {
if(window.parentWindow && window.parentOrigin) { if(window.parentWindow && window.parentOrigin) {
window.parentWindow.postMessage({type: "np", title: obj.np[0].title}, window.parentOrigin); window.parentWindow.postMessage({type: "np", title: obj.np[0].title}, window.parentOrigin);
@@ -89,6 +90,7 @@ var Player = {
conf = obj.conf[0]; conf = obj.conf[0];
time = obj.time; time = obj.time;
seekTo = (time - conf.startTime) + Player.np.start; seekTo = (time - conf.startTime) + Player.np.start;
startTime = time - conf.startTime;
song_title = obj.np[0].title; song_title = obj.np[0].title;
duration = obj.np[0].duration; duration = obj.np[0].duration;
//Player.setBGimage(video_id); //Player.setBGimage(video_id);
@@ -116,6 +118,7 @@ var Player = {
conf = obj.conf[0]; conf = obj.conf[0];
time = obj.time; time = obj.time;
seekTo = (time - conf.startTime) + Player.np.start; seekTo = (time - conf.startTime) + Player.np.start;
startTime = time - conf.startTime;
song_title = obj.np[0].title; song_title = obj.np[0].title;
duration = obj.np[0].duration; duration = obj.np[0].duration;
@@ -210,10 +213,15 @@ var Player = {
"New state\nState: ", "New state\nState: ",
newState newState
]); ]);
try{ if(player.getCurrentTime() > startTime + Player.np.start && !fix_too_far) {
Player.seekTo(seekTo);
Player.playVideo();
fix_too_far = true;
}
try {
Helper.log(["Duration: " + Player.player.getDuration(), "Current time: " + Player.player.getCurrentTime()]); Helper.log(["Duration: " + Player.player.getDuration(), "Current time: " + Player.player.getCurrentTime()]);
Helper.log(["getVideoUrl(): " + Player.player.getVideoUrl().split('v=')[1]]); Helper.log(["getVideoUrl(): " + Player.player.getVideoUrl().split('v=')[1]]);
}catch(e){} } catch(e){}
Helper.log(["video_id variable: " + video_id]); Helper.log(["video_id variable: " + video_id]);
switch(newState.data) { switch(newState.data) {
case YT.PlayerState.UNSTARTED: case YT.PlayerState.UNSTARTED:
@@ -221,6 +229,7 @@ var Player = {
case YT.PlayerState.ENDED: case YT.PlayerState.ENDED:
playing = false; playing = false;
paused = false; paused = false;
if(!offline) { if(!offline) {
socket.emit("end", {id: video_id, channel: chan.toLowerCase(), pass: embed ? '' : Crypt.crypt_pass(Crypt.get_userpass(chan.toLowerCase()))}); socket.emit("end", {id: video_id, channel: chan.toLowerCase(), pass: embed ? '' : Crypt.crypt_pass(Crypt.get_userpass(chan.toLowerCase()))});
} else { } else {
@@ -482,7 +491,7 @@ var Player = {
if(!user_auth_started) { if(!user_auth_started) {
if(newState.data == 5 || newState.data == 100 || newState.data == 101 || newState.data == 150) { if(newState.data == 5 || newState.data == 100 || newState.data == 101 || newState.data == 150) {
curr_playing = Player.player.getVideoUrl().replace("https://www.youtube.com/watch?v=", ""); curr_playing = Player.player.getVideoUrl().replace("https://www.youtube.com/watch?v=", "");
socket.emit("skip", {error: newState.data, id: video_id, pass: adminpass == "" ? "" : Crypt.crypt_pass(adminpass), channel: chan.toLowerCase(), userpass: embed ? '' : Crypt.crypt_pass(Crypt.get_userpass(chan.toLowerCase()))}); emit("skip", {error: newState.data, id: video_id, pass: adminpass == "" ? "" : Crypt.crypt_pass(adminpass), channel: chan.toLowerCase(), userpass: embed ? '' : Crypt.crypt_pass(Crypt.get_userpass(chan.toLowerCase()))});
} else if(video_id !== undefined) { } else if(video_id !== undefined) {
Player.loadVideoById(video_id, duration); Player.loadVideoById(video_id, duration);
@@ -573,7 +582,7 @@ var Player = {
notifyUser: function(id, title) { notifyUser: function(id, title) {
title = title.replace(/\\\'/g, "'").replace(/"/g,"'").replace(/&/g,"&"); title = title.replace(/\\\'/g, "'").replace(/"/g,"'").replace(/&/g,"&");
if (Notification.permission === "granted" && document.hidden && !embed) { if (Notification.permission === "granted" && document.hidden && !embed) {
var notification = new Notification("Now Playing", {body: title, icon: "https://i.ytimg.com/vi/"+id+"/mqdefault.jpg", iconUrl: "http://i.ytimg.com/vi/"+id+"/mqdefault.jpg"}); var notification = new Notification("Now Playing", {body: title, icon: "https://img.youtube.com/vi/"+id+"/mqdefault.jpg", iconUrl: "http://img.youtube.com/vi/"+id+"/mqdefault.jpg"});
notification.onclick = function(x) { window.focus(); this.cancel(); }; notification.onclick = function(x) { window.focus(); this.cancel(); };
setTimeout(function(){ setTimeout(function(){
notification.close(); notification.close();