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