From 7c28a86913c74f8aa59ca2ae905968b38ee4eca2 Mon Sep 17 00:00:00 2001 From: gered Date: Mon, 16 May 2016 13:39:08 -0400 Subject: [PATCH] added server-side close! function for "politely" disconnecting a client --- .../src/net/thegeez/browserchannel/server.clj | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/clj-browserchannel/src/net/thegeez/browserchannel/server.clj b/clj-browserchannel/src/net/thegeez/browserchannel/server.clj index fb3490a..ff674a5 100644 --- a/clj-browserchannel/src/net/thegeez/browserchannel/server.clj +++ b/clj-browserchannel/src/net/thegeez/browserchannel/server.clj @@ -656,11 +656,24 @@ (contains? @sessions session-id)) (defn disconnect! - "disconnects the client identified by session-id." + "forcefully closes/disconnects the client session identified by session-id. + NOTE: the client code in net.thegeez.browserchannel.client will treat + this as an error and may try to reconnect. if you do not wish this + to happen, use close! instead." [session-id & [reason]] (if-let [session-agent (get @sessions session-id)] (send-off session-agent close nil (or reason "Client disconnected by server")))) +(defn close! + "sends a message to the client requesting that it not attempt a + reconnection and when the message has been sent over the backchannel, + closes/disconnects the session. + NOTE: because we wait for a message to be sent before closing the session, + it is possible the session won't be closed right away if e.g. the + client does not currently have an active backchannel." + [session-id & [reason]] + (send-map session-id ["stop"] {:on-sent #(disconnect! session-id reason)})) + (defn get-status "returns connection status info about the client identified by session-id" [session-id]