-
Notifications
You must be signed in to change notification settings - Fork 5
/
permissions.html
123 lines (112 loc) · 4.5 KB
/
permissions.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<!DOCTYPE html>
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<link rel="manifest" href="manifest.json">
<link href="https://fonts.googleapis.com/css?family=Hanalei+Fill" rel="stylesheet">
<title>Permissions test page</title>
</head>
<!-- This is a page for testing app permissions: camera, microphone, notifications, location.
The source code can be found at https://github.com/mozilla-mobile/testapp
-->
<body>
<section>
<p class="header">Location Menu</p>
<button id="location">Get Location</button>
<p id="location-result"></p>
</section>
<section>
<p class="header">Test Camera Dialogue</p>
<input id=video type=button value="Open camera" onclick=open_camera() >
<p id="camera-result"></p>
</section>
<section>
<p class="header">Test Microphone Dialogue</p>
<input id=audio type=button value="Open microphone" onclick=open_microphone() >
<p id="microphone-result"></p>
</section>
<section>
<p class="header">Test Camera & Microphone Dialogue</p>
<input id=audioVideo type=button value="Camera & Microphone" onclick=open_audioVideo() >
<p id="audioVideo-result"></p>
</section>
<section>
<p class="header">Test Notifications Dialogue</p>
<input id=notify type=button value="Open notifications dialogue" onclick=open_notifications() >
<p id="notifications-result"></p>
</section>
<script>
// Grab elements, create settings, etc.
function open_camera() {
var video = document.getElementById('video');
// Get access to the camera!
if(navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
// Not adding `{ audio: true }` since we only want video now
navigator.mediaDevices.getUserMedia({ video: true })
.then(function(stream) {
document.getElementById('camera-result').innerText = "Camera allowed";
})
.catch(function(err) {
document.getElementById('camera-result').innerText = "Camera not allowed";
});
}
}
function open_microphone() {
var audio = document.getElementById('audio');
// Get access to the microphone!
if(navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
navigator.mediaDevices.getUserMedia({ audio: true })
.then(function(stream) {
document.getElementById('microphone-result').innerText = "Microphone allowed";
})
.catch(function(err) {
document.getElementById('microphone-result').innerText = "Microphone not allowed";
});
}
}
function open_audioVideo() {
var audioVideo = document.getElementById('audioVideo');
// Get access to the microphone and camera!
if(navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
navigator.mediaDevices.getUserMedia({ audio: true, video: true,})
.then(function(stream) {
document.getElementById('audioVideo-result').innerText = "Camera and Microphone allowed";
})
.catch(function(err) {
document.getElementById('audioVideo-result').innerText = "Camera and Microphone not allowed";
});
}
}
function open_notifications() {
Notification.requestPermission().then(function(result) {
if (result === 'denied' || result === 'default') {
document.getElementById('notifications-result').innerText = "Notifications not allowed";
return;
}
if (result === 'granted') {
document.getElementById('notifications-result').innerText = "Notifications allowed";
return;
}
});
}
</script>
</body>
<script type="text/javascript">
document.getElementById('location').addEventListener('click', function() {
navigator.geolocation.getCurrentPosition(
function(pos) {
document.getElementById('location-result').innerText = JSON.stringify({
longitude: pos.coords.longitude,
latitude: pos.coords.latitude
});
},
function(error) {
document.getElementById('location-result').innerText = error.message;
});
});
</script>
</html>