This folder contains JavaScript source code for the Quickstart guide, using the promises interface.
For Node.js:
npm install ably
For JavaScript:
<!DOCTYPE html>
<html lang="en">
<head>
<script src="//cdn.ably.com/lib/ably.min-1.js"></script>
</head>
<body>
...
For Node.js client:
const Ably = require('ably/promises');
const ably = new Ably.Realtime.Promise({ authUrl: 'https://ably.com/ably-auth/token/docs' });
For JavaScript (browser client):
<body>
...
<script>
const ably = new Ably.Realtime.Promise({
authUrl: "/auth",
});
await ably.connection.once('connected');
console.log('connected');
// get the channel to subscribe to
const channel = ably.channels.get('quickstart');
// the promise resolves when the channel is attached
// (and resolves synchronously if the channel is already attached)
await channel.subscribe('greeting', (message) => {
console.log('Message is ==> '+ message.data)
});
await channel.publish('greeting', 'hello');
console.log("Closing connection...");
ably.close();
console.log('Closed the connection to Ably.');