Last active
May 20, 2020 15:03
-
-
Save thisisjofrank/dcd66bdba221993914641366f3349616 to your computer and use it in GitHub Desktop.
Connecting to a data channel with Ably
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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