Push Messages #2

This commit is contained in:
JonatanRek
2019-10-08 16:49:08 +02:00
parent 1f456aaaac
commit e5f1fc61d6
6 changed files with 168 additions and 66 deletions

View File

@@ -29,14 +29,16 @@
}
?>
</div>
<select class="select m-1" name="room">
<option value="all">All</option>
<?php foreach ($ROOMS as $key => $room) {
if ($room['device_count'] > 0) { ?>
<option value="<?php echo $room['room_id']?>"><?php echo $room['name'] ?></option>
<div class="m-1">
<select class="select" name="room">
<option value="all">All</option>
<?php foreach ($ROOMS as $key => $room) {
if ($room['device_count'] > 0) { ?>
<option value="<?php echo $room['room_id']?>"><?php echo $room['name'] ?></option>
<?php } ?>
<?php } ?>
<?php } ?>
</select>
</select>
</div>
<div class="row no-gutters">
<?php foreach ($DATA as $roomId => $room) { ?>
<?php foreach ($room['devices'] as $deviceId => $device) { ?>

View File

@@ -25,12 +25,31 @@ if ('serviceWorker' in navigator) {
})
.then(function(token) {
console.log("token is : " + token);
$.ajax({
url: 'ajax',
type: 'POST',
data: {
"token": token
},
success: function(data){
console.log('saved', data);
},
error: function (request, status, error) {
console.log("ERROR ", request, error);
}
});
})
.catch(function (err) {
console.log("Unable to get permission to notify.", err);
});
messaging.onMessage(function(payload) {
console.log("Message received. ", payload);
var notification = new Notification('hello', {
body: "Hey there!",
});
notification.onclick = function () {
window.open("http://google.com");
};
});
})
.catch(err => {