Skip to content
This repository has been archived by the owner on Apr 9, 2021. It is now read-only.

Commit

Permalink
Fix sending to multiple WS clients ... maybe?
Browse files Browse the repository at this point in the history
  • Loading branch information
freyacodes committed Feb 18, 2019
1 parent e173513 commit a13aba9
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions FredBoat/src/main/java/fredboat/ws/UserSessionHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import org.springframework.web.reactive.socket.WebSocketHandler
import org.springframework.web.reactive.socket.WebSocketMessage
import org.springframework.web.reactive.socket.WebSocketSession
import reactor.core.publisher.Mono
import java.lang.Exception
import java.util.concurrent.ConcurrentHashMap

@Controller
Expand Down Expand Up @@ -71,13 +72,19 @@ class UserSessionHandler(
else list.remove(session)
}

final inline fun sendLazy(guildId: Long, producer: () -> Any) {
final fun sendLazy(guildId: Long, producer: () -> Any) {
val sessions = this[guildId]
if (sessions.isEmpty()) return

val msg = sessions.first().textMessage(gson.toJson(producer()))
val msg = gson.toJson(producer())
sessions.forEach {
if (it.isOpen) it.send(msg)
log.info("Sending message to ${it.session.id}. Open: ${it.isOpen}")
//if (it.isOpen) it.send(it.textMessage(msg))
try {
it.send(it.textMessage(msg))
} catch(e: Exception) {
log.error("Error sending WS message")
}
}
}

Expand Down

0 comments on commit a13aba9

Please sign in to comment.