Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom query params to make-channel-socket! #158

Merged
merged 1 commit into from
Aug 28, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/taoensso/sente.cljx
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@

#+cljs ;; Handles reconnects, keep-alives, callbacks:
(defrecord ChWebSocket
[client-id url chs socket_ kalive-ms kalive-timer_ kalive-due?_ nattempt_
[client-id url params chs socket_ kalive-ms kalive-timer_ kalive-due?_ nattempt_
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

client-id and params could be combined.

cbs-waiting_ ; {<cb-uuid> <fn> ...}
state_ ; {:type _ :open? _ :uid _ :csrf-token _ :destroyed? _}
packer ; IPacker
Expand Down Expand Up @@ -815,7 +815,8 @@
(if-let [socket
(try
(WebSocket. (enc/merge-url-with-query-string url
{:client-id client-id}))
; We want params first so people don't clobber our query params accidentally
(merge params {:client-id client-id})))
(catch js/Error e
(errorf e "WebSocket js/Error")
nil))]
Expand Down Expand Up @@ -869,7 +870,7 @@

#+cljs
(defrecord ChAjaxSocket
[client-id url chs timeout-ms ajax-opts curr-xhr_ state_ packer
[client-id url params chs timeout-ms ajax-opts curr-xhr_ state_ packer
backoff-ms-fn]
IChSocket
(chsk-send!* [chsk ev {:as opts ?timeout-ms :timeout-ms ?cb :cb :keys [flush?]}]
Expand Down Expand Up @@ -937,6 +938,7 @@
:resp-type :text ; Prefer to do our own pstr reading
:params
(merge
params ; We want params first so people don't clobber our query params accidentally
{:_ (enc/now-udt) ; Force uncached resp
:client-id client-id}

Expand Down Expand Up @@ -987,14 +989,16 @@
Common options:
:type ; e/o #{:auto :ws :ajax}. You'll usually want the default (:auto)
:host ; Server host (defaults to current page's host)
:params ; A map of query parameters to put in the chsk request URL.
; Keywords will be converted to strings.
:ws-kalive-ms ; Ping to keep a WebSocket conn alive if no activity w/in given
; number of milliseconds
:lp-kalive-ms ; Ping to keep a long-polling (Ajax) conn alive ''
:packer ; :edn (default), or an IPacker implementation (experimental)
:ajax-opts ; Base opts map provided to `taoensso.encore/ajax-lite`
:wrap-recv-evs? ; Should events from server be wrapped in [:chsk/recv _]?"
[path &
[{:keys [type host recv-buf-or-n ws-kalive-ms lp-timeout-ms packer
[{:keys [type host params recv-buf-or-n ws-kalive-ms lp-timeout-ms packer
client-id ajax-opts wrap-recv-evs? backoff-ms-fn]
:as opts
:or {type :auto
Expand Down Expand Up @@ -1067,6 +1071,7 @@
:url (if-let [f (:chsk-url-fn opts)]
(f path win-location :ws) ; Deprecated
(get-chsk-url win-protocol host path :ws))
:params params
:chs private-chs
:packer packer
:socket_ (atom nil)
Expand All @@ -1086,6 +1091,7 @@
:url (if-let [f (:chsk-url-fn opts)]
(f path win-location :ajax) ; Deprecated
(get-chsk-url win-protocol host path :ajax))
:params params
:chs private-chs
:packer packer
:timeout-ms lp-timeout-ms
Expand Down