You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/getting-started/javascript.textile
+8-8Lines changed: 8 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -35,13 +35,13 @@ Clients establish a connection with Ably when they instantiate an SDK. This enab
35
35
* 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:
36
36
37
37
```[javascript]
38
-
const PubSub = require('ably');
38
+
import * as Ably from 'ably';
39
39
40
40
async function getStarted() {
41
41
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' });
@@ -77,15 +77,15 @@ Presence enables clients to be aware of one another if they are present on the s
77
77
78
78
```[javascript]
79
79
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)}`)
81
81
});
82
82
83
-
await channel.presence.enter(`I'm here!`);
83
+
await channel.presence.enter("I'm here!");
84
84
```
85
85
86
86
* 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.
87
87
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"}'@.
89
89
90
90
h2(#step-4). Step 4: Retrieve message history
91
91
@@ -99,7 +99,7 @@ For example, using the Ably CLI to publish 5 messages: @ably channels publish --
0 commit comments