Skip to content

Commit 0a9d837

Browse files
committed
fixup! Add javascript getting started to pubsub
1 parent ccf5272 commit 0a9d837

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

content/getting-started/javascript.textile

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ Clients establish a connection with Ably when they instantiate an SDK. This enab
3535
* Run the following function to instantiate the SDK and establish a connection to Ably. At the minimum you need to provide an authentication mechanism. Use an API key for simplicity, but you should use token authentication in a production app. A @clientId@ ensures the client is identified, which is required to use certain features, such as presence:
3636

3737
```[javascript]
38-
const PubSub = require('ably');
38+
import * as Ably from 'ably';
3939

4040
async function getStarted() {
4141

42-
const realtimeClient = new PubSub.Realtime({ key: '{{API_KEY}}', clientId: 'my-first-client' });
42+
const realtimeClient = new Ably.Realtime({ key: '{{API_KEY}}', clientId: 'my-first-client' });
4343

44-
await realtimeClient.connection.once('connected');
44+
await realtimeClient.connection.once('connected');
4545
console.log(`Made my first connection!`);
4646

4747
};
@@ -61,7 +61,7 @@ Messages contain the data that a client is communicating, such as a short 'hello
6161
const channel = realtimeClient.channels.get('my-first-channel');
6262

6363
await channel.subscribe((message) => {
64-
console.log(`Received message: ${message.data}`);
64+
console.log(`Received message: ${message.data}`);
6565
});
6666
```
6767

@@ -77,15 +77,15 @@ Presence enables clients to be aware of one another if they are present on the s
7777

7878
```[javascript]
7979
await channel.presence.subscribe((member) => {
80-
console.log(`Event type: ${member.action} from ${member.clientId} with the data ${member.data}`)
80+
console.log(`Event type: ${member.action} from ${member.clientId} with the data ${JSON.stringify(member.data)}`)
8181
});
8282

83-
await channel.presence.enter(`I'm here!`);
83+
await channel.presence.enter("I'm here!");
8484
```
8585

8686
* In the "dev console":https://ably.com/accounts/any/apps/any/console of your first app, attach to @my-first-channel@. Enter a @clientId@, such as @my-dev-console@, and then join the presence set of the channel. You'll see that @my-first-client@ is already present in the channel. In the console of your browser or IDE you'll see that an event was received when the dev console client joined the channel.
8787

88-
* You can have another client join the presence set using the Ably CLI: @ably channels presence enter my-first-channel --client-id "my-cli"@.
88+
* You can have another client join the presence set using the Ably CLI: @ably channels presence enter my-first-channel --client-id "my-cli" --data '{"status":"online"}'@.
8989

9090
h2(#step-4). Step 4: Retrieve message history
9191

@@ -99,7 +99,7 @@ For example, using the Ably CLI to publish 5 messages: @ably channels publish --
9999

100100
```[javascript]
101101
const history = await channel.history();
102-
console.log(history.items.map((message) => message.data));
102+
console.log(history.items.map((message) => message.data));
103103
```
104104

105105
The output will look similar to the following:

0 commit comments

Comments
 (0)