mirror of
				https://github.com/KevinMidboe/zoff.git
				synced 2025-10-29 18:00:23 +00:00 
			
		
		
		
	More indentation
This commit is contained in:
		| @@ -1,125 +1,125 @@ | ||||
|  | ||||
| function chat(msg, guid, offline, socket) { | ||||
|   if(typeof(msg) !== 'object' && !msg.hasOwnProperty('data') && !msg.hasOwnProperty('channel') && !msg.hasOwnProperty('pass')) { | ||||
|     socket.emit('update_required'); | ||||
|     return; | ||||
|   } | ||||
|   var coll = msg.channel; | ||||
|   db.collection(coll).find({views:{$exists:true}}, function(err, docs){ | ||||
|     if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (msg.hasOwnProperty('pass') && docs[0].userpass == Functions.decrypt_string(socket.zoff_id, msg.pass)))) { | ||||
|       var data = msg.data; | ||||
|       Functions.check_inlist(coll, guid, socket, offline); | ||||
|       if(data !== "" && data !== undefined && data !== null && | ||||
|       data.length < 151 && data.replace(/\s/g, '').length){ | ||||
|         db.collection("user_names").find({"guid": guid}, function(err, docs) { | ||||
|           if(docs.length == 1) { | ||||
|             io.to(coll).emit('chat', {from: docs[0].name, msg: ": " + data}); | ||||
|           } else if(docs.length == 0){ | ||||
|             get_name(guid, {announce: false, channel: coll, message: data, all: false}); | ||||
|           } | ||||
|         }); | ||||
|       } | ||||
|     } else { | ||||
|       socket.emit('auth_required'); | ||||
|     if(typeof(msg) !== 'object' && !msg.hasOwnProperty('data') && !msg.hasOwnProperty('channel') && !msg.hasOwnProperty('pass')) { | ||||
|         socket.emit('update_required'); | ||||
|         return; | ||||
|     } | ||||
|   }); | ||||
|     var coll = msg.channel; | ||||
|     db.collection(coll).find({views:{$exists:true}}, function(err, docs){ | ||||
|         if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (msg.hasOwnProperty('pass') && docs[0].userpass == Functions.decrypt_string(socket.zoff_id, msg.pass)))) { | ||||
|             var data = msg.data; | ||||
|             Functions.check_inlist(coll, guid, socket, offline); | ||||
|             if(data !== "" && data !== undefined && data !== null && | ||||
|             data.length < 151 && data.replace(/\s/g, '').length){ | ||||
|                 db.collection("user_names").find({"guid": guid}, function(err, docs) { | ||||
|                     if(docs.length == 1) { | ||||
|                         io.to(coll).emit('chat', {from: docs[0].name, msg: ": " + data}); | ||||
|                     } else if(docs.length == 0){ | ||||
|                         get_name(guid, {announce: false, channel: coll, message: data, all: false}); | ||||
|                     } | ||||
|                 }); | ||||
|             } | ||||
|         } else { | ||||
|             socket.emit('auth_required'); | ||||
|         } | ||||
|     }); | ||||
| } | ||||
|  | ||||
| function all_chat(msg, guid, offline, socket) { | ||||
|   if(typeof(msg) !== 'object' || !msg.hasOwnProperty("channel") || !msg.hasOwnProperty("data")) { | ||||
|     socket.emit('update_required'); | ||||
|     return; | ||||
|   } | ||||
|   var coll = msg.channel; | ||||
|   var data = msg.data; | ||||
|     if(typeof(msg) !== 'object' || !msg.hasOwnProperty("channel") || !msg.hasOwnProperty("data")) { | ||||
|         socket.emit('update_required'); | ||||
|         return; | ||||
|     } | ||||
|     var coll = msg.channel; | ||||
|     var data = msg.data; | ||||
|  | ||||
|   Functions.check_inlist(coll, guid, socket, offline); | ||||
|   if(data !== "" && data !== undefined && data !== null && | ||||
|   data.length < 151 && data.replace(/\s/g, '').length){ | ||||
|     db.collection("user_names").find({"guid": guid}, function(err, docs) { | ||||
|       if(docs.length == 1) { | ||||
|         io.sockets.emit('chat.all', {from: docs[0].name, msg: ": " + data, channel: coll}); | ||||
|       } else if(docs.length == 0) { | ||||
|         get_name(guid, {announce: false, channel: coll, message: data, all: true}); | ||||
|       } | ||||
|     }); | ||||
|   } | ||||
|     Functions.check_inlist(coll, guid, socket, offline); | ||||
|     if(data !== "" && data !== undefined && data !== null && | ||||
|     data.length < 151 && data.replace(/\s/g, '').length){ | ||||
|         db.collection("user_names").find({"guid": guid}, function(err, docs) { | ||||
|             if(docs.length == 1) { | ||||
|                 io.sockets.emit('chat.all', {from: docs[0].name, msg: ": " + data, channel: coll}); | ||||
|             } else if(docs.length == 0) { | ||||
|                 get_name(guid, {announce: false, channel: coll, message: data, all: true}); | ||||
|             } | ||||
|         }); | ||||
|     } | ||||
| } | ||||
|  | ||||
| function namechange(data, guid, coll) { | ||||
|   if(typeof(data) !== "string" || coll == undefined) return; | ||||
|   data = encodeURIComponent(data).replace(/\W/g, '').replace(/[^\x00-\x7F]/g, ""); | ||||
|   db.collection("user_names").find({"guid": guid}, function(err, docs) { | ||||
|     if(docs.length == 1) { | ||||
|       if(docs[0].name == data) return; | ||||
|       var change_name = function(new_name, guid, old_name) { | ||||
|         if(new_name.length > 9) { | ||||
|           return; | ||||
|         } else { | ||||
|           db.collection("user_names").update({"_id": "all_names"}, {$addToSet: {names: new_name}}, function(err, updated) { | ||||
|             if(updated.nModified == 1) { | ||||
|               db.collection("user_names").update({"guid": guid}, {$set: {name: new_name}}, function(err, updated) { | ||||
|                 db.collection("user_names").update({"_id": "all_names"}, {$pull: {names: old_name}}, function(err, updated) {}); | ||||
|                 name = new_name; | ||||
|                 io.to(coll).emit('chat', {from: old_name, msg: " changed name to " + name}); | ||||
|                 io.sockets.emit('chat.all', {from: old_name , msg: " changed name to " + name, channel: coll}); | ||||
|               }); | ||||
|             } else { | ||||
|               change_name(new_name + "_", guid, old_name); | ||||
|     if(typeof(data) !== "string" || coll == undefined) return; | ||||
|     data = encodeURIComponent(data).replace(/\W/g, '').replace(/[^\x00-\x7F]/g, ""); | ||||
|     db.collection("user_names").find({"guid": guid}, function(err, docs) { | ||||
|         if(docs.length == 1) { | ||||
|             if(docs[0].name == data) return; | ||||
|             var change_name = function(new_name, guid, old_name) { | ||||
|                 if(new_name.length > 9) { | ||||
|                     return; | ||||
|                 } else { | ||||
|                     db.collection("user_names").update({"_id": "all_names"}, {$addToSet: {names: new_name}}, function(err, updated) { | ||||
|                         if(updated.nModified == 1) { | ||||
|                             db.collection("user_names").update({"guid": guid}, {$set: {name: new_name}}, function(err, updated) { | ||||
|                                 db.collection("user_names").update({"_id": "all_names"}, {$pull: {names: old_name}}, function(err, updated) {}); | ||||
|                                 name = new_name; | ||||
|                                 io.to(coll).emit('chat', {from: old_name, msg: " changed name to " + name}); | ||||
|                                 io.sockets.emit('chat.all', {from: old_name , msg: " changed name to " + name, channel: coll}); | ||||
|                             }); | ||||
|                         } else { | ||||
|                             change_name(new_name + "_", guid, old_name); | ||||
|                         } | ||||
|                     }); | ||||
|                 } | ||||
|             } | ||||
|           }); | ||||
|  | ||||
|             var old_name = docs[0].name; | ||||
|             change_name(data, guid, old_name); | ||||
|  | ||||
|         } | ||||
|       } | ||||
|  | ||||
|       var old_name = docs[0].name; | ||||
|       change_name(data, guid, old_name); | ||||
|  | ||||
|     } | ||||
|   }); | ||||
|     }); | ||||
| } | ||||
|  | ||||
| function removename(guid, coll) { | ||||
|   db.collection("user_names").find({"guid": guid}, function(err, docs) { | ||||
|     if(docs.length == 1) { | ||||
|       var old_name = docs[0].name; | ||||
|       db.collection("user_names").update({"_id": "all_names"}, {$pull: {names: old_name}}, function(err, updated) { | ||||
|         db.collection("user_names").remove({"guid": guid}, function(err, removed) { | ||||
|           get_name(guid, {announce: true, old_name: old_name, channel: coll}); | ||||
|         }); | ||||
|       }); | ||||
|     } | ||||
|   }); | ||||
|     db.collection("user_names").find({"guid": guid}, function(err, docs) { | ||||
|         if(docs.length == 1) { | ||||
|             var old_name = docs[0].name; | ||||
|             db.collection("user_names").update({"_id": "all_names"}, {$pull: {names: old_name}}, function(err, updated) { | ||||
|                 db.collection("user_names").remove({"guid": guid}, function(err, removed) { | ||||
|                     get_name(guid, {announce: true, old_name: old_name, channel: coll}); | ||||
|                 }); | ||||
|             }); | ||||
|         } | ||||
|     }); | ||||
| } | ||||
|  | ||||
| function generate_name(guid, announce_payload) { | ||||
|   var tmp_name = Functions.rndName(guid, 8); | ||||
|   db.collection("user_names").update({"_id": "all_names"}, {$addToSet: {names: tmp_name}}, {upsert: true}, function(err, updated) { | ||||
|     if(updated.nModified == 1 || (updated.hasOwnProperty("upserted") && n == 1)) { | ||||
|       db.collection("user_names").update({"guid": guid}, {$set: {name: tmp_name}}, {upsert: true}, function(err, update){ | ||||
|         name = tmp_name; | ||||
|         if(announce_payload.announce) { | ||||
|           io.to(announce_payload.channel).emit('chat', {from: announce_payload.old_name,  msg: " changed name to " + name}); | ||||
|           io.sockets.emit('chat.all', {from: announce_payload.old_name , msg: " changed name to " + name, channel: announce_payload.channel}); | ||||
|         } else if(announce_payload.message && !announce_payload.all) { | ||||
|           io.to(announce_payload.channel).emit('chat', {from: name, msg: ": " + announce_payload.message}); | ||||
|         } else if(announce_payload.message && announce_payload.all) { | ||||
|           io.sockets.emit('chat.all', {from: name, msg: ": " + announce_payload.message, channel: announce_payload.channel}); | ||||
|     var tmp_name = Functions.rndName(guid, 8); | ||||
|     db.collection("user_names").update({"_id": "all_names"}, {$addToSet: {names: tmp_name}}, {upsert: true}, function(err, updated) { | ||||
|         if(updated.nModified == 1 || (updated.hasOwnProperty("upserted") && n == 1)) { | ||||
|             db.collection("user_names").update({"guid": guid}, {$set: {name: tmp_name}}, {upsert: true}, function(err, update){ | ||||
|                 name = tmp_name; | ||||
|                 if(announce_payload.announce) { | ||||
|                     io.to(announce_payload.channel).emit('chat', {from: announce_payload.old_name,  msg: " changed name to " + name}); | ||||
|                     io.sockets.emit('chat.all', {from: announce_payload.old_name , msg: " changed name to " + name, channel: announce_payload.channel}); | ||||
|                 } else if(announce_payload.message && !announce_payload.all) { | ||||
|                     io.to(announce_payload.channel).emit('chat', {from: name, msg: ": " + announce_payload.message}); | ||||
|                 } else if(announce_payload.message && announce_payload.all) { | ||||
|                     io.sockets.emit('chat.all', {from: name, msg: ": " + announce_payload.message, channel: announce_payload.channel}); | ||||
|                 } | ||||
|             }); | ||||
|         } else { | ||||
|             Chat.generate_name(tmp_name, announce_payload); | ||||
|         } | ||||
|       }); | ||||
|     } else { | ||||
|       Chat.generate_name(tmp_name, announce_payload); | ||||
|     } | ||||
|   }) | ||||
|     }) | ||||
| } | ||||
|  | ||||
| function get_name(guid, announce_payload) { | ||||
|   db.collection("user_names").find({"guid": guid}, function(err, docs) { | ||||
|     if(docs.length == 0) { | ||||
|       Chat.generate_name(guid, announce_payload); | ||||
|     } else { | ||||
|       name = docs[0].name; | ||||
|     } | ||||
|   }) | ||||
|     db.collection("user_names").find({"guid": guid}, function(err, docs) { | ||||
|         if(docs.length == 0) { | ||||
|             Chat.generate_name(guid, announce_payload); | ||||
|         } else { | ||||
|             name = docs[0].name; | ||||
|         } | ||||
|     }) | ||||
| } | ||||
|  | ||||
| module.exports.chat = chat; | ||||
|   | ||||
| @@ -3,11 +3,11 @@ var mongojs = require('mongojs'); | ||||
| var db = mongojs(mongo_db_cred.config); | ||||
|  | ||||
| db.on('connected', function(err) { | ||||
| 	console.log("connected"); | ||||
|     console.log("connected"); | ||||
| }) | ||||
|  | ||||
| db.on('error',function(err) { | ||||
| 	console.log("\n" + new Date().toString() + "\n Database error: ", err); | ||||
|     console.log("\n" + new Date().toString() + "\n Database error: ", err); | ||||
| }); | ||||
|  | ||||
| module.exports = db; | ||||
|   | ||||
| @@ -1,21 +1,21 @@ | ||||
| function frontpage_lists(msg, socket) { | ||||
|   if(!msg.hasOwnProperty('version') || msg.version != VERSION || msg.version == undefined) { | ||||
|     socket.emit("update_required"); | ||||
|   } | ||||
|     if(!msg.hasOwnProperty('version') || msg.version != VERSION || msg.version == undefined) { | ||||
|         socket.emit("update_required"); | ||||
|     } | ||||
|  | ||||
|   db.collection("frontpage_lists").find({frontpage:true}, function(err, docs){ | ||||
|     db.collection("connected_users").find({"_id": "total_users"}, function(err, tot){ | ||||
|         socket.compress(true).emit("playlists", {channels: docs, viewers: tot[0].total_users}); | ||||
|      }); | ||||
|   }); | ||||
|     db.collection("frontpage_lists").find({frontpage:true}, function(err, docs){ | ||||
|         db.collection("connected_users").find({"_id": "total_users"}, function(err, tot){ | ||||
|             socket.compress(true).emit("playlists", {channels: docs, viewers: tot[0].total_users}); | ||||
|         }); | ||||
|     }); | ||||
| } | ||||
|  | ||||
| function update_frontpage(coll, id, title) { | ||||
|         db.collection("frontpage_lists").update({_id: coll}, {$set: { | ||||
|                 id: id, | ||||
|                 title: title, | ||||
|                 accessed: Functions.get_time()} | ||||
|         },{upsert: true}, function(err, returnDocs){}); | ||||
|     db.collection("frontpage_lists").update({_id: coll}, {$set: { | ||||
|         id: id, | ||||
|         title: title, | ||||
|         accessed: Functions.get_time()} | ||||
|     },{upsert: true}, function(err, returnDocs){}); | ||||
| } | ||||
|  | ||||
| module.exports.frontpage_lists = frontpage_lists; | ||||
|   | ||||
| @@ -1,124 +1,122 @@ | ||||
|  | ||||
| function remove_unique_id(short_id) { | ||||
| 	db.collection("unique_ids").update({"_id": "unique_ids"}, {$pull: {unique_ids: short_id}}, function(err, docs) {}); | ||||
|     db.collection("unique_ids").update({"_id": "unique_ids"}, {$pull: {unique_ids: short_id}}, function(err, docs) {}); | ||||
| } | ||||
|  | ||||
| function remove_name_from_db(guid, name) { | ||||
| 	db.collection("user_names").update({"_id": "all_names"}, {$pull: {names: name}}, function(err, updated) { | ||||
| 		db.collection("user_names").remove({"guid": guid}, function(err, removed) {	}); | ||||
| 	}); | ||||
|     db.collection("user_names").update({"_id": "all_names"}, {$pull: {names: name}}, function(err, updated) { | ||||
|         db.collection("user_names").remove({"guid": guid}, function(err, removed) {	}); | ||||
|     }); | ||||
| } | ||||
|  | ||||
| function remove_from_array(array, element){ | ||||
| 	if(Functions.contains(array, element)){ | ||||
| 		var index = array.indexOf(element); | ||||
| 		if(index != -1) | ||||
| 		array.splice(index, 1); | ||||
| 	} | ||||
|     if(Functions.contains(array, element)){ | ||||
|         var index = array.indexOf(element); | ||||
|         if(index != -1) | ||||
|         array.splice(index, 1); | ||||
|     } | ||||
| } | ||||
|  | ||||
| function get_short_id(socket) { | ||||
| 	var new_short_id = uniqid.time().toLowerCase(); | ||||
|     var new_short_id = uniqid.time().toLowerCase(); | ||||
|  | ||||
| 	socket.join(new_short_id); | ||||
| 	socket.emit("id", new_short_id); | ||||
|     socket.join(new_short_id); | ||||
|     socket.emit("id", new_short_id); | ||||
| } | ||||
|  | ||||
| function check_inlist(coll, guid, socket, offline) | ||||
| { | ||||
| 	if(!offline && coll != undefined){ | ||||
| 		db.collection("connected_users").update({"_id": coll}, {$addToSet:{users: guid}}, {upsert: true}, function(err, updated) { | ||||
| 			if(updated.nModified > 0) { | ||||
| 				db.collection("connected_users").find({"_id": coll}, function(err, new_doc) { | ||||
| 					db.collection("frontpage_lists").update({"_id": coll}, {$set: {"viewers": new_doc[0].users.length}}, function(){ | ||||
|                       if(new_doc[0].users == undefined || new_doc[0].users.length == undefined) { | ||||
|                           io.to(coll).emit("viewers", 1); | ||||
|                       } else { | ||||
| 	                    io.to(coll).emit("viewers", new_doc[0].users.length); | ||||
|                       } | ||||
| 						db.collection("user_names").find({"guid": guid}, function(err, docs) { | ||||
| 							if(docs.length == 1) { | ||||
| 								socket.broadcast.to(coll).emit('chat', {from: docs[0].name, msg: " joined"}); | ||||
| 							} | ||||
| 						}); | ||||
|     if(!offline && coll != undefined){ | ||||
|         db.collection("connected_users").update({"_id": coll}, {$addToSet:{users: guid}}, {upsert: true}, function(err, updated) { | ||||
|             if(updated.nModified > 0) { | ||||
|                 db.collection("connected_users").find({"_id": coll}, function(err, new_doc) { | ||||
|                     db.collection("frontpage_lists").update({"_id": coll}, {$set: {"viewers": new_doc[0].users.length}}, function(){ | ||||
|                         if(new_doc[0].users == undefined || new_doc[0].users.length == undefined) { | ||||
|                             io.to(coll).emit("viewers", 1); | ||||
|                         } else { | ||||
|                             io.to(coll).emit("viewers", new_doc[0].users.length); | ||||
|                         } | ||||
|                         db.collection("user_names").find({"guid": guid}, function(err, docs) { | ||||
|                             if(docs.length == 1) { | ||||
|                                 socket.broadcast.to(coll).emit('chat', {from: docs[0].name, msg: " joined"}); | ||||
|                             } | ||||
|                         }); | ||||
|  | ||||
| 						db.collection("connected_users").update({"_id": "total_users"}, {$inc: {total_users: 1}}, function(err, docs){}); | ||||
| 					}); | ||||
| 				}); | ||||
| 			} | ||||
| 		}); | ||||
|                         db.collection("connected_users").update({"_id": "total_users"}, {$inc: {total_users: 1}}, function(err, docs){}); | ||||
|                     }); | ||||
|                 }); | ||||
|             } | ||||
|         }); | ||||
|  | ||||
| 	} else { | ||||
| 		db.collection("connected_users").update({"_id": coll}, {$addToSet: {users: guid}}, function(err, docs){}); | ||||
| 		db.collection("connected_users").update({"_id": "total_users"}, {$inc: {total_users: 1}}, function(err, docs) {}); | ||||
| 	} | ||||
|     } else { | ||||
|         db.collection("connected_users").update({"_id": coll}, {$addToSet: {users: guid}}, function(err, docs){}); | ||||
|         db.collection("connected_users").update({"_id": "total_users"}, {$inc: {total_users: 1}}, function(err, docs) {}); | ||||
|     } | ||||
| } | ||||
|  | ||||
| function rndName(seed, len) { | ||||
| 	var vowels = ['a', 'e', 'i', 'o', 'u']; | ||||
| 	consts =  ['b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'r', 's', 't', 'v', 'w', 'x', 'y']; | ||||
| 	len = Math.floor(len); | ||||
| 	word = ''; | ||||
| 	is_vowel = false; | ||||
| 	var arr; | ||||
| 	for (var i = 0; i < len; i++) { | ||||
| 		if (is_vowel) arr = vowels; | ||||
| 		else arr = consts; | ||||
| 		is_vowel = !is_vowel; | ||||
| 		word += arr[(seed[i%seed.length].charCodeAt()+i) % (arr.length-1)]; | ||||
| 	} | ||||
| 	return word; | ||||
|     var vowels = ['a', 'e', 'i', 'o', 'u']; | ||||
|     consts =  ['b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'r', 's', 't', 'v', 'w', 'x', 'y']; | ||||
|     len = Math.floor(len); | ||||
|     word = ''; | ||||
|     is_vowel = false; | ||||
|     var arr; | ||||
|     for (var i = 0; i < len; i++) { | ||||
|         if (is_vowel) arr = vowels; | ||||
|         else arr = consts; | ||||
|         is_vowel = !is_vowel; | ||||
|         word += arr[(seed[i%seed.length].charCodeAt()+i) % (arr.length-1)]; | ||||
|     } | ||||
|     return word; | ||||
| } | ||||
|  | ||||
| function decrypt_string(socket_id, pw){ | ||||
| 	try { | ||||
| 		var input = pw.split("$"); | ||||
| 		pw = input[0]; | ||||
| 		var testKey = ((new Buffer(socket_id).toString('base64')) + (new Buffer(socket_id).toString('base64'))).substring(0,32); | ||||
| 		var keyNew = (new Buffer(testKey)).toString('base64'); | ||||
| 		var encrypted = CryptoJS.enc.Base64.parse(pw); | ||||
| 		var key = CryptoJS.enc.Base64.parse(keyNew); | ||||
| 		var iv = CryptoJS.enc.Base64.parse(input[1]); | ||||
| 		var decrypted = CryptoJS.enc.Utf8.stringify( | ||||
| 			CryptoJS.AES.decrypt({ | ||||
| 				ciphertext: encrypted | ||||
| 			}, | ||||
|     	key, | ||||
|      // edit: changed to Pkcs5 | ||||
|     	{ | ||||
| 				mode: CryptoJS.mode.CBC, | ||||
| 				padding: CryptoJS.pad.Pkcs7, | ||||
| 				iv: iv, | ||||
| 			})); | ||||
| 			return decrypted; | ||||
| 	} catch(e) { | ||||
| 		return ""; | ||||
| 	} | ||||
|     try { | ||||
|         var input = pw.split("$"); | ||||
|         pw = input[0]; | ||||
|         var testKey = ((new Buffer(socket_id).toString('base64')) + (new Buffer(socket_id).toString('base64'))).substring(0,32); | ||||
|         var keyNew = (new Buffer(testKey)).toString('base64'); | ||||
|         var encrypted = CryptoJS.enc.Base64.parse(pw); | ||||
|         var key = CryptoJS.enc.Base64.parse(keyNew); | ||||
|         var iv = CryptoJS.enc.Base64.parse(input[1]); | ||||
|         var decrypted = CryptoJS.enc.Utf8.stringify( | ||||
|             CryptoJS.AES.decrypt({ | ||||
|                 ciphertext: encrypted | ||||
|             }, key, { | ||||
|                 mode: CryptoJS.mode.CBC, | ||||
|                 padding: CryptoJS.pad.Pkcs7, | ||||
|                 iv: iv, | ||||
|             }) | ||||
|         ); | ||||
|         return decrypted; | ||||
|     } catch(e) { | ||||
|         return ""; | ||||
|     } | ||||
| } | ||||
|  | ||||
| function get_time() | ||||
| { | ||||
| 	var d = new Date(); | ||||
| 	var time = Math.floor(d.getTime() / 1000); | ||||
| 	return time; | ||||
|     var d = new Date(); | ||||
|     var time = Math.floor(d.getTime() / 1000); | ||||
|     return time; | ||||
| } | ||||
|  | ||||
| function contains(a, obj) { | ||||
| 	try{ | ||||
| 		var i = a.length; | ||||
| 		while (i--) { | ||||
| 			if (a[i] === obj) { | ||||
| 				return true; | ||||
| 			} | ||||
| 		} | ||||
| 		return false; | ||||
| 	}catch(e){ | ||||
| 		return false; | ||||
| 	} | ||||
|     try{ | ||||
|         var i = a.length; | ||||
|         while (i--) { | ||||
|             if (a[i] === obj) { | ||||
|                 return true; | ||||
|             } | ||||
|         } | ||||
|         return false; | ||||
|     }catch(e){ | ||||
|         return false; | ||||
|     } | ||||
| } | ||||
|  | ||||
| function hash_pass(adminpass) { | ||||
| 	return crypto.createHash('sha256').update(adminpass).digest('base64'); | ||||
|     return crypto.createHash('sha256').update(adminpass).digest('base64'); | ||||
| } | ||||
|  | ||||
| module.exports.remove_unique_id = remove_unique_id; | ||||
|   | ||||
| @@ -1,381 +1,359 @@ | ||||
| module.exports = function() { | ||||
| 	io.on('connection', function(socket){ | ||||
| 		socket.zoff_id = socket.id; | ||||
| 		socket.emit("get_list"); | ||||
|     io.on('connection', function(socket){ | ||||
|         socket.zoff_id = socket.id; | ||||
|         socket.emit("get_list"); | ||||
|  | ||||
| 		var guid = Functions.hash_pass(socket.handshake.headers["user-agent"] + socket.handshake.address + socket.handshake.headers["accept-language"]); | ||||
|         var guid = Functions.hash_pass(socket.handshake.headers["user-agent"] + socket.handshake.address + socket.handshake.headers["accept-language"]); | ||||
|  | ||||
| 		socket.on('close', function() { | ||||
| 		}); | ||||
|         socket.on('close', function() { | ||||
|         }); | ||||
|  | ||||
| 		socket.on('pinging', function() { | ||||
| 			socket.emit("ok"); | ||||
| 		}); | ||||
|         socket.on('pinging', function() { | ||||
|             socket.emit("ok"); | ||||
|         }); | ||||
|  | ||||
| 		var ping_timeout; | ||||
| 		var socketid = socket.zoff_id; | ||||
| 		var coll; | ||||
| 		var in_list = false; | ||||
| 	    var name = ""; | ||||
| 		var short_id; | ||||
| 		Chat.get_name(guid, {announce: false}); | ||||
| 		var offline = false; | ||||
| 		var chromecast_object = false; | ||||
|         var ping_timeout; | ||||
|         var socketid = socket.zoff_id; | ||||
|         var coll; | ||||
|         var in_list = false; | ||||
|         var name = ""; | ||||
|         var short_id; | ||||
|         Chat.get_name(guid, {announce: false}); | ||||
|         var offline = false; | ||||
|         var chromecast_object = false; | ||||
|  | ||||
| 		socket.emit("guid", guid); | ||||
|         socket.emit("guid", guid); | ||||
|  | ||||
| 		socket.on('self_ping', function(msg) { | ||||
| 			var channel = msg.channel; | ||||
| 			if(offline) { | ||||
| 				db.collection("connected_users").update({"_id": "offline_users"}, {$addToSet: {users: guid}}, {upsert: true}, function(err, docs){}); | ||||
| 			} else { | ||||
| 				db.collection("connected_users").update({"_id": channel}, {$addToSet: {users: guid}}, {upsert: true}, function(err, docs){ | ||||
| 					db.collection("frontpage_lists").update({"_id": channel}, {$inc: {viewers: 1}}, {upsert: true}, function(){}); | ||||
| 				}); | ||||
| 			} | ||||
| 			/*if(name != "") { | ||||
| 				db.collection("user_names").update({"_id": "all_names"}, {$addToSet: {names: name}}, {upsert: true}, function(err, updated) { | ||||
| 					if(updated.nModified == 1) { | ||||
| 						db.collection("user_names").update({"guid": guid}, {$set: {name: name}}, {upsert:true}, function(err, update){}); | ||||
| 					} | ||||
| 				}); | ||||
| 			}*/ | ||||
| 			db.collection("connected_users").update({"_id": "total_users"}, {$inc: {total_users: 1}}, {upsert: true}, function(err, docs){}); | ||||
| 		}); | ||||
|         socket.on('self_ping', function(msg) { | ||||
|             var channel = msg.channel; | ||||
|             if(offline) { | ||||
|                 db.collection("connected_users").update({"_id": "offline_users"}, {$addToSet: {users: guid}}, {upsert: true}, function(err, docs){}); | ||||
|             } else { | ||||
|                 db.collection("connected_users").update({"_id": channel}, {$addToSet: {users: guid}}, {upsert: true}, function(err, docs){ | ||||
|                     db.collection("frontpage_lists").update({"_id": channel}, {$inc: {viewers: 1}}, {upsert: true}, function(){}); | ||||
|                 }); | ||||
|             } | ||||
|  | ||||
| 		socket.on('chromecast', function(msg) { | ||||
| 			try { | ||||
| 				if(typeof(msg) == "object" && msg.hasOwnProperty("guid") && msg.hasOwnProperty("socket_id") && msg.hasOwnProperty("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) { | ||||
| 							guid = msg.guid; | ||||
| 							socketid = msg.socket_id; | ||||
| 							socket.zoff_id = socketid; | ||||
| 							coll = msg.channel; | ||||
| 							in_list = true; | ||||
| 							chromecast_object = true; | ||||
| 							socket.join(coll); | ||||
| 						} | ||||
| 					}); | ||||
| 				} | ||||
| 			} catch(e) { | ||||
| 				return; | ||||
| 			} | ||||
| 		}); | ||||
|             db.collection("connected_users").update({"_id": "total_users"}, {$inc: {total_users: 1}}, {upsert: true}, function(err, docs){}); | ||||
|         }); | ||||
|  | ||||
| 		socket.on("get_spread", function(){ | ||||
| 			db.collection("connected_users").find({"_id": "total_users"}, function(err, tot) { | ||||
| 	            db.collection("connected_users").find({"_id": "offline_users"}, function(err, off) { | ||||
| 					db.collection("connected_users").find({"_id": {$ne: "total_users"}, "_id": {$ne: "offline_users"}}, function(err, users_list) { | ||||
| 	                    if(tot.length > 0 && off.length == 0) { | ||||
| 	                        socket.emit("spread_listeners", {offline: 0, total: tot[0].total_users, online_users: users_list}); | ||||
| 	                    } else if(tot.length > 0 && off.length > 0){ | ||||
| 							socket.emit("spread_listeners", {offline: off[0].users.length, total: tot[0].total_users, online_users: users_list}); | ||||
| 						} | ||||
| 					}); | ||||
| 	            }); | ||||
| 			}); | ||||
| 		}); | ||||
|         socket.on('chromecast', function(msg) { | ||||
|             try { | ||||
|                 if(typeof(msg) == "object" && msg.hasOwnProperty("guid") && msg.hasOwnProperty("socket_id") && msg.hasOwnProperty("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) { | ||||
|                             guid = msg.guid; | ||||
|                             socketid = msg.socket_id; | ||||
|                             socket.zoff_id = socketid; | ||||
|                             coll = msg.channel; | ||||
|                             in_list = true; | ||||
|                             chromecast_object = true; | ||||
|                             socket.join(coll); | ||||
|                         } | ||||
|                     }); | ||||
|                 } | ||||
|             } catch(e) { | ||||
|                 return; | ||||
|             } | ||||
|         }); | ||||
|  | ||||
| 		socket.on('suggest_thumbnail', function(msg){ | ||||
| 			Suggestions.thumbnail(msg, coll, guid, offline, socket); | ||||
| 		}); | ||||
|         socket.on("get_spread", function(){ | ||||
|             db.collection("connected_users").find({"_id": "total_users"}, function(err, tot) { | ||||
|                 db.collection("connected_users").find({"_id": "offline_users"}, function(err, off) { | ||||
|                     db.collection("connected_users").find({"_id": {$ne: "total_users"}, "_id": {$ne: "offline_users"}}, function(err, users_list) { | ||||
|                         if(tot.length > 0 && off.length == 0) { | ||||
|                             socket.emit("spread_listeners", {offline: 0, total: tot[0].total_users, online_users: users_list}); | ||||
|                         } else if(tot.length > 0 && off.length > 0){ | ||||
|                             socket.emit("spread_listeners", {offline: off[0].users.length, total: tot[0].total_users, online_users: users_list}); | ||||
|                         } | ||||
|                     }); | ||||
|                 }); | ||||
|             }); | ||||
|         }); | ||||
|  | ||||
| 		socket.on('suggest_description', function(msg){ | ||||
| 			Suggestions.description(msg, coll, guid, offline, socket); | ||||
| 		}); | ||||
|         socket.on('suggest_thumbnail', function(msg){ | ||||
|             Suggestions.thumbnail(msg, coll, guid, offline, socket); | ||||
|         }); | ||||
|  | ||||
| 		socket.on("offline", function(msg){ | ||||
| 			if(!msg.hasOwnProperty('status') && !msg.hasOwnProperty('channel')) { | ||||
| 				socket.emit("update_required"); | ||||
| 				return; | ||||
| 			} | ||||
| 			var status = msg.status; | ||||
| 			var channel = msg.channel; | ||||
| 			if(status){ | ||||
| 				in_list = false; | ||||
| 				offline = true; | ||||
| 				if(channel != "") coll = channel; | ||||
| 				if(coll !== undefined) { | ||||
| 					db.collection("connected_users").findAndModify({ | ||||
| 						query: {"_id": coll}, | ||||
| 						update: {$pull: {users: guid}}, | ||||
| 						upsert: true, | ||||
| 					}, function(err, updated) { | ||||
| 						if(updated.nModified > 0) { | ||||
| 							io.to(coll).emit("viewers", updated.users); | ||||
| 							db.collection("connected_users").update({"_id": "total_users"}, {$inc: {total_users: -1}}, function(err, docs){}); | ||||
| 						} | ||||
| 						Functions.remove_name_from_db(guid, name); | ||||
| 					}); | ||||
| 				} | ||||
|         socket.on('suggest_description', function(msg){ | ||||
|             Suggestions.description(msg, coll, guid, offline, socket); | ||||
|         }); | ||||
|  | ||||
| 				Functions.remove_unique_id(short_id); | ||||
|         socket.on("offline", function(msg){ | ||||
|             if(!msg.hasOwnProperty('status') && !msg.hasOwnProperty('channel')) { | ||||
|                 socket.emit("update_required"); | ||||
|                 return; | ||||
|             } | ||||
|             var status = msg.status; | ||||
|             var channel = msg.channel; | ||||
|             if(status){ | ||||
|                 in_list = false; | ||||
|                 offline = true; | ||||
|                 if(channel != "") coll = channel; | ||||
|                 if(coll !== undefined) { | ||||
|                     db.collection("connected_users").findAndModify({ | ||||
|                         query: {"_id": coll}, | ||||
|                         update: {$pull: {users: guid}}, | ||||
|                         upsert: true, | ||||
|                     }, function(err, updated) { | ||||
|                         if(updated.nModified > 0) { | ||||
|                             io.to(coll).emit("viewers", updated.users); | ||||
|                             db.collection("connected_users").update({"_id": "total_users"}, {$inc: {total_users: -1}}, function(err, docs){}); | ||||
|                         } | ||||
|                         Functions.remove_name_from_db(guid, name); | ||||
|                     }); | ||||
|                 } | ||||
|  | ||||
| 				db.collection("connected_users").update({"_id": "offline_users"}, {$addToSet: {users: guid}}, function(err, docs) {}); | ||||
| 				db.collection("connected_users").update({"_id": "total_users"}, {$inc: {total_users: 1}}, function(err, docs) {}); | ||||
| 			} else { | ||||
| 				offline = false; | ||||
| 				db.collection("connected_users").update({"_id": "offline_users"}, {$pull: {users: guid}}, function(err, docs) { | ||||
| 					Functions.check_inlist(coll, guid, socket, offline); | ||||
| 				}); | ||||
| 			} | ||||
| 		}); | ||||
|                 Functions.remove_unique_id(short_id); | ||||
|  | ||||
| 		/*socket.on('namechange', function(msg) | ||||
| 		{ | ||||
| 	        if(coll == undefined) { | ||||
| 	            coll = msg.channel; | ||||
| 	        } | ||||
| 			Chat.namechange(msg.name, guid, coll, function(new_name) { | ||||
| 				name = new_name; | ||||
| 			}); | ||||
| 		}); | ||||
|                 db.collection("connected_users").update({"_id": "offline_users"}, {$addToSet: {users: guid}}, function(err, docs) {}); | ||||
|                 db.collection("connected_users").update({"_id": "total_users"}, {$inc: {total_users: 1}}, function(err, docs) {}); | ||||
|             } else { | ||||
|                 offline = false; | ||||
|                 db.collection("connected_users").update({"_id": "offline_users"}, {$pull: {users: guid}}, function(err, docs) { | ||||
|                     Functions.check_inlist(coll, guid, socket, offline); | ||||
|                 }); | ||||
|             } | ||||
|         }); | ||||
|          | ||||
|         socket.on('chat', function (msg) { | ||||
|             Chat.chat(msg, guid, offline, socket); | ||||
|         }); | ||||
|  | ||||
| 		socket.on('removename', function() | ||||
| 		{ | ||||
| 			Chat.removename(guid, coll); | ||||
| 			name = ""; | ||||
| 		});*/ | ||||
|         socket.on("all,chat", function(data) | ||||
|         { | ||||
|             Chat.all_chat(data, guid, offline, socket); | ||||
|         }); | ||||
|  | ||||
| 		socket.on('chat', function (msg) { | ||||
| 			Chat.chat(msg, guid, offline, socket); | ||||
| 		}); | ||||
|         socket.on('frontpage_lists', function(msg) | ||||
|         { | ||||
|             Frontpage.frontpage_lists(msg, socket); | ||||
|         }); | ||||
|  | ||||
| 		socket.on("all,chat", function(data) | ||||
| 		{ | ||||
| 			Chat.all_chat(data, guid, offline, socket); | ||||
| 		}); | ||||
|         socket.on('now_playing', function(list, fn) | ||||
|         { | ||||
|             List.now_playing(list, fn, socket); | ||||
|         }); | ||||
|  | ||||
| 		socket.on('frontpage_lists', function(msg) | ||||
| 		{ | ||||
| 			Frontpage.frontpage_lists(msg, socket); | ||||
| 		}); | ||||
|         socket.on('id', function(arr) | ||||
|         { | ||||
|             if(typeof(arr) == 'object') | ||||
|             io.to(arr.id).emit(arr.id.toLowerCase(), {type: arr.type, value: arr.value}); | ||||
|         }); | ||||
|  | ||||
| 		socket.on('now_playing', function(list, fn) | ||||
| 		{ | ||||
| 			List.now_playing(list, fn, socket); | ||||
| 		}); | ||||
|         socket.on('list', function(msg) | ||||
|         { | ||||
|             try { | ||||
|                 var _list = msg.channel; | ||||
|                 if(_list.length == 0) return; | ||||
|                 coll = emojiStrip(_list).toLowerCase(); | ||||
|                 coll = coll.replace("_", ""); | ||||
|                 coll = encodeURIComponent(coll).replace(/\W/g, ''); | ||||
|                 coll = filter.clean(coll); | ||||
|             } catch(e) { | ||||
|                 return; | ||||
|             } | ||||
|             List.list(msg, guid, coll, offline, socket); | ||||
|             Functions.get_short_id(socket); | ||||
|         }); | ||||
|  | ||||
| 		socket.on('id', function(arr) | ||||
| 		{ | ||||
| 			if(typeof(arr) == 'object') | ||||
| 			io.to(arr.id).emit(arr.id.toLowerCase(), {type: arr.type, value: arr.value}); | ||||
| 		}); | ||||
|         socket.on('end', function(obj) | ||||
|         { | ||||
|             if(coll === undefined) { | ||||
|                 try { | ||||
|                     coll = obj.channel; | ||||
|                     if(coll.length == 0) return; | ||||
|                     coll = emojiStrip(coll).toLowerCase(); | ||||
|                     coll = coll.replace("_", ""); | ||||
|                     coll = encodeURIComponent(coll).replace(/\W/g, ''); | ||||
|                     coll = filter.clean(coll); | ||||
|                 } catch(e) { | ||||
|                     return; | ||||
|                 } | ||||
|             } | ||||
|             List.end(obj, coll, guid, offline, socket); | ||||
|         }); | ||||
|  | ||||
| 		socket.on('list', function(msg) | ||||
| 		{ | ||||
| 			try { | ||||
| 		      var _list = msg.channel; | ||||
| 		      if(_list.length == 0) return; | ||||
| 		      coll = emojiStrip(_list).toLowerCase(); | ||||
| 		      coll = coll.replace("_", ""); | ||||
| 		      coll = encodeURIComponent(coll).replace(/\W/g, ''); | ||||
| 		      coll = filter.clean(coll); | ||||
| 		    } catch(e) { | ||||
| 		      return; | ||||
| 		    } | ||||
| 			List.list(msg, guid, coll, offline, socket); | ||||
| 			Functions.get_short_id(socket); | ||||
| 		}); | ||||
|         socket.on('add', function(arr) | ||||
|         { | ||||
|             if(coll !== undefined) { | ||||
|                 try { | ||||
|                     coll = arr.list; | ||||
|                     if(coll.length == 0) return; | ||||
|                     coll = emojiStrip(coll).toLowerCase(); | ||||
|                     coll = coll.replace("_", ""); | ||||
|                     coll = encodeURIComponent(coll).replace(/\W/g, ''); | ||||
|                     coll = filter.clean(coll); | ||||
|                 } catch(e) { | ||||
|                     return; | ||||
|                 } | ||||
|             } | ||||
|             ListChange.add_function(arr, coll, guid, offline, socket); | ||||
|         }); | ||||
|  | ||||
| 		socket.on('end', function(obj) | ||||
| 		{ | ||||
| 			if(coll === undefined) { | ||||
| 	      try { | ||||
| 	        coll = obj.channel; | ||||
| 	        if(coll.length == 0) return; | ||||
| 	        coll = emojiStrip(coll).toLowerCase(); | ||||
| 	        coll = coll.replace("_", ""); | ||||
| 	        coll = encodeURIComponent(coll).replace(/\W/g, ''); | ||||
| 	        coll = filter.clean(coll); | ||||
| 	      } catch(e) { | ||||
| 	        return; | ||||
| 	      } | ||||
| 	    } | ||||
| 			List.end(obj, coll, guid, offline, socket); | ||||
| 		}); | ||||
|         socket.on('delete_all', function(msg) { | ||||
|             if(coll !== undefined) { | ||||
|                 try { | ||||
|                     coll = msg.channel; | ||||
|                     if(coll.length == 0) return; | ||||
|                     coll = emojiStrip(coll).toLowerCase(); | ||||
|                     coll = coll.replace("_", ""); | ||||
|                     coll = encodeURIComponent(coll).replace(/\W/g, ''); | ||||
|                     coll = filter.clean(coll); | ||||
|                 } catch(e) { | ||||
|                     return; | ||||
|                 } | ||||
|             } | ||||
|  | ||||
| 		socket.on('add', function(arr) | ||||
| 		{ | ||||
| 			if(coll !== undefined) { | ||||
| 	      try { | ||||
| 	        coll = arr.list; | ||||
| 	        if(coll.length == 0) return; | ||||
| 	        coll = emojiStrip(coll).toLowerCase(); | ||||
| 	        coll = coll.replace("_", ""); | ||||
| 	        coll = encodeURIComponent(coll).replace(/\W/g, ''); | ||||
| 	        coll = filter.clean(coll); | ||||
| 	      } catch(e) { | ||||
| 	        return; | ||||
| 	      } | ||||
| 	    } | ||||
| 			ListChange.add_function(arr, coll, guid, offline, socket); | ||||
| 		}); | ||||
|             ListChange.delete_all(msg, coll, guid, offline, socket); | ||||
|         }); | ||||
|  | ||||
| 		socket.on('delete_all', function(msg) { | ||||
| 			if(coll !== undefined) { | ||||
| 				try { | ||||
| 					coll = msg.channel; | ||||
| 					if(coll.length == 0) return; | ||||
| 					coll = emojiStrip(coll).toLowerCase(); | ||||
| 					coll = coll.replace("_", ""); | ||||
| 					coll = encodeURIComponent(coll).replace(/\W/g, ''); | ||||
| 					coll = filter.clean(coll); | ||||
| 				} catch(e) { | ||||
| 					return; | ||||
| 				} | ||||
| 			} | ||||
|         socket.on('vote', function(msg) | ||||
|         { | ||||
|             if(coll !== undefined) { | ||||
|                 try { | ||||
|                     coll = msg.channel; | ||||
|                     if(coll.length == 0) return; | ||||
|                     coll = emojiStrip(coll).toLowerCase(); | ||||
|                     coll = coll.replace("_", ""); | ||||
|                     coll = encodeURIComponent(coll).replace(/\W/g, ''); | ||||
|                     coll = filter.clean(coll); | ||||
|                 } catch(e) { | ||||
|                     return; | ||||
|                 } | ||||
|             } | ||||
|             ListChange.voteUndecided(msg, coll, guid, offline, socket); | ||||
|         }); | ||||
|  | ||||
| 			ListChange.delete_all(msg, coll, guid, offline, socket); | ||||
| 		}); | ||||
|         socket.on('password', function(inp) | ||||
|         { | ||||
|             ListSettings.password(inp, coll, guid, offline, socket); | ||||
|         }); | ||||
|  | ||||
| 		socket.on('vote', function(msg) | ||||
| 		{ | ||||
| 			if(coll !== undefined) { | ||||
| 	      try { | ||||
| 	        coll = msg.channel; | ||||
| 	        if(coll.length == 0) return; | ||||
| 	        coll = emojiStrip(coll).toLowerCase(); | ||||
| 	        coll = coll.replace("_", ""); | ||||
| 	        coll = encodeURIComponent(coll).replace(/\W/g, ''); | ||||
| 	        coll = filter.clean(coll); | ||||
| 	      } catch(e) { | ||||
| 	        return; | ||||
| 	      } | ||||
| 	    } | ||||
| 			ListChange.voteUndecided(msg, coll, guid, offline, socket); | ||||
| 		}); | ||||
|         socket.on('skip', function(list) | ||||
|         { | ||||
|             if(coll !== undefined) { | ||||
|                 try { | ||||
|                     coll = list.channel; | ||||
|                     if(coll.length == 0) return; | ||||
|                     coll = emojiStrip(coll).toLowerCase(); | ||||
|                     coll = coll.replace("_", ""); | ||||
|                     coll = encodeURIComponent(coll).replace(/\W/g, ''); | ||||
|                     coll = filter.clean(coll); | ||||
|                 } catch(e) { | ||||
|                     return; | ||||
|                 } | ||||
|             } | ||||
|             List.skip(list, guid, coll, offline, socket); | ||||
|         }); | ||||
|  | ||||
| 		socket.on('password', function(inp) | ||||
| 		{ | ||||
| 			ListSettings.password(inp, coll, guid, offline, socket); | ||||
| 		}); | ||||
|         socket.on('conf', function(params) | ||||
|         { | ||||
|             ListSettings.conf_function(params, coll, guid, offline, socket); | ||||
|         }); | ||||
|  | ||||
| 		socket.on('skip', function(list) | ||||
| 		{ | ||||
| 			if(coll !== undefined) { | ||||
| 	      try { | ||||
| 	        coll = list.channel; | ||||
| 	        if(coll.length == 0) return; | ||||
| 	        coll = emojiStrip(coll).toLowerCase(); | ||||
| 	        coll = coll.replace("_", ""); | ||||
| 	        coll = encodeURIComponent(coll).replace(/\W/g, ''); | ||||
| 	        coll = filter.clean(coll); | ||||
| 	      } catch(e) { | ||||
| 	        return; | ||||
| 	      } | ||||
| 	    } | ||||
| 			List.skip(list, guid, coll, offline, socket); | ||||
| 		}); | ||||
|         socket.on('shuffle', function(msg) | ||||
|         { | ||||
|             if(coll !== undefined) { | ||||
|                 try { | ||||
|                     coll = msg.channel; | ||||
|                     if(coll.length == 0) return; | ||||
|                     coll = emojiStrip(coll).toLowerCase(); | ||||
|                     coll = coll.replace("_", ""); | ||||
|                     coll = encodeURIComponent(coll).replace(/\W/g, ''); | ||||
|                     coll = filter.clean(coll); | ||||
|                 } catch(e) { | ||||
|                     return; | ||||
|                 } | ||||
|             } | ||||
|             ListChange.shuffle(msg, coll, guid, offline, socket); | ||||
|         }); | ||||
|  | ||||
| 		socket.on('conf', function(params) | ||||
| 		{ | ||||
| 			ListSettings.conf_function(params, coll, guid, offline, socket); | ||||
| 		}); | ||||
|         socket.on('change_channel', function(obj) | ||||
|         { | ||||
|             if(coll === undefined && obj !== undefined && obj.channel !== undefined){ | ||||
|                 try { | ||||
|                     coll = obj.channel; | ||||
|                     if(coll.length == 0) return; | ||||
|                     coll = emojiStrip(coll).toLowerCase(); | ||||
|                     coll = coll.replace("_", ""); | ||||
|                     coll = encodeURIComponent(coll).replace(/\W/g, ''); | ||||
|                     coll = filter.clean(coll); | ||||
|                 } catch(e) { | ||||
|                     return; | ||||
|                 } | ||||
|             } | ||||
|             List.left_channel(coll, guid, short_id, in_list, socket, true); | ||||
|             in_list = false; | ||||
|         }); | ||||
|  | ||||
| 		socket.on('shuffle', function(msg) | ||||
| 		{ | ||||
| 			if(coll !== undefined) { | ||||
| 	      try { | ||||
| 	        coll = msg.channel; | ||||
| 	        if(coll.length == 0) return; | ||||
| 	        coll = emojiStrip(coll).toLowerCase(); | ||||
| 	        coll = coll.replace("_", ""); | ||||
| 	        coll = encodeURIComponent(coll).replace(/\W/g, ''); | ||||
| 	        coll = filter.clean(coll); | ||||
| 	      } catch(e) { | ||||
| 	        return; | ||||
| 	      } | ||||
| 	    } | ||||
| 			ListChange.shuffle(msg, coll, guid, offline, socket); | ||||
| 		}); | ||||
|         socket.on('disconnect', function() | ||||
|         { | ||||
|             List.left_channel(coll, guid, short_id, in_list, socket, false); | ||||
|         }); | ||||
|  | ||||
| 		socket.on('change_channel', function(obj) | ||||
| 		{ | ||||
| 			if(coll === undefined && obj !== undefined && obj.channel !== undefined){ | ||||
| 				try { | ||||
| 					coll = obj.channel; | ||||
| 					if(coll.length == 0) return; | ||||
| 					coll = emojiStrip(coll).toLowerCase(); | ||||
| 					coll = coll.replace("_", ""); | ||||
| 					coll = encodeURIComponent(coll).replace(/\W/g, ''); | ||||
| 					coll = filter.clean(coll); | ||||
| 				} catch(e) { | ||||
| 					return; | ||||
| 				} | ||||
| 			} | ||||
| 			List.left_channel(coll, guid, short_id, in_list, socket, true); | ||||
| 			in_list = false; | ||||
| 		}); | ||||
|         socket.on('disconnected', function() | ||||
|         { | ||||
|             List.left_channel(coll, guid, short_id, in_list, socket, false); | ||||
|         }); | ||||
|  | ||||
| 		socket.on('disconnect', function() | ||||
| 		{ | ||||
| 			List.left_channel(coll, guid, short_id, in_list, socket, false); | ||||
| 		}); | ||||
|         socket.on('reconnect_failed', function() | ||||
|         { | ||||
|             List.left_channel(coll, guid, short_id, in_list, socket, false); | ||||
|         }); | ||||
|  | ||||
| 		socket.on('disconnected', function() | ||||
| 		{ | ||||
| 			List.left_channel(coll, guid, short_id, in_list, socket, false); | ||||
| 		}); | ||||
|         socket.on('connect_timeout', function() | ||||
|         { | ||||
|             List.left_channel(coll, guid, short_id, in_list, socket, false); | ||||
|         }); | ||||
|  | ||||
| 		socket.on('reconnect_failed', function() | ||||
| 		{ | ||||
| 			List.left_channel(coll, guid, short_id, in_list, socket, false); | ||||
| 		}); | ||||
|         socket.on('error', function() | ||||
|         { | ||||
|             List.left_channel(coll, guid, short_id, in_list, socket, false); | ||||
|         }); | ||||
|  | ||||
| 		socket.on('connect_timeout', function() | ||||
| 		{ | ||||
| 			List.left_channel(coll, guid, short_id, in_list, socket, false); | ||||
| 		}); | ||||
|         socket.on('pos', function(obj) | ||||
|         { | ||||
|  | ||||
| 		socket.on('error', function() | ||||
| 		{ | ||||
| 			List.left_channel(coll, guid, short_id, in_list, socket, false); | ||||
| 		}); | ||||
|             if(coll !== undefined) { | ||||
|                 try { | ||||
|                     coll = obj.channel; | ||||
|                     if(coll.length == 0) return; | ||||
|                     coll = emojiStrip(coll).toLowerCase(); | ||||
|                     coll = coll.replace("_", ""); | ||||
|                     coll = encodeURIComponent(coll).replace(/\W/g, ''); | ||||
|                     coll = filter.clean(coll); | ||||
|                 } catch(e) { | ||||
|                     return; | ||||
|                 } | ||||
|             } | ||||
|  | ||||
| 		socket.on('pos', function(obj) | ||||
| 		{ | ||||
|             if(coll == "" || coll == undefined || coll == null) { | ||||
|                 socket.emit("update_required"); | ||||
|                 return; | ||||
|             } | ||||
|  | ||||
| 			if(coll !== undefined) { | ||||
| 				try { | ||||
| 					coll = obj.channel; | ||||
| 					if(coll.length == 0) return; | ||||
| 					coll = emojiStrip(coll).toLowerCase(); | ||||
| 					coll = coll.replace("_", ""); | ||||
| 					coll = encodeURIComponent(coll).replace(/\W/g, ''); | ||||
| 					coll = filter.clean(coll); | ||||
| 				} catch(e) { | ||||
| 					return; | ||||
| 				} | ||||
| 			} | ||||
|             db.collection(coll).find({views: {$exists: true}}, function(err, docs) { | ||||
|                 if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (obj.hasOwnProperty('pass') && docs[0].userpass == Functions.decrypt_string(socketid, obj.pass)))) { | ||||
|                     Functions.check_inlist(coll, guid, socket, offline); | ||||
|                     List.send_play(coll, socket); | ||||
|                 } else { | ||||
|                     socket.emit("auth_required"); | ||||
|                 } | ||||
|             }); | ||||
|         }); | ||||
|     }); | ||||
|  | ||||
| 			if(coll == "" || coll == undefined || coll == null) { | ||||
| 				socket.emit("update_required"); | ||||
| 				return; | ||||
| 			} | ||||
|  | ||||
| 			db.collection(coll).find({views: {$exists: true}}, function(err, docs) { | ||||
| 				if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (obj.hasOwnProperty('pass') && docs[0].userpass == Functions.decrypt_string(socketid, obj.pass)))) { | ||||
| 					Functions.check_inlist(coll, guid, socket, offline); | ||||
| 					List.send_play(coll, socket); | ||||
| 				} else { | ||||
| 					socket.emit("auth_required"); | ||||
| 				} | ||||
| 			}); | ||||
| 		}); | ||||
| 	}); | ||||
|  | ||||
| 	send_ping(); | ||||
|     send_ping(); | ||||
| } | ||||
|  | ||||
| function send_ping() { | ||||
| 	db.collection("connected_users").update({users: {$exists: true}}, {$set: {users: []}}, {multi: true}, function(err, docs){ | ||||
| 		db.collection("connected_users").update({"_id": "total_users"}, {$set: {total_users: 0}}, {multi: true}, function(err, docs){ | ||||
| 			db.collection("frontpage_lists").update({viewers: {$ne: 0}}, {$set: {"viewers": 0}}, {multi: true}, function(err, docs) { | ||||
| 				io.emit("self_ping"); | ||||
| 				setTimeout(send_ping, 25000); | ||||
| 			}); | ||||
| 		}); | ||||
| 	}); | ||||
|     db.collection("connected_users").update({users: {$exists: true}}, {$set: {users: []}}, {multi: true}, function(err, docs){ | ||||
|         db.collection("connected_users").update({"_id": "total_users"}, {$set: {total_users: 0}}, {multi: true}, function(err, docs){ | ||||
|             db.collection("frontpage_lists").update({viewers: {$ne: 0}}, {$set: {"viewers": 0}}, {multi: true}, function(err, docs) { | ||||
|                 io.emit("self_ping"); | ||||
|                 setTimeout(send_ping, 25000); | ||||
|             }); | ||||
|         }); | ||||
|     }); | ||||
| } | ||||
|   | ||||
| @@ -1,499 +1,499 @@ | ||||
|  | ||||
| function now_playing(list, fn, socket) { | ||||
|   if(typeof(list) !== 'string' || typeof(fn) !== 'function') { | ||||
|     socket.emit('update_required'); | ||||
|     return; | ||||
|   } | ||||
|   db.collection(list).find({now_playing:true}, function(err, docs){ | ||||
|     if(docs.length === 0){ | ||||
|       fn("No song currently playing"); | ||||
|       return; | ||||
|     if(typeof(list) !== 'string' || typeof(fn) !== 'function') { | ||||
|         socket.emit('update_required'); | ||||
|         return; | ||||
|     } | ||||
|     var title = docs[0].title; | ||||
|     if(title === undefined) fn("No song currently playing"); | ||||
|     else fn(title); | ||||
|   }); | ||||
|     db.collection(list).find({now_playing:true}, function(err, docs){ | ||||
|         if(docs.length === 0){ | ||||
|             fn("No song currently playing"); | ||||
|             return; | ||||
|         } | ||||
|         var title = docs[0].title; | ||||
|         if(title === undefined) fn("No song currently playing"); | ||||
|         else fn(title); | ||||
|     }); | ||||
| } | ||||
|  | ||||
| function list(msg, guid, coll, offline, socket) { | ||||
|   var socketid = socket.zoff_id; | ||||
|     var socketid = socket.zoff_id; | ||||
|  | ||||
|   if(typeof(msg) === 'object' && msg !== undefined && msg !== null && msg.hasOwnProperty("channel") && msg.hasOwnProperty('pass')) | ||||
|   { | ||||
|     if(!msg.hasOwnProperty('version') || msg.version != VERSION || msg.version == undefined) { | ||||
|       socket.emit("update_required"); | ||||
|     } | ||||
|     if(typeof(msg) === 'object' && msg !== undefined && msg !== null && msg.hasOwnProperty("channel") && msg.hasOwnProperty('pass')) | ||||
|     { | ||||
|         if(!msg.hasOwnProperty('version') || msg.version != VERSION || msg.version == undefined) { | ||||
|             socket.emit("update_required"); | ||||
|         } | ||||
|  | ||||
|     if(coll == "" || coll == undefined || coll == null) { | ||||
|       socket.emit("update_required"); | ||||
|       return; | ||||
|     } | ||||
|     var pass = Functions.decrypt_string(socketid, msg.pass); | ||||
|     db.collection('frontpage_lists').find({"_id": coll}, function(err, frontpage_lists){ | ||||
|       if(frontpage_lists.length == 1) | ||||
|       { | ||||
|         db.collection(coll).find({views: {$exists: true}}, function(err, docs) { | ||||
|           if(docs.length == 0 || (docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || docs[0].userpass == pass))) { | ||||
|             if(docs.length > 0 && docs[0].hasOwnProperty('userpass') && docs[0].userpass != "" && docs[0].userpass == pass) { | ||||
|               socket.emit("auth_accepted", {value: true}); | ||||
|         if(coll == "" || coll == undefined || coll == null) { | ||||
|             socket.emit("update_required"); | ||||
|             return; | ||||
|         } | ||||
|         var pass = Functions.decrypt_string(socketid, msg.pass); | ||||
|         db.collection('frontpage_lists').find({"_id": coll}, function(err, frontpage_lists){ | ||||
|             if(frontpage_lists.length == 1) | ||||
|             { | ||||
|                 db.collection(coll).find({views: {$exists: true}}, function(err, docs) { | ||||
|                     if(docs.length == 0 || (docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || docs[0].userpass == pass))) { | ||||
|                         if(docs.length > 0 && docs[0].hasOwnProperty('userpass') && docs[0].userpass != "" && docs[0].userpass == pass) { | ||||
|                             socket.emit("auth_accepted", {value: true}); | ||||
|                         } | ||||
|                         in_list = true; | ||||
|                         socket.join(coll); | ||||
|                         Functions.check_inlist(coll, guid, socket, offline); | ||||
|  | ||||
|                         if(frontpage_lists.viewers != undefined){ | ||||
|                             io.to(coll).emit("viewers", frontpage_lists.viewers); | ||||
|                         } else { | ||||
|                             io.to(coll).emit("viewers", 1); | ||||
|                         } | ||||
|  | ||||
|                         List.send_list(coll, socket, true, false, true); | ||||
|  | ||||
|                     } else { | ||||
|                         socket.emit("auth_required"); | ||||
|                     } | ||||
|                 }); | ||||
|             } else{ | ||||
|                 db.createCollection(coll, function(err, docs){ | ||||
|                     db.collection(coll).insert({"addsongs":false, "adminpass":"", "allvideos":true, "frontpage":true, "longsongs":false, "removeplay": false, "shuffle": true, "skip": false, "skips": [], "startTime":Functions.get_time(), "views": [], "vote": false, "desc": ""}, function(err, docs){ | ||||
|                         List.send_list(coll, socket, true, false, true); | ||||
|                         db.collection("frontpage_lists").insert({"_id": coll, "count" : 0, "frontpage": true, "accessed": Functions.get_time()}); | ||||
|                     }); | ||||
|                 }); | ||||
|             } | ||||
|             in_list = true; | ||||
|             socket.join(coll); | ||||
|             Functions.check_inlist(coll, guid, socket, offline); | ||||
|  | ||||
|             if(frontpage_lists.viewers != undefined){ | ||||
|               io.to(coll).emit("viewers", frontpage_lists.viewers); | ||||
|             } else { | ||||
|               io.to(coll).emit("viewers", 1); | ||||
|             } | ||||
|  | ||||
|             List.send_list(coll, socket, true, false, true); | ||||
|  | ||||
|           } else { | ||||
|             socket.emit("auth_required"); | ||||
|           } | ||||
|         }); | ||||
|       } else{ | ||||
|         db.createCollection(coll, function(err, docs){ | ||||
|           db.collection(coll).insert({"addsongs":false, "adminpass":"", "allvideos":true, "frontpage":true, "longsongs":false, "removeplay": false, "shuffle": true, "skip": false, "skips": [], "startTime":Functions.get_time(), "views": [], "vote": false, "desc": ""}, function(err, docs){ | ||||
|             List.send_list(coll, socket, true, false, true); | ||||
|             db.collection("frontpage_lists").insert({"_id": coll, "count" : 0, "frontpage": true, "accessed": Functions.get_time()}); | ||||
|           }); | ||||
|         }); | ||||
|       } | ||||
|     }); | ||||
|   } else { | ||||
|     socket.emit('update_required'); | ||||
|   } | ||||
|     } else { | ||||
|         socket.emit('update_required'); | ||||
|     } | ||||
| } | ||||
|  | ||||
| function skip(list, guid, coll, offline, socket) { | ||||
|   var socketid = socket.zoff_id; | ||||
|   if(list !== undefined && list !== null && list !== "") | ||||
|   { | ||||
|     var socketid = socket.zoff_id; | ||||
|     if(list !== undefined && list !== null && list !== "") | ||||
|     { | ||||
|  | ||||
|     if(coll == "" || coll == undefined || coll == null) { | ||||
|       socket.emit("update_required"); | ||||
|       return; | ||||
|     } | ||||
|  | ||||
|     db.collection(coll).find({views:{$exists:true}}, function(err, docs){ | ||||
|       if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (list.hasOwnProperty('userpass') && docs[0].userpass == Functions.decrypt_string(socketid, list.userpass)))) { | ||||
|  | ||||
|         Functions.check_inlist(coll, guid, socket, offline); | ||||
|  | ||||
|         adminpass = ""; | ||||
|         video_id  = list.id; | ||||
|         err       = list.error; | ||||
|         var error = false; | ||||
|         var video_id; | ||||
|         if(err != "5" && err != "100" && err != "101" && err != "150") | ||||
|         { | ||||
|           adminpass = list.pass; | ||||
|         }else if(err == "5" || err == "100" || err == "101" || err == "150"){ | ||||
|           error = true; | ||||
|         if(coll == "" || coll == undefined || coll == null) { | ||||
|             socket.emit("update_required"); | ||||
|             return; | ||||
|         } | ||||
|  | ||||
|         if(adminpass !== undefined && adminpass !== null && adminpass !== "") | ||||
|         hash = Functions.hash_pass(Functions.decrypt_string(socketid, adminpass)); | ||||
|         else | ||||
|         hash = ""; | ||||
|         db.collection(coll).find({views:{$exists:true}}, function(err, docs){ | ||||
|             if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (list.hasOwnProperty('userpass') && docs[0].userpass == Functions.decrypt_string(socketid, list.userpass)))) { | ||||
|  | ||||
|         db.collection(coll).find({views: {$exists:true}}, function(err, docs){ | ||||
|                 Functions.check_inlist(coll, guid, socket, offline); | ||||
|  | ||||
|           if(docs !== null && docs.length !== 0) | ||||
|           { | ||||
|             if(!docs[0].skip || (docs[0].adminpass == hash && docs[0].adminpass !== "") || error) | ||||
|             { | ||||
|               db.collection("frontpage_lists").find({"_id": coll}, function(err, frontpage_viewers){ | ||||
|                 if((frontpage_viewers[0].viewers/2 <= docs[0].skips.length+1 && !Functions.contains(docs[0].skips, guid) && frontpage_viewers[0].viewers != 2) || | ||||
|                 (frontpage_viewers[0].viewers == 2 && docs[0].skips.length+1 == 2 && !Functions.contains(docs[0].skips, guid)) || | ||||
|                 (docs[0].adminpass == hash && docs[0].adminpass !== "" && docs[0].skip)) | ||||
|                 adminpass = ""; | ||||
|                 video_id  = list.id; | ||||
|                 err       = list.error; | ||||
|                 var error = false; | ||||
|                 var video_id; | ||||
|                 if(err != "5" && err != "100" && err != "101" && err != "150") | ||||
|                 { | ||||
|                   List.change_song(coll, error, video_id); | ||||
|                   socket.emit("toast", "skip"); | ||||
|                   io.to(coll).emit('chat', {from: name, msg: " skipped"}); | ||||
|                 }else if(!Functions.contains(docs[0].skips, guid)){ | ||||
|                   db.collection(coll).update({views:{$exists:true}}, {$push:{skips:guid}}, function(err, d){ | ||||
|                     if(frontpage_viewers[0].viewers == 2) | ||||
|                     to_skip = 1; | ||||
|                     else | ||||
|                     to_skip = (Math.ceil(frontpage_viewers[0].viewers/2) - docs[0].skips.length-1); | ||||
|                     socket.emit("toast", to_skip + " more are needed to skip!"); | ||||
|                     socket.broadcast.to(coll).emit('chat', {from: name, msg: " voted to skip"}); | ||||
|                   }); | ||||
|                 }else{ | ||||
|                   socket.emit("toast", "alreadyskip"); | ||||
|                     adminpass = list.pass; | ||||
|                 }else if(err == "5" || err == "100" || err == "101" || err == "150"){ | ||||
|                     error = true; | ||||
|                 } | ||||
|               }); | ||||
|             }else | ||||
|             socket.emit("toast", "noskip"); | ||||
|           } | ||||
|  | ||||
|                 if(adminpass !== undefined && adminpass !== null && adminpass !== "") | ||||
|                 hash = Functions.hash_pass(Functions.decrypt_string(socketid, adminpass)); | ||||
|                 else | ||||
|                 hash = ""; | ||||
|  | ||||
|                 db.collection(coll).find({views: {$exists:true}}, function(err, docs){ | ||||
|  | ||||
|                     if(docs !== null && docs.length !== 0) | ||||
|                     { | ||||
|                         if(!docs[0].skip || (docs[0].adminpass == hash && docs[0].adminpass !== "") || error) | ||||
|                         { | ||||
|                             db.collection("frontpage_lists").find({"_id": coll}, function(err, frontpage_viewers){ | ||||
|                                 if((frontpage_viewers[0].viewers/2 <= docs[0].skips.length+1 && !Functions.contains(docs[0].skips, guid) && frontpage_viewers[0].viewers != 2) || | ||||
|                                 (frontpage_viewers[0].viewers == 2 && docs[0].skips.length+1 == 2 && !Functions.contains(docs[0].skips, guid)) || | ||||
|                                 (docs[0].adminpass == hash && docs[0].adminpass !== "" && docs[0].skip)) | ||||
|                                 { | ||||
|                                     List.change_song(coll, error, video_id); | ||||
|                                     socket.emit("toast", "skip"); | ||||
|                                     io.to(coll).emit('chat', {from: name, msg: " skipped"}); | ||||
|                                 }else if(!Functions.contains(docs[0].skips, guid)){ | ||||
|                                     db.collection(coll).update({views:{$exists:true}}, {$push:{skips:guid}}, function(err, d){ | ||||
|                                         if(frontpage_viewers[0].viewers == 2) | ||||
|                                         to_skip = 1; | ||||
|                                         else | ||||
|                                         to_skip = (Math.ceil(frontpage_viewers[0].viewers/2) - docs[0].skips.length-1); | ||||
|                                         socket.emit("toast", to_skip + " more are needed to skip!"); | ||||
|                                         socket.broadcast.to(coll).emit('chat', {from: name, msg: " voted to skip"}); | ||||
|                                     }); | ||||
|                                 }else{ | ||||
|                                     socket.emit("toast", "alreadyskip"); | ||||
|                                 } | ||||
|                             }); | ||||
|                         }else | ||||
|                         socket.emit("toast", "noskip"); | ||||
|                     } | ||||
|                 }); | ||||
|             } else { | ||||
|                 socket.emit("auth_required"); | ||||
|             } | ||||
|         }); | ||||
|       } else { | ||||
|         socket.emit("auth_required"); | ||||
|       } | ||||
|     }); | ||||
|   } else { | ||||
|     socket.emit('update_required'); | ||||
|   } | ||||
|     } else { | ||||
|         socket.emit('update_required'); | ||||
|     } | ||||
| } | ||||
|  | ||||
| function change_song(coll, error, id) { | ||||
| 	db.collection(coll).find({views:{$exists:true}}, function(err, docs){ | ||||
| 		var startTime = docs[0].startTime; | ||||
| 		if(docs !== null && docs.length !== 0) | ||||
| 		{ | ||||
| 			db.collection(coll).aggregate([{ | ||||
| 				$match:{ | ||||
| 					views:{ | ||||
| 						$exists: false | ||||
| 					}, | ||||
| 					type:{ | ||||
| 						$ne: "suggested" | ||||
| 					} | ||||
| 				} | ||||
| 			}, { | ||||
| 				$sort:{ | ||||
| 					now_playing: -1, | ||||
| 					votes:-1, | ||||
| 					added:1, | ||||
| 					title: 1 | ||||
| 				} | ||||
| 			}, { | ||||
| 				$limit:2 | ||||
| 			}], function(err, now_playing_doc){ | ||||
| 				if((id && id == now_playing_doc[0].id) || !id) { | ||||
| 					if(error){ | ||||
| 						request('http://img.youtube.com/vi/'+now_playing_doc[0].id+'/mqdefault.jpg', function (err, response, body) { | ||||
| 							if (err || response.statusCode == 404) { | ||||
| 								db.collection(coll).remove({now_playing:true, id:id}, function(err, docs){ | ||||
| 									var next_song; | ||||
| 									if(now_playing_doc.length == 2) next_song = now_playing_doc[1].id; | ||||
| 									List.change_song_post(coll, next_song); | ||||
| 									io.to(coll).emit("channel", {type: "deleted", value: now_playing_doc[0].id, removed: true}); | ||||
| 									db.collection("frontpage_lists").update({_id: coll}, {$inc: {count: -1}, $set:{accessed: Functions.get_time()}}, {upsert: true}, function(err, docs){}); | ||||
| 								}); | ||||
| 							} else { | ||||
| 								if((docs[0].skipped_time != undefined && docs[0].skipped_time != Functions.get_time()) || docs[0].skipped_time == undefined) { | ||||
| 									db.collection(coll).update({views: {$exists: true}}, {$set: {skipped_time: Functions.get_time()}}, function(err, updated){ | ||||
| 										db.collection(coll).update({now_playing:true, id:id}, { | ||||
| 											$set:{ | ||||
| 												now_playing:false, | ||||
| 												votes:0, | ||||
| 												guids:[] | ||||
| 											} | ||||
| 										},{multi:true}, function(err, docs){ | ||||
| 											var next_song; | ||||
| 											if(now_playing_doc.length == 2) next_song = now_playing_doc[1].id; | ||||
| 											if(docs.n >= 1) List.change_song_post(coll, next_song); | ||||
| 										}); | ||||
| 									}); | ||||
| 								} | ||||
| 							} | ||||
| 						}); | ||||
|     db.collection(coll).find({views:{$exists:true}}, function(err, docs){ | ||||
|         var startTime = docs[0].startTime; | ||||
|         if(docs !== null && docs.length !== 0) | ||||
|         { | ||||
|             db.collection(coll).aggregate([{ | ||||
|                 $match:{ | ||||
|                     views:{ | ||||
|                         $exists: false | ||||
|                     }, | ||||
|                     type:{ | ||||
|                         $ne: "suggested" | ||||
|                     } | ||||
|                 } | ||||
|             }, { | ||||
|                 $sort:{ | ||||
|                     now_playing: -1, | ||||
|                     votes:-1, | ||||
|                     added:1, | ||||
|                     title: 1 | ||||
|                 } | ||||
|             }, { | ||||
|                 $limit:2 | ||||
|             }], function(err, now_playing_doc){ | ||||
|                 if((id && id == now_playing_doc[0].id) || !id) { | ||||
|                     if(error){ | ||||
|                         request('http://img.youtube.com/vi/'+now_playing_doc[0].id+'/mqdefault.jpg', function (err, response, body) { | ||||
|                             if (err || response.statusCode == 404) { | ||||
|                                 db.collection(coll).remove({now_playing:true, id:id}, function(err, docs){ | ||||
|                                     var next_song; | ||||
|                                     if(now_playing_doc.length == 2) next_song = now_playing_doc[1].id; | ||||
|                                     List.change_song_post(coll, next_song); | ||||
|                                     io.to(coll).emit("channel", {type: "deleted", value: now_playing_doc[0].id, removed: true}); | ||||
|                                     db.collection("frontpage_lists").update({_id: coll}, {$inc: {count: -1}, $set:{accessed: Functions.get_time()}}, {upsert: true}, function(err, docs){}); | ||||
|                                 }); | ||||
|                             } else { | ||||
|                                 if((docs[0].skipped_time != undefined && docs[0].skipped_time != Functions.get_time()) || docs[0].skipped_time == undefined) { | ||||
|                                     db.collection(coll).update({views: {$exists: true}}, {$set: {skipped_time: Functions.get_time()}}, function(err, updated){ | ||||
|                                         db.collection(coll).update({now_playing:true, id:id}, { | ||||
|                                             $set:{ | ||||
|                                                 now_playing:false, | ||||
|                                                 votes:0, | ||||
|                                                 guids:[] | ||||
|                                             } | ||||
|                                         },{multi:true}, function(err, docs){ | ||||
|                                             var next_song; | ||||
|                                             if(now_playing_doc.length == 2) next_song = now_playing_doc[1].id; | ||||
|                                             if(docs.n >= 1) List.change_song_post(coll, next_song); | ||||
|                                         }); | ||||
|                                     }); | ||||
|                                 } | ||||
|                             } | ||||
|                         }); | ||||
|  | ||||
| 					} else if(docs[0].removeplay === true){ | ||||
| 						db.collection(coll).remove({now_playing:true, id:id}, function(err, docs){ | ||||
| 							var next_song; | ||||
| 							if(now_playing_doc.length == 2) next_song = now_playing_doc[1].id; | ||||
| 							List.change_song_post(coll, next_song); | ||||
| 							io.to(coll).emit("channel", {type: "deleted", value: now_playing_doc[0].id, removed: true}); | ||||
| 							db.collection("frontpage_lists").update({_id: coll}, {$inc: {count: -1}, $set:{accessed: Functions.get_time()}}, {upsert: true}, function(err, docs){}); | ||||
| 						}); | ||||
| 					} else { | ||||
| 						if((docs[0].skipped_time != undefined && docs[0].skipped_time != Functions.get_time()) || docs[0].skipped_time == undefined) { | ||||
| 							db.collection(coll).update({now_playing:true, id:id}, { | ||||
| 								$set:{ | ||||
| 									now_playing:false, | ||||
| 									votes:0, | ||||
| 									guids:[] | ||||
| 								} | ||||
| 							},{multi:true}, function(err, docs){ | ||||
| 								var next_song; | ||||
| 								if(now_playing_doc.length == 2) next_song = now_playing_doc[1].id; | ||||
| 								List.change_song_post(coll, next_song); | ||||
| 							}); | ||||
| 						} | ||||
| 					} | ||||
| 				} else { | ||||
| 					return; | ||||
| 				} | ||||
| 			}); | ||||
| 		} | ||||
| 	}); | ||||
|                     } else if(docs[0].removeplay === true){ | ||||
|                         db.collection(coll).remove({now_playing:true, id:id}, function(err, docs){ | ||||
|                             var next_song; | ||||
|                             if(now_playing_doc.length == 2) next_song = now_playing_doc[1].id; | ||||
|                             List.change_song_post(coll, next_song); | ||||
|                             io.to(coll).emit("channel", {type: "deleted", value: now_playing_doc[0].id, removed: true}); | ||||
|                             db.collection("frontpage_lists").update({_id: coll}, {$inc: {count: -1}, $set:{accessed: Functions.get_time()}}, {upsert: true}, function(err, docs){}); | ||||
|                         }); | ||||
|                     } else { | ||||
|                         if((docs[0].skipped_time != undefined && docs[0].skipped_time != Functions.get_time()) || docs[0].skipped_time == undefined) { | ||||
|                             db.collection(coll).update({now_playing:true, id:id}, { | ||||
|                                 $set:{ | ||||
|                                     now_playing:false, | ||||
|                                     votes:0, | ||||
|                                     guids:[] | ||||
|                                 } | ||||
|                             },{multi:true}, function(err, docs){ | ||||
|                                 var next_song; | ||||
|                                 if(now_playing_doc.length == 2) next_song = now_playing_doc[1].id; | ||||
|                                 List.change_song_post(coll, next_song); | ||||
|                             }); | ||||
|                         } | ||||
|                     } | ||||
|                 } else { | ||||
|                     return; | ||||
|                 } | ||||
|             }); | ||||
|         } | ||||
|     }); | ||||
| } | ||||
|  | ||||
| function change_song_post(coll, next_song) | ||||
| { | ||||
| 	db.collection(coll).aggregate([{ | ||||
| 		$match:{ | ||||
| 			now_playing:false, | ||||
| 			type:{ | ||||
| 				$ne: "suggested" | ||||
| 			} | ||||
| 		} | ||||
| 	}, { | ||||
| 		$sort:{ | ||||
| 			votes:-1, | ||||
| 			added:1, | ||||
| 			title: 1 | ||||
| 		} | ||||
| 	}, { | ||||
| 		$limit:2 | ||||
| 	}], function(err, docs){ | ||||
| 		if(docs !== null && docs.length > 0){ | ||||
| 			var id = docs[0].id; | ||||
| 			if(next_song && next_song != id) { | ||||
| 				if((docs.length == 2 && next_song == docs[1].id)) { | ||||
| 					id = docs[1].id; | ||||
| 				} else { | ||||
| 					return; | ||||
| 				} | ||||
| 			} | ||||
| 			db.collection(coll).update({id:id},{ | ||||
| 				$set:{ | ||||
| 					now_playing:true, | ||||
| 					votes:0, | ||||
| 					guids:[], | ||||
| 					added:Functions.get_time() | ||||
| 				} | ||||
| 			}, function(err, returnDocs){ | ||||
| 				db.collection(coll).update({views:{$exists:true}},{ | ||||
| 					$set:{ | ||||
| 						startTime:Functions.get_time(), | ||||
| 						skips:[] | ||||
| 					} | ||||
| 				}, function(err, returnDocs){ | ||||
| 					db.collection(coll).find({views:{$exists:true}}, function(err, conf){ | ||||
| 						io.to(coll).emit("channel", {type: "song_change", time: Functions.get_time(), remove: conf[0].removeplay}); | ||||
| 						List.send_play(coll); | ||||
| 						Frontpage.update_frontpage(coll, docs[0].id, docs[0].title); | ||||
| 					}); | ||||
| 				}); | ||||
| 			}); | ||||
| 		} | ||||
| 	}); | ||||
|     db.collection(coll).aggregate([{ | ||||
|         $match:{ | ||||
|             now_playing:false, | ||||
|             type:{ | ||||
|                 $ne: "suggested" | ||||
|             } | ||||
|         } | ||||
|     }, { | ||||
|         $sort:{ | ||||
|             votes:-1, | ||||
|             added:1, | ||||
|             title: 1 | ||||
|         } | ||||
|     }, { | ||||
|         $limit:2 | ||||
|     }], function(err, docs){ | ||||
|         if(docs !== null && docs.length > 0){ | ||||
|             var id = docs[0].id; | ||||
|             if(next_song && next_song != id) { | ||||
|                 if((docs.length == 2 && next_song == docs[1].id)) { | ||||
|                     id = docs[1].id; | ||||
|                 } else { | ||||
|                     return; | ||||
|                 } | ||||
|             } | ||||
|             db.collection(coll).update({id:id},{ | ||||
|                 $set:{ | ||||
|                     now_playing:true, | ||||
|                     votes:0, | ||||
|                     guids:[], | ||||
|                     added:Functions.get_time() | ||||
|                 } | ||||
|             }, function(err, returnDocs){ | ||||
|                 db.collection(coll).update({views:{$exists:true}},{ | ||||
|                     $set:{ | ||||
|                         startTime:Functions.get_time(), | ||||
|                         skips:[] | ||||
|                     } | ||||
|                 }, function(err, returnDocs){ | ||||
|                     db.collection(coll).find({views:{$exists:true}}, function(err, conf){ | ||||
|                         io.to(coll).emit("channel", {type: "song_change", time: Functions.get_time(), remove: conf[0].removeplay}); | ||||
|                         List.send_play(coll); | ||||
|                         Frontpage.update_frontpage(coll, docs[0].id, docs[0].title); | ||||
|                     }); | ||||
|                 }); | ||||
|             }); | ||||
|         } | ||||
|     }); | ||||
| } | ||||
|  | ||||
| function send_list(coll, socket, send, list_send, configs, shuffled) | ||||
| { | ||||
| 	db.collection(coll).find({views:{$exists:true}}, function(err, conf){ | ||||
| 		db.collection(coll).find({views:{$exists:false}, type: {$ne: "suggested"}}, function(err, docs) | ||||
| 		{ | ||||
| 			if(docs.length > 0) { | ||||
| 				db.collection(coll).find({now_playing: true}, function(err, np_docs) { | ||||
| 					if(np_docs.length == 0) { | ||||
| 						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, now_playing_doc){ | ||||
| 							if(now_playing_doc[0].now_playing == false) { | ||||
| 								db.collection(coll).update({id:now_playing_doc[0].id}, { | ||||
| 									$set:{ | ||||
| 										now_playing:true, | ||||
| 										votes:0, | ||||
| 										guids:[], | ||||
| 										added:Functions.get_time() | ||||
| 									} | ||||
| 								}, function(err, returnDocs){ | ||||
| 									db.collection(coll).update({views:{$exists:true}}, { | ||||
| 										$set:{ | ||||
| 											startTime: Functions.get_time(), | ||||
| 											skips:[] | ||||
| 										} | ||||
| 									}, function(err, returnDocs){ | ||||
| 										Frontpage.update_frontpage(coll, now_playing_doc[0].id, now_playing_doc[0].title); | ||||
| 										List.send_list(coll, socket, send, list_send, configs, shuffled); | ||||
| 									}); | ||||
| 								}); | ||||
| 							} | ||||
| 						}); | ||||
| 					} else { | ||||
| 						if(list_send) { | ||||
| 							io.to(coll).emit("channel", {type: "list", playlist: docs, shuffled: shuffled}); | ||||
| 						} else if(!list_send) { | ||||
| 							socket.emit("channel", {type: "list", playlist: docs, shuffled: shuffled}); | ||||
| 						} | ||||
| 						if(socket === undefined && send) { | ||||
| 							List.send_play(coll); | ||||
| 						} else if(send) { | ||||
| 							List.send_play(coll, socket); | ||||
| 						} | ||||
| 					} | ||||
| 				}); | ||||
| 			} else { | ||||
| 				if(list_send) { | ||||
| 					io.to(coll).emit("channel", {type: "list", playlist: docs, shuffled: shuffled}); | ||||
| 				} else if(!list_send) { | ||||
| 					socket.emit("channel", {type: "list", playlist: docs, shuffled: shuffled}); | ||||
| 				} | ||||
| 				if(socket === undefined && send) { | ||||
| 					List.send_play(coll); | ||||
| 				} else if(send) { | ||||
| 					List.send_play(coll, socket); | ||||
| 				} | ||||
| 			} | ||||
| 		}); | ||||
|     db.collection(coll).find({views:{$exists:true}}, function(err, conf){ | ||||
|         db.collection(coll).find({views:{$exists:false}, type: {$ne: "suggested"}}, function(err, docs) | ||||
|         { | ||||
|             if(docs.length > 0) { | ||||
|                 db.collection(coll).find({now_playing: true}, function(err, np_docs) { | ||||
|                     if(np_docs.length == 0) { | ||||
|                         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, now_playing_doc){ | ||||
|                             if(now_playing_doc[0].now_playing == false) { | ||||
|                                 db.collection(coll).update({id:now_playing_doc[0].id}, { | ||||
|                                     $set:{ | ||||
|                                         now_playing:true, | ||||
|                                         votes:0, | ||||
|                                         guids:[], | ||||
|                                         added:Functions.get_time() | ||||
|                                     } | ||||
|                                 }, function(err, returnDocs){ | ||||
|                                     db.collection(coll).update({views:{$exists:true}}, { | ||||
|                                         $set:{ | ||||
|                                             startTime: Functions.get_time(), | ||||
|                                             skips:[] | ||||
|                                         } | ||||
|                                     }, function(err, returnDocs){ | ||||
|                                         Frontpage.update_frontpage(coll, now_playing_doc[0].id, now_playing_doc[0].title); | ||||
|                                         List.send_list(coll, socket, send, list_send, configs, shuffled); | ||||
|                                     }); | ||||
|                                 }); | ||||
|                             } | ||||
|                         }); | ||||
|                     } else { | ||||
|                         if(list_send) { | ||||
|                             io.to(coll).emit("channel", {type: "list", playlist: docs, shuffled: shuffled}); | ||||
|                         } else if(!list_send) { | ||||
|                             socket.emit("channel", {type: "list", playlist: docs, shuffled: shuffled}); | ||||
|                         } | ||||
|                         if(socket === undefined && send) { | ||||
|                             List.send_play(coll); | ||||
|                         } else if(send) { | ||||
|                             List.send_play(coll, socket); | ||||
|                         } | ||||
|                     } | ||||
|                 }); | ||||
|             } else { | ||||
|                 if(list_send) { | ||||
|                     io.to(coll).emit("channel", {type: "list", playlist: docs, shuffled: shuffled}); | ||||
|                 } else if(!list_send) { | ||||
|                     socket.emit("channel", {type: "list", playlist: docs, shuffled: shuffled}); | ||||
|                 } | ||||
|                 if(socket === undefined && send) { | ||||
|                     List.send_play(coll); | ||||
|                 } else if(send) { | ||||
|                     List.send_play(coll, socket); | ||||
|                 } | ||||
|             } | ||||
|         }); | ||||
|  | ||||
|  | ||||
| 		if(configs) | ||||
| 		{ | ||||
| 			if(conf[0].adminpass !== "") conf[0].adminpass = true; | ||||
| 			if(conf[0].hasOwnProperty("userpass") && conf[0].userpass != "") conf[0].userpass = true; | ||||
| 			else conf[0].userpass = false; | ||||
| 			io.to(coll).emit("conf", conf); | ||||
| 		} | ||||
| 	}); | ||||
| 	if(socket){ | ||||
| 		db.collection(coll).find({type:"suggested"}).sort({added: 1}, function(err, sugg){ | ||||
| 			socket.emit("suggested", sugg); | ||||
| 		}); | ||||
| 	} | ||||
|         if(configs) | ||||
|         { | ||||
|             if(conf[0].adminpass !== "") conf[0].adminpass = true; | ||||
|             if(conf[0].hasOwnProperty("userpass") && conf[0].userpass != "") conf[0].userpass = true; | ||||
|             else conf[0].userpass = false; | ||||
|             io.to(coll).emit("conf", conf); | ||||
|         } | ||||
|     }); | ||||
|     if(socket){ | ||||
|         db.collection(coll).find({type:"suggested"}).sort({added: 1}, function(err, sugg){ | ||||
|             socket.emit("suggested", sugg); | ||||
|         }); | ||||
|     } | ||||
| } | ||||
|  | ||||
| function end(obj, coll, guid, offline, socket) { | ||||
|   if(typeof(obj) !== 'object') { | ||||
|     return; | ||||
|   } | ||||
|   id = obj.id; | ||||
|   if(id !== undefined && id !== null && id !== "") { | ||||
|  | ||||
|     if(coll == "" || coll == undefined || coll == null) { | ||||
|       socket.emit("update_required"); | ||||
|       return; | ||||
|     if(typeof(obj) !== 'object') { | ||||
|         return; | ||||
|     } | ||||
|     id = obj.id; | ||||
|     if(id !== undefined && id !== null && id !== "") { | ||||
|  | ||||
|     db.collection(coll).find({views:{$exists:true}}, function(err, docs){ | ||||
|       if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (obj.hasOwnProperty('pass') && docs[0].userpass == Functions.decrypt_string(socketid, obj.pass)))) { | ||||
|         if(coll == "" || coll == undefined || coll == null) { | ||||
|             socket.emit("update_required"); | ||||
|             return; | ||||
|         } | ||||
|  | ||||
|         Functions.check_inlist(coll, guid, socket, offline); | ||||
|         db.collection(coll).find({now_playing:true}, function(err, np){ | ||||
|           if(err !== null) console.log(err); | ||||
|           if(np !== null && np !== undefined && np.length == 1 && np[0].id == id){ | ||||
|             db.collection(coll).find({views:{$exists:true}}, function(err, docs){ | ||||
|               var startTime = docs[0].startTime; | ||||
|               if(docs[0].removeplay === true && startTime+parseInt(np[0].duration)<=Functions.get_time()+5) | ||||
|               { | ||||
|                 db.collection(coll).remove({now_playing:true}, function(err, docs){ | ||||
|                   List.change_song_post(coll); | ||||
|                   db.collection("frontpage_lists").update({_id:coll}, {$inc:{count:-1}, $set:{accessed: Functions.get_time()}}, {upsert:true}, function(err, docs){}); | ||||
|         db.collection(coll).find({views:{$exists:true}}, function(err, docs){ | ||||
|             if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (obj.hasOwnProperty('pass') && docs[0].userpass == Functions.decrypt_string(socketid, obj.pass)))) { | ||||
|  | ||||
|                 Functions.check_inlist(coll, guid, socket, offline); | ||||
|                 db.collection(coll).find({now_playing:true}, function(err, np){ | ||||
|                     if(err !== null) console.log(err); | ||||
|                     if(np !== null && np !== undefined && np.length == 1 && np[0].id == id){ | ||||
|                         db.collection(coll).find({views:{$exists:true}}, function(err, docs){ | ||||
|                             var startTime = docs[0].startTime; | ||||
|                             if(docs[0].removeplay === true && startTime+parseInt(np[0].duration)<=Functions.get_time()+5) | ||||
|                             { | ||||
|                                 db.collection(coll).remove({now_playing:true}, function(err, docs){ | ||||
|                                     List.change_song_post(coll); | ||||
|                                     db.collection("frontpage_lists").update({_id:coll}, {$inc:{count:-1}, $set:{accessed: Functions.get_time()}}, {upsert:true}, function(err, docs){}); | ||||
|                                 }); | ||||
|                             }else{ | ||||
|                                 if(startTime+parseInt(np[0].duration)<=Functions.get_time()+5) | ||||
|                                 { | ||||
|                                     List.change_song(coll, false, id); | ||||
|                                 } | ||||
|                             } | ||||
|                         }); | ||||
|                     } | ||||
|                 }); | ||||
|               }else{ | ||||
|                 if(startTime+parseInt(np[0].duration)<=Functions.get_time()+5) | ||||
|                 { | ||||
|                   List.change_song(coll, false, id); | ||||
|                 } | ||||
|               } | ||||
|             }); | ||||
|           } | ||||
|             } else { | ||||
|                 socket.emit("auth_required"); | ||||
|             } | ||||
|         }); | ||||
|       } else { | ||||
|         socket.emit("auth_required"); | ||||
|       } | ||||
|     }); | ||||
|   } else { | ||||
|     socket.emit('update_required'); | ||||
|   } | ||||
|     } else { | ||||
|         socket.emit('update_required'); | ||||
|     } | ||||
| } | ||||
|  | ||||
| function send_play(coll, socket) | ||||
| { | ||||
| 	db.collection(coll).find({now_playing:true}, function(err, np){ | ||||
| 		db.collection(coll).find({views:{$exists:true}}, function(err, conf){ | ||||
| 			if(err !== null) console.log(err); | ||||
| 			try{ | ||||
| 				if(Functions.get_time()-conf[0].startTime > np[0].duration){ | ||||
| 					List.change_song(coll, false, np[0].id); | ||||
| 				}else if(conf !== null && conf !== undefined && conf.length !== 0) | ||||
| 				{ | ||||
| 					if(conf[0].adminpass !== "") conf[0].adminpass = true; | ||||
| 					if(conf[0].hasOwnProperty("userpass") && conf[0].userpass != "") conf[0].userpass = true; | ||||
| 					else conf[0].userpass = false; | ||||
| 					toSend = {np: np, conf: conf, time: Functions.get_time()}; | ||||
| 					if(socket === undefined) { | ||||
| 						io.to(coll).emit("np", toSend); | ||||
| 						List.getNextSong(coll) | ||||
| 					} else { | ||||
| 						socket.emit("np", toSend); | ||||
| 					} | ||||
| 				} | ||||
| 			} catch(e){ | ||||
| 				if(socket) { | ||||
| 					socket.emit("np", {}); | ||||
| 				} else { | ||||
| 					io.to(coll).emit("np", {}); | ||||
| 				} | ||||
| 			} | ||||
| 		}); | ||||
| 	}); | ||||
|     db.collection(coll).find({now_playing:true}, function(err, np){ | ||||
|         db.collection(coll).find({views:{$exists:true}}, function(err, conf){ | ||||
|             if(err !== null) console.log(err); | ||||
|             try{ | ||||
|                 if(Functions.get_time()-conf[0].startTime > np[0].duration){ | ||||
|                     List.change_song(coll, false, np[0].id); | ||||
|                 }else if(conf !== null && conf !== undefined && conf.length !== 0) | ||||
|                 { | ||||
|                     if(conf[0].adminpass !== "") conf[0].adminpass = true; | ||||
|                     if(conf[0].hasOwnProperty("userpass") && conf[0].userpass != "") conf[0].userpass = true; | ||||
|                     else conf[0].userpass = false; | ||||
|                     toSend = {np: np, conf: conf, time: Functions.get_time()}; | ||||
|                     if(socket === undefined) { | ||||
|                         io.to(coll).emit("np", toSend); | ||||
|                         List.getNextSong(coll) | ||||
|                     } else { | ||||
|                         socket.emit("np", toSend); | ||||
|                     } | ||||
|                 } | ||||
|             } catch(e){ | ||||
|                 if(socket) { | ||||
|                     socket.emit("np", {}); | ||||
|                 } else { | ||||
|                     io.to(coll).emit("np", {}); | ||||
|                 } | ||||
|             } | ||||
|         }); | ||||
|     }); | ||||
| } | ||||
|  | ||||
| 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}); | ||||
| 			} | ||||
| 		}); | ||||
|     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 left_channel(coll, guid, short_id, in_list, socket, change) | ||||
| { | ||||
| 	if(!coll) return; | ||||
| 	db.collection("connected_users").update({"_id": coll}, {$pull: {users: guid}}, function(err, updated) { | ||||
| 		if(updated.nModified > 0) { | ||||
| 			db.collection("connected_users").find({"_id": coll}, function(err, new_doc){ | ||||
| 				db.collection("frontpage_lists").update({"_id": coll, viewers: {$gt: 0}}, {$inc: {viewers: -1}}, function(err, doc) { | ||||
| 					db.collection("user_names").find({"guid": guid}, function(err, docs) { | ||||
| 						if(docs.length == 1) { | ||||
| 							io.to(coll).emit('chat', {from: docs[0].name, msg: " left"}); | ||||
| 						} | ||||
| 					}); | ||||
| 					io.to(coll).emit("viewers", new_doc[0].users.length); | ||||
| 					socket.leave(coll); | ||||
| 				}); | ||||
| 				db.collection("connected_users").update({"_id": "total_users"}, {$inc: {total_users: -1}}, function(err, updated){}); | ||||
|     if(!coll) return; | ||||
|     db.collection("connected_users").update({"_id": coll}, {$pull: {users: guid}}, function(err, updated) { | ||||
|         if(updated.nModified > 0) { | ||||
|             db.collection("connected_users").find({"_id": coll}, function(err, new_doc){ | ||||
|                 db.collection("frontpage_lists").update({"_id": coll, viewers: {$gt: 0}}, {$inc: {viewers: -1}}, function(err, doc) { | ||||
|                     db.collection("user_names").find({"guid": guid}, function(err, docs) { | ||||
|                         if(docs.length == 1) { | ||||
|                             io.to(coll).emit('chat', {from: docs[0].name, msg: " left"}); | ||||
|                         } | ||||
|                     }); | ||||
|                     io.to(coll).emit("viewers", new_doc[0].users.length); | ||||
|                     socket.leave(coll); | ||||
|                 }); | ||||
|                 db.collection("connected_users").update({"_id": "total_users"}, {$inc: {total_users: -1}}, function(err, updated){}); | ||||
|  | ||||
| 				if(!change) { | ||||
| 					Functions.remove_name_from_db(guid, name); | ||||
| 				} | ||||
| 			}); | ||||
| 		} | ||||
| 	}); | ||||
| 	Functions.remove_unique_id(short_id); | ||||
|                 if(!change) { | ||||
|                     Functions.remove_name_from_db(guid, name); | ||||
|                 } | ||||
|             }); | ||||
|         } | ||||
|     }); | ||||
|     Functions.remove_unique_id(short_id); | ||||
| } | ||||
|  | ||||
| module.exports.now_playing = now_playing; | ||||
|   | ||||
| @@ -1,307 +1,307 @@ | ||||
| function add_function(arr, coll, guid, offline, socket) { | ||||
|   var socketid = socket.zoff_id; | ||||
|   if(typeof(arr) === 'object' && arr !== undefined && arr !== null && arr !== "" && !isNaN(parseInt(arr.duration))) | ||||
|   { | ||||
|     var socketid = socket.zoff_id; | ||||
|     if(typeof(arr) === 'object' && arr !== undefined && arr !== null && arr !== "" && !isNaN(parseInt(arr.duration))) | ||||
|     { | ||||
|  | ||||
|     if(coll == "" || coll == undefined || coll == null) { | ||||
|       socket.emit("update_required"); | ||||
|       return; | ||||
|     } | ||||
|         if(coll == "" || coll == undefined || coll == null) { | ||||
|             socket.emit("update_required"); | ||||
|             return; | ||||
|         } | ||||
|  | ||||
|     db.collection(coll).find({views:{$exists:true}}, function(err, docs){ | ||||
|       if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (arr.hasOwnProperty('pass') && docs[0].userpass == Functions.decrypt_string(socketid, arr.pass)))) { | ||||
|         db.collection(coll).find({views:{$exists:true}}, function(err, docs){ | ||||
|             if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (arr.hasOwnProperty('pass') && docs[0].userpass == Functions.decrypt_string(socketid, arr.pass)))) { | ||||
|  | ||||
|         Functions.check_inlist(coll, guid, socket, offline); | ||||
|                 Functions.check_inlist(coll, guid, socket, offline); | ||||
|  | ||||
|         var id = arr.id; | ||||
|         var title = arr.title; | ||||
|         var hash = Functions.hash_pass(Functions.decrypt_string(socketid, arr.adminpass)); | ||||
|         var duration = parseInt(arr.duration); | ||||
|         var full_list = arr.playlist; | ||||
|         var last = arr.num == arr.total - 1; | ||||
|         var num = arr.num; | ||||
|         var total = arr.total; | ||||
|         db.collection(coll).find({views:{$exists:true}}, function(err, docs) | ||||
|         { | ||||
|           conf = docs; | ||||
|           if(docs !== null && docs.length !== 0 && ((docs[0].addsongs === true && (hash == docs[0].adminpass || docs[0].adminpass === "")) || | ||||
|           docs[0].addsongs === false)) | ||||
|           { | ||||
|             db.collection(coll).find({id:id, type:{$ne:"suggested"}}, function(err, docs){ | ||||
|               if(docs !== null && docs.length === 0) | ||||
|               { | ||||
|                 var guids = full_list === true ? [] : [guid]; | ||||
|                 var votes; | ||||
|                 var added; | ||||
|                 if(full_list) { | ||||
|                   var time = Functions.get_time()-total; | ||||
|                   time = time.toString(); | ||||
|                   var total_len = total.toString().length; | ||||
|                   var now_len = num.toString().length; | ||||
|                   var to_add = num.toString(); | ||||
|                   while(now_len < total_len) { | ||||
|                     to_add = "0" + to_add; | ||||
|                     now_len = to_add.length; | ||||
|                   } | ||||
|                   time = time.substring(0, time.length - total_len); | ||||
|                   time = time + to_add; | ||||
|                   time = parseInt(time); | ||||
|                   added = time; | ||||
|                   votes = 0; | ||||
|                 } else { | ||||
|                   added = Functions.get_time(); | ||||
|                   votes = 1; | ||||
|                 } | ||||
|  | ||||
|                 db.collection(coll).find({now_playing:true}, function(err, docs){ | ||||
|                   if((docs !== null && docs.length === 0)){ | ||||
|                     np = true; | ||||
|                     if(full_list && num === 0){ | ||||
|                       np = true; | ||||
|                       time = time.toString(); | ||||
|                       total += 1; | ||||
|                       var total_len = total.toString().length; | ||||
|                       var now_len = total.toString().length; | ||||
|                       var to_add = total.toString(); | ||||
|                       while(now_len < total_len) { | ||||
|                         to_add = "0" + to_add; | ||||
|                         now_len = to_add.length; | ||||
|                       } | ||||
|                       time = time.substring(0, time.length - total_len); | ||||
|                       time = parseInt(time).toString() + to_add; | ||||
|                       time = parseInt(time); | ||||
|                       added = time; | ||||
|                       votes = 0; | ||||
|                     } else if(full_list) { | ||||
|                       np = false; | ||||
|                     } | ||||
|                   } else { | ||||
|                     np = false; | ||||
|                   } | ||||
|                   db.collection(coll).update({id: id}, {"added": added,"guids":guids,"id":id,"now_playing":np,"title":title,"votes":votes, "duration":duration}, {upsert: true}, function(err, docs){ | ||||
|                     if(np) | ||||
|                 var id = arr.id; | ||||
|                 var title = arr.title; | ||||
|                 var hash = Functions.hash_pass(Functions.decrypt_string(socketid, arr.adminpass)); | ||||
|                 var duration = parseInt(arr.duration); | ||||
|                 var full_list = arr.playlist; | ||||
|                 var last = arr.num == arr.total - 1; | ||||
|                 var num = arr.num; | ||||
|                 var total = arr.total; | ||||
|                 db.collection(coll).find({views:{$exists:true}}, function(err, docs) | ||||
|                 { | ||||
|                     conf = docs; | ||||
|                     if(docs !== null && docs.length !== 0 && ((docs[0].addsongs === true && (hash == docs[0].adminpass || docs[0].adminpass === "")) || | ||||
|                     docs[0].addsongs === false)) | ||||
|                     { | ||||
|                       List.send_list(coll, undefined, false, true, false); | ||||
|                       db.collection(coll).update({views:{$exists:true}}, {$set:{startTime: Functions.get_time()}}); | ||||
|                       List.send_play(coll, undefined); | ||||
|                       Frontpage.update_frontpage(coll, id, title); | ||||
|                     } else { | ||||
|                       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(coll).find({id:id, type:{$ne:"suggested"}}, function(err, docs){ | ||||
|                             if(docs !== null && docs.length === 0) | ||||
|                             { | ||||
|                                 var guids = full_list === true ? [] : [guid]; | ||||
|                                 var votes; | ||||
|                                 var added; | ||||
|                                 if(full_list) { | ||||
|                                     var time = Functions.get_time()-total; | ||||
|                                     time = time.toString(); | ||||
|                                     var total_len = total.toString().length; | ||||
|                                     var now_len = num.toString().length; | ||||
|                                     var to_add = num.toString(); | ||||
|                                     while(now_len < total_len) { | ||||
|                                         to_add = "0" + to_add; | ||||
|                                         now_len = to_add.length; | ||||
|                                     } | ||||
|                                     time = time.substring(0, time.length - total_len); | ||||
|                                     time = time + to_add; | ||||
|                                     time = parseInt(time); | ||||
|                                     added = time; | ||||
|                                     votes = 0; | ||||
|                                 } else { | ||||
|                                     added = Functions.get_time(); | ||||
|                                     votes = 1; | ||||
|                                 } | ||||
|  | ||||
|                                 db.collection(coll).find({now_playing:true}, function(err, docs){ | ||||
|                                     if((docs !== null && docs.length === 0)){ | ||||
|                                         np = true; | ||||
|                                         if(full_list && num === 0){ | ||||
|                                             np = true; | ||||
|                                             time = time.toString(); | ||||
|                                             total += 1; | ||||
|                                             var total_len = total.toString().length; | ||||
|                                             var now_len = total.toString().length; | ||||
|                                             var to_add = total.toString(); | ||||
|                                             while(now_len < total_len) { | ||||
|                                                 to_add = "0" + to_add; | ||||
|                                                 now_len = to_add.length; | ||||
|                                             } | ||||
|                                             time = time.substring(0, time.length - total_len); | ||||
|                                             time = parseInt(time).toString() + to_add; | ||||
|                                             time = parseInt(time); | ||||
|                                             added = time; | ||||
|                                             votes = 0; | ||||
|                                         } else if(full_list) { | ||||
|                                             np = false; | ||||
|                                         } | ||||
|                                     } else { | ||||
|                                         np = false; | ||||
|                                     } | ||||
|                                     db.collection(coll).update({id: id}, {"added": added,"guids":guids,"id":id,"now_playing":np,"title":title,"votes":votes, "duration":duration}, {upsert: true}, function(err, docs){ | ||||
|                                         if(np) | ||||
|                                         { | ||||
|                                             List.send_list(coll, undefined, false, true, false); | ||||
|                                             db.collection(coll).update({views:{$exists:true}}, {$set:{startTime: Functions.get_time()}}); | ||||
|                                             List.send_play(coll, undefined); | ||||
|                                             Frontpage.update_frontpage(coll, id, title); | ||||
|                                         } else { | ||||
|                                             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: Functions.get_time()}}, {upsert:true}, function(err, docs){}); | ||||
|                                         List.getNextSong(coll); | ||||
|                                     }); | ||||
|                                     if(!full_list) { | ||||
|                                         socket.emit("toast", "addedsong"); | ||||
|                                     } else if(full_list && last) { | ||||
|                                         socket.emit("toast", "addedplaylist"); | ||||
|                                     } | ||||
|                                 }); | ||||
|                             } else if(!full_list) { | ||||
|                                 ListChange.vote(coll, id, guid, socket, full_list, last); | ||||
|                                 if(full_list && last) { | ||||
|                                     socket.emit("toast", "addedplaylist"); | ||||
|                                 } | ||||
|                             } else if(full_list && last) { | ||||
|                                 socket.emit("toast", "addedplaylist"); | ||||
|                             } | ||||
|                         }); | ||||
|                     } else if(!full_list) { | ||||
|                         db.collection(coll).find({id: id}, function(err, docs) { | ||||
|                             if(docs.length === 0) { | ||||
|                                 db.collection(coll).update({id: id}, {$set:{ | ||||
|                                     "added":Functions.get_time(), | ||||
|                                     "guids": [guid], | ||||
|                                     "id":id, | ||||
|                                     "now_playing": false, | ||||
|                                     "title":title, | ||||
|                                     "votes":1, | ||||
|                                     "duration":duration, | ||||
|                                     "type":"suggested"} | ||||
|                                 }, | ||||
|                                 {upsert:true}, function(err, docs){ | ||||
|                                     socket.emit("toast", "suggested"); | ||||
|                                     io.to(coll).emit("suggested", {id: id, title: title, duration: duration}); | ||||
|                                 }); | ||||
|                             } else if(docs[0].now_playing === true){ | ||||
|                                 socket.emit("toast", "alreadyplay"); | ||||
|                             } else{ | ||||
|                                 if(conf[0].vote === false) ListChange.vote(coll, id, guid, socket, full_list, last); | ||||
|                                 else socket.emit("toast", "listhaspass"); | ||||
|                             } | ||||
|                         }); | ||||
|                     } else if (full_list){ | ||||
|                         if(arr.num == 0) { | ||||
|                             socket.emit("toast", "listhaspass"); | ||||
|                         } | ||||
|                     } | ||||
|                     db.collection("frontpage_lists").update({_id:coll}, {$inc:{count:1}, $set:{accessed: Functions.get_time()}}, {upsert:true}, function(err, docs){}); | ||||
|                     List.getNextSong(coll); | ||||
|                   }); | ||||
|                   if(!full_list) { | ||||
|                     socket.emit("toast", "addedsong"); | ||||
|                   } else if(full_list && last) { | ||||
|                     socket.emit("toast", "addedplaylist"); | ||||
|                   } | ||||
|                 }); | ||||
|               } else if(!full_list) { | ||||
|                 ListChange.vote(coll, id, guid, socket, full_list, last); | ||||
|                 if(full_list && last) { | ||||
|                   socket.emit("toast", "addedplaylist"); | ||||
|                 } | ||||
|               } else if(full_list && last) { | ||||
|                 socket.emit("toast", "addedplaylist"); | ||||
|               } | ||||
|             }); | ||||
|           } else if(!full_list) { | ||||
|             db.collection(coll).find({id: id}, function(err, docs) { | ||||
|               if(docs.length === 0) { | ||||
|                 db.collection(coll).update({id: id}, {$set:{ | ||||
|                   "added":Functions.get_time(), | ||||
|                   "guids": [guid], | ||||
|                   "id":id, | ||||
|                   "now_playing": false, | ||||
|                   "title":title, | ||||
|                   "votes":1, | ||||
|                   "duration":duration, | ||||
|                   "type":"suggested"} | ||||
|                 }, | ||||
|                 {upsert:true}, function(err, docs){ | ||||
|                   socket.emit("toast", "suggested"); | ||||
|                   io.to(coll).emit("suggested", {id: id, title: title, duration: duration}); | ||||
|                 }); | ||||
|               } else if(docs[0].now_playing === true){ | ||||
|                 socket.emit("toast", "alreadyplay"); | ||||
|               } else{ | ||||
|                 if(conf[0].vote === false) ListChange.vote(coll, id, guid, socket, full_list, last); | ||||
|                 else socket.emit("toast", "listhaspass"); | ||||
|               } | ||||
|             }); | ||||
|           } else if (full_list){ | ||||
|             if(arr.num == 0) { | ||||
|               socket.emit("toast", "listhaspass"); | ||||
|             } else { | ||||
|                 socket.emit("auth_required"); | ||||
|             } | ||||
|           } | ||||
|         }); | ||||
|       } else { | ||||
|         socket.emit("auth_required"); | ||||
|       } | ||||
|     }); | ||||
|   } else { | ||||
|     socket.emit('update_required'); | ||||
|   } | ||||
|     } else { | ||||
|         socket.emit('update_required'); | ||||
|     } | ||||
| } | ||||
|  | ||||
| function voteUndecided(msg, coll, guid, offline, socket) { | ||||
|   var socketid = socket.zoff_id; | ||||
|   if(typeof(msg) === 'object' && msg !== undefined && msg !== null){ | ||||
|     var socketid = socket.zoff_id; | ||||
|     if(typeof(msg) === 'object' && msg !== undefined && msg !== null){ | ||||
|  | ||||
|     if(coll == "" || coll == undefined || coll == null || !msg.hasOwnProperty("adminpass") || !msg.hasOwnProperty("pass") || !msg.hasOwnProperty("id")) { | ||||
|       socket.emit("update_required"); | ||||
|       return; | ||||
|     } | ||||
|  | ||||
|     db.collection(coll).find({views:{$exists:true}}, function(err, docs){ | ||||
|       if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (msg.hasOwnProperty('pass') && docs[0].userpass == Functions.decrypt_string(socketid, msg.pass)))) { | ||||
|  | ||||
|         Functions.check_inlist(coll, guid, socket, offline); | ||||
|  | ||||
|         if(msg.type == "del") | ||||
|         ListChange.del(msg, socket, socketid); | ||||
|         else | ||||
|         { | ||||
|           var id = msg.id; | ||||
|           var hash = Functions.hash_pass(Functions.decrypt_string(socketid, msg.adminpass)); | ||||
|           db.collection(coll).find({views:{$exists:true}}, function(err, docs){ | ||||
|             if(docs !== null && docs.length !== 0 && ((docs[0].vote === true && (hash == docs[0].adminpass || docs[0].adminpass === "")) || | ||||
|             docs[0].vote === false)) | ||||
|             { | ||||
|               ListChange.vote(coll, id, guid, socket, false, false); | ||||
|             }else{ | ||||
|               socket.emit("toast", "listhaspass"); | ||||
|             } | ||||
|           }); | ||||
|         if(coll == "" || coll == undefined || coll == null || !msg.hasOwnProperty("adminpass") || !msg.hasOwnProperty("pass") || !msg.hasOwnProperty("id")) { | ||||
|             socket.emit("update_required"); | ||||
|             return; | ||||
|         } | ||||
|       } else { | ||||
|         socket.emit("auth_required"); | ||||
|       } | ||||
|     }); | ||||
|   } else { | ||||
|     socket.emit('update_required'); | ||||
|   } | ||||
|  | ||||
|         db.collection(coll).find({views:{$exists:true}}, function(err, docs){ | ||||
|             if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (msg.hasOwnProperty('pass') && docs[0].userpass == Functions.decrypt_string(socketid, msg.pass)))) { | ||||
|  | ||||
|                 Functions.check_inlist(coll, guid, socket, offline); | ||||
|  | ||||
|                 if(msg.type == "del") | ||||
|                 ListChange.del(msg, socket, socketid); | ||||
|                 else | ||||
|                 { | ||||
|                     var id = msg.id; | ||||
|                     var hash = Functions.hash_pass(Functions.decrypt_string(socketid, msg.adminpass)); | ||||
|                     db.collection(coll).find({views:{$exists:true}}, function(err, docs){ | ||||
|                         if(docs !== null && docs.length !== 0 && ((docs[0].vote === true && (hash == docs[0].adminpass || docs[0].adminpass === "")) || | ||||
|                         docs[0].vote === false)) | ||||
|                         { | ||||
|                             ListChange.vote(coll, id, guid, socket, false, false); | ||||
|                         }else{ | ||||
|                             socket.emit("toast", "listhaspass"); | ||||
|                         } | ||||
|                     }); | ||||
|                 } | ||||
|             } else { | ||||
|                 socket.emit("auth_required"); | ||||
|             } | ||||
|         }); | ||||
|     } else { | ||||
|         socket.emit('update_required'); | ||||
|     } | ||||
| } | ||||
|  | ||||
| function shuffle(msg, coll, guid, offline, socket) { | ||||
|   var socketid = socket.zoff_id; | ||||
|   if(msg.hasOwnProperty('adminpass') && msg.adminpass !== undefined && msg.adminpass !== null) | ||||
|   { | ||||
|     if(coll == "" || coll == undefined || coll == null) { | ||||
|       socket.emit("update_required"); | ||||
|       return; | ||||
|     } | ||||
|     var socketid = socket.zoff_id; | ||||
|     if(msg.hasOwnProperty('adminpass') && msg.adminpass !== undefined && msg.adminpass !== null) | ||||
|     { | ||||
|         if(coll == "" || coll == undefined || coll == null) { | ||||
|             socket.emit("update_required"); | ||||
|             return; | ||||
|         } | ||||
|  | ||||
|     Functions.check_inlist(coll, guid, socket, offline); | ||||
|     var hash; | ||||
|     if(msg.adminpass === "") hash = msg.adminpass; | ||||
|     else hash = Functions.hash_pass(Functions.decrypt_string(socketid, msg.adminpass)); | ||||
|     db.collection(coll).find({views:{$exists:true}}, function(err, docs){ | ||||
|       if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (msg.hasOwnProperty('pass') && docs[0].userpass == Functions.decrypt_string(socketid, msg.pass)))) { | ||||
|         if(docs !== null && docs.length !== 0 && ((docs[0].adminpass == hash || docs[0].adminpass === "") || docs[0].shuffle === false)) | ||||
|         { | ||||
|           db.collection(coll).find({now_playing:false}).forEach(function(err, docs){ | ||||
|             if(!docs){ | ||||
|               List.send_list(coll, undefined, false, true, false, true); | ||||
|               socket.emit("toast", "shuffled"); | ||||
|         Functions.check_inlist(coll, guid, socket, offline); | ||||
|         var hash; | ||||
|         if(msg.adminpass === "") hash = msg.adminpass; | ||||
|         else hash = Functions.hash_pass(Functions.decrypt_string(socketid, msg.adminpass)); | ||||
|         db.collection(coll).find({views:{$exists:true}}, function(err, docs){ | ||||
|             if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (msg.hasOwnProperty('pass') && docs[0].userpass == Functions.decrypt_string(socketid, msg.pass)))) { | ||||
|                 if(docs !== null && docs.length !== 0 && ((docs[0].adminpass == hash || docs[0].adminpass === "") || docs[0].shuffle === false)) | ||||
|                 { | ||||
|                     db.collection(coll).find({now_playing:false}).forEach(function(err, docs){ | ||||
|                         if(!docs){ | ||||
|                             List.send_list(coll, undefined, false, true, false, true); | ||||
|                             socket.emit("toast", "shuffled"); | ||||
|  | ||||
|               return; | ||||
|             }else{ | ||||
|               num = Math.floor(Math.random()*1000000); | ||||
|               db.collection(coll).update({id:docs.id}, {$set:{added:num}}); | ||||
|                             return; | ||||
|                         }else{ | ||||
|                             num = Math.floor(Math.random()*1000000); | ||||
|                             db.collection(coll).update({id:docs.id}, {$set:{added:num}}); | ||||
|                         } | ||||
|                     }); | ||||
|                 }else | ||||
|                 socket.emit("toast", "wrongpass"); | ||||
|             } else { | ||||
|                 socket.emit("auth_required"); | ||||
|             } | ||||
|           }); | ||||
|         }else | ||||
|         socket.emit("toast", "wrongpass"); | ||||
|       } else { | ||||
|         socket.emit("auth_required"); | ||||
|       } | ||||
|     }); | ||||
|         }); | ||||
|  | ||||
|     var complete = function(tot, curr){ | ||||
|       if(tot == curr) | ||||
|       { | ||||
|         List.send_list(coll, undefined, false, true, false); | ||||
|         List.getNextSong(coll); | ||||
|       } | ||||
|     }; | ||||
|         var complete = function(tot, curr){ | ||||
|             if(tot == curr) | ||||
|             { | ||||
|                 List.send_list(coll, undefined, false, true, false); | ||||
|                 List.getNextSong(coll); | ||||
|             } | ||||
|         }; | ||||
|  | ||||
|   }else | ||||
|   socket.emit("toast", "wrongpass"); | ||||
|     }else | ||||
|     socket.emit("toast", "wrongpass"); | ||||
| } | ||||
|  | ||||
| function del(params, socket, socketid) { | ||||
| 	if(params.id){ | ||||
| 		var coll = emojiStrip(params.channel).toLowerCase(); | ||||
| 		coll = coll.replace("_", ""); | ||||
| 		coll = encodeURIComponent(coll).replace(/\W/g, ''); | ||||
| 		coll = filter.clean(coll); | ||||
| 		db.collection(coll).find({views:{$exists:true}}, function(err, docs){ | ||||
| 			if(docs !== null && docs.length !== 0 && docs[0].adminpass == Functions.hash_pass(Functions.decrypt_string(socketid, params.adminpass))) | ||||
| 			{ | ||||
| 				db.collection(coll).find({id:params.id}, function(err, docs){ | ||||
| 					dont_increment = true; | ||||
| 					if(docs[0]){ | ||||
| 						if(docs[0].type == "suggested"){ | ||||
| 							dont_increment = false; | ||||
| 						} | ||||
| 						db.collection(coll).remove({id:params.id}, function(err, docs){ | ||||
| 							socket.emit("toast", "deletesong"); | ||||
| 							io.to(coll).emit("channel", {type:"deleted", value: params.id}); | ||||
| 							if(dont_increment) db.collection("frontpage_lists").update({_id: coll}, {$inc: {count: -1}, $set:{accessed: Functions.get_time()}}, {upsert: true}, function(err, docs){}); | ||||
| 						}); | ||||
| 					} | ||||
| 				}); | ||||
|     if(params.id){ | ||||
|         var coll = emojiStrip(params.channel).toLowerCase(); | ||||
|         coll = coll.replace("_", ""); | ||||
|         coll = encodeURIComponent(coll).replace(/\W/g, ''); | ||||
|         coll = filter.clean(coll); | ||||
|         db.collection(coll).find({views:{$exists:true}}, function(err, docs){ | ||||
|             if(docs !== null && docs.length !== 0 && docs[0].adminpass == Functions.hash_pass(Functions.decrypt_string(socketid, params.adminpass))) | ||||
|             { | ||||
|                 db.collection(coll).find({id:params.id}, function(err, docs){ | ||||
|                     dont_increment = true; | ||||
|                     if(docs[0]){ | ||||
|                         if(docs[0].type == "suggested"){ | ||||
|                             dont_increment = false; | ||||
|                         } | ||||
|                         db.collection(coll).remove({id:params.id}, function(err, docs){ | ||||
|                             socket.emit("toast", "deletesong"); | ||||
|                             io.to(coll).emit("channel", {type:"deleted", value: params.id}); | ||||
|                             if(dont_increment) db.collection("frontpage_lists").update({_id: coll}, {$inc: {count: -1}, $set:{accessed: Functions.get_time()}}, {upsert: true}, function(err, docs){}); | ||||
|                         }); | ||||
|                     } | ||||
|                 }); | ||||
|  | ||||
| 			} | ||||
| 		}); | ||||
| 	} | ||||
|             } | ||||
|         }); | ||||
|     } | ||||
| } | ||||
|  | ||||
| function delete_all(msg, coll, guid, offline, socket) { | ||||
|   var socketid = socket.zoff_id; | ||||
|   if(typeof(msg) == 'object' && msg.hasOwnProperty('channel') && msg.hasOwnProperty('adminpass') && msg.hasOwnProperty('pass')) { | ||||
|     var hash = Functions.hash_pass(Functions.decrypt_string(socketid, msg.adminpass)); | ||||
|     var hash_userpass = Functions.decrypt_string(socketid, msg.pass); | ||||
|     var socketid = socket.zoff_id; | ||||
|     if(typeof(msg) == 'object' && msg.hasOwnProperty('channel') && msg.hasOwnProperty('adminpass') && msg.hasOwnProperty('pass')) { | ||||
|         var hash = Functions.hash_pass(Functions.decrypt_string(socketid, msg.adminpass)); | ||||
|         var hash_userpass = Functions.decrypt_string(socketid, msg.pass); | ||||
|  | ||||
|     db.collection(coll).find({views: {$exists: true}}, function(err, conf) { | ||||
|       if(conf.length == 1 && conf) { | ||||
|         conf = conf[0]; | ||||
|         if(conf.adminpass == hash && conf.adminpass != "" && (conf.userpass == "" || conf.userpass == undefined || (conf.userpass != "" && conf.userpass != undefined && conf.pass == hash_userpass))) { | ||||
|           db.collection(coll).remove({views: {$exists: false}}, {multi: true}, function(err, succ) { | ||||
|             List.send_list(coll, false, true, true, true); | ||||
|             db.collection("frontpage_lists").update({_id: coll}, {$set: {count: 0, accessed: Functions.get_time()}}, {upsert: true}, function(err, docs) {}); | ||||
|             socket.emit("toast", "deleted_songs"); | ||||
|           }); | ||||
|         } else { | ||||
|           socket.emit("toast", "listhaspass"); | ||||
|         } | ||||
|       } | ||||
|     }); | ||||
|   } else { | ||||
|     socket.emit("update_required"); | ||||
|     return; | ||||
|   } | ||||
|         db.collection(coll).find({views: {$exists: true}}, function(err, conf) { | ||||
|             if(conf.length == 1 && conf) { | ||||
|                 conf = conf[0]; | ||||
|                 if(conf.adminpass == hash && conf.adminpass != "" && (conf.userpass == "" || conf.userpass == undefined || (conf.userpass != "" && conf.userpass != undefined && conf.pass == hash_userpass))) { | ||||
|                     db.collection(coll).remove({views: {$exists: false}}, {multi: true}, function(err, succ) { | ||||
|                         List.send_list(coll, false, true, true, true); | ||||
|                         db.collection("frontpage_lists").update({_id: coll}, {$set: {count: 0, accessed: Functions.get_time()}}, {upsert: true}, function(err, docs) {}); | ||||
|                         socket.emit("toast", "deleted_songs"); | ||||
|                     }); | ||||
|                 } else { | ||||
|                     socket.emit("toast", "listhaspass"); | ||||
|                 } | ||||
|             } | ||||
|         }); | ||||
|     } else { | ||||
|         socket.emit("update_required"); | ||||
|         return; | ||||
|     } | ||||
| } | ||||
|  | ||||
| function vote(coll, id, guid, socket, full_list, last) { | ||||
| 	db.collection(coll).find({id:id, now_playing: false}, function(err, docs){ | ||||
| 		if(docs !== null && docs.length > 0 && !Functions.contains(docs[0].guids, guid)) | ||||
| 		{ | ||||
| 			db.collection(coll).update({id:id}, {$inc:{votes:1}, $set:{added:Functions.get_time()}, $push :{guids: guid}}, function(err, docs) | ||||
| 			{ | ||||
| 				if((full_list && last) || (!full_list)) | ||||
| 				socket.emit("toast", "voted"); | ||||
| 				io.to(coll).emit("channel", {type: "vote", value: id, time: Functions.get_time()}); | ||||
|     db.collection(coll).find({id:id, now_playing: false}, function(err, docs){ | ||||
|         if(docs !== null && docs.length > 0 && !Functions.contains(docs[0].guids, guid)) | ||||
|         { | ||||
|             db.collection(coll).update({id:id}, {$inc:{votes:1}, $set:{added:Functions.get_time()}, $push :{guids: guid}}, function(err, docs) | ||||
|             { | ||||
|                 if((full_list && last) || (!full_list)) | ||||
|                 socket.emit("toast", "voted"); | ||||
|                 io.to(coll).emit("channel", {type: "vote", value: id, time: Functions.get_time()}); | ||||
|  | ||||
| 				List.getNextSong(coll); | ||||
| 			}); | ||||
| 		}else | ||||
| 		{ | ||||
| 			socket.emit("toast", "alreadyvoted"); | ||||
| 		} | ||||
| 	}); | ||||
|                 List.getNextSong(coll); | ||||
|             }); | ||||
|         }else | ||||
|         { | ||||
|             socket.emit("toast", "alreadyvoted"); | ||||
|         } | ||||
|     }); | ||||
| } | ||||
|  | ||||
| module.exports.add_function = add_function; | ||||
|   | ||||
| @@ -1,156 +1,156 @@ | ||||
| function password(inp, coll, guid, offline, socket) { | ||||
|   if(inp !== undefined && inp !== null && inp !== "") | ||||
|   { | ||||
|     pw = inp.password; | ||||
|     opw = inp.password; | ||||
|     try { | ||||
|       coll = inp.channel; | ||||
|       if(coll.length == 0) return; | ||||
|       coll = emojiStrip(coll).toLowerCase(); | ||||
|       coll = coll.replace("_", ""); | ||||
|       coll = encodeURIComponent(coll).replace(/\W/g, ''); | ||||
|       coll = filter.clean(coll); | ||||
|     } catch(e) { | ||||
|       return; | ||||
|     } | ||||
|  | ||||
|     if(coll == "" || coll == undefined || coll == null) { | ||||
|       socket.emit("update_required"); | ||||
|       return; | ||||
|     } | ||||
|  | ||||
|     uncrypted = pw; | ||||
|     pw = Functions.decrypt_string(socket.zoff_id, pw); | ||||
|  | ||||
|     Functions.check_inlist(coll, guid, socket, offline); | ||||
|  | ||||
|     if(inp.oldpass) | ||||
|     if(inp !== undefined && inp !== null && inp !== "") | ||||
|     { | ||||
|       opw = inp.oldpass; | ||||
|     } | ||||
|     opw = Functions.decrypt_string(socket.zoff_id, opw); | ||||
|         pw = inp.password; | ||||
|         opw = inp.password; | ||||
|         try { | ||||
|             coll = inp.channel; | ||||
|             if(coll.length == 0) return; | ||||
|             coll = emojiStrip(coll).toLowerCase(); | ||||
|             coll = coll.replace("_", ""); | ||||
|             coll = encodeURIComponent(coll).replace(/\W/g, ''); | ||||
|             coll = filter.clean(coll); | ||||
|         } catch(e) { | ||||
|             return; | ||||
|         } | ||||
|  | ||||
|     db.collection(coll).find({views:{$exists:true}}, function(err, docs){ | ||||
|       if(docs !== null && docs.length !== 0) | ||||
|       { | ||||
|         if(docs[0].adminpass === "" || docs[0].adminpass == Functions.hash_pass(opw)) | ||||
|         if(coll == "" || coll == undefined || coll == null) { | ||||
|             socket.emit("update_required"); | ||||
|             return; | ||||
|         } | ||||
|  | ||||
|         uncrypted = pw; | ||||
|         pw = Functions.decrypt_string(socket.zoff_id, pw); | ||||
|  | ||||
|         Functions.check_inlist(coll, guid, socket, offline); | ||||
|  | ||||
|         if(inp.oldpass) | ||||
|         { | ||||
|           db.collection(coll).update({views:{$exists:true}}, {$set:{adminpass:Functions.hash_pass(pw)}}, function(err, docs){ | ||||
|             if(inp.oldpass) | ||||
|             socket.emit("toast", "changedpass"); | ||||
|             else | ||||
|             socket.emit("toast", "correctpass"); | ||||
|             socket.emit("pw", true); | ||||
|           }); | ||||
|         }else | ||||
|         socket.emit("toast", "wrongpass"); | ||||
|       } | ||||
|     }); | ||||
|   } else { | ||||
|     socket.emit('update_required'); | ||||
|   } | ||||
|             opw = inp.oldpass; | ||||
|         } | ||||
|         opw = Functions.decrypt_string(socket.zoff_id, opw); | ||||
|  | ||||
|         db.collection(coll).find({views:{$exists:true}}, function(err, docs){ | ||||
|             if(docs !== null && docs.length !== 0) | ||||
|             { | ||||
|                 if(docs[0].adminpass === "" || docs[0].adminpass == Functions.hash_pass(opw)) | ||||
|                 { | ||||
|                     db.collection(coll).update({views:{$exists:true}}, {$set:{adminpass:Functions.hash_pass(pw)}}, function(err, docs){ | ||||
|                         if(inp.oldpass) | ||||
|                         socket.emit("toast", "changedpass"); | ||||
|                         else | ||||
|                         socket.emit("toast", "correctpass"); | ||||
|                         socket.emit("pw", true); | ||||
|                     }); | ||||
|                 }else | ||||
|                 socket.emit("toast", "wrongpass"); | ||||
|             } | ||||
|         }); | ||||
|     } else { | ||||
|         socket.emit('update_required'); | ||||
|     } | ||||
| } | ||||
|  | ||||
| function conf_function(params, coll, guid, offline, socket) { | ||||
|   if(params !== undefined && params !== null && params !== "" && | ||||
|   params.hasOwnProperty('voting') && | ||||
|   params.hasOwnProperty('addsongs') && | ||||
|   params.hasOwnProperty('longsongs') && | ||||
|   params.hasOwnProperty('frontpage') && | ||||
|   params.hasOwnProperty('allvideos') && | ||||
|   params.hasOwnProperty('removeplay') && | ||||
|   params.hasOwnProperty('adminpass') && | ||||
|   params.hasOwnProperty('skipping') && | ||||
|   params.hasOwnProperty('shuffling') && | ||||
|   params.hasOwnProperty('channel')) | ||||
|   { | ||||
|     if(coll !== undefined) { | ||||
|       try { | ||||
|         coll = params.channel; | ||||
|         if(coll.length == 0) return; | ||||
|         coll = emojiStrip(coll).toLowerCase(); | ||||
|         coll = coll.replace("_", ""); | ||||
|         coll = encodeURIComponent(coll).replace(/\W/g, ''); | ||||
|         coll = filter.clean(coll); | ||||
|       } catch(e) { | ||||
|         return; | ||||
|       } | ||||
|     } | ||||
|  | ||||
|     if(coll == "" || coll == undefined || coll == null) { | ||||
|       socket.emit("update_required"); | ||||
|       return; | ||||
|     } | ||||
|  | ||||
|     Functions.check_inlist(coll, guid, socket, offline); | ||||
|  | ||||
|     var voting = params.voting; | ||||
|     var addsongs = params.addsongs; | ||||
|     var longsongs = params.longsongs; | ||||
|     var frontpage = params.frontpage; | ||||
|     var allvideos = params.allvideos; | ||||
|     var removeplay = params.removeplay; | ||||
|     var adminpass = params.adminpass; | ||||
|     var skipping = params.skipping; | ||||
|     var shuffling = params.shuffling; | ||||
|     var userpass = Functions.decrypt_string(socket.zoff_id, params.userpass); | ||||
|  | ||||
|     if((!params.userpass_changed && frontpage) || (params.userpass_changed && userpass == "")) { | ||||
|       userpass = ""; | ||||
|     } else if(params.userpass_changed && userpass != "") { | ||||
|       frontpage = false; | ||||
|     } | ||||
|     var description = ""; | ||||
|     var hash; | ||||
|     if(params.description) description = params.description; | ||||
|  | ||||
|     if(adminpass !== "") { | ||||
|       hash = Functions.hash_pass(Functions.decrypt_string(socket.zoff_id, adminpass)); | ||||
|     } else { | ||||
|       hash = adminpass; | ||||
|     } | ||||
|     db.collection(coll).find({views:{$exists:true}}, function(err, docs){ | ||||
|       if(docs !== null && docs.length !== 0 && (docs[0].adminpass === "" || docs[0].adminpass == hash)) { | ||||
|         var obj = { | ||||
|           addsongs:addsongs, | ||||
|             allvideos:allvideos, | ||||
|             frontpage:frontpage, | ||||
|             skip:skipping, | ||||
|             vote:voting, | ||||
|             removeplay:removeplay, | ||||
|             shuffle:shuffling, | ||||
|             longsongs:longsongs, | ||||
|             adminpass:hash, | ||||
|             desc: description, | ||||
|         }; | ||||
|         if(params.userpass_changed) { | ||||
|           obj["userpass"] = userpass; | ||||
|         } else if (frontpage) { | ||||
|           obj["userpass"] = ""; | ||||
|     if(params !== undefined && params !== null && params !== "" && | ||||
|     params.hasOwnProperty('voting') && | ||||
|     params.hasOwnProperty('addsongs') && | ||||
|     params.hasOwnProperty('longsongs') && | ||||
|     params.hasOwnProperty('frontpage') && | ||||
|     params.hasOwnProperty('allvideos') && | ||||
|     params.hasOwnProperty('removeplay') && | ||||
|     params.hasOwnProperty('adminpass') && | ||||
|     params.hasOwnProperty('skipping') && | ||||
|     params.hasOwnProperty('shuffling') && | ||||
|     params.hasOwnProperty('channel')) | ||||
|     { | ||||
|         if(coll !== undefined) { | ||||
|             try { | ||||
|                 coll = params.channel; | ||||
|                 if(coll.length == 0) return; | ||||
|                 coll = emojiStrip(coll).toLowerCase(); | ||||
|                 coll = coll.replace("_", ""); | ||||
|                 coll = encodeURIComponent(coll).replace(/\W/g, ''); | ||||
|                 coll = filter.clean(coll); | ||||
|             } catch(e) { | ||||
|                 return; | ||||
|             } | ||||
|         } | ||||
|         db.collection(coll).update({views:{$exists:true}}, { | ||||
|           $set:obj | ||||
|         }, function(err, docs){ | ||||
|           db.collection(coll).find({views:{$exists:true}}, function(err, docs){ | ||||
|             if(docs[0].adminpass !== "") docs[0].adminpass = true; | ||||
|             if(docs[0].hasOwnProperty("userpass") && docs[0].userpass != "") docs[0].userpass = true; | ||||
|             else docs[0].userpass = false; | ||||
|             io.to(coll).emit("conf", docs); | ||||
|             socket.emit("toast", "savedsettings"); | ||||
|  | ||||
|             db.collection("frontpage_lists").update({_id: coll}, {$set:{ | ||||
|               frontpage:frontpage, accessed: Functions.get_time()} | ||||
|             }, | ||||
|             {upsert:true}, function(err, docs){}); | ||||
|           }); | ||||
|         if(coll == "" || coll == undefined || coll == null) { | ||||
|             socket.emit("update_required"); | ||||
|             return; | ||||
|         } | ||||
|  | ||||
|         Functions.check_inlist(coll, guid, socket, offline); | ||||
|  | ||||
|         var voting = params.voting; | ||||
|         var addsongs = params.addsongs; | ||||
|         var longsongs = params.longsongs; | ||||
|         var frontpage = params.frontpage; | ||||
|         var allvideos = params.allvideos; | ||||
|         var removeplay = params.removeplay; | ||||
|         var adminpass = params.adminpass; | ||||
|         var skipping = params.skipping; | ||||
|         var shuffling = params.shuffling; | ||||
|         var userpass = Functions.decrypt_string(socket.zoff_id, params.userpass); | ||||
|  | ||||
|         if((!params.userpass_changed && frontpage) || (params.userpass_changed && userpass == "")) { | ||||
|             userpass = ""; | ||||
|         } else if(params.userpass_changed && userpass != "") { | ||||
|             frontpage = false; | ||||
|         } | ||||
|         var description = ""; | ||||
|         var hash; | ||||
|         if(params.description) description = params.description; | ||||
|  | ||||
|         if(adminpass !== "") { | ||||
|             hash = Functions.hash_pass(Functions.decrypt_string(socket.zoff_id, adminpass)); | ||||
|         } else { | ||||
|             hash = adminpass; | ||||
|         } | ||||
|         db.collection(coll).find({views:{$exists:true}}, function(err, docs){ | ||||
|             if(docs !== null && docs.length !== 0 && (docs[0].adminpass === "" || docs[0].adminpass == hash)) { | ||||
|                 var obj = { | ||||
|                     addsongs:addsongs, | ||||
|                     allvideos:allvideos, | ||||
|                     frontpage:frontpage, | ||||
|                     skip:skipping, | ||||
|                     vote:voting, | ||||
|                     removeplay:removeplay, | ||||
|                     shuffle:shuffling, | ||||
|                     longsongs:longsongs, | ||||
|                     adminpass:hash, | ||||
|                     desc: description, | ||||
|                 }; | ||||
|                 if(params.userpass_changed) { | ||||
|                     obj["userpass"] = userpass; | ||||
|                 } else if (frontpage) { | ||||
|                     obj["userpass"] = ""; | ||||
|                 } | ||||
|                 db.collection(coll).update({views:{$exists:true}}, { | ||||
|                     $set:obj | ||||
|                 }, function(err, docs){ | ||||
|                     db.collection(coll).find({views:{$exists:true}}, function(err, docs){ | ||||
|                         if(docs[0].adminpass !== "") docs[0].adminpass = true; | ||||
|                         if(docs[0].hasOwnProperty("userpass") && docs[0].userpass != "") docs[0].userpass = true; | ||||
|                         else docs[0].userpass = false; | ||||
|                         io.to(coll).emit("conf", docs); | ||||
|                         socket.emit("toast", "savedsettings"); | ||||
|  | ||||
|                         db.collection("frontpage_lists").update({_id: coll}, {$set:{ | ||||
|                             frontpage:frontpage, accessed: Functions.get_time()} | ||||
|                         }, | ||||
|                         {upsert:true}, function(err, docs){}); | ||||
|                     }); | ||||
|                 }); | ||||
|             } else { | ||||
|                 socket.emit("toast", "wrongpass"); | ||||
|             } | ||||
|         }); | ||||
|       } else { | ||||
|         socket.emit("toast", "wrongpass"); | ||||
|       } | ||||
|     }); | ||||
|   } else { | ||||
|     socket.emit('update_required'); | ||||
|   } | ||||
|     } else { | ||||
|         socket.emit('update_required'); | ||||
|     } | ||||
| } | ||||
|  | ||||
| module.exports.password = password; | ||||
|   | ||||
| @@ -1,43 +1,43 @@ | ||||
| function thumbnail(msg, coll, guid, offline, socket) { | ||||
|   if(msg.thumbnail && msg.channel && msg.adminpass && msg.thumbnail.indexOf("i.imgur.com") > -1){ | ||||
|     msg.thumbnail = msg.thumbnail.replace(/^https?\:\/\//i, ""); | ||||
|     if(msg.thumbnail.substring(0,2) != "//") msg.thumbnail = "//" + msg.thumbnail; | ||||
|     var channel = msg.channel.toLowerCase(); | ||||
|     var hash = Functions.hash_pass(Functions.decrypt_string(socket.zoff_id, msg.adminpass)); | ||||
|     db.collection(channel).find({views:{$exists:true}}, function(err, docs){ | ||||
|       if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (msg.hasOwnProperty('pass') && docs[0].userpass == Functions.decrypt_string(socketid, msg.pass)))) { | ||||
|         if(docs !== null && docs.length !== 0 && docs[0].adminpass !== "" && docs[0].adminpass == hash){ | ||||
|           db.collection("suggested_thumbnails").update({channel: channel}, {$set:{thumbnail: msg.thumbnail}}, {upsert:true}, function(err, docs){ | ||||
|             socket.emit("toast", "suggested_thumbnail"); | ||||
|           }); | ||||
|         } | ||||
|       } else { | ||||
|         socket.emit("auth_required"); | ||||
|       } | ||||
|     }); | ||||
|   } else { | ||||
|     socket.emit("toast", "thumbnail_denied"); | ||||
|   } | ||||
|     if(msg.thumbnail && msg.channel && msg.adminpass && msg.thumbnail.indexOf("i.imgur.com") > -1){ | ||||
|         msg.thumbnail = msg.thumbnail.replace(/^https?\:\/\//i, ""); | ||||
|         if(msg.thumbnail.substring(0,2) != "//") msg.thumbnail = "//" + msg.thumbnail; | ||||
|         var channel = msg.channel.toLowerCase(); | ||||
|         var hash = Functions.hash_pass(Functions.decrypt_string(socket.zoff_id, msg.adminpass)); | ||||
|         db.collection(channel).find({views:{$exists:true}}, function(err, docs){ | ||||
|             if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (msg.hasOwnProperty('pass') && docs[0].userpass == Functions.decrypt_string(socketid, msg.pass)))) { | ||||
|                 if(docs !== null && docs.length !== 0 && docs[0].adminpass !== "" && docs[0].adminpass == hash){ | ||||
|                     db.collection("suggested_thumbnails").update({channel: channel}, {$set:{thumbnail: msg.thumbnail}}, {upsert:true}, function(err, docs){ | ||||
|                         socket.emit("toast", "suggested_thumbnail"); | ||||
|                     }); | ||||
|                 } | ||||
|             } else { | ||||
|                 socket.emit("auth_required"); | ||||
|             } | ||||
|         }); | ||||
|     } else { | ||||
|         socket.emit("toast", "thumbnail_denied"); | ||||
|     } | ||||
| } | ||||
|  | ||||
| function description(msg, coll, guid, offline, socket) { | ||||
|   if(msg.description && msg.channel && msg.adminpass && msg.description.length < 100){ | ||||
|     var channel = msg.channel.toLowerCase(); | ||||
|     var hash = Functions.hash_pass(Functions.decrypt_string(socket.zoff_id, msg.adminpass)); | ||||
|     db.collection(channel).find({views:{$exists:true}}, function(err, docs){ | ||||
|       if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (msg.hasOwnProperty('pass') && docs[0].userpass == Functions.decrypt_string(socketid, msg.pass)))) { | ||||
|         if(docs !== null && docs.length !== 0 && docs[0].adminpass !== "" && docs[0].adminpass == hash){ | ||||
|           db.collection("suggested_descriptions").update({channel: channel}, {$set:{description: msg.description}}, {upsert:true}, function(err, docs){ | ||||
|             socket.emit("toast", "suggested_description"); | ||||
|           }); | ||||
|         } | ||||
|       } else { | ||||
|         socket.emit("auth_required"); | ||||
|       } | ||||
|     }); | ||||
|   } else { | ||||
|     socket.emit("toast", "description_denied"); | ||||
|   } | ||||
|     if(msg.description && msg.channel && msg.adminpass && msg.description.length < 100){ | ||||
|         var channel = msg.channel.toLowerCase(); | ||||
|         var hash = Functions.hash_pass(Functions.decrypt_string(socket.zoff_id, msg.adminpass)); | ||||
|         db.collection(channel).find({views:{$exists:true}}, function(err, docs){ | ||||
|             if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (msg.hasOwnProperty('pass') && docs[0].userpass == Functions.decrypt_string(socketid, msg.pass)))) { | ||||
|                 if(docs !== null && docs.length !== 0 && docs[0].adminpass !== "" && docs[0].adminpass == hash){ | ||||
|                     db.collection("suggested_descriptions").update({channel: channel}, {$set:{description: msg.description}}, {upsert:true}, function(err, docs){ | ||||
|                         socket.emit("toast", "suggested_description"); | ||||
|                     }); | ||||
|                 } | ||||
|             } else { | ||||
|                 socket.emit("auth_required"); | ||||
|             } | ||||
|         }); | ||||
|     } else { | ||||
|         socket.emit("toast", "description_denied"); | ||||
|     } | ||||
| } | ||||
|  | ||||
| module.exports.thumbnail = thumbnail; | ||||
|   | ||||
| @@ -1,40 +1,40 @@ | ||||
| window.addEventListener("load", function() { | ||||
| 	var query = getQueryHash(window.location.hash); | ||||
| 	var redirect  = window.location.protocol + "//" + window.location.hostname + "/o_callback"; | ||||
| 	var client_id; | ||||
| 	var response; | ||||
| 	var scope; | ||||
|     var query = getQueryHash(window.location.hash); | ||||
|     var redirect  = window.location.protocol + "//" + window.location.hostname + "/o_callback"; | ||||
|     var client_id; | ||||
|     var response; | ||||
|     var scope; | ||||
|  | ||||
| 	if(query.spotify) { | ||||
| 		client_id = "b934ecdd173648f5bcd38738af529d58"; | ||||
| 		response  = "token"; | ||||
| 		scope     = "playlist-read-private playlist-read-collaborative user-read-private playlist-modify-public"; | ||||
| 		state     = query.nonce; | ||||
| 		window.location.href = "https://accounts.spotify.com/authorize?client_id=" + client_id + "&scope=" + scope + "&show_dialog=false&response_type=" + response + "&redirect_uri=" + redirect + "&state=" + state; | ||||
|     if(query.spotify) { | ||||
|         client_id = "b934ecdd173648f5bcd38738af529d58"; | ||||
|         response  = "token"; | ||||
|         scope     = "playlist-read-private playlist-read-collaborative user-read-private playlist-modify-public"; | ||||
|         state     = query.nonce; | ||||
|         window.location.href = "https://accounts.spotify.com/authorize?client_id=" + client_id + "&scope=" + scope + "&show_dialog=false&response_type=" + response + "&redirect_uri=" + redirect + "&state=" + state; | ||||
|  | ||||
| 	} else if (query.youtube) { | ||||
| 		client_id = "944988770273-butsmlr1aotlsskk8lmgvh0etqqekigf.apps.googleusercontent.com"; | ||||
| 		response  = "token"; | ||||
| 		scope     = "https://www.googleapis.com/auth/youtube"; | ||||
| 		state     = query.nonce; | ||||
|     } else if (query.youtube) { | ||||
|         client_id = "944988770273-butsmlr1aotlsskk8lmgvh0etqqekigf.apps.googleusercontent.com"; | ||||
|         response  = "token"; | ||||
|         scope     = "https://www.googleapis.com/auth/youtube"; | ||||
|         state     = query.nonce; | ||||
|  | ||||
| 		//window.opener.callback(query); | ||||
| 		window.location.href = "https://accounts.google.com/o/oauth2/v2/auth?client_id=" + client_id + "&response_type=" + response + "&state=" + state + "&redirect_uri=" + redirect + "&scope=" + scope; | ||||
| 	} else { | ||||
| 		var query_parameters = getQueryHash(window.location.hash); | ||||
| 		window.opener.callback(query_parameters); | ||||
| 	} | ||||
|         //window.opener.callback(query); | ||||
|         window.location.href = "https://accounts.google.com/o/oauth2/v2/auth?client_id=" + client_id + "&response_type=" + response + "&state=" + state + "&redirect_uri=" + redirect + "&scope=" + scope; | ||||
|     } else { | ||||
|         var query_parameters = getQueryHash(window.location.hash); | ||||
|         window.opener.callback(query_parameters); | ||||
|     } | ||||
| }); | ||||
|  | ||||
| function getQueryHash(url) { | ||||
| 	var temp_arr = url.substring(1).split("&"); | ||||
| 	var done_obj = {}; | ||||
| 	var splitted; | ||||
| 	for(var i in temp_arr) { | ||||
| 		splitted = temp_arr[i].split("="); | ||||
| 		if(splitted.length == 2) { | ||||
| 			done_obj[splitted[0]] = splitted[1]; | ||||
| 		} | ||||
| 	} | ||||
| 	return done_obj; | ||||
|     var temp_arr = url.substring(1).split("&"); | ||||
|     var done_obj = {}; | ||||
|     var splitted; | ||||
|     for(var i in temp_arr) { | ||||
|         splitted = temp_arr[i].split("="); | ||||
|         if(splitted.length == 2) { | ||||
|             done_obj[splitted[0]] = splitted[1]; | ||||
|         } | ||||
|     } | ||||
|     return done_obj; | ||||
| } | ||||
|   | ||||
| @@ -1,149 +1,149 @@ | ||||
| var Chat = { | ||||
|  | ||||
| 	channel_received: 0, | ||||
| 	all_received: 0, | ||||
| 	chat_help: [/*"/name <new name> to change name", "/removename to remove name"*/ "There are no commands.. As of now!"], | ||||
|     channel_received: 0, | ||||
|     all_received: 0, | ||||
|     chat_help: [/*"/name <new name> to change name", "/removename to remove name"*/ "There are no commands.. As of now!"], | ||||
|  | ||||
| 	namechange: function(newName) { | ||||
| 		socket.emit("namechange", {name: newName, channel: chan.toLowerCase()}); | ||||
| 		Crypt.set_name(newName); | ||||
| 	}, | ||||
|     namechange: function(newName) { | ||||
|         socket.emit("namechange", {name: newName, channel: chan.toLowerCase()}); | ||||
|         Crypt.set_name(newName); | ||||
|     }, | ||||
|  | ||||
| 	removename: function() { | ||||
| 		socket.emit("removename"); | ||||
| 		Crypt.remove_name(); | ||||
| 	}, | ||||
|     removename: function() { | ||||
|         socket.emit("removename"); | ||||
|         Crypt.remove_name(); | ||||
|     }, | ||||
|  | ||||
| 	chat: function(data) { | ||||
| 		if(data.value.length > 150) | ||||
| 		      return; | ||||
| 		/*if(data.value.startsWith("/name ")){ | ||||
| 			Chat.namechange(data.value.substring(6)); | ||||
| 		} else */ | ||||
|         if(data.value.startsWith("/help")) { | ||||
| 			if($(".chat-tab-li a.active").attr("href") == "#all_chat"){ | ||||
| 				if($("#chatall").children().length > 100) { | ||||
| 					$("#chatall").children()[0].remove() | ||||
| 				} | ||||
| 				for(var x = 0; x < Chat.chat_help.length; x++) { | ||||
| 					var color = Helper.intToARGB(Helper.hashCode("System")); | ||||
| 					if(color.length < 6) { | ||||
| 						for(x = color.length; x < 6; x++) { | ||||
| 							color = "0" + color; | ||||
| 						} | ||||
| 					} | ||||
| 					color = Helper.hexToRgb(color.substring(0,6)); | ||||
| 					var color_temp = Helper.rgbToHsl([color.r, color.g, color.b], false); | ||||
| 					$("#chatall").append("<li title='Zoff''><span style='color:"+color_temp+";'>System</span>: </li>"); | ||||
| 					var in_text = document.createTextNode(Chat.chat_help[x]); | ||||
| 					$("#chatall li:last")[0].appendChild(in_text); | ||||
| 					document.getElementById("chatall").scrollTop = document.getElementById("chatall").scrollHeight; | ||||
| 				} | ||||
| 			} else { | ||||
| 				if($("#chatchannel").children().length > 100) { | ||||
| 					$("#chatchannel").children()[0].remove() | ||||
| 				} | ||||
| 				for(var x = 0; x < Chat.chat_help.length; x++) { | ||||
|     chat: function(data) { | ||||
|         if(data.value.length > 150) | ||||
|         return; | ||||
|         /*if(data.value.startsWith("/name ")){ | ||||
|         Chat.namechange(data.value.substring(6)); | ||||
|     } else */ | ||||
|     if(data.value.startsWith("/help")) { | ||||
|         if($(".chat-tab-li a.active").attr("href") == "#all_chat"){ | ||||
|             if($("#chatall").children().length > 100) { | ||||
|                 $("#chatall").children()[0].remove() | ||||
|             } | ||||
|             for(var x = 0; x < Chat.chat_help.length; x++) { | ||||
|                 var color = Helper.intToARGB(Helper.hashCode("System")); | ||||
|                 if(color.length < 6) { | ||||
|                     for(x = color.length; x < 6; x++) { | ||||
|                         color = "0" + color; | ||||
|                     } | ||||
|                 } | ||||
|                 color = Helper.hexToRgb(color.substring(0,6)); | ||||
|                 var color_temp = Helper.rgbToHsl([color.r, color.g, color.b], false); | ||||
|                 $("#chatall").append("<li title='Zoff''><span style='color:"+color_temp+";'>System</span>: </li>"); | ||||
|                 var in_text = document.createTextNode(Chat.chat_help[x]); | ||||
|                 $("#chatall li:last")[0].appendChild(in_text); | ||||
|                 document.getElementById("chatall").scrollTop = document.getElementById("chatall").scrollHeight; | ||||
|             } | ||||
|         } else { | ||||
|             if($("#chatchannel").children().length > 100) { | ||||
|                 $("#chatchannel").children()[0].remove() | ||||
|             } | ||||
|             for(var x = 0; x < Chat.chat_help.length; x++) { | ||||
|  | ||||
| 					var color = Helper.intToARGB(Helper.hashCode("System")); | ||||
| 					if(color.length < 6) { | ||||
| 						for(x = color.length; x < 6; x++) { | ||||
| 							color = "0" + color; | ||||
| 						} | ||||
| 					} | ||||
| 					color = Helper.hexToRgb(color.substring(0,6)); | ||||
| 					var color_temp = Helper.rgbToHsl([color.r, color.g, color.b], false); | ||||
| 					$("#chatchannel").append("<li><span style='color:"+color_temp+";'>System</span>: </li>"); | ||||
| 					var in_text = document.createTextNode(Chat.chat_help[x]); | ||||
| 					$("#chatchannel li:last")[0].appendChild(in_text); | ||||
| 					document.getElementById("chatchannel").scrollTop = document.getElementById("chatchannel").scrollHeight; | ||||
| 				} | ||||
| 			} | ||||
| 		} else if(data.value.startsWith("/removename")) { | ||||
| 			Chat.removename(); | ||||
| 		} else if($(".chat-tab-li a.active").attr("href") == "#all_chat") { | ||||
| 			socket.emit("all,chat", {channel: chan.toLowerCase(), data: data.value}); | ||||
| 		} else { | ||||
| 			socket.emit("chat", {channel: chan.toLowerCase(), data: data.value, pass: embed ? '' : Crypt.crypt_pass(Crypt.get_userpass(chan.toLowerCase()))}); | ||||
| 		} | ||||
| 		data.value = ""; | ||||
| 		return; | ||||
| 	}, | ||||
|                 var color = Helper.intToARGB(Helper.hashCode("System")); | ||||
|                 if(color.length < 6) { | ||||
|                     for(x = color.length; x < 6; x++) { | ||||
|                         color = "0" + color; | ||||
|                     } | ||||
|                 } | ||||
|                 color = Helper.hexToRgb(color.substring(0,6)); | ||||
|                 var color_temp = Helper.rgbToHsl([color.r, color.g, color.b], false); | ||||
|                 $("#chatchannel").append("<li><span style='color:"+color_temp+";'>System</span>: </li>"); | ||||
|                 var in_text = document.createTextNode(Chat.chat_help[x]); | ||||
|                 $("#chatchannel li:last")[0].appendChild(in_text); | ||||
|                 document.getElementById("chatchannel").scrollTop = document.getElementById("chatchannel").scrollHeight; | ||||
|             } | ||||
|         } | ||||
|     } else if(data.value.startsWith("/removename")) { | ||||
|         Chat.removename(); | ||||
|     } else if($(".chat-tab-li a.active").attr("href") == "#all_chat") { | ||||
|         socket.emit("all,chat", {channel: chan.toLowerCase(), data: data.value}); | ||||
|     } else { | ||||
|         socket.emit("chat", {channel: chan.toLowerCase(), data: data.value, pass: embed ? '' : Crypt.crypt_pass(Crypt.get_userpass(chan.toLowerCase()))}); | ||||
|     } | ||||
|     data.value = ""; | ||||
|     return; | ||||
| }, | ||||
|  | ||||
| 	allchat: function(inp) { | ||||
| 		if(inp.msg.substring(0,1) == ":" && !chat_active) { | ||||
| 			Chat.all_received += 1; | ||||
| 			$("#favicon").attr("href", "/assets/images/highlogo.png"); | ||||
| 			unseen = true; | ||||
| 			chat_unseen = true; | ||||
| 			if($(".chat-link span.badge.new.white").hasClass("hide")){ | ||||
| 				$(".chat-link span.badge.new.white").removeClass("hide"); | ||||
| 			} | ||||
| 			var to_display = Chat.channel_received + Chat.all_received > 9 ? "9+" : Chat.channel_received + Chat.all_received; | ||||
| 			$(".chat-link span.badge.new.white").html(to_display); | ||||
| 		} | ||||
| allchat: function(inp) { | ||||
|     if(inp.msg.substring(0,1) == ":" && !chat_active) { | ||||
|         Chat.all_received += 1; | ||||
|         $("#favicon").attr("href", "/assets/images/highlogo.png"); | ||||
|         unseen = true; | ||||
|         chat_unseen = true; | ||||
|         if($(".chat-link span.badge.new.white").hasClass("hide")){ | ||||
|             $(".chat-link span.badge.new.white").removeClass("hide"); | ||||
|         } | ||||
|         var to_display = Chat.channel_received + Chat.all_received > 9 ? "9+" : Chat.channel_received + Chat.all_received; | ||||
|         $(".chat-link span.badge.new.white").html(to_display); | ||||
|     } | ||||
|  | ||||
| 		if(document.hidden)	{ | ||||
| 			$("#favicon").attr("href", "/assets/images/highlogo.png"); | ||||
| 		} | ||||
|     if(document.hidden)	{ | ||||
|         $("#favicon").attr("href", "/assets/images/highlogo.png"); | ||||
|     } | ||||
|  | ||||
| 		if($("#chatall").children().length > 100) { | ||||
| 			$("#chatall").children()[0].remove() | ||||
| 		} | ||||
| 		var color = Helper.intToARGB(Helper.hashCode(inp.from)); | ||||
| 		if(color.length < 6) { | ||||
| 			for(x = color.length; x < 6; x++){ | ||||
| 				color = "0" + color; | ||||
| 			} | ||||
| 		} | ||||
| 		color = Helper.hexToRgb(color.substring(0,6)); | ||||
| 		var color_temp = Helper.rgbToHsl([color.r, color.g, color.b], false); | ||||
| 		$("#chatall").append("<li title='"+inp.channel+"''><span style='color:"+color_temp+";'>"+inp.from+"</span></li>"); | ||||
| 		var in_text = document.createTextNode(inp.msg); | ||||
| 		$("#chatall li:last")[0].appendChild(in_text); | ||||
| 		document.getElementById("chatall").scrollTop = document.getElementById("chatall").scrollHeight; | ||||
| 	}, | ||||
|     if($("#chatall").children().length > 100) { | ||||
|         $("#chatall").children()[0].remove() | ||||
|     } | ||||
|     var color = Helper.intToARGB(Helper.hashCode(inp.from)); | ||||
|     if(color.length < 6) { | ||||
|         for(x = color.length; x < 6; x++){ | ||||
|             color = "0" + color; | ||||
|         } | ||||
|     } | ||||
|     color = Helper.hexToRgb(color.substring(0,6)); | ||||
|     var color_temp = Helper.rgbToHsl([color.r, color.g, color.b], false); | ||||
|     $("#chatall").append("<li title='"+inp.channel+"''><span style='color:"+color_temp+";'>"+inp.from+"</span></li>"); | ||||
|     var in_text = document.createTextNode(inp.msg); | ||||
|     $("#chatall li:last")[0].appendChild(in_text); | ||||
|     document.getElementById("chatall").scrollTop = document.getElementById("chatall").scrollHeight; | ||||
| }, | ||||
|  | ||||
| 	channelchat: function(data) { | ||||
| 		if(data.msg.substring(0,1) == ":" && !chat_active) { | ||||
| 			$("#favicon").attr("href", "/assets/images/highlogo.png"); | ||||
| 			unseen = true; | ||||
| 			chat_unseen = true; | ||||
| 			Chat.channel_received += 1; | ||||
| 			//blink_interval = setTimeout(Chat.chat_blink, 1000); | ||||
| 			if($(".chat-link span.badge.new.white").hasClass("hide")) { | ||||
| 				$(".chat-link span.badge.new.white").removeClass("hide"); | ||||
| 			} | ||||
| 			var to_display = Chat.channel_received + Chat.all_received > 9 ? "9+" : Chat.channel_received + Chat.all_received; | ||||
| 			$(".chat-link span.badge.new.white").html(to_display); | ||||
| 		} | ||||
| channelchat: function(data) { | ||||
|     if(data.msg.substring(0,1) == ":" && !chat_active) { | ||||
|         $("#favicon").attr("href", "/assets/images/highlogo.png"); | ||||
|         unseen = true; | ||||
|         chat_unseen = true; | ||||
|         Chat.channel_received += 1; | ||||
|         //blink_interval = setTimeout(Chat.chat_blink, 1000); | ||||
|         if($(".chat-link span.badge.new.white").hasClass("hide")) { | ||||
|             $(".chat-link span.badge.new.white").removeClass("hide"); | ||||
|         } | ||||
|         var to_display = Chat.channel_received + Chat.all_received > 9 ? "9+" : Chat.channel_received + Chat.all_received; | ||||
|         $(".chat-link span.badge.new.white").html(to_display); | ||||
|     } | ||||
|  | ||||
| 		if($("#chatchannel").children().length > 100) { | ||||
| 			$("#chatchannel").children()[0].remove() | ||||
| 		} | ||||
|     if($("#chatchannel").children().length > 100) { | ||||
|         $("#chatchannel").children()[0].remove() | ||||
|     } | ||||
|  | ||||
| 		var color = Helper.intToARGB(Helper.hashCode(data.from)); | ||||
| 		if(color.length < 6) { | ||||
| 			for(x = color.length; x < 6; x++) { | ||||
| 				color = "0" + color; | ||||
| 			} | ||||
| 		} | ||||
| 		color = Helper.hexToRgb(color.substring(0,6)); | ||||
| 		var color_temp = Helper.rgbToHsl([color.r, color.g, color.b], false); | ||||
| 		$("#chatchannel").append("<li><span style='color:"+color_temp+";'>"+data.from+"</span></li>"); | ||||
| 		var in_text = document.createTextNode(data.msg); | ||||
| 		$("#chatchannel li:last")[0].appendChild(in_text); | ||||
| 		document.getElementById("chatchannel").scrollTop = document.getElementById("chatchannel").scrollHeight; | ||||
| 	}, | ||||
|     var color = Helper.intToARGB(Helper.hashCode(data.from)); | ||||
|     if(color.length < 6) { | ||||
|         for(x = color.length; x < 6; x++) { | ||||
|             color = "0" + color; | ||||
|         } | ||||
|     } | ||||
|     color = Helper.hexToRgb(color.substring(0,6)); | ||||
|     var color_temp = Helper.rgbToHsl([color.r, color.g, color.b], false); | ||||
|     $("#chatchannel").append("<li><span style='color:"+color_temp+";'>"+data.from+"</span></li>"); | ||||
|     var in_text = document.createTextNode(data.msg); | ||||
|     $("#chatchannel li:last")[0].appendChild(in_text); | ||||
|     document.getElementById("chatchannel").scrollTop = document.getElementById("chatchannel").scrollHeight; | ||||
| }, | ||||
|  | ||||
| 	chat_blink: function() { | ||||
| 		blinking = true; | ||||
| 		$(".chat-link").attr("style", "color: grey !important;"); | ||||
| 		setTimeout(function () { | ||||
| 			$(".chat-link").attr("style", "color: white !important;"); | ||||
| 			setTimeout(function() { | ||||
| 				if(blinking) Chat.chat_blink(); | ||||
| 			}, 1000); | ||||
| 		}, 1000); | ||||
| 	} | ||||
| chat_blink: function() { | ||||
|     blinking = true; | ||||
|     $(".chat-link").attr("style", "color: grey !important;"); | ||||
|     setTimeout(function () { | ||||
|         $(".chat-link").attr("style", "color: white !important;"); | ||||
|         setTimeout(function() { | ||||
|             if(blinking) Chat.chat_blink(); | ||||
|         }, 1000); | ||||
|     }, 1000); | ||||
| } | ||||
| }; | ||||
|   | ||||
| @@ -1,238 +1,238 @@ | ||||
| var Crypt = { | ||||
|  | ||||
| 	conf_pass: undefined, | ||||
| 	user_pass: undefined, | ||||
| 	tmp_pass: "", | ||||
|     conf_pass: undefined, | ||||
|     user_pass: undefined, | ||||
|     tmp_pass: "", | ||||
|  | ||||
| 	init: function() { | ||||
|     init: function() { | ||||
|  | ||||
| 		if(window.location.pathname != "/") { | ||||
| 			if (location.protocol != "https:") { | ||||
| 				document.cookie = chan.toLowerCase() + '=;path=/' + chan.toLowerCase() + ';expires=' + new Date(0).toUTCString(); | ||||
| 			} else { | ||||
| 				document.cookie = chan.toLowerCase() + '=;path=/' + chan.toLowerCase() + ';secure;expires=' + new Date(0).toUTCString(); | ||||
| 			} | ||||
| 		} | ||||
|         if(window.location.pathname != "/") { | ||||
|             if (location.protocol != "https:") { | ||||
|                 document.cookie = chan.toLowerCase() + '=;path=/' + chan.toLowerCase() + ';expires=' + new Date(0).toUTCString(); | ||||
|             } else { | ||||
|                 document.cookie = chan.toLowerCase() + '=;path=/' + chan.toLowerCase() + ';secure;expires=' + new Date(0).toUTCString(); | ||||
|             } | ||||
|         } | ||||
|  | ||||
| 		try { | ||||
| 			conf_arr = Crypt.decrypt(Crypt.getCookie("_opt"), "_opt"); | ||||
| 		} catch(err) { | ||||
| 			conf_arr = Crypt.decrypt(Crypt.create_cookie("_opt"), "_opt"); | ||||
| 		} | ||||
|         try { | ||||
|             conf_arr = Crypt.decrypt(Crypt.getCookie("_opt"), "_opt"); | ||||
|         } catch(err) { | ||||
|             conf_arr = Crypt.decrypt(Crypt.create_cookie("_opt"), "_opt"); | ||||
|         } | ||||
|  | ||||
| 		if(window.location.pathname != "/") { | ||||
| 			try { | ||||
| 				Crypt.conf_pass = Crypt.decrypt(Crypt.getCookie(chan.toLowerCase()), chan.toLowerCase()); | ||||
| 			} catch(err) { | ||||
| 				Crypt.conf_pass = Crypt.decrypt(Crypt.create_cookie(chan.toLowerCase()), chan.toLowerCase()); | ||||
| 			} | ||||
|         if(window.location.pathname != "/") { | ||||
|             try { | ||||
|                 Crypt.conf_pass = Crypt.decrypt(Crypt.getCookie(chan.toLowerCase()), chan.toLowerCase()); | ||||
|             } catch(err) { | ||||
|                 Crypt.conf_pass = Crypt.decrypt(Crypt.create_cookie(chan.toLowerCase()), chan.toLowerCase()); | ||||
|             } | ||||
|  | ||||
| 			Hostcontroller.change_enabled(conf_arr.remote); | ||||
| 			if(conf_arr.width != 100) Player.set_width(conf_arr.width); | ||||
| 			//if(conf_arr.name !== undefined && conf_arr.name !== "") Chat.namechange(conf_arr.name); | ||||
| 		} | ||||
| 	}, | ||||
|             Hostcontroller.change_enabled(conf_arr.remote); | ||||
|             if(conf_arr.width != 100) Player.set_width(conf_arr.width); | ||||
|             //if(conf_arr.name !== undefined && conf_arr.name !== "") Chat.namechange(conf_arr.name); | ||||
|         } | ||||
|     }, | ||||
|  | ||||
| 	decrypt: function(cookie, name) { | ||||
| 		if(Crypt.getCookie(name) === undefined) { | ||||
| 			cookie = Crypt.create_cookie(name); | ||||
| 		} | ||||
| 		var key = btoa("0103060703080703080701") + btoa("0103060703080703080701"); | ||||
| 		key = key.substring(0,32); | ||||
| 		key = btoa(key); | ||||
| 		var decrypted = CryptoJS.AES.decrypt( | ||||
| 			cookie,key, | ||||
| 			{ | ||||
| 				mode: CryptoJS.mode.CBC, | ||||
| 				padding: CryptoJS.pad.Pkcs7 | ||||
| 			} | ||||
| 		); | ||||
|     decrypt: function(cookie, name) { | ||||
|         if(Crypt.getCookie(name) === undefined) { | ||||
|             cookie = Crypt.create_cookie(name); | ||||
|         } | ||||
|         var key = btoa("0103060703080703080701") + btoa("0103060703080703080701"); | ||||
|         key = key.substring(0,32); | ||||
|         key = btoa(key); | ||||
|         var decrypted = CryptoJS.AES.decrypt( | ||||
|             cookie,key, | ||||
|             { | ||||
|                 mode: CryptoJS.mode.CBC, | ||||
|                 padding: CryptoJS.pad.Pkcs7 | ||||
|             } | ||||
|         ); | ||||
|  | ||||
| 		return $.parseJSON(decrypted.toString(CryptoJS.enc.Utf8)); | ||||
| 	}, | ||||
|         return $.parseJSON(decrypted.toString(CryptoJS.enc.Utf8)); | ||||
|     }, | ||||
|  | ||||
| 	decrypt_pass: function(pass) { | ||||
| 		var key = btoa(socket.id) + btoa(socket.id); | ||||
| 		key = key.substring(0,32); | ||||
| 		key = btoa(key); | ||||
| 		var decrypted = CryptoJS.AES.decrypt( | ||||
| 			pass,key, | ||||
| 			{ | ||||
| 				mode: CryptoJS.mode.CBC, | ||||
| 				padding: CryptoJS.pad.Pkcs7 | ||||
| 			} | ||||
| 		); | ||||
| 		return decrypted.toString(CryptoJS.enc.Utf8); | ||||
| 	}, | ||||
|     decrypt_pass: function(pass) { | ||||
|         var key = btoa(socket.id) + btoa(socket.id); | ||||
|         key = key.substring(0,32); | ||||
|         key = btoa(key); | ||||
|         var decrypted = CryptoJS.AES.decrypt( | ||||
|             pass,key, | ||||
|             { | ||||
|                 mode: CryptoJS.mode.CBC, | ||||
|                 padding: CryptoJS.pad.Pkcs7 | ||||
|             } | ||||
|         ); | ||||
|         return decrypted.toString(CryptoJS.enc.Utf8); | ||||
|     }, | ||||
|  | ||||
| 	encrypt: function(json_formated, cookie) { | ||||
| 		var to_encrypt = JSON.stringify(json_formated); | ||||
| 		var key = btoa("0103060703080703080701") + btoa("0103060703080703080701"); | ||||
| 		key = key.substring(0,32); | ||||
| 		key = btoa(key); | ||||
| 		var encrypted = CryptoJS.AES.encrypt( | ||||
| 			to_encrypt, | ||||
| 			key, | ||||
| 			{ | ||||
| 				mode: CryptoJS.mode.CBC, | ||||
| 				padding: CryptoJS.pad.Pkcs7 | ||||
| 			} | ||||
| 		); | ||||
|     encrypt: function(json_formated, cookie) { | ||||
|         var to_encrypt = JSON.stringify(json_formated); | ||||
|         var key = btoa("0103060703080703080701") + btoa("0103060703080703080701"); | ||||
|         key = key.substring(0,32); | ||||
|         key = btoa(key); | ||||
|         var encrypted = CryptoJS.AES.encrypt( | ||||
|             to_encrypt, | ||||
|             key, | ||||
|             { | ||||
|                 mode: CryptoJS.mode.CBC, | ||||
|                 padding: CryptoJS.pad.Pkcs7 | ||||
|             } | ||||
|         ); | ||||
|  | ||||
| 		var CookieDate = new Date(); | ||||
| 		CookieDate.setFullYear(CookieDate.getFullYear( ) +1); | ||||
| 		if (location.protocol != "https:"){ | ||||
| 			document.cookie = cookie+"="+encrypted.toString()+";expires="+CookieDate.toGMTString()+";path=/;"; | ||||
| 		} else { | ||||
| 			document.cookie = cookie+"="+encrypted.toString()+";secure;expires="+CookieDate.toGMTString()+";path=/;"; | ||||
| 		} | ||||
| 	}, | ||||
|         var CookieDate = new Date(); | ||||
|         CookieDate.setFullYear(CookieDate.getFullYear( ) +1); | ||||
|         if (location.protocol != "https:"){ | ||||
|             document.cookie = cookie+"="+encrypted.toString()+";expires="+CookieDate.toGMTString()+";path=/;"; | ||||
|         } else { | ||||
|             document.cookie = cookie+"="+encrypted.toString()+";secure;expires="+CookieDate.toGMTString()+";path=/;"; | ||||
|         } | ||||
|     }, | ||||
|  | ||||
| 	get_volume: function() { | ||||
| 		return Crypt.decrypt(Crypt.getCookie("_opt"), "_opt").volume; | ||||
| 		//return conf_arr.volume; | ||||
| 	}, | ||||
|     get_volume: function() { | ||||
|         return Crypt.decrypt(Crypt.getCookie("_opt"), "_opt").volume; | ||||
|         //return conf_arr.volume; | ||||
|     }, | ||||
|  | ||||
| 	get_offline: function() { | ||||
| 		var temp_offline = Crypt.decrypt(Crypt.getCookie("_opt"), "_opt").offline; | ||||
| 		if(temp_offline != undefined){ | ||||
| 			return Crypt.decrypt(Crypt.getCookie("_opt"), "_opt").offline; | ||||
| 		} else { | ||||
| 			Crypt.set_offline(false); | ||||
| 			return false; | ||||
| 		} | ||||
| 	}, | ||||
|     get_offline: function() { | ||||
|         var temp_offline = Crypt.decrypt(Crypt.getCookie("_opt"), "_opt").offline; | ||||
|         if(temp_offline != undefined){ | ||||
|             return Crypt.decrypt(Crypt.getCookie("_opt"), "_opt").offline; | ||||
|         } else { | ||||
|             Crypt.set_offline(false); | ||||
|             return false; | ||||
|         } | ||||
|     }, | ||||
|  | ||||
| 	set_volume: function(val) { | ||||
| 		conf_arr.volume = val; | ||||
| 		Crypt.encrypt(conf_arr, "_opt"); | ||||
| 	}, | ||||
|     set_volume: function(val) { | ||||
|         conf_arr.volume = val; | ||||
|         Crypt.encrypt(conf_arr, "_opt"); | ||||
|     }, | ||||
|  | ||||
| 	create_cookie: function(name) { | ||||
| 		if(name == "_opt") cookie_object = {volume: 100, width: 100, remote: true, name: "", offline: false}; | ||||
| 		else cookie_object = {passwords: {}}; | ||||
|     create_cookie: function(name) { | ||||
|         if(name == "_opt") cookie_object = {volume: 100, width: 100, remote: true, name: "", offline: false}; | ||||
|         else cookie_object = {passwords: {}}; | ||||
|  | ||||
| 		var string_it = JSON.stringify(cookie_object); | ||||
| 		var key = btoa("0103060703080703080701") + btoa("0103060703080703080701"); | ||||
| 		key = key.substring(0,32); | ||||
| 		key = btoa(key); | ||||
| 		var encrypted = CryptoJS.AES.encrypt( | ||||
| 			string_it, | ||||
| 			key, | ||||
| 			{ | ||||
| 				mode: CryptoJS.mode.CBC, | ||||
| 				padding: CryptoJS.pad.Pkcs7 | ||||
| 			} | ||||
| 		); | ||||
|         var string_it = JSON.stringify(cookie_object); | ||||
|         var key = btoa("0103060703080703080701") + btoa("0103060703080703080701"); | ||||
|         key = key.substring(0,32); | ||||
|         key = btoa(key); | ||||
|         var encrypted = CryptoJS.AES.encrypt( | ||||
|             string_it, | ||||
|             key, | ||||
|             { | ||||
|                 mode: CryptoJS.mode.CBC, | ||||
|                 padding: CryptoJS.pad.Pkcs7 | ||||
|             } | ||||
|         ); | ||||
|  | ||||
| 		var CookieDate = new Date(); | ||||
| 		CookieDate.setFullYear(CookieDate.getFullYear( ) +1); | ||||
|         var CookieDate = new Date(); | ||||
|         CookieDate.setFullYear(CookieDate.getFullYear( ) +1); | ||||
|  | ||||
| 		if (location.protocol != "https:"){ | ||||
| 			document.cookie = name+"="+encrypted.toString()+";expires="+CookieDate.toGMTString()+";path=/;"; | ||||
| 		} else { | ||||
| 			document.cookie = name+"="+encrypted.toString()+";secure;expires="+CookieDate.toGMTString()+";path=/;"; | ||||
| 		} | ||||
| 		//document.cookie = name+"="+encrypted.toString()+";expires="+CookieDate.toGMTString()+";path=/;" | ||||
| 		//document.cookie = na"="+encrypted.toString()+";expires="+CookieDate.toGMTString()+";path=/;" | ||||
| 		return Crypt.getCookie(name); | ||||
| 	}, | ||||
|         if (location.protocol != "https:"){ | ||||
|             document.cookie = name+"="+encrypted.toString()+";expires="+CookieDate.toGMTString()+";path=/;"; | ||||
|         } else { | ||||
|             document.cookie = name+"="+encrypted.toString()+";secure;expires="+CookieDate.toGMTString()+";path=/;"; | ||||
|         } | ||||
|         //document.cookie = name+"="+encrypted.toString()+";expires="+CookieDate.toGMTString()+";path=/;" | ||||
|         //document.cookie = na"="+encrypted.toString()+";expires="+CookieDate.toGMTString()+";path=/;" | ||||
|         return Crypt.getCookie(name); | ||||
|     }, | ||||
|  | ||||
| 	set_pass: function(chan, pass) { | ||||
| 		Crypt.conf_pass.passwords[chan] = pass; | ||||
| 		Crypt.encrypt(Crypt.conf_pass, chan); | ||||
| 	}, | ||||
|     set_pass: function(chan, pass) { | ||||
|         Crypt.conf_pass.passwords[chan] = pass; | ||||
|         Crypt.encrypt(Crypt.conf_pass, chan); | ||||
|     }, | ||||
|  | ||||
| 	remove_pass:function(chan) { | ||||
| 		delete Crypt.conf_pass.passwords[chan]; | ||||
| 		Crypt.encrypt(Crypt.conf_pass, chan.toLowerCase()); | ||||
| 	}, | ||||
|     remove_pass:function(chan) { | ||||
|         delete Crypt.conf_pass.passwords[chan]; | ||||
|         Crypt.encrypt(Crypt.conf_pass, chan.toLowerCase()); | ||||
|     }, | ||||
|  | ||||
| 	set_userpass: function(chan, pass) { | ||||
| 		Crypt.conf_pass.passwords["userpass"] = pass; | ||||
| 		Crypt.encrypt(Crypt.conf_pass, chan); | ||||
| 	}, | ||||
|     set_userpass: function(chan, pass) { | ||||
|         Crypt.conf_pass.passwords["userpass"] = pass; | ||||
|         Crypt.encrypt(Crypt.conf_pass, chan); | ||||
|     }, | ||||
|  | ||||
| 	remove_userpass:function(chan) { | ||||
| 		delete Crypt.conf_pass.passwords["userpass"]; | ||||
| 		Crypt.encrypt(Crypt.conf_pass, chan.toLowerCase()); | ||||
| 	}, | ||||
|     remove_userpass:function(chan) { | ||||
|         delete Crypt.conf_pass.passwords["userpass"]; | ||||
|         Crypt.encrypt(Crypt.conf_pass, chan.toLowerCase()); | ||||
|     }, | ||||
|  | ||||
| 	set_name:function(name) { | ||||
| 		conf_arr.name = encodeURIComponent(name).replace(/\W/g, ''); | ||||
| 		Crypt.encrypt(conf_arr, "_opt"); | ||||
| 	}, | ||||
|     set_name:function(name) { | ||||
|         conf_arr.name = encodeURIComponent(name).replace(/\W/g, ''); | ||||
|         Crypt.encrypt(conf_arr, "_opt"); | ||||
|     }, | ||||
|  | ||||
| 	set_offline: function(enabled) { | ||||
| 		conf_arr.offline = enabled; | ||||
| 		Crypt.encrypt(conf_arr, "_opt"); | ||||
| 	}, | ||||
|     set_offline: function(enabled) { | ||||
|         conf_arr.offline = enabled; | ||||
|         Crypt.encrypt(conf_arr, "_opt"); | ||||
|     }, | ||||
|  | ||||
| 	remove_name:function() { | ||||
| 		conf_arr.name = ""; | ||||
| 		Crypt.encrypt(conf_arr, "_opt"); | ||||
| 	}, | ||||
|     remove_name:function() { | ||||
|         conf_arr.name = ""; | ||||
|         Crypt.encrypt(conf_arr, "_opt"); | ||||
|     }, | ||||
|  | ||||
| 	get_pass: function(chan) { | ||||
| 		if(Crypt.conf_pass !== undefined) return Crypt.conf_pass.passwords[chan]; | ||||
| 		return undefined; | ||||
| 	}, | ||||
|     get_pass: function(chan) { | ||||
|         if(Crypt.conf_pass !== undefined) return Crypt.conf_pass.passwords[chan]; | ||||
|         return undefined; | ||||
|     }, | ||||
|  | ||||
| 	get_userpass: function(chan) { | ||||
| 		if(Crypt.conf_pass !== undefined) return Crypt.conf_pass.passwords["userpass"]; | ||||
| 		return ""; | ||||
| 	}, | ||||
|     get_userpass: function(chan) { | ||||
|         if(Crypt.conf_pass !== undefined) return Crypt.conf_pass.passwords["userpass"]; | ||||
|         return ""; | ||||
|     }, | ||||
|  | ||||
| 	set_remote: function(val) { | ||||
| 		conf_arr.remote = val; | ||||
| 		Crypt.encrypt(conf_arr, "_opt"); | ||||
| 	}, | ||||
|     set_remote: function(val) { | ||||
|         conf_arr.remote = val; | ||||
|         Crypt.encrypt(conf_arr, "_opt"); | ||||
|     }, | ||||
|  | ||||
| 	get_remote: function(val) { | ||||
| 		return conf_arr.remote; | ||||
| 	}, | ||||
|     get_remote: function(val) { | ||||
|         return conf_arr.remote; | ||||
|     }, | ||||
|  | ||||
| 	crypt_pass: function(pass) { | ||||
| 		Crypt.tmp_pass = pass; | ||||
| 		var key = btoa(socket.id) + btoa(socket.id); | ||||
| 		key = key.substring(0,32); | ||||
| 		key = btoa(key); | ||||
| 		var iv = btoa(Crypt.makeiv()); | ||||
| 		var encrypted = CryptoJS.AES.encrypt( | ||||
| 			pass, | ||||
| 			CryptoJS.enc.Base64.parse(key), | ||||
| 			{ | ||||
| 				mode: CryptoJS.mode.CBC, | ||||
| 				padding: CryptoJS.pad.Pkcs7, | ||||
| 				iv: CryptoJS.enc.Base64.parse(iv), | ||||
| 			} | ||||
| 		); | ||||
| 		window.encrypted = encrypted; | ||||
| 		return encrypted.toString() + "$" + iv; | ||||
| 	}, | ||||
|     crypt_pass: function(pass) { | ||||
|         Crypt.tmp_pass = pass; | ||||
|         var key = btoa(socket.id) + btoa(socket.id); | ||||
|         key = key.substring(0,32); | ||||
|         key = btoa(key); | ||||
|         var iv = btoa(Crypt.makeiv()); | ||||
|         var encrypted = CryptoJS.AES.encrypt( | ||||
|             pass, | ||||
|             CryptoJS.enc.Base64.parse(key), | ||||
|             { | ||||
|                 mode: CryptoJS.mode.CBC, | ||||
|                 padding: CryptoJS.pad.Pkcs7, | ||||
|                 iv: CryptoJS.enc.Base64.parse(iv), | ||||
|             } | ||||
|         ); | ||||
|         window.encrypted = encrypted; | ||||
|         return encrypted.toString() + "$" + iv; | ||||
|     }, | ||||
|  | ||||
| 	makeiv: function() { | ||||
|     var text = ""; | ||||
|     var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; | ||||
|     makeiv: function() { | ||||
|         var text = ""; | ||||
|         var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; | ||||
|  | ||||
|     for( var i=0; i < 16; i++ ) | ||||
|         for( var i=0; i < 16; i++ ) | ||||
|         text += possible.charAt(Math.floor(Math.random() * possible.length)); | ||||
|  | ||||
|     return text; | ||||
| 	}, | ||||
|         return text; | ||||
|     }, | ||||
|  | ||||
| 	get_width: function() { | ||||
| 		return conf_arr.width; | ||||
| 	}, | ||||
|     get_width: function() { | ||||
|         return conf_arr.width; | ||||
|     }, | ||||
|  | ||||
| 	set_width: function(val) { | ||||
| 		conf_arr.width = val; | ||||
| 		Crypt.encrypt(conf_arr, "_opt"); | ||||
| 	}, | ||||
|     set_width: function(val) { | ||||
|         conf_arr.width = val; | ||||
|         Crypt.encrypt(conf_arr, "_opt"); | ||||
|     }, | ||||
|  | ||||
| 	getCookie: function(name) { | ||||
| 		var value = "; " + document.cookie; | ||||
| 		var parts = value.split("; " + name + "="); | ||||
| 		if (parts.length == 2) return parts.pop().split(";").shift(); | ||||
| 	} | ||||
|     getCookie: function(name) { | ||||
|         var value = "; " + document.cookie; | ||||
|         var parts = value.split("; " + name + "="); | ||||
|         if (parts.length == 2) return parts.pop().split(";").shift(); | ||||
|     } | ||||
| }; | ||||
|   | ||||
| @@ -28,136 +28,136 @@ var user_auth_started = false; | ||||
| var user_auth_avoid = false; | ||||
|  | ||||
| var connection_options = { | ||||
| 	'sync disconnect on unload':true, | ||||
| 	'secure': true, | ||||
| 	'force new connection': true | ||||
|     'sync disconnect on unload':true, | ||||
|     'secure': true, | ||||
|     'force new connection': true | ||||
| }; | ||||
|  | ||||
| var Crypt = { | ||||
| 	crypt_pass: function(pass) { | ||||
| 		return pass; | ||||
| 	} | ||||
|     crypt_pass: function(pass) { | ||||
|         return pass; | ||||
|     } | ||||
| }; | ||||
|  | ||||
| function receiveMessage(event) { | ||||
| 	if(event.data == "parent") { | ||||
| 		//console.log(event); | ||||
| 		window.parentWindow = event.source; | ||||
| 		window.parentOrigin = event.origin; | ||||
| 	} | ||||
| 	if(event.data == "lower") { | ||||
| 		window.setVolume(10); | ||||
| 	}else if(event.data == "reset") { | ||||
| 		window.setVolume(100); | ||||
| 	} else if(event.data == "get_info") { | ||||
| 		window.parentWindow.postMessage({type: "np", title: song_title}, window.parentOrigin); | ||||
| 		window.parentWindow.postMessage({type: "controller", id: Hostcontroller.old_id}, window.parentOrigin); | ||||
| 		if(full_playlist.length > 0) { | ||||
| 			Player.sendNext({title: full_playlist[0].title, videoId: full_playlist[0].id}); | ||||
| 		} | ||||
| 	} | ||||
|     if(event.data == "parent") { | ||||
|         //console.log(event); | ||||
|         window.parentWindow = event.source; | ||||
|         window.parentOrigin = event.origin; | ||||
|     } | ||||
|     if(event.data == "lower") { | ||||
|         window.setVolume(10); | ||||
|     }else if(event.data == "reset") { | ||||
|         window.setVolume(100); | ||||
|     } else if(event.data == "get_info") { | ||||
|         window.parentWindow.postMessage({type: "np", title: song_title}, window.parentOrigin); | ||||
|         window.parentWindow.postMessage({type: "controller", id: Hostcontroller.old_id}, window.parentOrigin); | ||||
|         if(full_playlist.length > 0) { | ||||
|             Player.sendNext({title: full_playlist[0].title, videoId: full_playlist[0].id}); | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
| window.addEventListener("message", receiveMessage, false); | ||||
|  | ||||
| $(document).ready(function() { | ||||
|  | ||||
| 	if(hash.length >= 3 && hash[2] == "autoplay"){ | ||||
| 		autoplay = true; | ||||
| 	} else { | ||||
| 		paused = true; | ||||
| 	} | ||||
|     if(hash.length >= 3 && hash[2] == "autoplay"){ | ||||
|         autoplay = true; | ||||
|     } else { | ||||
|         paused = true; | ||||
|     } | ||||
|  | ||||
| 	if(hash.indexOf("videoonly") > -1) { | ||||
| 		$("#playlist").addClass("hide"); | ||||
| 		$("#controls").addClass("hide"); | ||||
| 		$("#player").addClass("video_only"); | ||||
| 	} | ||||
|     if(hash.indexOf("videoonly") > -1) { | ||||
|         $("#playlist").addClass("hide"); | ||||
|         $("#controls").addClass("hide"); | ||||
|         $("#player").addClass("video_only"); | ||||
|     } | ||||
|  | ||||
| 	$("#locked_channel").modal({ | ||||
| 		dismissible: false | ||||
| 	}); | ||||
| 	color = "#" + hash[1]; | ||||
| 	add = "https://zoff.me"; | ||||
| 	socket = io.connect(''+add+':8080', connection_options); | ||||
|     $("#locked_channel").modal({ | ||||
|         dismissible: false | ||||
|     }); | ||||
|     color = "#" + hash[1]; | ||||
|     add = "https://zoff.me"; | ||||
|     socket = io.connect(''+add+':8080', connection_options); | ||||
|  | ||||
| 	socket.on('auth_required', function() { | ||||
| 		$("#locked_channel").modal('open'); | ||||
| 	}); | ||||
|     socket.on('auth_required', function() { | ||||
|         $("#locked_channel").modal('open'); | ||||
|     }); | ||||
|  | ||||
| 	socket.on("get_list", function() { | ||||
| 		setTimeout(function(){socket.emit('list', {channel: chan.toLowerCase(), pass: ''});},1000); | ||||
| 	}); | ||||
|     socket.on("get_list", function() { | ||||
|         setTimeout(function(){socket.emit('list', {channel: chan.toLowerCase(), pass: ''});},1000); | ||||
|     }); | ||||
|  | ||||
| 	socket.on("self_ping", function() { | ||||
| 		if(chan != undefined && chan.toLowerCase() != "") { | ||||
| 			socket.emit("self_ping", {channel: chan.toLowerCase()}); | ||||
| 		} | ||||
| 	}); | ||||
|     socket.on("self_ping", function() { | ||||
|         if(chan != undefined && chan.toLowerCase() != "") { | ||||
|             socket.emit("self_ping", {channel: chan.toLowerCase()}); | ||||
|         } | ||||
|     }); | ||||
|  | ||||
| 	socket.on("viewers", function(view) { | ||||
| 		viewers = view; | ||||
|     socket.on("viewers", function(view) { | ||||
|         viewers = view; | ||||
|  | ||||
| 		if(song_title !== undefined) | ||||
| 		Player.getTitle(song_title, viewers); | ||||
| 	}); | ||||
|         if(song_title !== undefined) | ||||
|         Player.getTitle(song_title, viewers); | ||||
|     }); | ||||
|  | ||||
| 	setup_host_initialization(); | ||||
| 	setup_youtube_listener(); | ||||
| 	setup_list_listener(); | ||||
|     setup_host_initialization(); | ||||
|     setup_youtube_listener(); | ||||
|     setup_list_listener(); | ||||
|  | ||||
| 	window.onYouTubeIframeAPIReady = Player.onYouTubeIframeAPIReady; | ||||
|     window.onYouTubeIframeAPIReady = Player.onYouTubeIframeAPIReady; | ||||
|  | ||||
| 	Player.loadPlayer(); | ||||
|     Player.loadPlayer(); | ||||
|  | ||||
| 	Playercontrols.initSlider(); | ||||
|     Playercontrols.initSlider(); | ||||
|  | ||||
| 	window.setVolume = setVolume; | ||||
| 	$("#controls").css("background-color", color); | ||||
| 	$("#playlist").css("background-color", color); | ||||
| 	if(hash.indexOf("controll") > -1) { | ||||
| 		Hostcontroller.change_enabled(true); | ||||
| 	} else { | ||||
| 		Hostcontroller.change_enabled(false); | ||||
| 	} | ||||
|     window.setVolume = setVolume; | ||||
|     $("#controls").css("background-color", color); | ||||
|     $("#playlist").css("background-color", color); | ||||
|     if(hash.indexOf("controll") > -1) { | ||||
|         Hostcontroller.change_enabled(true); | ||||
|     } else { | ||||
|         Hostcontroller.change_enabled(false); | ||||
|     } | ||||
| }); | ||||
|  | ||||
| function setup_host_listener(id) { | ||||
| 	socket.on(id, Hostcontroller.host_on_action); | ||||
|     socket.on(id, Hostcontroller.host_on_action); | ||||
| } | ||||
|  | ||||
| function setup_host_initialization() { | ||||
| 	socket.on("id", Hostcontroller.host_listener); | ||||
|     socket.on("id", Hostcontroller.host_listener); | ||||
| } | ||||
|  | ||||
| function setup_youtube_listener() { | ||||
| 	socket.on("np", Player.youtube_listener); | ||||
|     socket.on("np", Player.youtube_listener); | ||||
| } | ||||
|  | ||||
| function setup_list_listener() { | ||||
| 	socket.on("channel", List.channel_function); | ||||
|     socket.on("channel", List.channel_function); | ||||
| } | ||||
|  | ||||
| function setVolume(val) { | ||||
| 	$("#volume").slider('value', val); | ||||
| 	Playercontrols.setVolume(val); | ||||
|     $("#volume").slider('value', val); | ||||
|     Playercontrols.setVolume(val); | ||||
| } | ||||
|  | ||||
| $(document).on( "click", "#zoffbutton", function(e) { | ||||
| 	window.open("https://zoff.me/" + chan.toLowerCase() + "/", '_blank'); | ||||
|     window.open("https://zoff.me/" + chan.toLowerCase() + "/", '_blank'); | ||||
| }); | ||||
|  | ||||
| $(document).on( "click", ".vote-container", function(e) { | ||||
| 	var id = $(this).attr("data-video-id"); | ||||
| 	List.vote(id, "pos"); | ||||
|     var id = $(this).attr("data-video-id"); | ||||
|     List.vote(id, "pos"); | ||||
| }); | ||||
|  | ||||
| $(document).on("click", ".prev_page", function(e) { | ||||
| 	e.preventDefault(); | ||||
| 	List.dynamicContentPage(-1); | ||||
|     e.preventDefault(); | ||||
|     List.dynamicContentPage(-1); | ||||
| }); | ||||
|  | ||||
| $(document).on("click", ".next_page", function(e) { | ||||
| 	e.preventDefault(); | ||||
| 	List.dynamicContentPage(1); | ||||
|     e.preventDefault(); | ||||
|     List.dynamicContentPage(1); | ||||
| }); | ||||
|   | ||||
| @@ -7,462 +7,462 @@ var rotation_timeout; | ||||
|  | ||||
| var Frontpage = { | ||||
|  | ||||
| 	blob_list: [], | ||||
|     blob_list: [], | ||||
|  | ||||
| 	winter: (new Date()).getMonth() >= 10 ? true : false, | ||||
|     winter: (new Date()).getMonth() >= 10 ? true : false, | ||||
|  | ||||
| 	times_rotated: 0, | ||||
|     times_rotated: 0, | ||||
|  | ||||
| 	all_channels: [], | ||||
|     all_channels: [], | ||||
|  | ||||
| 	frontpage_function: function(msg) { | ||||
| 		frontpage = true; | ||||
|     frontpage_function: function(msg) { | ||||
|         frontpage = true; | ||||
|  | ||||
| 		Helper.log("-----------"); | ||||
| 		Helper.log("Frontpage fetch"); | ||||
| 		Helper.log(msg); | ||||
| 		Helper.log("------------"); | ||||
| 		Frontpage.all_channels = msg.channels; | ||||
| 		Frontpage.populate_channels(msg.channels, true); | ||||
| 		Frontpage.set_viewers(msg.viewers); | ||||
| 	}, | ||||
|         Helper.log("-----------"); | ||||
|         Helper.log("Frontpage fetch"); | ||||
|         Helper.log(msg); | ||||
|         Helper.log("------------"); | ||||
|         Frontpage.all_channels = msg.channels; | ||||
|         Frontpage.populate_channels(msg.channels, true); | ||||
|         Frontpage.set_viewers(msg.viewers); | ||||
|     }, | ||||
|  | ||||
| 	populate_channels: function(lists, popular) { | ||||
| 		$("#channels").empty(); | ||||
|     populate_channels: function(lists, popular) { | ||||
|         $("#channels").empty(); | ||||
|  | ||||
| 		var num = 0; | ||||
|         var num = 0; | ||||
|  | ||||
| 		if(popular) { | ||||
| 			lists = lists.sort(Helper.predicate({ | ||||
| 				name: 'pinned', | ||||
| 				reverse: true | ||||
| 			}, { | ||||
| 				name: 'viewers', | ||||
| 				reverse: true | ||||
| 			}, { | ||||
| 				name: 'accessed', | ||||
| 				reverse: true | ||||
| 			}, { | ||||
| 				name: 'count', | ||||
| 				reverse: true | ||||
| 			})); | ||||
| 		} else { | ||||
| 			lists = lists.sort(Helper.predicate({ | ||||
| 				name: 'viewers', | ||||
| 				reverse: true | ||||
| 			}, { | ||||
| 				name: 'count', | ||||
| 				reverse: true | ||||
| 			})); | ||||
| 		} | ||||
|         if(popular) { | ||||
|             lists = lists.sort(Helper.predicate({ | ||||
|                 name: 'pinned', | ||||
|                 reverse: true | ||||
|             }, { | ||||
|                 name: 'viewers', | ||||
|                 reverse: true | ||||
|             }, { | ||||
|                 name: 'accessed', | ||||
|                 reverse: true | ||||
|             }, { | ||||
|                 name: 'count', | ||||
|                 reverse: true | ||||
|             })); | ||||
|         } else { | ||||
|             lists = lists.sort(Helper.predicate({ | ||||
|                 name: 'viewers', | ||||
|                 reverse: true | ||||
|             }, { | ||||
|                 name: 'count', | ||||
|                 reverse: true | ||||
|             })); | ||||
|         } | ||||
|  | ||||
| 		if(!Helper.mobilecheck()) { | ||||
| 			clearTimeout(rotation_timeout); | ||||
| 			Frontpage.add_backdrop(lists, 0); | ||||
| 		} | ||||
|         if(!Helper.mobilecheck()) { | ||||
|             clearTimeout(rotation_timeout); | ||||
|             Frontpage.add_backdrop(lists, 0); | ||||
|         } | ||||
|  | ||||
| 		pre_card = $(channel_list); | ||||
|         pre_card = $(channel_list); | ||||
|  | ||||
| 		Helper.log("------------"); | ||||
| 		Helper.log(pre_card); | ||||
| 		Helper.log("-------------"); | ||||
|         Helper.log("------------"); | ||||
|         Helper.log(pre_card); | ||||
|         Helper.log("-------------"); | ||||
|  | ||||
| 		for(var x in lists) { | ||||
| 			var chan = lists[x]._id; | ||||
| 			if(num<12 || !popular) { | ||||
| 				var id = lists[x].id; | ||||
| 				var viewers = lists[x].viewers; | ||||
| 				var description = lists[x].description; | ||||
| 				var img = "background-image:url('https://img.youtube.com/vi/"+id+"/hqdefault.jpg');"; | ||||
| 				if(lists[x].thumbnail) { | ||||
| 					img = "background-image:url('" + lists[x].thumbnail + "');"; | ||||
| 				} | ||||
|         for(var x in lists) { | ||||
|             var chan = lists[x]._id; | ||||
|             if(num<12 || !popular) { | ||||
|                 var id = lists[x].id; | ||||
|                 var viewers = lists[x].viewers; | ||||
|                 var description = lists[x].description; | ||||
|                 var img = "background-image:url('https://img.youtube.com/vi/"+id+"/hqdefault.jpg');"; | ||||
|                 if(lists[x].thumbnail) { | ||||
|                     img = "background-image:url('" + lists[x].thumbnail + "');"; | ||||
|                 } | ||||
|  | ||||
| 				var song_count = lists[x].count; | ||||
|                 var song_count = lists[x].count; | ||||
|  | ||||
| 				var card = pre_card.clone(); | ||||
| 				if(lists[x].pinned == 1) { | ||||
| 					card.find(".pin").attr("style", "display:block;"); | ||||
| 					card.find(".card").attr("title", "Pinned!"); | ||||
| 				} else { | ||||
| 					card.find(".pin").attr("style", "display:none;"); | ||||
| 					card.find(".card").attr("title", ""); | ||||
| 				} | ||||
| 				card.find(".chan-name").text(chan); | ||||
| 				card.find(".chan-name").attr("title", chan); | ||||
| 				card.find(".chan-views").text(viewers); | ||||
| 				card.find(".chan-songs").text(song_count); | ||||
| 				card.find(".chan-bg").attr("style", img); | ||||
| 				card.find(".chan-link").attr("href", chan + "/"); | ||||
|                 var card = pre_card.clone(); | ||||
|                 if(lists[x].pinned == 1) { | ||||
|                     card.find(".pin").attr("style", "display:block;"); | ||||
|                     card.find(".card").attr("title", "Pinned!"); | ||||
|                 } else { | ||||
|                     card.find(".pin").attr("style", "display:none;"); | ||||
|                     card.find(".card").attr("title", ""); | ||||
|                 } | ||||
|                 card.find(".chan-name").text(chan); | ||||
|                 card.find(".chan-name").attr("title", chan); | ||||
|                 card.find(".chan-views").text(viewers); | ||||
|                 card.find(".chan-songs").text(song_count); | ||||
|                 card.find(".chan-bg").attr("style", img); | ||||
|                 card.find(".chan-link").attr("href", chan + "/"); | ||||
|  | ||||
| 				if(description != "" && description != undefined && !Helper.mobilecheck()) { | ||||
| 					card.find(".card-title").text(chan); | ||||
| 					card.find(".description_text").text(description); | ||||
| 					description = ""; | ||||
| 				} else { | ||||
| 					card.find(".card-reveal").remove(); | ||||
| 					card.find(".card").removeClass("sticky-action") | ||||
| 				} | ||||
|                 if(description != "" && description != undefined && !Helper.mobilecheck()) { | ||||
|                     card.find(".card-title").text(chan); | ||||
|                     card.find(".description_text").text(description); | ||||
|                     description = ""; | ||||
|                 } else { | ||||
|                     card.find(".card-reveal").remove(); | ||||
|                     card.find(".card").removeClass("sticky-action") | ||||
|                 } | ||||
|  | ||||
| 				$("#channels").append(card.html()); | ||||
| 			} | ||||
| 			num++; | ||||
| 		} | ||||
|                 $("#channels").append(card.html()); | ||||
|             } | ||||
|             num++; | ||||
|         } | ||||
|  | ||||
| 		var options_list = lists.slice(); | ||||
|         var options_list = lists.slice(); | ||||
|  | ||||
| 		options_list = options_list.sort(Frontpage.sortFunction_active); | ||||
| 		var data = {}; | ||||
| 		for(var x in options_list) { | ||||
| 			data[options_list[x]._id] = null; | ||||
| 		} | ||||
|         options_list = options_list.sort(Frontpage.sortFunction_active); | ||||
|         var data = {}; | ||||
|         for(var x in options_list) { | ||||
|             data[options_list[x]._id] = null; | ||||
|         } | ||||
|  | ||||
| 		var to_autocomplete = "input.desktop-search"; | ||||
| 		if(Helper.mobilecheck()) to_autocomplete = "input.mobile-search"; | ||||
|         var to_autocomplete = "input.desktop-search"; | ||||
|         if(Helper.mobilecheck()) to_autocomplete = "input.mobile-search"; | ||||
|  | ||||
| 		$(to_autocomplete).autocomplete({ | ||||
| 			data: data, | ||||
| 			limit: 5, // The max amount of results that can be shown at once. Default: Infinity. | ||||
| 			onAutocomplete: function(val) { | ||||
| 				Frontpage.to_channel(val, false); | ||||
| 			}, | ||||
| 		}); | ||||
|         $(to_autocomplete).autocomplete({ | ||||
|             data: data, | ||||
|             limit: 5, // The max amount of results that can be shown at once. Default: Infinity. | ||||
|             onAutocomplete: function(val) { | ||||
|                 Frontpage.to_channel(val, false); | ||||
|             }, | ||||
|         }); | ||||
|  | ||||
| 		document.getElementById("preloader").style.display = "none"; | ||||
| 		//Materialize.fadeInImage('#channels'); | ||||
| 		$("#channels").fadeIn(800); | ||||
| 		$("#searchFrontpage").focus(); | ||||
| 		num = 0; | ||||
| 	}, | ||||
|         document.getElementById("preloader").style.display = "none"; | ||||
|         //Materialize.fadeInImage('#channels'); | ||||
|         $("#channels").fadeIn(800); | ||||
|         $("#searchFrontpage").focus(); | ||||
|         num = 0; | ||||
|     }, | ||||
|  | ||||
| 	sortFunction: function(a, b) { | ||||
| 		var o1 = a.viewers; | ||||
| 		var o2 = b.viewers; | ||||
|     sortFunction: function(a, b) { | ||||
|         var o1 = a.viewers; | ||||
|         var o2 = b.viewers; | ||||
|  | ||||
| 		var p1 = a.count; | ||||
| 		var p2 = b.count; | ||||
|         var p1 = a.count; | ||||
|         var p2 = b.count; | ||||
|  | ||||
| 		if (o1 < o2) return 1; | ||||
| 		if (o1 > o2) return -1; | ||||
| 		if (p1 < p2) return 1; | ||||
| 		if (p1 > p2) return -1; | ||||
| 		return 0; | ||||
| 	}, | ||||
|         if (o1 < o2) return 1; | ||||
|         if (o1 > o2) return -1; | ||||
|         if (p1 < p2) return 1; | ||||
|         if (p1 > p2) return -1; | ||||
|         return 0; | ||||
|     }, | ||||
|  | ||||
| 	sortFunction_active: function(a, b){ | ||||
| 		var o1 = a.accessed; | ||||
| 		var o2 = b.accessed; | ||||
|     sortFunction_active: function(a, b){ | ||||
|         var o1 = a.accessed; | ||||
|         var o2 = b.accessed; | ||||
|  | ||||
| 		var p1 = a.count; | ||||
| 		var p2 = b.count; | ||||
|         var p1 = a.count; | ||||
|         var p2 = b.count; | ||||
|  | ||||
| 		if (o1 < o2) return 1; | ||||
| 		if (o1 > o2) return -1; | ||||
| 		if (p1 < p2) return 1; | ||||
| 		if (p1 > p2) return -1; | ||||
| 		return 0; | ||||
| 	}, | ||||
|         if (o1 < o2) return 1; | ||||
|         if (o1 > o2) return -1; | ||||
|         if (p1 < p2) return 1; | ||||
|         if (p1 > p2) return -1; | ||||
|         return 0; | ||||
|     }, | ||||
|  | ||||
| 	getCookie: function(cname) { | ||||
| 		var name = cname + "="; | ||||
| 		var ca = document.cookie.split(';'); | ||||
| 		for(var i=0; i<ca.length; i++) { | ||||
| 			var c = ca[i]; | ||||
| 			while (c.charAt(0)==' ') c = c.substring(1); | ||||
| 			if (c.indexOf(name) === 0) return c.substring(name.length,c.length); | ||||
| 		} | ||||
| 		return ""; | ||||
| 	}, | ||||
|     getCookie: function(cname) { | ||||
|         var name = cname + "="; | ||||
|         var ca = document.cookie.split(';'); | ||||
|         for(var i=0; i<ca.length; i++) { | ||||
|             var c = ca[i]; | ||||
|             while (c.charAt(0)==' ') c = c.substring(1); | ||||
|             if (c.indexOf(name) === 0) return c.substring(name.length,c.length); | ||||
|         } | ||||
|         return ""; | ||||
|     }, | ||||
|  | ||||
| 	add_backdrop: function(list, i) { | ||||
| 		if(i >= list.length || i >= 20) i = 0; | ||||
|     add_backdrop: function(list, i) { | ||||
|         if(i >= list.length || i >= 20) i = 0; | ||||
|  | ||||
| 		var id = list[i].id; | ||||
| 		if(Frontpage.blob_list[i] !== undefined){ | ||||
| 			//$(".room-namer").css("opacity", 0); | ||||
| 			setTimeout(function(){ | ||||
| 				if(frontpage){ | ||||
| 					$("#mega-background").css("background", "url(data:image/png;base64,"+Frontpage.blob_list[i]+")"); | ||||
| 					$("#mega-background").css("background-size" , "200%"); | ||||
| 					$("#mega-background").css("opacity", 1); | ||||
| 					$(".desktop-search").attr("placeholder", list[i]._id); | ||||
| 					//$(".room-namer").css("opacity", 1); | ||||
| 				} | ||||
| 			},500); | ||||
| 		} else { | ||||
| 			var img = new Image(); | ||||
| 			img.src = "/assets/images/thumbnails/"+id+".jpg"; | ||||
|         var id = list[i].id; | ||||
|         if(Frontpage.blob_list[i] !== undefined){ | ||||
|             //$(".room-namer").css("opacity", 0); | ||||
|             setTimeout(function(){ | ||||
|                 if(frontpage){ | ||||
|                     $("#mega-background").css("background", "url(data:image/png;base64,"+Frontpage.blob_list[i]+")"); | ||||
|                     $("#mega-background").css("background-size" , "200%"); | ||||
|                     $("#mega-background").css("opacity", 1); | ||||
|                     $(".desktop-search").attr("placeholder", list[i]._id); | ||||
|                     //$(".room-namer").css("opacity", 1); | ||||
|                 } | ||||
|             },500); | ||||
|         } else { | ||||
|             var img = new Image(); | ||||
|             img.src = "/assets/images/thumbnails/"+id+".jpg"; | ||||
|  | ||||
| 			img.onerror = function(){ // Failed to load | ||||
| 				$.ajax({ | ||||
| 					type: "POST", | ||||
| 					data: {id:id}, | ||||
| 					url: "/api/imageblob", | ||||
| 					success: function(data){ | ||||
| 						setTimeout(function(){ | ||||
| 							$("#mega-background").css("background", "url(/assets/images/thumbnails/"+data+")"); | ||||
| 							$("#mega-background").css("background-size" , "200%"); | ||||
| 							$("#mega-background").css("opacity", 1); | ||||
| 							$(".desktop-search").attr("placeholder", list[i]._id); | ||||
| 						},500); | ||||
| 					} | ||||
| 				}); | ||||
| 			}; | ||||
| 			img.onload = function(){ // Loaded successfully | ||||
| 				$("#mega-background").css("background", "url("+img.src+")"); | ||||
| 				$("#mega-background").css("background-size" , "200%"); | ||||
| 				$("#mega-background").css("opacity", 1); | ||||
| 				$(".desktop-search").attr("placeholder", list[i]._id); | ||||
| 			}; | ||||
|             img.onerror = function(){ // Failed to load | ||||
|                 $.ajax({ | ||||
|                     type: "POST", | ||||
|                     data: {id:id}, | ||||
|                     url: "/api/imageblob", | ||||
|                     success: function(data){ | ||||
|                         setTimeout(function(){ | ||||
|                             $("#mega-background").css("background", "url(/assets/images/thumbnails/"+data+")"); | ||||
|                             $("#mega-background").css("background-size" , "200%"); | ||||
|                             $("#mega-background").css("opacity", 1); | ||||
|                             $(".desktop-search").attr("placeholder", list[i]._id); | ||||
|                         },500); | ||||
|                     } | ||||
|                 }); | ||||
|             }; | ||||
|             img.onload = function(){ // Loaded successfully | ||||
|                 $("#mega-background").css("background", "url("+img.src+")"); | ||||
|                 $("#mega-background").css("background-size" , "200%"); | ||||
|                 $("#mega-background").css("opacity", 1); | ||||
|                 $(".desktop-search").attr("placeholder", list[i]._id); | ||||
|             }; | ||||
|  | ||||
| 		} | ||||
| 		rotation_timeout = setTimeout(function(){ | ||||
| 			if(Frontpage.times_rotated == 50 && frontpage){ | ||||
| 				Frontpage.times_rotated = 0; | ||||
| 				i = 0; | ||||
| 				Frontpage.get_frontpage_lists(); | ||||
| 				//socket.emit("frontpage_lists", {version: parseInt(localStorage.getItem("VERSION"))}); | ||||
| 				socket.emit('get_userlists', Crypt.getCookie('_uI')); | ||||
| 			}else if(frontpage){ | ||||
| 				Frontpage.times_rotated += 1; | ||||
| 				Frontpage.add_backdrop(list, i+1); | ||||
| 			} | ||||
| 		},6000); | ||||
| 	}, | ||||
|         } | ||||
|         rotation_timeout = setTimeout(function(){ | ||||
|             if(Frontpage.times_rotated == 50 && frontpage){ | ||||
|                 Frontpage.times_rotated = 0; | ||||
|                 i = 0; | ||||
|                 Frontpage.get_frontpage_lists(); | ||||
|                 //socket.emit("frontpage_lists", {version: parseInt(localStorage.getItem("VERSION"))}); | ||||
|                 socket.emit('get_userlists', Crypt.getCookie('_uI')); | ||||
|             }else if(frontpage){ | ||||
|                 Frontpage.times_rotated += 1; | ||||
|                 Frontpage.add_backdrop(list, i+1); | ||||
|             } | ||||
|         },6000); | ||||
|     }, | ||||
|  | ||||
| 	get_frontpage_lists: function() { | ||||
| 		$.ajax({ | ||||
| 			url: "/api/frontpages", | ||||
| 			method: "get", | ||||
| 			success: function(response){ | ||||
| 				Frontpage.frontpage_function(response); | ||||
| 			}, | ||||
| 			error: function() { | ||||
| 				Materialize.toast("Couldn't fetch lists, trying again in 3 seconds..", 3000, "red lighten connect_error"); | ||||
| 				retry_frontpage = setTimeout(function(){ | ||||
| 					Frontpage.get_frontpage_lists(); | ||||
| 				}, 3000); | ||||
| 			}, | ||||
| 		}); | ||||
| 	}, | ||||
|     get_frontpage_lists: function() { | ||||
|         $.ajax({ | ||||
|             url: "/api/frontpages", | ||||
|             method: "get", | ||||
|             success: function(response){ | ||||
|                 Frontpage.frontpage_function(response); | ||||
|             }, | ||||
|             error: function() { | ||||
|                 Materialize.toast("Couldn't fetch lists, trying again in 3 seconds..", 3000, "red lighten connect_error"); | ||||
|                 retry_frontpage = setTimeout(function(){ | ||||
|                     Frontpage.get_frontpage_lists(); | ||||
|                 }, 3000); | ||||
|             }, | ||||
|         }); | ||||
|     }, | ||||
|  | ||||
| 	start_snowfall: function() { | ||||
| 		setTimeout(function(){ | ||||
| 			var x = Math.floor((Math.random() * window.innerWidth) + 1); | ||||
| 			var snow = document.createElement("div"); | ||||
| 			var parent = document.getElementsByClassName("mega")[0]; | ||||
|     start_snowfall: function() { | ||||
|         setTimeout(function(){ | ||||
|             var x = Math.floor((Math.random() * window.innerWidth) + 1); | ||||
|             var snow = document.createElement("div"); | ||||
|             var parent = document.getElementsByClassName("mega")[0]; | ||||
|  | ||||
| 			snow.className = "snow"; | ||||
| 			//snow.attr("left", x); | ||||
| 			snow.style.left = x+"px"; | ||||
| 			snow.style.top = "0px"; | ||||
| 			parent.appendChild(snow); | ||||
| 			Frontpage.fall_snow(snow); | ||||
| 			Frontpage.start_snowfall(); | ||||
| 		}, 800); | ||||
| 	}, | ||||
|             snow.className = "snow"; | ||||
|             //snow.attr("left", x); | ||||
|             snow.style.left = x+"px"; | ||||
|             snow.style.top = "0px"; | ||||
|             parent.appendChild(snow); | ||||
|             Frontpage.fall_snow(snow); | ||||
|             Frontpage.start_snowfall(); | ||||
|         }, 800); | ||||
|     }, | ||||
|  | ||||
| 	fall_snow: function(corn) { | ||||
| 		corn.style.top = (parseInt(corn.style.top.replace("px", ""))+2)+"px"; | ||||
| 		if(parseInt(corn.style.top.replace("px", "")) < document.getElementById("mega-background").offsetHeight-2.5){ | ||||
| 			setTimeout(function(){ | ||||
| 				Frontpage.fall_snow(corn); | ||||
| 			},50); | ||||
| 		}else{ | ||||
| 			corn.remove(); | ||||
| 		} | ||||
| 	}, | ||||
|     fall_snow: function(corn) { | ||||
|         corn.style.top = (parseInt(corn.style.top.replace("px", ""))+2)+"px"; | ||||
|         if(parseInt(corn.style.top.replace("px", "")) < document.getElementById("mega-background").offsetHeight-2.5){ | ||||
|             setTimeout(function(){ | ||||
|                 Frontpage.fall_snow(corn); | ||||
|             },50); | ||||
|         }else{ | ||||
|             corn.remove(); | ||||
|         } | ||||
|     }, | ||||
|  | ||||
| 	set_viewers: function(viewers) { | ||||
| 		$("#frontpage-viewer-counter").html("<i class='material-icons frontpage-viewers'>visibility</i>" + viewers); | ||||
| 	}, | ||||
|     set_viewers: function(viewers) { | ||||
|         $("#frontpage-viewer-counter").html("<i class='material-icons frontpage-viewers'>visibility</i>" + viewers); | ||||
|     }, | ||||
|  | ||||
| 	to_channel: function(new_channel, popstate) { | ||||
| 		$("#channel-load").css("display", "block"); | ||||
| 		window.scrollTo(0, 0); | ||||
| 		frontpage = false; | ||||
| 		new_channel = new_channel.toLowerCase(); | ||||
| 		clearTimeout(rotation_timeout); | ||||
| 		if(Helper.mobilecheck()){ | ||||
| 			Helper.log("removing all listeners"); | ||||
| 			socket.removeAllListeners(); | ||||
| 		} | ||||
| 		$("#main-container").css("background-color", "#2d2d2d"); | ||||
| 		$("#frontpage-viewer-counter").tooltip("remove"); | ||||
| 		$("#offline-mode").tooltip("remove"); | ||||
| 		currently_showing_channels = 1; | ||||
| 		clearTimeout(retry_frontpage); | ||||
| 		$.ajax({ | ||||
| 			url: "/" + new_channel, | ||||
| 			method: "get", | ||||
| 			data: {channel: new_channel}, | ||||
| 			success: function(e){ | ||||
|     to_channel: function(new_channel, popstate) { | ||||
|         $("#channel-load").css("display", "block"); | ||||
|         window.scrollTo(0, 0); | ||||
|         frontpage = false; | ||||
|         new_channel = new_channel.toLowerCase(); | ||||
|         clearTimeout(rotation_timeout); | ||||
|         if(Helper.mobilecheck()){ | ||||
|             Helper.log("removing all listeners"); | ||||
|             socket.removeAllListeners(); | ||||
|         } | ||||
|         $("#main-container").css("background-color", "#2d2d2d"); | ||||
|         $("#frontpage-viewer-counter").tooltip("remove"); | ||||
|         $("#offline-mode").tooltip("remove"); | ||||
|         currently_showing_channels = 1; | ||||
|         clearTimeout(retry_frontpage); | ||||
|         $.ajax({ | ||||
|             url: "/" + new_channel, | ||||
|             method: "get", | ||||
|             data: {channel: new_channel}, | ||||
|             success: function(e){ | ||||
|  | ||||
| 				if(Player.player !== ""){ | ||||
| 					//Player.player.destroy(); | ||||
| 					socket.emit("change_channel", {channel: chan.toLowerCase()}); | ||||
| 				} | ||||
| 				$("#frontpage_player").empty(); | ||||
| 				if(Helper.mobilecheck()) { | ||||
| 					Helper.log("disconnecting"); | ||||
| 					socket.disconnect(); | ||||
| 				} | ||||
|                 if(Player.player !== ""){ | ||||
|                     //Player.player.destroy(); | ||||
|                     socket.emit("change_channel", {channel: chan.toLowerCase()}); | ||||
|                 } | ||||
|                 $("#frontpage_player").empty(); | ||||
|                 if(Helper.mobilecheck()) { | ||||
|                     Helper.log("disconnecting"); | ||||
|                     socket.disconnect(); | ||||
|                 } | ||||
|  | ||||
| 				if(!popstate){ | ||||
| 					window.history.pushState("to the channel!", "Title", "/" + new_channel); | ||||
| 					if(prev_chan_list == "") prev_chan_list = new_channel; | ||||
| 					if(prev_chan_player == "") prev_chan_player = new_channel; | ||||
| 					window.chan = new_channel; | ||||
| 				} | ||||
|                 if(!popstate){ | ||||
|                     window.history.pushState("to the channel!", "Title", "/" + new_channel); | ||||
|                     if(prev_chan_list == "") prev_chan_list = new_channel; | ||||
|                     if(prev_chan_player == "") prev_chan_player = new_channel; | ||||
|                     window.chan = new_channel; | ||||
|                 } | ||||
|  | ||||
| 				var response = $("<div>" + e + "</div>"); | ||||
|                 var response = $("<div>" + e + "</div>"); | ||||
|  | ||||
| 				$('select').material_select('destroy'); | ||||
| 				$(".mega").remove(); | ||||
| 				$(".mobile-search").remove(); | ||||
| 				$("main").attr("class", "container center-align main"); | ||||
| 				$("#main-container").addClass("channelpage"); | ||||
| 				//$("header").html($($(e)[63]).html()); | ||||
| 				$("header").html($(response.find("header")).html()); | ||||
| 				if($("#alreadychannel").length === 0 || Helper.mobilecheck() || Player.player === undefined){ | ||||
| 					$("main").html($(response.find("main")).html()); | ||||
| 				} else { | ||||
| 					$("#main-row").append($(response.find("#playlist").wrap("<div>").parent().html())); | ||||
| 					$("#video-container").append($(response.find("#main_components").wrap("<div>").parent().html())); | ||||
| 					$("#main-row").append("<div id='playbar'></div>"); | ||||
| 					$("#player").removeClass("player_bottom"); | ||||
| 					$("#main-row").removeClass("frontpage_modified_heights"); | ||||
| 					$("#main_section_frontpage").remove(); | ||||
| 					$("#closePlayer").remove(); | ||||
| 					$("#player_bottom_overlay").remove(); | ||||
| 				} | ||||
| 				$("#search").attr("placeholder", "Find song on YouTube..."); | ||||
| 				$(".page-footer").addClass("padding-bottom-novideo"); | ||||
| 				from_frontpage = true; | ||||
| 				if($("#alreadychannel").length == 1){ | ||||
| 					init(); | ||||
| 				}else{ | ||||
| 					fromFront = true; | ||||
| 					init(); | ||||
| 				} | ||||
| 				if($("#alreadyfp").length === 0) $("head").append("<div id='alreadyfp'></div>"); | ||||
|                 $('select').material_select('destroy'); | ||||
|                 $(".mega").remove(); | ||||
|                 $(".mobile-search").remove(); | ||||
|                 $("main").attr("class", "container center-align main"); | ||||
|                 $("#main-container").addClass("channelpage"); | ||||
|                 //$("header").html($($(e)[63]).html()); | ||||
|                 $("header").html($(response.find("header")).html()); | ||||
|                 if($("#alreadychannel").length === 0 || Helper.mobilecheck() || Player.player === undefined){ | ||||
|                     $("main").html($(response.find("main")).html()); | ||||
|                 } else { | ||||
|                     $("#main-row").append($(response.find("#playlist").wrap("<div>").parent().html())); | ||||
|                     $("#video-container").append($(response.find("#main_components").wrap("<div>").parent().html())); | ||||
|                     $("#main-row").append("<div id='playbar'></div>"); | ||||
|                     $("#player").removeClass("player_bottom"); | ||||
|                     $("#main-row").removeClass("frontpage_modified_heights"); | ||||
|                     $("#main_section_frontpage").remove(); | ||||
|                     $("#closePlayer").remove(); | ||||
|                     $("#player_bottom_overlay").remove(); | ||||
|                 } | ||||
|                 $("#search").attr("placeholder", "Find song on YouTube..."); | ||||
|                 $(".page-footer").addClass("padding-bottom-novideo"); | ||||
|                 from_frontpage = true; | ||||
|                 if($("#alreadychannel").length == 1){ | ||||
|                     init(); | ||||
|                 }else{ | ||||
|                     fromFront = true; | ||||
|                     init(); | ||||
|                 } | ||||
|                 if($("#alreadyfp").length === 0) $("head").append("<div id='alreadyfp'></div>"); | ||||
|  | ||||
| 			} | ||||
| 		}); | ||||
| 	} | ||||
|             } | ||||
|         }); | ||||
|     } | ||||
| }; | ||||
|  | ||||
| String.prototype.capitalizeFirstLetter = function() { | ||||
| 	return this.charAt(0).toUpperCase() + this.slice(1); | ||||
|     return this.charAt(0).toUpperCase() + this.slice(1); | ||||
| }; | ||||
|  | ||||
| function share_link_modifier_frontpage() { | ||||
| 	$("#facebook-code-link").attr("href", "https://www.facebook.com/sharer/sharer.php?u=https://zoff.me/"); | ||||
| 	$("#facebook-code-link").attr("onclick", "window.open('https://www.facebook.com/sharer/sharer.php?u=https://zoff.me/', 'Share Zoff','width=600,height=300'); return false;"); | ||||
| 	$("#twitter-code-link").attr("href", "https://twitter.com/intent/tweet?url=https://zoff.me/&text=Check%20out%20Zoff!&via=zoffmusic"); | ||||
| 	$("#twitter-code-link").attr("onclick", "window.open('https://twitter.com/intent/tweet?url=https://zoff.me/&text=Check%20out%20Zoff!&via=zoffmusic','Share Playlist','width=600,height=300'); return false;"); | ||||
| 	//$("#qr-code-link").attr("href", "//chart.googleapis.com/chart?chs=500x500&cht=qr&chl=https://zoff.me/&choe=UTF-8&chld=L%7C1"); | ||||
| 	$("#qr-code-image-link").attr("src", "//chart.googleapis.com/chart?chs=150x150&cht=qr&chl=https://zoff.me/&choe=UTF-8&chld=L%7C1"); | ||||
|     $("#facebook-code-link").attr("href", "https://www.facebook.com/sharer/sharer.php?u=https://zoff.me/"); | ||||
|     $("#facebook-code-link").attr("onclick", "window.open('https://www.facebook.com/sharer/sharer.php?u=https://zoff.me/', 'Share Zoff','width=600,height=300'); return false;"); | ||||
|     $("#twitter-code-link").attr("href", "https://twitter.com/intent/tweet?url=https://zoff.me/&text=Check%20out%20Zoff!&via=zoffmusic"); | ||||
|     $("#twitter-code-link").attr("onclick", "window.open('https://twitter.com/intent/tweet?url=https://zoff.me/&text=Check%20out%20Zoff!&via=zoffmusic','Share Playlist','width=600,height=300'); return false;"); | ||||
|     //$("#qr-code-link").attr("href", "//chart.googleapis.com/chart?chs=500x500&cht=qr&chl=https://zoff.me/&choe=UTF-8&chld=L%7C1"); | ||||
|     $("#qr-code-image-link").attr("src", "//chart.googleapis.com/chart?chs=150x150&cht=qr&chl=https://zoff.me/&choe=UTF-8&chld=L%7C1"); | ||||
| } | ||||
|  | ||||
| function initfp() { | ||||
|  | ||||
| 	var date = new Date(); | ||||
| 	Frontpage.blob_list = []; | ||||
| 	if(date.getMonth() == 3 && date.getDate() == 1){ | ||||
| 		$(".mega").css("-webkit-transform", "rotate(180deg)"); | ||||
| 		$(".mega").css("-moz-transform", "rotate(180deg)"); | ||||
| 		//Materialize.toast('<p id="aprilfools">We suck at pranks..<a class="waves-effect waves-light btn light-green" style="pointer-events:none;">Agreed</a></p>', 100000); | ||||
| 	} | ||||
|     var date = new Date(); | ||||
|     Frontpage.blob_list = []; | ||||
|     if(date.getMonth() == 3 && date.getDate() == 1){ | ||||
|         $(".mega").css("-webkit-transform", "rotate(180deg)"); | ||||
|         $(".mega").css("-moz-transform", "rotate(180deg)"); | ||||
|         //Materialize.toast('<p id="aprilfools">We suck at pranks..<a class="waves-effect waves-light btn light-green" style="pointer-events:none;">Agreed</a></p>', 100000); | ||||
|     } | ||||
|  | ||||
|  | ||||
| 	window.onpopstate = function(e){ | ||||
| 		var url_split = window.location.href.split("/"); | ||||
|     window.onpopstate = function(e){ | ||||
|         var url_split = window.location.href.split("/"); | ||||
|  | ||||
| 		if(url_split[3] !== "" && url_split[3].substring(0,1) != "#"){ | ||||
| 			Frontpage.to_channel(url_split[3], true); | ||||
| 		} | ||||
| 	}; | ||||
|         if(url_split[3] !== "" && url_split[3].substring(0,1) != "#"){ | ||||
|             Frontpage.to_channel(url_split[3], true); | ||||
|         } | ||||
|     }; | ||||
|  | ||||
| 	channel_list = $("#channel-list-container").clone().html(); | ||||
|     channel_list = $("#channel-list-container").clone().html(); | ||||
|  | ||||
| 	if(window.location.hostname != "fb.zoff.me") share_link_modifier_frontpage(); | ||||
|     if(window.location.hostname != "fb.zoff.me") share_link_modifier_frontpage(); | ||||
|  | ||||
| 	if(window.location.hostname == "zoff.me" || window.location.hostname == "fb.zoff.me") add = "https://zoff.me"; | ||||
| 	else add = window.location.hostname; | ||||
| 	if(socket === undefined || Helper.mobilecheck() || user_auth_avoid) { | ||||
| 		socket = io.connect(''+add+':8080', connection_options); | ||||
| 		socket.on('update_required', function() { | ||||
| 			window.location.reload(true); | ||||
| 		}); | ||||
| 	} | ||||
| 	if($("#alreadyfp").length === 0 || Helper.mobilecheck() || !socket._callbacks.$playlists || user_auth_avoid){ | ||||
| 		setup_playlist_listener(); | ||||
| 	} | ||||
|     if(window.location.hostname == "zoff.me" || window.location.hostname == "fb.zoff.me") add = "https://zoff.me"; | ||||
|     else add = window.location.hostname; | ||||
|     if(socket === undefined || Helper.mobilecheck() || user_auth_avoid) { | ||||
|         socket = io.connect(''+add+':8080', connection_options); | ||||
|         socket.on('update_required', function() { | ||||
|             window.location.reload(true); | ||||
|         }); | ||||
|     } | ||||
|     if($("#alreadyfp").length === 0 || Helper.mobilecheck() || !socket._callbacks.$playlists || user_auth_avoid){ | ||||
|         setup_playlist_listener(); | ||||
|     } | ||||
|  | ||||
| 	$("#about").modal(); | ||||
| 	$("#help").modal(); | ||||
| 	$("#contact").modal(); | ||||
| 	$('select').material_select(); | ||||
|     $("#about").modal(); | ||||
|     $("#help").modal(); | ||||
|     $("#contact").modal(); | ||||
|     $('select').material_select(); | ||||
|  | ||||
| 	Helper.log("----"); | ||||
| 	Helper.log("Sending frontpage_lists"); | ||||
| 	Helper.log("Socket", socket); | ||||
| 	Helper.log("-----"); | ||||
|     Helper.log("----"); | ||||
|     Helper.log("Sending frontpage_lists"); | ||||
|     Helper.log("Socket", socket); | ||||
|     Helper.log("-----"); | ||||
|  | ||||
| 	Crypt.init(); | ||||
| 	if(Crypt.get_offline()){ | ||||
| 		change_offline(true, offline); | ||||
| 	} else { | ||||
| 		$("#offline-mode").tooltip({ | ||||
| 			delay: 5, | ||||
| 			position: "bottom", | ||||
| 			tooltip: "Enable local mode" | ||||
| 		}); | ||||
| 	} | ||||
| 	$("#frontpage-viewer-counter").tooltip({ | ||||
| 		delay: 5, | ||||
| 		position: "bottom", | ||||
| 		tooltip: "Total Viewers" | ||||
| 	}); | ||||
| 	Frontpage.get_frontpage_lists(); | ||||
| 	//socket.emit('frontpage_lists', {version: parseInt(localStorage.getItem("VERSION"))}); | ||||
| 	//socket.emit('get_userlists', Crypt.getCookie('_uI')); | ||||
|     Crypt.init(); | ||||
|     if(Crypt.get_offline()){ | ||||
|         change_offline(true, offline); | ||||
|     } else { | ||||
|         $("#offline-mode").tooltip({ | ||||
|             delay: 5, | ||||
|             position: "bottom", | ||||
|             tooltip: "Enable local mode" | ||||
|         }); | ||||
|     } | ||||
|     $("#frontpage-viewer-counter").tooltip({ | ||||
|         delay: 5, | ||||
|         position: "bottom", | ||||
|         tooltip: "Total Viewers" | ||||
|     }); | ||||
|     Frontpage.get_frontpage_lists(); | ||||
|     //socket.emit('frontpage_lists', {version: parseInt(localStorage.getItem("VERSION"))}); | ||||
|     //socket.emit('get_userlists', Crypt.getCookie('_uI')); | ||||
|  | ||||
| 	$("#channel-load").css("display", "none"); | ||||
| 	//Materialize.toast("<a href='/remote' style='color:white;'>Try out our new feature, remote!</a>", 8000) | ||||
| 	if(window.location.hash == "#donation") { | ||||
| 		window.location.hash = "#"; | ||||
| 		$('#donation').modal(); | ||||
| 		$('#donation').modal('open'); | ||||
| 	} | ||||
|     $("#channel-load").css("display", "none"); | ||||
|     //Materialize.toast("<a href='/remote' style='color:white;'>Try out our new feature, remote!</a>", 8000) | ||||
|     if(window.location.hash == "#donation") { | ||||
|         window.location.hash = "#"; | ||||
|         $('#donation').modal(); | ||||
|         $('#donation').modal('open'); | ||||
|     } | ||||
|  | ||||
| 	if(!localStorage.ok_cookie){ | ||||
| 		before_toast(); | ||||
| 		Materialize.toast("We're using cookies to enhance your experience!  <a class='waves-effect waves-light btn light-green' href='#' id='cookieok' style='cursor:pointer;pointer-events:all;'> ok</a>", 10000); | ||||
| 	} | ||||
|     if(!localStorage.ok_cookie){ | ||||
|         before_toast(); | ||||
|         Materialize.toast("We're using cookies to enhance your experience!  <a class='waves-effect waves-light btn light-green' href='#' id='cookieok' style='cursor:pointer;pointer-events:all;'> ok</a>", 10000); | ||||
|     } | ||||
|  | ||||
| 	var pad = 0; | ||||
| 	document.getElementById("zicon").addEventListener("click", function(){ | ||||
| 		pad+=10; | ||||
| 		document.getElementById("zicon").style.paddingLeft = pad+"%"; | ||||
| 		if(pad >= 100) | ||||
| 		window.location.href = 'http://etys.no'; | ||||
| 	}); | ||||
|     var pad = 0; | ||||
|     document.getElementById("zicon").addEventListener("click", function(){ | ||||
|         pad+=10; | ||||
|         document.getElementById("zicon").style.paddingLeft = pad+"%"; | ||||
|         if(pad >= 100) | ||||
|         window.location.href = 'http://etys.no'; | ||||
|     }); | ||||
|  | ||||
| 	if(!Helper.mobilecheck() && Frontpage.winter) { | ||||
| 		$(".mega").prepend('<div id="snow"></div>'); | ||||
| 		//Frontpage.start_snowfall(); | ||||
| 	} | ||||
|     if(!Helper.mobilecheck() && Frontpage.winter) { | ||||
|         $(".mega").prepend('<div id="snow"></div>'); | ||||
|         //Frontpage.start_snowfall(); | ||||
|     } | ||||
|  | ||||
| 	if(Helper.mobilecheck()){ | ||||
| 		$('input#searchFrontpage').characterCounter(); | ||||
| 	} | ||||
|     if(Helper.mobilecheck()){ | ||||
|         $('input#searchFrontpage').characterCounter(); | ||||
|     } | ||||
|  | ||||
| 	window['__onGCastApiAvailable'] = function(loaded, errorInfo) { | ||||
| 		if (loaded) { | ||||
| 			chromecastReady = true; | ||||
| 		} else { | ||||
| 		} | ||||
| 	} | ||||
|     window['__onGCastApiAvailable'] = function(loaded, errorInfo) { | ||||
|         if (loaded) { | ||||
|             chromecastReady = true; | ||||
|         } else { | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user