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
Gered f48818b137 move clj-browserchannel dependency to provided
since it will always be included as a dependency of projects using
either of these adapters anyway
2016-05-17 14:37:25 -04:00
..
src/net/thegeez/browserchannel update jetty adapter to just use the jetty instance pulled in by ring 2016-05-09 19:09:07 -04:00
project.clj move clj-browserchannel dependency to provided 2016-05-17 14:37:25 -04:00
README.md update READMEs 2016-05-16 18:56:52 -04:00

clj-browserchannel-jetty-adapter

Jetty async adapter for BrowserChannel.

See also: clj-browserchannel

Leiningen

[gered/clj-browserchannel-jetty-adapter "0.1.0"]

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.