|
76 | 76 | const title = 'Notification title'; |
77 | 77 |
|
78 | 78 | const options = { |
79 | | - body: `This notification can have a maximum of ${Notification.maxActions || 0} action button(s). Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.`, |
| 79 | + body: `This notification can have a maximum of ${window.Notification?.maxActions || 0} action button(s). Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.`, |
80 | 80 | data: { |
81 | 81 | url: 'https://google.com', |
82 | 82 | }, |
|
119 | 119 | ], |
120 | 120 | }; |
121 | 121 |
|
122 | | - const showNotification = () => serviceWorkerRegistration.showNotification(title, options); |
| 122 | + const showNotification = () => serviceWorkerRegistration?.showNotification?.(title, options); |
123 | 123 |
|
124 | 124 | let deferredPrompt; |
125 | 125 |
|
|
130 | 130 | }); |
131 | 131 |
|
132 | 132 | const installPWA = async (success, _) => { |
133 | | - deferredPrompt.prompt(); |
134 | | - const { outcome } = await deferredPrompt.userChoice; |
| 133 | + deferredPrompt?.prompt(); |
| 134 | + const { outcome } = await deferredPrompt?.userChoice; |
135 | 135 | if (outcome === 'accepted') { |
136 | 136 | success(); |
137 | 137 | } |
|
189 | 189 | { |
190 | 190 | icon: '../media/textures/microphone-button.png', |
191 | 191 | callback: (success, fail) => { |
192 | | - navigator.mediaDevices.getUserMedia({ audio: true }) |
| 192 | + navigator.mediaDevices?.getUserMedia?.({ audio: true }) |
193 | 193 | .then(success, fail); |
194 | 194 | } |
195 | 195 | }, |
196 | 196 | { |
197 | 197 | icon: '../media/textures/camera-button.png', |
198 | 198 | callback: (success, fail) => { |
199 | | - navigator.mediaDevices.getUserMedia({ video: true }) |
| 199 | + navigator.mediaDevices?.getUserMedia?.({ video: true }) |
200 | 200 | .then(success, fail); |
201 | 201 | } |
202 | 202 | }, |
203 | 203 | { |
204 | 204 | icon: '../media/textures/screenshare-button.png', |
205 | 205 | callback: (success, fail) => { |
206 | | - navigator.mediaDevices.getDisplayMedia() |
| 206 | + navigator.mediaDevices?.getDisplayMedia?.() |
207 | 207 | .then(success, fail); |
208 | 208 | } |
209 | 209 | }, |
210 | 210 | { |
211 | 211 | icon: '../media/textures/location-button.png', |
212 | 212 | callback: (success, fail) => { |
213 | | - navigator.geolocation.getCurrentPosition(success, fail); |
| 213 | + navigator.geolocation?.getCurrentPosition?.(success, fail); |
214 | 214 | } |
215 | 215 | }, |
216 | 216 | { |
217 | 217 | icon: '../media/textures/notifications-button.png', |
218 | 218 | callback: (success, fail) => { |
219 | | - Notification.requestPermission(outcome => { |
| 219 | + window.Notification?.requestPermission?.(outcome => { |
220 | 220 | switch(outcome) { |
221 | 221 | case 'granted': |
222 | 222 | success(); |
|
237 | 237 | { |
238 | 238 | icon: '../media/textures/bluetooth-button.png', |
239 | 239 | callback: (success, fail) => { |
240 | | - navigator.bluetooth.requestDevice({ |
| 240 | + navigator.bluetooth?.requestDevice?.({ |
241 | 241 | // filters: [...] <- Prefer filters to save energy & show relevant devices. |
242 | 242 | // acceptAllDevices here ensures dialog can populate, we don't care with what. |
243 | 243 | acceptAllDevices: true |
|
249 | 249 | { |
250 | 250 | icon: '../media/textures/usb-button.png', |
251 | 251 | callback: (success, fail) => { |
252 | | - navigator.usb.requestDevice({ filters: [{}] }) |
| 252 | + navigator.usb?.requestDevice?.({ filters: [{}] }) |
253 | 253 | .then(success, fail); |
254 | 254 | } |
255 | 255 | }, |
256 | 256 | { |
257 | 257 | icon: '../media/textures/hid-button.png', |
258 | 258 | callback: (success, fail) => { |
259 | | - navigator.hid.requestDevice({ filters: [] }) |
| 259 | + navigator.hid?.requestDevice?.({ filters: [] }) |
260 | 260 | .then(devices => { devices.length > 0 ? success() : fail() }); |
261 | 261 | } |
262 | 262 | }, |
263 | 263 | { |
264 | 264 | icon: '../media/textures/midi-button.png', |
265 | 265 | callback: (success, fail) => { |
266 | | - navigator.requestMIDIAccess({ sysex: true }) |
| 266 | + navigator.requestMIDIAccess?.({ sysex: true }) |
267 | 267 | .then(success, fail); |
268 | 268 | } |
269 | 269 | }, |
270 | 270 | { |
271 | 271 | icon: '../media/textures/serial-button.png', |
272 | 272 | callback: (success, fail) => { |
273 | | - navigator.serial.requestPort({ filters: [] }) |
| 273 | + navigator.serial?.requestPort?.({ filters: [] }) |
274 | 274 | .then(success, fail); |
275 | 275 | } |
276 | 276 | }, |
|
0 commit comments