diff --git a/server/handlers/functions.js b/server/handlers/functions.js index 75da87e5..52ab33bc 100644 --- a/server/handlers/functions.js +++ b/server/handlers/functions.js @@ -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].userpass != undefined) userpass = d[0].userpass; - if(d[0].adminpass != undefined) adminpass = d[0].adminpass; + 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); } - 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; diff --git a/server/handlers/io.js b/server/handlers/io.js index 7b53fba4..ed2a3166 100644 --- a/server/handlers/io.js +++ b/server/handlers/io.js @@ -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) { diff --git a/server/public/assets/js/functions.js b/server/public/assets/js/functions.js index 6d5240a3..7ae15d0d 100644 --- a/server/public/assets/js/functions.js +++ b/server/public/assets/js/functions.js @@ -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()}) }) } diff --git a/server/public/assets/js/listeners.js b/server/public/assets/js/listeners.js index a5426203..da00e801 100755 --- a/server/public/assets/js/listeners.js +++ b/server/public/assets/js/listeners.js @@ -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);