🎉 Add ping message on websocket communication.

Every 30seconds (for reset the default nginx proxy timeout).
This commit is contained in:
Andrey Antukh 2020-02-07 13:12:05 +01:00
parent e805515767
commit 044f8487e2
3 changed files with 22 additions and 15 deletions

View file

@ -20,11 +20,12 @@
[uxbox.util.uuid :as uuid]
[vertx.eventbus :as ve]
[vertx.http :as vh]
[vertx.impl :as vi]
[vertx.util :as vu]
[vertx.timers :as vt]
[vertx.web :as vw]
[vertx.web.websockets :as ws])
(:import
java.lang.AutoCloseable
io.vertx.core.Handler
io.vertx.core.Promise
io.vertx.core.Vertx
@ -91,9 +92,11 @@
ws (assoc ws
:user-id user-id
:file-id file-id)
sem (start-eventbus-consumer! ctx ws file-id)]
send-ping #(send! ws {:type :ping})
sem1 (start-eventbus-consumer! ctx ws file-id)
sem2 (vt/schedule-periodic! ctx 30000 send-ping)]
(handle-message ws {:type :connect})
(assoc ws ::sem sem)))
(assoc ws ::sem1 sem1 ::sem2 sem2)))
(defn- on-text-message
[ws message]
@ -106,7 +109,8 @@
(let [file-id (:file-id ws)]
(handle-message ws {:type :disconnect
:file-id file-id})
(.unregister (::sem ws))))
(.close ^AutoCloseable (::sem1 ws))
(.close ^AutoCloseable (::sem2 ws))))
(defn handler
[{:keys [user] :as req}]