forked from WiseEngineering/dovzhenko
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sse_sns_example.html
64 lines (46 loc) · 1.43 KB
/
sse_sns_example.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Subscriber</title>
</head>
<body>
<h1>Subscriber</h1>
<fieldset>
<p>
<label>Server:</label>
<input type="text" id="server" placeholder="server" value="http://localhost:3300">
</p>
<p>
<label>Slug:</label>
<input type="text" id="slug" placeholder="slug">
</p>
<p>
<label>Event:</label>
<input type="text" id="event" placeholder="event">
</p>
<p>
<button type="button" id="button">Subscribe to topic</button>
</p>
</fieldset>
<script>
const button = document.querySelector('#button');
const server = document.querySelector('#server');
const bid_slug = document.querySelector('#slug');
const event = document.querySelector('#event');
button.addEventListener('click', async (evt) => {
let es = new EventSource(`${server.value}/bid/${bid_slug.value}`);
es.addEventListener(event.value, function (evt) {
console.log(`incoming message`, JSON.parse(evt.data));
});
es.addEventListener('open', function (evt) {
console.log('connected', evt);
});
es.addEventListener('error', function (evt) {
console.log('error', evt);
});
});
</script>
</body>
</html>