Adding token on command

This commit is contained in:
BrokenFire 2018-02-14 10:25:08 +01:00
parent ebe635acd9
commit 2f6914a307

View File

@ -25,11 +25,11 @@ $(document).ready(function() {
$('#btn_play').click(function () { $('#btn_play').click(function () {
switch (state){ switch (state){
case "PLAYING": case "PLAYING":
sendCommand(JSON.stringify({ command: "PAUSE"})) sendCommand({ command: "PAUSE"})
break; break;
case "PAUSE": case "PAUSE":
sendCommand(JSON.stringify({ command: "PLAY"})) sendCommand({ command: "PLAY"})
break; break;
} }
@ -38,10 +38,10 @@ $(document).ready(function() {
$('#btn_next').click(function () { $('#btn_next').click(function () {
sendCommand(JSON.stringify({ command: "NEXT"})); sendCommand({ command: "NEXT"});
}); });
$('#btn_stop').click(function () { $('#btn_stop').click(function () {
sendCommand(JSON.stringify({ command: "STOP"})); sendCommand({ command: "STOP"});
}); });
$('.dropdown-button').dropdown({ $('.dropdown-button').dropdown({
@ -85,7 +85,7 @@ $(document).ready(function() {
var command = { var command = {
command: "FLUSH" command: "FLUSH"
}; };
sendCommand(JSON.stringify(command)); sendCommand(command);
}); });
$('#btn_add_top').click(function () { $('#btn_add_top').click(function () {
@ -96,7 +96,7 @@ $(document).ready(function() {
onHead: true onHead: true
}; };
$('#input_link').val(''); $('#input_link').val('');
sendCommand(JSON.stringify(command)); sendCommand(command);
}); });
$('#btn_add_bottom').click(function () { $('#btn_add_bottom').click(function () {
@ -108,7 +108,7 @@ $(document).ready(function() {
onHead: false onHead: false
}; };
$('#input_link').val(''); $('#input_link').val('');
sendCommand(JSON.stringify(command)); sendCommand(command);
}); });
$('#btn_ok_channel').click(function () { $('#btn_ok_channel').click(function () {
@ -117,7 +117,7 @@ $(document).ready(function() {
command: "CONNECT", command: "CONNECT",
chanelId: $('input[name=vocalRadio]:checked').val() chanelId: $('input[name=vocalRadio]:checked').val()
}; };
sendCommand(JSON.stringify(command)); sendCommand(command);
}); });
}) })
@ -144,8 +144,7 @@ function getCurentMusic() {
$('#btn_info').addClass("determinate").removeClass("indeterminate"); $('#btn_info').addClass("determinate").removeClass("indeterminate");
} }
$('#music_progress').width("0%"); $('#music_progress').width("0%");
if(Cookies.get('token') != undefined){
$('#btn_play').children().text("play_arrow");
if (!$('#btn_stop').hasClass("disabled")) { if (!$('#btn_stop').hasClass("disabled")) {
$('#btn_stop').addClass("disabled"); $('#btn_stop').addClass("disabled");
} }
@ -165,6 +164,30 @@ function getCurentMusic() {
if ($('#btn_next').hasClass("disabled")) { if ($('#btn_next').hasClass("disabled")) {
$('#btn_next').removeClass("disabled"); $('#btn_next').removeClass("disabled");
} }
}
else{
if (!$('#btn_stop').hasClass("disabled")) {
$('#btn_stop').addClass("disabled");
}
if (!$('#btn_info').hasClass("disabled")) {
$('#btn_info').addClass("disabled");
}
if (!$('#add_btn').hasClass("disabled")) {
$('#add_btn').addClass("disabled");
}
if (!$('#flush_btn').hasClass("disabled")) {
$('#flush_btn').addClass("disabled");
}
if (!$('#btn_play').hasClass("disabled")) {
$('#btn_play').addClass("disabled");
}
if (!$('#btn_next').hasClass("disabled")) {
$('#btn_next').addClass("disabled");
}
}
$('#btn_play').children().text("play_arrow");
$('#music_img').attr("src","/img/no_music.jpg"); $('#music_img').attr("src","/img/no_music.jpg");
$('#total_time').text("00:00"); $('#total_time').text("00:00");
@ -206,6 +229,7 @@ function getCurentMusic() {
$('#music_progress').width("0%"); $('#music_progress').width("0%");
$('#btn_play').children().text("play_arrow"); $('#btn_play').children().text("play_arrow");
if (!$('#btn_play').hasClass("disabled")) { if (!$('#btn_play').hasClass("disabled")) {
$('#btn_play').addClass("disabled"); $('#btn_play').addClass("disabled");
} }
@ -227,11 +251,13 @@ function getCurentMusic() {
$('#music_img').attr("src","/img/disconnected.png"); $('#music_img').attr("src","/img/disconnected.png");
if(Cookies.get('token') != undefined){
if(!disconected){ if(!disconected){
getChannels(); getChannels();
disconected = true; disconected = true;
} }
}
@ -278,7 +304,7 @@ function getPlayList() {
command: "DELL", command: "DELL",
url: $(this).attr("data_url") url: $(this).attr("data_url")
}; };
sendCommand(JSON.stringify(command)); sendCommand(command);
}); });
@ -334,11 +360,12 @@ function updateControl(data){
$('#music_text').text(data.info.title); $('#music_text').text(data.info.title);
var percent = (data.currentPos / data.info.length) * 100; var percent = (data.currentPos / data.info.length) * 100;
// console.log(percent) // console.log(percent)
if (!$('#btn_info').hasClass("indeterminate")) { if (!$('#music_progress').hasClass("indeterminate")) {
$('#btn_info').addClass("determinate").removeClass("indeterminate"); $('#music_progress').addClass("determinate").removeClass("indeterminate");
} }
$('#music_progress').width(percent + "%"); $('#music_progress').width(percent + "%");
if(Cookies.get('token') != undefined){
if ($('#btn_play').hasClass("disabled")) { if ($('#btn_play').hasClass("disabled")) {
$('#btn_play').removeClass("disabled"); $('#btn_play').removeClass("disabled");
} }
@ -358,6 +385,30 @@ function updateControl(data){
if ($('#btn_next').hasClass("disabled")) { if ($('#btn_next').hasClass("disabled")) {
$('#btn_next').removeClass("disabled"); $('#btn_next').removeClass("disabled");
} }
}
else
{
if (!$('#btn_play').hasClass("disabled")) {
$('#btn_play').addClass("disabled");
}
if (!$('#btn_stop').hasClass("disabled")) {
$('#btn_stop').addClass("disabled");
}
if (!$('#btn_info').hasClass("disabled")) {
$('#btn_info').addClass("disabled");
}
if (!$('#add_btn').hasClass("disabled")) {
$('#add_btn').addClass("disabled");
}
if (!$('#flush_btn').hasClass("disabled")) {
$('#flush_btn').addClass("disabled");
}
if (!$('#btn_next').hasClass("disabled")) {
$('#btn_next').addClass("disabled");
}
}
$('#music_img').attr("src","https://img.youtube.com/vi/"+data.info.identifier+"/hqdefault.jpg"); $('#music_img').attr("src","https://img.youtube.com/vi/"+data.info.identifier+"/hqdefault.jpg");
// console.log(data); // console.log(data);
@ -366,13 +417,14 @@ function updateControl(data){
updateModal(data); updateModal(data);
} }
function sendCommand(commandStr){ function sendCommand(command){
command["token"] = Cookies.get('token');
$.ajax({ $.ajax({
type: "POST", type: "POST",
dataType: 'json', dataType: 'json',
contentType: 'application/json', contentType: 'application/json',
url: "/api/music/command", url: "/api/music/command",
data: commandStr, data: JSON.stringify(command),
success: function (data) { success: function (data) {
console.log(data); console.log(data);
} }