Skip to content

Commit bba720b

Browse files
authored
Add SerializedName to PhxMessage (#18)
* Expose OkHttpClient and clear connection on failure * Added SerializedName to PhxMessage. Updated ReadME
1 parent f82063e commit bba720b

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ fun connectToChatRoom() {
1515

1616
// Create the Socket
1717
val params = hashMapOf("token" to "abc123")
18-
val socket = PhxSocket("http://localhost:4000/socket/websocket", multipleParams
18+
val socket = PhxSocket("http://localhost:4000/socket/websocket", multipleParams)
1919

2020
// Listen to events on the Socket
2121
socket.logger = { Log.d("TAG", it) }
@@ -38,6 +38,19 @@ fun connectToChatRoom() {
3838
}
3939
```
4040

41+
You can also inject your own OkHttp Client into the Socket to provide your own configuration
42+
```kotlin
43+
// Create the Socket with a pre-configured OkHttp Client
44+
val client = OkHttpClient.Builder()
45+
.connectTimeout(1000, TimeUnit.MILLISECONDS)
46+
.build()
47+
48+
val params = hashMapOf("token" to "abc123")
49+
val socket = PhxSocket("http://localhost:4000/socket/websocket",
50+
multipleParams,
51+
client)
52+
```
53+
4154

4255
### Installation
4356

src/main/kotlin/org/phoenixframework/PhxMessage.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
11
package org.phoenixframework
22

3+
import com.google.gson.annotations.SerializedName
4+
35
class PhxMessage(
46
/** The unique string ref. Empty if not present */
7+
@SerializedName("ref")
58
val ref: String = "",
9+
610
/** Property "topic" is never used */
11+
@SerializedName("topic")
712
val topic: String = "",
13+
814
/** Property "topic" is never used */
15+
@SerializedName("event")
916
val event: String = "",
17+
1018
/** Property "topic" is never used */
19+
@SerializedName("payload")
1120
val payload: Payload = HashMap(),
21+
1222
/** The ref sent during a join event. Empty if not present. */
23+
@SerializedName("join_ref")
1324
val joinRef: String? = null) {
1425

1526

0 commit comments

Comments
 (0)