Mobile 'hack'

This commit is contained in:
Kasper Rynning-Tønnesen
2017-06-02 11:03:00 +02:00
parent a85623dbbf
commit 7f13a71771
4 changed files with 102 additions and 41 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -59,6 +59,7 @@ var prev_chan_player = "";
var chromecastReady = false; var chromecastReady = false;
var found_array = []; var found_array = [];
var found_array_index = 0; var found_array_index = 0;
var guid = "";
var castSession; var castSession;
var width_timeout; var width_timeout;
var tap_target_timeout; var tap_target_timeout;
@@ -125,6 +126,12 @@ $().ready(function(){
initfp(); initfp();
} }
if(Helper.mobilecheck()) {
socket.on("guid", function(msg) {
guid = msg;
});
}
socket.on("connect", function(){ socket.on("connect", function(){
if(connect_error){ if(connect_error){
connect_error = false; connect_error = false;
@@ -399,44 +406,49 @@ initializeCastApi = function() {
Helper.log(event.sessionState); Helper.log(event.sessionState);
switch (event.sessionState) { switch (event.sessionState) {
case cast.framework.SessionState.SESSION_STARTED: case cast.framework.SessionState.SESSION_STARTED:
castSession = cast.framework.CastContext.getInstance().getCurrentSession(); castSession = cast.framework.CastContext.getInstance().getCurrentSession();
castSession.addMessageListener("urn:x-cast:zoff.me", chromecastListener) castSession.addMessageListener("urn:x-cast:zoff.me", chromecastListener)
chrome.cast.media.GenericMediaMetadata({title:song_title, image: 'https://img.youtube.com/vi/'+video_id+'/mqdefault.jpg'}); chrome.cast.media.GenericMediaMetadata({title:song_title, image: 'https://img.youtube.com/vi/'+video_id+'/mqdefault.jpg'});
chrome.cast.Image('https://img.youtube.com/vi/'+video_id+'/mqdefault.jpg'); chrome.cast.Image('https://img.youtube.com/vi/'+video_id+'/mqdefault.jpg');
chromecastAvailable = true; chromecastAvailable = true;
paused = false; paused = false;
mobile_beginning = false; mobile_beginning = false;
var _seekTo; var _seekTo;
try{ try{
_seekTo = Player.player.getCurrentTime(); _seekTo = Player.player.getCurrentTime();
} catch(e){ } catch(e){
_seekTo = seekTo; _seekTo = seekTo;
} }
castSession.sendMessage("urn:x-cast:zoff.me", {type: "loadVideo", videoId: video_id, seekTo: _seekTo}) castSession.sendMessage("urn:x-cast:zoff.me", {type: "loadVideo", videoId: video_id, seekTo: _seekTo})
castSession.sendMessage("urn:x-cast:zoff.me", {type: "nextVideo", videoId: full_playlist[0].id, title: full_playlist[0].title}) castSession.sendMessage("urn:x-cast:zoff.me", {type: "nextVideo", videoId: full_playlist[0].id, title: full_playlist[0].title})
hide_native(1);
break; if(Helper.mobilecheck()) {
castSession.sendMessage("urn:x-cast:zoff.me", {type: "mobilespecs", guid: guid, socketid: socket.id, adminpass: adminpass == "" ? "" : Crypt.crypt_pass(adminpass), channel: chan.toLowerCase(), userpass: embed ? '' : Crypt.crypt_pass(Crypt.get_userpass(chan.toLowerCase()))})
}
hide_native(1);
break;
case cast.framework.SessionState.SESSION_RESUMED: case cast.framework.SessionState.SESSION_RESUMED:
castSession = cast.framework.CastContext.getInstance().getCurrentSession(); castSession = cast.framework.CastContext.getInstance().getCurrentSession();
castSession.addMessageListener("urn:x-cast:zoff.me", chromecastListener); castSession.addMessageListener("urn:x-cast:zoff.me", chromecastListener);
chrome.cast.media.GenericMediaMetadata({title:song_title, image: 'https://img.youtube.com/vi/'+video_id+'/mqdefault.jpg'}); chrome.cast.media.GenericMediaMetadata({title:song_title, image: 'https://img.youtube.com/vi/'+video_id+'/mqdefault.jpg'});
chrome.cast.Image('https://img.youtube.com/vi/'+video_id+'/mqdefault.jpg'); chrome.cast.Image('https://img.youtube.com/vi/'+video_id+'/mqdefault.jpg');
chromecastAvailable = true; chromecastAvailable = true;
paused = false; paused = false;
mobile_beginning = false; mobile_beginning = false;
var _seekTo; var _seekTo;
try{ try{
_seekTo = Player.player.getCurrentTime(); _seekTo = Player.player.getCurrentTime();
} catch(e){ } catch(e){
_seekTo = seekTo; _seekTo = seekTo;
} }
castSession.sendMessage("urn:x-cast:zoff.me", {type: "loadVideo", videoId: video_id, seekTo: _seekTo}) castSession.sendMessage("urn:x-cast:zoff.me", {type: "loadVideo", videoId: video_id, seekTo: _seekTo})
castSession.sendMessage("urn:x-cast:zoff.me", {type: "nextVideo", videoId: full_playlist[0].id, title: full_playlist[0].title}) castSession.sendMessage("urn:x-cast:zoff.me", {type: "nextVideo", videoId: full_playlist[0].id, title: full_playlist[0].title})
hide_native(1); hide_native(1);
break; break;
case cast.framework.SessionState.SESSION_ENDED: case cast.framework.SessionState.SESSION_ENDED:
chromecastAvailable = false; chromecastAvailable = false;
hide_native(0); hide_native(0);
break; break;
} }
}); });

View File

@@ -155,6 +155,23 @@ io.on('connection', function(socket){
else else
name = names[guid]; name = names[guid];
socket.emit("guid", guid);
socket.on("chromecast", function(msg) {
try {
if(typeof(msg) == "object" && msg.hasOwnProperty("guid") && msg.hasOwnProperty("socket_id") && msg.hasOwnProperty("channel")) {
if(lists[msg.channel].indexOf(msg.guid) > -1) {
guid = msg.guid;
socketid = msg.socket_id;
coll = msg.channel;
in_list = true;
}
}
} catch(e) {
return;
}
});
socket.on("get_userlists", function(id) { socket.on("get_userlists", function(id) {
db.collection("frontpage_lists_" + id).find(function(err, docs) { db.collection("frontpage_lists_" + id).find(function(err, docs) {
socket.emit("userlists", [docs]); socket.emit("userlists", [docs]);
@@ -605,6 +622,7 @@ io.on('connection', function(socket){
io.to(coll).emit("channel", {type: "added", value: {"_id": "asd", "added":added,"guids":guids,"id":id,"now_playing":np,"title":title,"votes":votes, "duration":duration}}); io.to(coll).emit("channel", {type: "added", value: {"_id": "asd", "added":added,"guids":guids,"id":id,"now_playing":np,"title":title,"votes":votes, "duration":duration}});
} }
db.collection("frontpage_lists").update({_id:coll}, {$inc:{count:1}, $set:{accessed: get_time()}}, {upsert:true}, function(err, docs){}); db.collection("frontpage_lists").update({_id:coll}, {$inc:{count:1}, $set:{accessed: get_time()}}, {upsert:true}, function(err, docs){});
getNextSong(coll);
}); });
if(!full_list) { if(!full_list) {
socket.emit("toast", "addedsong"); socket.emit("toast", "addedsong");
@@ -1031,6 +1049,7 @@ io.on('connection', function(socket){
if(!docs){ if(!docs){
send_list(coll, undefined, false, true, false, true); send_list(coll, undefined, false, true, false, true);
socket.emit("toast", "shuffled"); socket.emit("toast", "shuffled");
return; return;
}else{ }else{
num = Math.floor(Math.random()*1000000); num = Math.floor(Math.random()*1000000);
@@ -1048,6 +1067,7 @@ io.on('connection', function(socket){
if(tot == curr) if(tot == curr)
{ {
send_list(coll, undefined, false, true, false); send_list(coll, undefined, false, true, false);
getNextSong(coll);
} }
}; };
@@ -1310,6 +1330,8 @@ function vote(coll, id, guid, socket, full_list, last) {
if((full_list && last) || (!full_list)) if((full_list && last) || (!full_list))
socket.emit("toast", "voted"); socket.emit("toast", "voted");
io.to(coll).emit("channel", {type: "vote", value: id, time: get_time()}); io.to(coll).emit("channel", {type: "vote", value: id, time: get_time()});
getNextSong(coll);
}); });
}else }else
{ {
@@ -1318,6 +1340,32 @@ function vote(coll, id, guid, socket, full_list, last) {
}); });
} }
function getNextSong(coll) {
db.collection(coll).aggregate([{
$match:{
views:{
$exists: false
},
type:{
$ne: "suggested"
}
}
}, {
$sort:{
now_playing: 1,
votes:-1,
added:1,
title: 1
}
}, {
$limit:1
}], function(err, doc) {
if(doc.length == 1) {
io.to(coll).emit("next_song", {videoId: doc[0].id, title: doc[0].title});
}
});
}
function change_song(coll, error, id) { function change_song(coll, error, id) {
db.collection(coll).find({views:{$exists:true}}, function(err, docs){ db.collection(coll).find({views:{$exists:true}}, function(err, docs){
@@ -1565,9 +1613,10 @@ function send_play(coll, socket)
if(conf[0].hasOwnProperty("userpass") && conf[0].userpass != "") conf[0].userpass = true; if(conf[0].hasOwnProperty("userpass") && conf[0].userpass != "") conf[0].userpass = true;
else conf[0].userpass = false; else conf[0].userpass = false;
toSend = {np: np, conf: conf, time: get_time()}; toSend = {np: np, conf: conf, time: get_time()};
if(socket === undefined) if(socket === undefined) {
io.to(coll).emit("np", toSend); io.to(coll).emit("np", toSend);
else{ getNextSong(coll)
} else {
socket.emit("np", toSend); socket.emit("np", toSend);
} }
} }