-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
56 lines (53 loc) · 1.82 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<!DOCTYPE html>
<html lang="en">
<head>
<title>Notifications</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>
<style>
#user_id{
margin-top: 10px;
}
</style>
</head>
<body>
<div class="container">
<div class="form-group">
<input class="form-control" type="text" id="user_id" placeholder="Enter your user_id">
</div>
</div>
<script type="text/javascript">
$(function() {
var user_id;
$('#user_id').change(function(){
user_id = $(this).val();
notifyMe();
});
if (!("Notification" in window) || !("WebSocket" in window)) {
return
}
var notifyMe = function(){
var notification_connection = new WebSocket("ws://localhost:5000/ws");
notification_connection.onopen = function(){
notification_connection.send(user_id);
}
notification_connection.onmessage = function(evt) {
new Notification('Notification:', {
body: evt.data
})
}
}
if (Notification.permission === "granted") {
notifyMe();
} else if (Notification.permission !== 'denied') {
Notification.requestPermission(function (permission) {
if (permission === "granted") {
notifyMe();
}
});
}
});
</script>
</body>
</html>