Skip to content

Commit bd84003

Browse files
author
James Lees
committed
Update example
- Use the current API - Import the built service worker, rather than the src - Start the client in an event handler - Some browsers only allow requesting permission to send notifications in response to a user gesture squash
1 parent 5582754 commit bd84003

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

example.html

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,27 @@
44
<meta charset="UTF-8" />
55
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
66
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
7+
<script src="./dist/push-notifications-cdn.js"></script>
78
<title>Example</title>
89
</head>
910
<body>
10-
<script src="./dist/push-notifications-cdn.js"></script>
11-
<script>
12-
let tokenProvider = new PusherPushNotifications.TokenProvider({
13-
url: 'https://deadc0de-beams-test-server.herokuapp.com/auth',
14-
});
11+
<h1>Example</h1>
12+
<button id="start">Start Beams</button>
13+
</body>
14+
<script>
15+
const beamsClient = new PusherPushNotifications.Client({
16+
instanceId: '2e65aab4-a26e-4cca-a9e6-b68589627a8d',
17+
});
1518

16-
let beamsClient;
17-
PusherPushNotifications.init({
18-
instanceId: 'deadc0de-2ce6-46e3-ad9a-5c02d0ab119b',
19-
})
20-
.then(c => {
21-
beamsClient = c;
19+
document.querySelector('#start').addEventListener('click', function() {
20+
beamsClient
21+
.start()
22+
.then(() => {
23+
console.log('Successfully started beams client');
2224
})
23-
.catch(console.error);
24-
</script>
25-
</body>
25+
.catch((err) => {
26+
console.error('Error starting beams client', err);
27+
});
28+
});
29+
</script>
2630
</html>

service-worker.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
importScripts('/src/service-worker.js');
1+
importScripts('/dist/service-worker.js');

0 commit comments

Comments
 (0)