-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
43 lines (36 loc) · 1.13 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<script src="//cdn.ably.com/lib/ably.min-1.js"></script>
</head>
<body>
<h1>Ably Quickstart</h1>
<ul>
<li><p id="status">Status</p></li>
<li><p id="message">Messages</p></li>
</ul>
<script>
const ably = new Ably.Realtime.Promise({
authUrl: "/auth",
});
const ablyRealtimePromiseExample = async () => {
// Connect to Ably
await ably.connection.once("connected");
document.getElementById("status").innerHTML = "Connected to Ably!";
// get the channel to subscribe to
const channel = ably.channels.get("quickstart");
/*
Subscribe to a channel.
The promise resolves when the channel is attached
(and resolves synchronously if the channel is already attached).
*/
await channel.subscribe("greeting", (message) => {
document.getElementById("message").innerHTML = message.data;
});
// Publish a message
await channel.publish("greeting", "hello");
};
ablyRealtimePromiseExample();
</script>
</body>
</html>