title: Use of Streams,Enumerator and Websockets in playframework
body: <p>I'm looking for the proper way to use play's Enumerator (play.api.libs.iteratee.Enumerator[A]) in my code, i have a stream of object of type "InfoBlock" and i want to redirect it to a websocket.What i actually do is:</p>
  
  <p>The data structure holding the blocks</p>
  
  <blockquote>
    <p>private lazy val buf:mutable.Queue[InfoBlock] = new mutable.SynchronizedQueue[InfoBlock]</p>
  </blockquote>
  
  <p>The callback to be used in the Enumerator</p>
  
  <pre><code>def getCallback: Future[Option[InfoBlock]] = Future{
  
  if (!buf.isEmpty)
    Some(buf.dequeue)
  else
    None}
  </code></pre>
  
  <p>Block are produced by another thread and added to the queue using:</p>
  
  <pre><code>buf += new InfoBlock(...) 
  </code></pre>
  
  <p>Then in the controller i want to set up a websocket to stream that data,doing:</p>
  
  <pre><code>def stream = WebSocket.using[String]{ request =&gt;
  
    val in = Iteratee.consume[String]()
  
    val enu:Enumerator[InfoBlock] = Enumerator.fromCallback1(
     isFirst =&gt; extractor.getCallback
    )
  
    val out:Enumerator[String] = enu &amp;&gt; Enumeratee.map(blk =&gt; blk.author+"  -&gt;  "+blk.msg)
  
  (in,out)}
  </code></pre>
  
  <p>It works but with a big problem, when a connection is open it sends a bunch of blocks (=~ 50) and stops, if i open a new websocket then i get another bunch of blocks but no more.I tried to set some property to the js object WebSocket in particular i tried setting </p>
  
  <pre><code> websocket.binaryType = "arraybuffer" 
  </code></pre>
  
  <p>because i thought using "blob" may be the cause but i was wrong the problem must be server side and i have no clue..</p>