Merge pull request #346 from zoff-music/feature/testing-chromecast-fixes

Feature/testing chromecast fixes
This commit is contained in:
Kasper Rynning-Tønnesen
2018-06-05 11:56:08 +02:00
committed by GitHub
4 changed files with 44 additions and 15 deletions

View File

@@ -62,6 +62,7 @@ function getSession(socket) {
var cookie = require("cookie");
var parsedCookies = cookie.parse(socket.handshake.headers.cookie);
return parsedCookies["_uI"];*/
if(socket.cookie_id == undefined) throw "Undefined error";
return socket.cookie_id;
} catch(e) {
return "empty";
@@ -252,6 +253,22 @@ function getSessionChatPass(id, callback) {
}
}
function setChromecastHost(id, other_id, list, callback) {
try {
if(id == "empty" || id == undefined) {
callback();
return;
}
connected_db.collection(id).update({_id: list}, {"chromecast": true, id: other_id}, {upsert: true}, function(e, docs) {
callback(true);
return;
});
} catch(e) {
callback(false);
}
}
function setSessionUserPass(id, userpass, list, callback) {
try {
if(id == "empty" || id == undefined) {
@@ -277,10 +294,16 @@ function getSessionAdminUser(id, list, callback) {
var userpass = "";
var adminpass = "";
if(d.length > 0) {
if(d[0].hasOwnProperty("chromecast") && d[0].chromecast) {
getSessionAdminUser(d[0].id, list, callback);
} else {
if(d[0].userpass != undefined) userpass = d[0].userpass;
if(d[0].adminpass != undefined) adminpass = d[0].adminpass;
}
callback(userpass, adminpass, true);
}
} else {
callback(userpass, adminpass, true);
}
})
} catch(e) {
callback("", "", false);
@@ -310,6 +333,7 @@ function removeSessionAdminPass(id, channel, callback) {
});
}
module.exports.setChromecastHost = setChromecastHost;
module.exports.decodeChannelName = decodeChannelName;
module.exports.encodeChannelName = encodeChannelName;
module.exports.isUrl = isUrl;

View File

@@ -82,22 +82,24 @@ module.exports = function() {
try {
if(typeof(msg) == "object" && msg.hasOwnProperty("guid") &&
msg.hasOwnProperty("socket_id") && msg.hasOwnProperty("channel") && typeof(msg.guid) == "string" &&
typeof(msg.channel) == "string" && typeof(msg.socket_id) == "string") {
typeof(msg.channel) == "string" && typeof(msg.socket_id) == "string" && msg.channel != "") {
db.collection("connected_users").find({"_id": msg.channel}, function(err, connected_users_channel) {
if(connected_users_channel.length > 0 && connected_users_channel[0].users.indexOf(msg.guid) > -1) {
socket.cookie_id = msg.guid;
guid = msg.guid;
socketid = msg.socket_id;
socket.zoff_id = socketid;
if(msg.hasOwnProperty("channel")) {
msg.channel = Functions.encodeChannelName(msg.channel);
}
coll = msg.channel.toLowerCase();//.replace(/ /g,'');
coll = Functions.removeEmojis(coll).toLowerCase();
coll = filter.clean(coll);
if(coll.indexOf("?") > -1){
coll = coll.substring(0, coll.indexOf("?"));
}
Functions.setChromecastHost(socket.cookie_id, msg.socket_id, msg.channel, function(results) {
});
//socket.cookie_id = msg.guid;
guid = msg.guid;
socketid = msg.socket_id;
socket.zoff_id = socketid;
if(msg.hasOwnProperty("channel")) {
msg.channel = Functions.encodeChannelName(msg.channel);
}
in_list = true;
chromecast_object = true;
socket.join(coll);
@@ -110,7 +112,7 @@ module.exports = function() {
});
socket.on("get_id", function() {
socket.emit("id_chromecast", Functions.getSession(socket));
socket.emit("id_chromecast", {cookie_id: Functions.getSession(socket), guid: guid});
});
socket.on("error_video", function(msg) {
@@ -674,7 +676,7 @@ module.exports = function() {
socket.emit('update_required', result);
return;
}
if(coll == undefined) return;
db.collection(coll + "_settings").find(function(err, docs) {
Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass, adminpass) {
if(userpass != "" || obj.pass == undefined) {

View File

@@ -450,7 +450,7 @@ function get_list_listener(){
});
socket.on("id_chromecast", function(msg) {
chromecast_specs_sent = true;
castSession.sendMessage("urn:x-cast:zoff.me", {type: "mobilespecs", guid: msg, socketid: socket.id})
castSession.sendMessage("urn:x-cast:zoff.me", {type: "mobilespecs", guid: msg.guid, socketid: msg.cookie_id, channel: chan.toLowerCase()})
})
}

View File

@@ -296,7 +296,7 @@ initializeCastApi = function() {
castSession.sendMessage("urn:x-cast:zoff.me", {type: "loadVideo", start: Player.np.start, end: Player.np.end, videoId: video_id, seekTo: _seekTo, channel: chan.toLowerCase(), source: videoSource, thumbnail: Player.np.thumbnail})
castSession.sendMessage("urn:x-cast:zoff.me", {type: "nextVideo", videoId: full_playlist[0].id, title: full_playlist[0].title, source: full_playlist[0].source, thumbnail: full_playlist[0].thumbnail})
if(Helper.mobilecheck() && !chromecast_specs_sent) {
if(Helper.mobilecheck()) {
socket.emit("get_id");
}
hide_native(1);
@@ -322,6 +322,9 @@ initializeCastApi = function() {
} catch(event){
_seekTo = seekTo;
}
if(Helper.mobilecheck()) {
socket.emit("get_id");
}
castSession.sendMessage("urn:x-cast:zoff.me", {type: "loadVideo", start: Player.np.start, end: Player.np.end, videoId: video_id, seekTo: _seekTo, channel: chan.toLowerCase(), source: videoSource, thumbnail: Player.np.thumbnail})
castSession.sendMessage("urn:x-cast:zoff.me", {type: "nextVideo", videoId: full_playlist[0].id, title: full_playlist[0].title, source: full_playlist[0].source, thumbnail: full_playlist[0].thumbnail})
hide_native(1);