Skip to content

Commit

Permalink
Merge pull request #19 from SmoKE585/master
Browse files Browse the repository at this point in the history
Новый релиз
  • Loading branch information
sergejey committed Jan 20, 2021
2 parents 6212042 + bef70c8 commit 47c0fd9
Show file tree
Hide file tree
Showing 12 changed files with 235 additions and 24 deletions.
2 changes: 1 addition & 1 deletion modules/yadevices/WSSC/Exceptions/WebSocketException.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class WebSocketException extends \Exception

public function printStack()
{
echo $this->getFile() . ' ' . $this->getLine() . ' ' . $this->getMessage() . PHP_EOL;
//echo $this->getFile() . ' ' . $this->getLine() . ' ' . $this->getMessage() . PHP_EOL;
echo $this->getTraceAsString();
}
}
106 changes: 99 additions & 7 deletions modules/yadevices/yadevices.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,21 @@ function getParams()
global $view_mode;
global $edit_mode;
global $tab;

global $station;
global $update;
global $zoom;

if (isset($station)) {
$this->station = $station;
}
if (isset($update)) {
$this->update = $update;
}
if (isset($zoom)) {
$this->zoom = $zoom;
}

if (isset($id)) {
$this->id = $id;
}
Expand Down Expand Up @@ -257,7 +272,7 @@ function admin(&$out) {
$this->redirect("?tab=" . $this->tab . "&view_mode=" . $this->view_mode);
}
}
if($this->view_mode == 'upload_coockie') {
if($this->view_mode == 'upload_Cookie') {
global $file;
if(!empty($file) && $_FILES["file"]["type"] == 'text/plain' && $_FILES["file"]["size"] <= '20000') {

Expand All @@ -269,7 +284,6 @@ function admin(&$out) {

//move_uploaded_file($file, DOC_ROOT . DIRECTORY_SEPARATOR . 'cms/cached/yadevices/new_yandex_coockie.txt');
copy($file, $directory_cookies.'new_yandex_coockie.txt');

//https://iot.quasar.yandex.ru/m/user/scenarios
$checkCoockie = $this->apiRequest('https://iot.quasar.yandex.ru/m/user/scenarios');

Expand Down Expand Up @@ -967,9 +981,77 @@ function getDeviceToken($device_id, $platform) {
*
* @access public
*/
function usual(&$out)
{
function usual(&$out) {
$this->admin($out);

//Функции плеера
global $station;
if(empty($station)) {
$station = $this->station;
}

//if(empty((int)$station)) {
// http_response_code(400);
// die();
//}

$out['STATION_ID'] = $station;
global $update;
if(empty($update)) {
$update = $this->update;
}

if($update < 1 || $update) $update = 5;
$out['UPDATE_TIME'] = $update;

global $zoom;
if(empty($zoom)) {
$zoom = $this->zoom;
}
$out['ZOOM_PLAYER'] = $zoom;

$ajax = gr('ajax');

$rec = SQLSelectOne("SELECT TITLE FROM yastations WHERE ID = '".dbSafe($station)."'");
$out['TITLE'] = $rec['TITLE'];

if ($ajax && $station && $out['TITLE']) {
header("HTTP/1.0: 200 OK\n");
header('Content-Type: text/html; charset=utf-8');
$control = gr('control');

if(!empty(strip_tags($control))) {
if($control == 'prev') {
$cmdToStation = 'предыдущий трек';
} else if($control == 'play') {
$cmdToStation = 'продолжи песню';
} else if($control == 'pause') {
$cmdToStation = 'пауза';
} else if($control == 'next') {
$cmdToStation = 'следующий трек';
} else if($control == 'volDown') {
$cmdToStation = 'тише';
} else if($control == 'volUp') {
$cmdToStation = 'громче';
}

callAPI('/api/module/yadevices','GET',array('station'=>$station,'command'=> $cmdToStation));

echo json_encode(array('status' => 'ok'));
} else {
$rec = SQLSelectOne("SELECT DEVICE_TOKEN, IP FROM yastations WHERE ID = '".dbSafe($station)."'");

if(!$rec) {
http_response_code(400);
die();
}

$status = $this->getStatus($rec['DEVICE_TOKEN'], $rec['IP']);

echo json_encode($status);
}
exit;
}
}

/**
Expand Down Expand Up @@ -1062,6 +1144,7 @@ function sendDataToStation($command, $token, $ip, $port = 1961, $dopParam = 0) {
// 'text' => $command,
)
);

if ($dopParam && ($command == 'setVolume')) {
$msg['payload']['command'] = $command;
$msg['payload']['volume'] = (float)$dopParam;
Expand Down Expand Up @@ -1123,8 +1206,7 @@ function stopListening($token, $ip, $port = 1961) {

}

function getStatus($token, $ip, $port = 1961)
{
function getStatus($token, $ip, $port = 1961) {
$clientConfig = new ClientConfig();
$clientConfig->setHeaders([
'X-Origin' => 'http://yandex.ru/',
Expand Down Expand Up @@ -1160,10 +1242,20 @@ function sendCommandToStationCloud($id, $command, $dopParam = 0)

function sendCommandToStation($id, $command, $dopParam = 0) {
if (!$command) return false;
$station = SQLSelectOne("SELECT * FROM yastations WHERE ID=" . (int)$id);

$station = SQLSelectOne("SELECT * FROM yastations WHERE ID=" . (int)$id);
if (!$station['ID'] || !$station['IP']) return false;

$this->getToken();
$token = $this->getDeviceToken($station['STATION_ID'], $station['PLATFORM']);

if (!$token) return false;

$station['DEVICE_TOKEN'] = $token;
SQLUpdate('yastations', $station);



if ($station['DEVICE_TOKEN']) {
if ($dopParam && ($command == 'setVolume')) {
$result = $this->sendDataToStation($command, $station['DEVICE_TOKEN'], $station['IP'], 1961, $dopParam);
Expand Down
8 changes: 5 additions & 3 deletions templates/yadevices/action_admin.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12 text-right" style="flex-direction: column;">
<a href="https://mjdm.ru/forum/viewtopic.php?f=5&t=7359" target="_blank" style="margin-right: 5px;border-right: 1px solid white;padding-right: 5px;color: white;text-decoration: none;"><i class="glyphicon glyphicon-fire"></i> Баги и обсуждение</a>

[#if VIEW_MODE="search_yastations" || VIEW_MODE="" || VIEW_MODE="search_yadevices"#]
<a href="?mode=refresh&tab=<#TAB#>&view_mode=<#VIEW_MODE#>" onclick="return confirm('Модуль обновляет данные автоматически, выполнение этой команды приведет к тому, что будут удалены все устройства и станции, а также отвязаны все свойства. После удаления, устройства и станции будут выгружены. Вы уверены?')" style="margin-right: 5px;border-right: 1px solid white;padding-right: 5px;color: white;text-decoration: none;"><i class="glyphicon glyphicon-refresh"></i> Обновить</a>
[#if COOKIE_FILE == 1#]
[#if VIEW_MODE="search_yastations" || VIEW_MODE="" || VIEW_MODE="search_yadevices"#]
<a href="?mode=refresh&tab=<#TAB#>&view_mode=<#VIEW_MODE#>" onclick="return confirm('Модуль обновляет данные автоматически, выполнение этой команды приведет к тому, что будут удалены все устройства и станции, а также отвязаны все свойства. После удаления, устройства и станции будут выгружены. Вы уверены?')" style="margin-right: 5px;border-right: 1px solid white;padding-right: 5px;color: white;text-decoration: none;"><i class="glyphicon glyphicon-refresh"></i> Обновить</a>
[#endif#]
<a href="javascript://" onclick="$('#settings_block').toggle();" style="margin-right: 5px;border-right: 1px solid white;padding-right: 5px;color: white;text-decoration: none;"><i class="glyphicon glyphicon-cog"></i> Настройки</a>
[#endif#]
<a href="javascript://" onclick="$('#settings_block').toggle();" style="margin-right: 5px;border-right: 1px solid white;padding-right: 5px;color: white;text-decoration: none;"><i class="glyphicon glyphicon-cog"></i> Настройки</a>
<a href="?view_mode=logout" onclick="return confirm('После выхода будут удалены все устройства и станции, а также отвязаны все свойства. Вы уверены?')" style="text-decoration:none;color:white;"><i class="glyphicon glyphicon-log-out"></i> Выход</a>
</div>
</div>
Expand Down
99 changes: 98 additions & 1 deletion templates/yadevices/action_usual.html
Original file line number Diff line number Diff line change
@@ -1 +1,98 @@
<!--# Action Usual #-->
<script>
//
function load(station) {
$.getJSON({
url: '/module/yadevices.html?station='+station+'&ajax=1',
success: function(responce) {
//console.log(responce);
console.log(responce.state.playerState.hasPlay);

if(!responce.state.playing) {
$('#cover_[#STATION_ID#]').css('background', 'url(https://music.yandex.ru/blocks/meta/i/og-image.png)');
$('#cover_[#STATION_ID#]').css('background-repeat', 'no-repeat');
$('#cover_[#STATION_ID#]').css('background-size', 'contain');

allowBtn('hasPause_[#STATION_ID#]', false);
allowBtn('hasPlay_[#STATION_ID#]', true);

$('#songName_[#STATION_ID#]').text('[#TITLE#]');
$('#artistName_[#STATION_ID#]').text('Управление музыкой');
} else {

//$('#nowPlay').show();

songName = responce.state.playerState.title;
artistName = responce.state.playerState.subtitle;
cover = responce.state.playerState.extra.coverURI;
cover = cover.replace(/%%/i, '150x150');;

$('#songName_[#STATION_ID#]').text(songName);
$('#artistName_[#STATION_ID#]').text(artistName);
$('#cover_[#STATION_ID#]').css('background', 'url(//'+cover+')');
$('#cover_[#STATION_ID#]').css('background-repeat', 'no-repeat');
$('#cover_[#STATION_ID#]').css('background-size', 'contain');

allowBtn('hasNext_[#STATION_ID#]', responce.state.playerState.hasNext);
allowBtn('hasPause_[#STATION_ID#]', responce.state.playerState.hasPause);
allowBtn('hasPlay_[#STATION_ID#]', responce.state.playerState.hasPlay);
allowBtn('hasPrev_[#STATION_ID#]', responce.state.playerState.hasPrev);
}


},
error: function(responce) {
console.log('Ошибка загрузки :(');
}
});
}

function allowBtn(btn, value) {
if(value) {
$('#' + btn).show();
} else {
$('#' + btn).hide();
}
}

function control(action) {
$.getJSON({
url: '/module/yadevices.html?station=[#STATION_ID#]&ajax=1&control=' + action,
success: function(responce) {
load([#STATION_ID#]);
},
error: function(responce) {
console.log('Ошибка запроса control() :(');
}
});
}

$(function() {
load([#STATION_ID#]);
setInterval(function() { load([#STATION_ID#]); }, [#UPDATE_TIME#]000);
});

</script>

<div id="nowPlay">
<div style="width: 100%;zoom: [#ZOOM_PLAYER#]">
<div style="border-radius: 150px;padding: 10px;border: 1px solid #6c13ee;margin: 5px;height: 100px;">
<div ></div>
<div id="cover_[#STATION_ID#]" style="background: url(https://music.yandex.ru/blocks/meta/i/og-image.png); background-repeat: no-repeat;background-size: contain;border-radius: 50px 0px 0px 50px;float: left;width: 90px;height: 100%;"></div>
<div style="float: left;width: 60%;">
<div style="font-size: 2rem;" id="songName_[#STATION_ID#]">[#TITLE#]</div>
<div style="font-size: 1rem;" id="artistName_[#STATION_ID#]">Управление музыкой</div>
<div style="word-spacing: 20px;">
<i id="hasPrev_[#STATION_ID#]" style="font-size: 3rem;cursor:pointer;" onclick="control('prev');" class="glyphicon glyphicon-fast-backward"></i>
<i id="hasPlay_[#STATION_ID#]" style="font-size: 3rem;cursor:pointer;" onclick="control('play');" class="glyphicon glyphicon-play"></i>
<i id="hasPause_[#STATION_ID#]" style="font-size: 3rem;cursor:pointer;" onclick="control('pause');" class="glyphicon glyphicon-pause"></i>
<i id="hasNext_[#STATION_ID#]" style="font-size: 3rem;cursor:pointer;" onclick="control('next');" class="glyphicon glyphicon-fast-forward"></i>

<span style="border-left: 1px solid;margin-left: 10px;margin-right: 20px;font-size: 3rem;"></span>

<i style="font-size: 3rem;cursor:pointer;" onclick="control('volDown');" class="glyphicon glyphicon-volume-down"></i>
<i style="font-size: 3rem;cursor:pointer;" onclick="control('volUp');" class="glyphicon glyphicon-volume-up"></i>
</div>
</div>
</div>
</div>
</div>
6 changes: 4 additions & 2 deletions templates/yadevices/login_form.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<div class="row" style="margin-right: -15px;margin-left: -15px;">
<div class="col-md-12">
<div style="display: flex;margin-top: -50px;margin-left: -30px;background: url(https://avatars.mds.yandex.net/get-lpc/1527204/b4791c94-a284-4c4d-a2db-15339f8b1c07/orig);width: 100%;height: 400px;position: absolute;background-repeat: no-repeat;"></div>
<div class="jumbotron" style="text-align: right;padding-left: 400px;min-height: 350px;margin-bottom: 10px;padding-top: 20px;padding-bottom: 10px;border-radius: 5px;background: radial-gradient(circle farthest-corner at 10px 10px, #582fff, #7309e7)">
<!---<div class="hidden-xs" style="display: flex;margin-top: -50px;margin-left: -30px;background: url(https://avatars.mds.yandex.net/get-lpc/1527204/b4791c94-a284-4c4d-a2db-15339f8b1c07/orig);width: 100%;height: 400px;position: absolute;background-repeat: no-repeat;"></div>-->
<div class="jumbotron" style="text-align: right;min-height: 350px;margin-bottom: 10px;padding: 10px 0px;border-radius: 5px;background: url(https://avatars.mds.yandex.net/get-lpc/1527204/b4791c94-a284-4c4d-a2db-15339f8b1c07/orig) no-repeat, radial-gradient(circle farthest-corner at 10px 10px, #582fff, #7309e7)">
<div class="col-md-8 col-md-offset-4">
<h2 style="color: white;font-weight: bold;">Привет, Алиса!</h2>
<p style="font-size: 11pt;color: white;">Привет! Это новый модуль Яндекс.Устройств. Мы изменили дизайн и внесли несколько исправлений в работу модуля!
Укажи свой логин и пароль от аккаунта Яндекс и работа модуля будет восстановлена!
Expand Down Expand Up @@ -34,6 +35,7 @@ <h2 style="color: white;font-weight: bold;">Привет, Алиса!</h2>
</div>
</form>
</p>
</div>
</div>
</div>
</div>
18 changes: 9 additions & 9 deletions templates/yadevices/need_coockie.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
<div class="alert alert-warning" style="margin-top: 20px;text-align: center;">
Что-то не так с вашим логином или паролем, модуль будет использовать резервный способ получения данных. Возможно, вы ввели неверный логин или пароль.
<br><br>
<span style="color: red;">Пока непонятно, что произошло, после загрузки Coockie файла модуль попробует авторизоваться снова и если все пройдет успешно,
<span style="color: red;">Пока непонятно, что произошло, после загрузки Cookie файла модуль попробует авторизоваться снова и если все пройдет успешно,
вместо <b>Привет, [Резервный способ входа]</b> будет ваше имя и фамилия.
</span>
</div>
[#endif#]
<div class="jumbotron" style="border: 1px solid #6f0dea;border-radius: 5px;background: white;">
<h2>Загрузите coockie!</h2>
<h2>Загрузите Cookie!</h2>
<p style="font-size: 1.4rem;">
Для полноценной работы модуля нужны coockie файл с сайта Яндекс. Это нужно для более стабильной работы модуля.
Для полноценной работы модуля нужны Cookie файл с сайта Яндекс. Это нужно для более стабильной работы модуля.
Раньше файл формировался автоматически, но модуль работал с ошибками.
Срок действия coockie - 17 лет, главное не выходить из аккаунта Яндекс.<br>
Процедура совпадает с получение coockie в модуле google location. Нужно установить расширение для браузера (<a href="https://mjdm.ru/forum/viewtopic.php?f=5&t=6309&p=123865&hilit=cookies.txt#p123865" target="_blank">Например это</a>) или
Срок действия Cookie - 17 лет, главное не выходить из аккаунта Яндекс.<br>
Процедура совпадает с получение Cookie в модуле google location. Нужно установить расширение для браузера (<a href="https://mjdm.ru/forum/viewtopic.php?f=5&t=6309&p=123865&hilit=cookies.txt#p123865" target="_blank">Например это</a>) или
любое другое аналогичное.
<br>Далее, со страницы <a href="https://yandex.ru/quasar/iot/" target="_blank">Yandex IOT</a> скачать coockie и загрузить в модуль.
<br>Далее, со страницы <a href="https://yandex.ru/quasar/iot/" target="_blank">Yandex IOT</a> скачать Cookie и загрузить в модуль.
</p>
<center>
[#if UPLOAD_ERROR !=''#]
Expand Down Expand Up @@ -91,9 +91,9 @@ <h2>Загрузите coockie!</h2>
</div>

<div class="text-center" style="margin-top: 15px">
<input type="submit" id="coockie_upload" style="display:none;" name="submit" value="Загрузить" class="btn btn-success">
<input type="submit" id="Cookie_upload" style="display:none;" name="submit" value="Загрузить" class="btn btn-success">
</div>
<input type="hidden" name="view_mode" value="upload_coockie">
<input type="hidden" name="view_mode" value="upload_Cookie">
</form>
<script>
let inputs = document.querySelectorAll('.input__file');
Expand All @@ -107,7 +107,7 @@ <h2>Загрузите coockie!</h2>
countFiles = this.files.length;
if (countFiles) {
label.querySelector('.input__file-button-text').innerText = '<#LANG_NEWSAVERESTORE_CHOUSES_FILES#> ' + countFiles;
$('#coockie_upload').show();
$('#Cookie_upload').show();
} else {
label.querySelector('.input__file-button-text').innerText = labelVal;
}
Expand Down
Loading

0 comments on commit 47c0fd9

Please sign in to comment.