Skip to content

Instantly share code, notes, and snippets.

@thisisjofrank
Last active May 20, 2020 15:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thisisjofrank/dcd66bdba221993914641366f3349616 to your computer and use it in GitHub Desktop.
Save thisisjofrank/dcd66bdba221993914641366f3349616 to your computer and use it in GitHub Desktop.
Connecting to a data channel with Ably
async function connect() {
// set up an instance of the Ably realtime library
const ably = new Ably.Realtime.Promise({ authUrl: '/api/createTokenRequest' });
// create a channel called "tshirt"
const channelId = "tshirt";
//connect to the tshirt channel
const channel = await ably.channels.get(channelId);
await channel.attach();
//subscribe to the channel to get updates and call processMessage
channel.subscribe(processMessage);
}
connect();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment