Commit 553785c
Fix isConnected (#39)
Currently `isConnected` is true when `connection` exists. However, this
is different from JS and Swift implementations.
In [JS][1] and [Swift][2] implementations `isConnected` is true only when the
socket is actually connected.
One of the problems this causes was the channels were closed during the
following scenario:
1. WebSocket connection established, one channel is joined..
2. Internet/Wifi disabled -> connection fails.
3. We periodically call `phxSocket.connect()` to reconnect.
4. Channels [try to rejoin as `isConnected` is true][4], but `phx_join`
messages are being queued instead as connection is still not established.
5. Internet/Wifi enabled -> multiple queued `phx_join` messages are sent,
Phoniex Server relies `phx_close` to all join messages but last.
On `phx_close` the channel is removed from the socket, even tho the logs
show that the state is being received.
`connect` method is changed to use `connection != null` check, the same
way it's done in [JS version][3].
[1]: https://github.com/phoenixframework/phoenix/blob/93db5ff3adf4c91a1ff1996e819e7dd5dfbddf1a/assets/js/phoenix.js#L906
[2]: https://github.com/davidstump/SwiftPhoenixClient/blob/ade5c27051a96aeeedff1594cb3e176b57a02f96/Sources/Socket.swift#L180
[3]: https://github.com/phoenixframework/phoenix/blob/93db5ff3adf4c91a1ff1996e819e7dd5dfbddf1a/assets/js/phoenix.js#L782
[4]: https://github.com/dsrees/JavaPhoenixClient/blob/master/src/main/kotlin/org/phoenixframework/PhxChannel.kt#L741 parent 49dc2a2 commit 553785c
File tree
2 files changed
+48
-4
lines changed- src
- main/kotlin/org/phoenixframework
- test/kotlin/org/phoenixframework
2 files changed
+48
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
99 | 99 | | |
100 | 100 | | |
101 | 101 | | |
102 | | - | |
103 | 102 | | |
104 | 103 | | |
105 | 104 | | |
| |||
154 | 153 | | |
155 | 154 | | |
156 | 155 | | |
157 | | - | |
158 | | - | |
| 156 | + | |
| 157 | + | |
159 | 158 | | |
160 | 159 | | |
161 | 160 | | |
| |||
173 | 172 | | |
174 | 173 | | |
175 | 174 | | |
176 | | - | |
| 175 | + | |
177 | 176 | | |
178 | 177 | | |
179 | 178 | | |
| |||
440 | 439 | | |
441 | 440 | | |
442 | 441 | | |
| 442 | + | |
443 | 443 | | |
444 | 444 | | |
445 | 445 | | |
| |||
451 | 451 | | |
452 | 452 | | |
453 | 453 | | |
| 454 | + | |
454 | 455 | | |
455 | 456 | | |
456 | 457 | | |
457 | 458 | | |
| 459 | + | |
458 | 460 | | |
459 | 461 | | |
460 | 462 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
| 6 | + | |
5 | 7 | | |
6 | 8 | | |
7 | 9 | | |
| |||
36 | 38 | | |
37 | 39 | | |
38 | 40 | | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
39 | 81 | | |
0 commit comments