@@ -25,7 +25,8 @@ const val DEFAULT_HEARTBEAT: Long = 30000
2525
2626open class PhxSocket (
2727 url : String ,
28- params : Payload ? = null
28+ params : Payload ? = null ,
29+ private val client : OkHttpClient = OkHttpClient .Builder ().build()
2930) : WebSocketListener() {
3031
3132 // ------------------------------------------------------------------------------
@@ -99,7 +100,6 @@ open class PhxSocket(
99100 .create()
100101
101102 private val request: Request
102- private val client: OkHttpClient
103103
104104 // / WebSocket connection to the server
105105 private var connection: WebSocket ? = null
@@ -133,7 +133,6 @@ open class PhxSocket(
133133
134134 // Create the request and client that will be used to connect to the WebSocket
135135 request = Request .Builder ().url(httpUrl).build()
136- client = OkHttpClient .Builder ().build()
137136 }
138137
139138
@@ -353,6 +352,12 @@ open class PhxSocket(
353352
354353 // Inform all channels that a socket error occurred
355354 this .triggerChannelError()
355+
356+ // There was an error, violently cancel the connection. This is a safe operation
357+ // since the underlying WebSocket will no longer return messages to the Connection
358+ // after a Failure
359+ connection?.cancel()
360+ connection = null
356361 }
357362
358363 /* * Triggers a message to the correct Channel when it comes through the Socket */
0 commit comments