appwrite / appwrite/sdk-for-android
Realtime only has a single socket even with different endpoints
- Dominant language
- Kotlin
- Stars
- 154
- Forks
- 30
- Avg merge
- 5h 41m
- Merged PRs (30d)
- 3
Description
### 👟 Reproduction steps
1. Create two Clients, and for each, create a Realtime.
2. Attempt to subscribe on each, possibly to different things.
Explicit example:
val clientA = Client().setEndpoint("http://localhost:8080/v1").setProject("1234")
val clientB = Client().setEndpoint("http://localhost:8088/v1").setProject("5678")
val realtimeA = Realtime(clientA).subscribe(...)
val realtimeB = Realtime(clientB).subscribe(...)
### 👍 Expected behavior
It should create one socket per Client, or at most per endpointRealtime.
If I have multiple Client objects connected to different backends, I should be able to have a separate socket to each.
Simply changing
```
class Realtime ... {
private companion object {
private var socket: RealWebSocket? = null
```
to
```
private val sockets: Map = mutableMapOf()
```
and making appropriate thread-safe changes to the few places sockets are created/destroyed would address this.
### 👎 Actual Behavior
It shares a single socket across all Client/Realtimes, as it puts the socket on a private companion object.
Thus when I create realtimeB and call subscribe, it will close the socket, and create a new socket to localhost:8088 but try to merge all the requests for updates together. It's possible there are different users on each backend, etc.
### 🎲 Appwrite version
Version 1.8.x
### 💻 Operating system
Linux
### 🧱 Your Environment
This is Kotlin using io.appwrite:sdk-for-android:11.4.0
Note that this is an unusual scenario to have multiple clients to multiple backends, but I'm designing a highly-resilient, client-driven multiple-backend project that can keep multiple backends in sync, so it's a requirement for my project.
### 👀 Have you spent some time to check if this issue has been raised before?
- [x] I checked and didn't find similar issue
### 🏢 Have you read the Code of Conduct?
- [x] I have read the [Code of Conduct](https://github.com/appwrite/.github/blob/main/CODE_OF_CONDUCT.md)
Contributor guide
Assessment
This issue has not been assessed yet.