From 23ae36dfc5a7f8ef1763571e992c2808d02e3adc Mon Sep 17 00:00:00 2001 From: JonatanRek Date: Fri, 11 Oct 2019 17:45:26 +0200 Subject: [PATCH] Notification That nev device vas Discovered --- api.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/api.php b/api.php index fd40baa..62bc277 100644 --- a/api.php +++ b/api.php @@ -104,12 +104,25 @@ if ($token == null || $token == "") { //Vstupní Checky if (!DeviceManager::registeret($token)) { + $notificationData = [ + 'title' => 'Info', + 'body' => 'New device Detected', + 'icon' => '', + ]; $deviceId = DeviceManager::create($token, $token); foreach ($values as $key => $value) { if (!SubDeviceManager::getSubDeviceByMaster($deviceId, $key)) { SubDeviceManager::create($deviceId, $key, UNITS[$key]); } } + + //Notification for newly added Device + $subscribers = $notificationMng::getSubscription(); + foreach ($subscribers as $key => $subscriber) { + $logManager->write("[NOTIFICATION] SENDING TO" . $subscriber['id'] . " "); + $notificationMng::sendSimpleNotification(SERVERKEY, $subscriber['token'], $notificationData); + } + header("HTTP/1.1 401 Unauthorized"); echo json_encode(array( 'state' => 'unsuccess',