Skip to content

Commit 19a623f

Browse files
authored
Merge pull request #186 from ably/fix/readme-documentation
Fix doc links and update README
2 parents 1ac4e5d + d53c5f7 commit 19a623f

File tree

1 file changed

+55
-1
lines changed

1 file changed

+55
-1
lines changed

README.md

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@ architectures.
1515

1616
Everything you need to get started with Ably Chat for JVM and Android:
1717

18-
* [Getting started: Chat with Kotlin.](https://ably.com/docs/chat/getting-started/kotlin)
18+
* [Getting started: Chat with Kotlin (Android).](https://ably.com/docs/chat/getting-started/android)
19+
* [Getting started: Chat with Kotlin (JVM).](https://ably.com/docs/chat/getting-started/jvm)
1920
* [SDK and usage docs in Kotlin.](https://ably.com/docs/chat/setup?lang=kotlin)
21+
* [API documentation.](https://sdk.ably.com/builds/ably/ably-chat-kotlin/main/dokka/)
22+
* [Chat Example App.](https://github.com/ably/ably-chat-kotlin/tree/main/example)
2023
* Play with the [livestream chat demo.](https://ably-livestream-chat-demo.vercel.app/)
2124

2225
---
@@ -54,6 +57,57 @@ For Kotlin Script (`build.gradle.kts`):
5457
implementation("com.ably.chat:chat:1.1.0")
5558
```
5659

60+
---
61+
62+
## Usage
63+
64+
The following code connects to Ably's chat service, subscribes to a chat room, and sends a message to that room:
65+
66+
```kotlin
67+
import com.ably.chat.ChatClient
68+
import com.ably.chat.RoomOptions
69+
import com.ably.chat.RoomStatus
70+
import io.ably.lib.realtime.AblyRealtime
71+
import io.ably.lib.types.ClientOptions
72+
73+
// Initialize Ably Realtime client
74+
val realtimeClient = AblyRealtime(
75+
ClientOptions().apply {
76+
key = "<your-ably-api-key>"
77+
clientId = "your-client-id"
78+
}
79+
)
80+
81+
// Create a chat client
82+
val chatClient = ChatClient(realtimeClient)
83+
84+
// Get a chat room
85+
val room = chatClient.rooms.get("my-room", RoomOptions())
86+
87+
// Attach to the room
88+
room.attach()
89+
90+
// Monitor room status
91+
room.onStatusChange { statusChange ->
92+
when (statusChange.current) {
93+
RoomStatus.Attached -> println("Room is attached")
94+
RoomStatus.Detached -> println("Room is detached")
95+
RoomStatus.Failed -> println("Room failed: ${statusChange.error}")
96+
else -> println("Room status: ${statusChange.current}")
97+
}
98+
}
99+
100+
// Subscribe to messages
101+
val subscription = room.messages.subscribe { message ->
102+
println("Received message: ${message.text}")
103+
}
104+
105+
// Send a message
106+
room.messages.send(text = "Hello, World!")
107+
```
108+
109+
---
110+
57111
## Releases
58112

59113
The [CHANGELOG.md](/ably/ably-chat-kotlin/blob/main/CHANGELOG.md) contains details of the latest releases for this SDK. You can also view all Ably releases on [changelog.ably.com](https://changelog.ably.com).

0 commit comments

Comments
 (0)