-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathEventStream-e2e-browser.html
More file actions
39 lines (30 loc) · 962 Bytes
/
EventStream-e2e-browser.html
File metadata and controls
39 lines (30 loc) · 962 Bytes
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
<!--
End-to-end test program for the event stream in the browser
Steps:
- npm run build
- Replace the path to particle.min.js
- Replace your access token in `auth`
- Open this file in the browser
- Follow the scenarios in EventStream.feature
-->
<html>
<body>
<p>Open the Javascript Console</p>
<script type="text/javascript" src="file:///home/user/path/to/particle-api-js/dist/particle.min.js"></script>
<script type="text/javascript">
const baseUrl = 'http://localhost:9090';
const auth = '<my-token>';
const particle = new Particle({ baseUrl });
particle.getEventStream({ deviceId: 'mine', auth }).then(stream => {
console.log('event stream connected');
['event', 'error', 'disconnect', 'reconnect', 'reconnect-success', 'reconnect-error'].forEach(eventName => {
stream.on(eventName, (arg) => {
console.log(eventName, arg);
});
});
}).catch(function (err) {
console.log(err);
});
</script>
</body>
</html>