Skip to content

Commit 65b4996

Browse files
committed
Add support max-text-message-size parameter for stalefruits/gniazdo#22
1 parent dad6b67 commit 65b4996

1 file changed

Lines changed: 20 additions & 3 deletions

File tree

src/slack_rtm/core.clj

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
(ns slack-rtm.core
2+
(:import (org.eclipse.jetty.websocket.client WebSocketClient)
3+
(org.eclipse.jetty.util.ssl SslContextFactory))
24
(:require [clj-slack.rtm :as rtm]
35
[clj-slack.core :refer [slack-request]]
46
[clojure.core.async :as async
@@ -26,12 +28,26 @@
2628
(recur))))
2729
ch))
2830

31+
(defn- client
32+
"Create a new instance of `WebSocketClient` with max-text-message-size.
33+
(for https://github.com/stalefruits/gniazdo/issues/22)"
34+
[max-text-message-size]
35+
(let [client (WebSocketClient. (SslContextFactory.))]
36+
(try
37+
(when max-text-message-size
38+
(.setMaxTextMessageSize (.getPolicy client) max-text-message-size))
39+
(.start client)
40+
(catch Throwable ex
41+
(.stop client)
42+
(throw ex)))))
43+
2944
(defn- ws-connect
3045
"Connects to the provided WebSocket URL and forward all listener
3146
events to the provided channel."
32-
[url callback-ch]
47+
[url callback-ch {:keys [max-text-message-size] :as connection}]
3348
(ws/connect
3449
url
50+
:client (client max-text-message-size)
3551
:on-connect #(go (>! callback-ch {:type :on-connect
3652
:session %}))
3753

@@ -101,7 +117,8 @@
101117
(defn- build-connection-map [token-or-map]
102118
(if (string? token-or-map)
103119
{:api-url "https://slack.com/api"
104-
:token token-or-map}
120+
:token token-or-map
121+
:max-text-message-size 65536}
105122
token-or-map))
106123

107124
(defn- internal-connect
@@ -154,7 +171,7 @@
154171
;; get a channel that can be used to send data to slack
155172
dispatcher (-> start
156173
:url
157-
(ws-connect callback-ch)
174+
(ws-connect callback-ch connection)
158175
spin-dispatcher-channel)]
159176
{:start start
160177
:websocket-publication websocket-publication

0 commit comments

Comments
 (0)