.. | ||
src/net/thegeez/browserchannel | ||
project.clj | ||
README.md |
clj-browserchannel-jetty-adapter
Jetty async adapter for BrowserChannel.
See also: clj-browserchannel
Leiningen
[gered/clj-browserchannel-jetty-adapter "0.1.1"]
Usage
This library does not directly include Jetty as a dependency so that it's not tied to one specific version of Jetty (allowing you to upgrade to newer versions easier as long as they remain compatible with this library). You will need to include these Ring dependencies at a minimum:
ring/ring-core
ring/ring-servlet
ring/ring-jetty-adapter
The top-level ring
dependency includes all of these. See the
Ring project page for more information and the relevant
dependency lines for your project.clj
.
To enable server-side BrowserChannel functionality, you should
start Jetty with the included run-jetty
function. For example:
(ns your-app
(:require
; ...
[net.thegeez.browserchannel.server :refer [wrap-browserchannel]
[net.thegeez.browserchannel.jetty-async-adapter :refer [run-jetty]]
; ...
))
(def event-handlers
; ... browserchannel event handler map ...
)
(def your-app-routes
; ...
)
(def ring-handler
(-> your-app-routes
; other middleware
(wrap-browserchannel event-handlers)))
(defn -main [& args]
(run-jetty
#'handler
{:join? false
:port 8080}))
The run-jetty
function takes the exact same set of options as
ring.adapter.jetty/run-jetty
does. See that function for more
information.
One additional option is made available to configure the length of time that BrowserChannel async requests will remain open before timing out. By default this timeout is 4 minutes. This default time period is based on what Google uses currently in their BrowserChannel usage on e.g. Gmail.
To change this, the option you need to pass in to run-jetty
is
:response-timeout
with a new time in milliseconds:
(run-jetty
#'handler
{:join? false
:port 8080
; 2 minute async request timeout
:response-timeout (* 2 60 1000)})
This timeout period directly controls the maximum time that a back channel request can remain open for before it gets closed and the client must open a new one.
About
Written by: Gijs Stuurman / @thegeez / Blog / GitHub
Updates in this fork by: Gered King / @geredking / GitHub
License
Copyright (c) 2012 Gijs Stuurman and released under an MIT license.