title: How is state managed in Scala Play! 2.0 Websockets?
body: <p>I'm looking at the example at <a href="https://github.com/playframework/Play20/tree/master/samples/scala/websocket-chat" rel="nofollow">https://github.com/playframework/Play20/tree/master/samples/scala/websocket-chat</a>  </p>
  
  <p>To make a websocket controller, you write something like:  </p>
  
  <pre><code>def chat(username: String) = WebSocket.async[JsValue] { request  =&gt;
      ChatRoom.join(username)
  }  
  </code></pre>
  
  <p>Chatroom.join returns a <strong>scala.concurrent.Future[(Iteratee[JsValue,_],Enumerator[JsValue])]</strong> . But where are the iteratee and the enumerator used within the Play! framework? The <strong>WebSocket</strong> class (WebSocket.scala) seems to ignore the inputs:  </p>
  
  <pre><code>case class WebSocket[A](f: RequestHeader =&gt; (Enumerator[A], Iteratee[A, Unit]) =&gt; Unit)        (implicit val frameFormatter: WebSocket.FrameFormatter[A]) extends Handler {
  
    type FRAMES_TYPE = A
  
    /**
     * Returns itself, for better support in the routes file.
     *
     * @return itself
     */
     def apply() = this
  }
  </code></pre>
  
  <p>How does Play! manage the changing state of the iteratee as it consumes input?  </p>