Bidirectional message channel between a servlet container and a browser
Scala JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
project
src/main
.gitignore
LICENSE
README
build.sbt

README

Bidirectional message channel between a servlet container and a browser

Facts
-   uses only a single HTTP connection
-   built on top of jetty continuations
-   messages are JSON encoded

To build this code, get and install SBT from
    https://github.com/sbt/sbt

Get and install these library/libraries before building:
    https://github.com/ritschwumm/scutil
    https://github.com/ritschwumm/scjson
    https://github.com/ritschwumm/scwebapp

Use these commands to build:
    git clone git@github.com:ritschwumm/rumms.git
    cd rumms
    sbt publish-local

Usage

    Add this code to your web.xml

        <listener>
            <listener-class>demo.DemoContextListener</listener-class>
        </listener>

    Note: If this servlet is reached through a filter, that filter must
    have <async-supported>true</async-supported> set, too.

    Implement the DemoContextListener

        package demo
        import javax.servlet._
        import rumms._
        final class DemoContextListener(sc:ServletContext) extends ServletContextListener {
            @volatile var rumms:Option[Rumms]   = None
            def contextInitialized(ev:ServletContextEvent) {
                val config  = RummsConfiguration("/rumms", "0")
                val rumms   = Rumms create (ev.getServletContext, config)
                rumms start new RummsCallbacks {
                    // ...
                }
            }
            def contextDestroyed(ev:ServletContextEvent) {
                rumms foreach { _.dispose() }
            }
        }

    In the webapp, include the client code like this

        <script type="text/javascript" src="rumms/code?_="></script>

    and connect to the server like this

        var conversation = new rumms.Conversation({
            connected:      function(conversationId)    { ... },
            disconnected:   function(conversationId)    { ... },
            upgraded:       function(version)           { ... },
            message:        function(object)            { ... },
            heartbeat:      function()                  { ... },
            error:          function(object)            { ... }//,
        });
        conversation.connect();