Skip to content

Commit

Permalink
Fix issue with closed websocket sessions not being registered (#21)
Browse files Browse the repository at this point in the history
* Fix issue with closed websocket sessions not being registered

* Update version
  • Loading branch information
andycate authored Feb 6, 2019
1 parent bc4bba2 commit 8939f28
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ dependencies {
}

group = 'org.team5499'
version = '0.1.3' /* Change this when deploying a new version */
version = '0.1.4' /* Change this when deploying a new version */

task sourcesJar(type: Jar) {
from sourceSets.main.allJava
Expand Down
19 changes: 16 additions & 3 deletions src/main/kotlin/org/team5499/dashboard/SocketHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import org.eclipse.jetty.websocket.api.annotations.WebSocket
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketConnect
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketClose
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketError
import org.eclipse.jetty.websocket.api.WebSocketException
import java.util.Queue
import java.util.concurrent.ConcurrentLinkedQueue
import java.lang.Thread
Expand Down Expand Up @@ -46,7 +48,12 @@ class SocketHandler {
public fun broadcastJSONMinusSession(json: JSONObject, session: Session) {
for (s in sessions) {
if (!s.equals(session)) {
sendJSON(s, json, "updates")
try {
sendJSON(s, json, "updates")
} catch (e: WebSocketException) {
session.close()
continue
}
}
}
}
Expand All @@ -59,8 +66,10 @@ class SocketHandler {
}

@OnWebSocketClose
fun onClose(session: Session, statusCode: Int, reason: String) {
sessions.remove(session)
fun onClose(session: Session?, statusCode: Int, reason: String?) {
if (session != null) {
sessions.remove(session)
}
}

@OnWebSocketMessage
Expand All @@ -70,6 +79,10 @@ class SocketHandler {
Dashboard.mergeVariableUpdates(updates)
}

@OnWebSocketError
fun onError(t: Throwable) {
}

@Suppress("EmptyDefaultConstructor")
class Broadcaster() : Runnable {
override fun run() {
Expand Down

0 comments on commit 8939f28

Please sign in to comment.