This repository has been archived on 2023-07-11. You can view files and clone it, but cannot push or open issues or pull requests.
clj-browserchannel/clj-browserchannel-jetty-adapter/README.md

107 lines
2.6 KiB
Markdown
Raw Normal View History

2012-04-07 15:02:59 -04:00
# clj-browserchannel-jetty-adapter
2016-05-16 18:56:52 -04:00
Jetty async adapter for BrowserChannel.
2012-04-07 15:02:59 -04:00
See also: [clj-browserchannel][1]
2016-05-16 18:56:52 -04:00
[1]:https://github.com/gered/clj-browserchannel
2016-05-16 18:56:52 -04:00
## Leiningen
[gered/clj-browserchannel-jetty-adapter "0.1.0"]
2016-05-16 18:56:52 -04:00
## 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][2] project page for more information and the relevant
dependency lines for your `project.clj`.
[2]: https://github.com/ring-clojure/ring
To enable server-side BrowserChannel functionality, you should
start Jetty with the included `run-jetty` function. For example:
```clj
(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:
```clj
(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.
2012-04-07 15:02:59 -04:00
## About
Written by:
2016-05-16 18:56:52 -04:00
Gijs Stuurman /
[@thegeez](http://twitter.com/thegeez) /
[Blog](http://thegeez.github.com) /
[GitHub](https://github.com/thegeez)
2012-04-07 15:02:59 -04:00
2016-05-16 18:56:52 -04:00
Updates in this fork by:
Gered King /
[@geredking](http://twitter.com/geredking) /
[GitHub](https://github.com/gered)
2012-04-07 15:02:59 -04:00
### License
Copyright (c) 2012 Gijs Stuurman and released under an MIT license.