Flocon/docs/websocket.md
Florent CHAMPIGNY ce1df58b9f
refact: doc content (#455)
Co-authored-by: Florent Champigny <florent@bere.al>
2025-12-24 14:55:53 +01:00

77 lines
2.1 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

### 💬 Inspect Websockets
<img width="1442" height="572" alt="Screenshot 2025-10-04 at 23 44 57" src="https://github.com/user-attachments/assets/49cef28f-87c9-4af7-a929-63d428d99f9e" />
Flocon doesnt stop at HTTP — it also captures **all WebSocket communications** made by your Android app.
This allows you to inspect real-time data exchanges between your app and the server with full visibility.
For each WebSocket connection, you can inspect:
- Connection URL
- **Sent and received frames** (text, binary, ping/pong)
- **Timestamps** and message order
- **Payloads**
- **Closes**
With this feature, you can:
- Debug real-time features like chat, live feeds, or multiplayer updates
- Verify the exact content of messages exchanged
- Diagnose disconnection or synchronization issues
#### With OkHttp3 (android only)
Flocon-Okhttp-Interceptor has built-in websocket methods (⚠️ it's not possible through interceptors ⚠️)
To log outgoing messages
```kotlin
webSocket.sendWithFlocon("\"$text\"") // extension method that log to Flocon and performs the send
```
To log incoming messages
```kotlin
val request = Request.Builder()
.url("wss://.......")
.build()
val listener = object : WebSocketListener() {
// your listener
}
webSocket = client.newWebSocket(
request,
listener.listenWithFlocon(id = "wss://......."), // extension method that wraps an existing WebSocketListener
)
}
```
#### 🧰 Manually (kotlin multi platform compatible)
If you are using other websockets libs than okhttp, you can easily forward events to FloconWebSocket
To log outgoing messages
```kotlin
val message = "hello"
webSocket.send(message)
floconLogWebSocketEvent(
FloconWebSocketEvent(
websocketUrl = "ws://...",
event = FloconWebSocketEvent.Event.SendMessage,
message = message,
)
)
```
To log incoming messages
```kotlin
myCustomWebSocket.onReceived {
floconLogWebSocketEvent(
FloconWebSocketEvent(
websocketUrl = "ws://..."
event = FloconWebSocketEvent.Event.ReceiveMessage,
message = it,
)
// handle your message
)
```