Note that there are some explanatory texts on larger screens.

plurals
  1. POScala Lift: Multiple Comet Actors on same page
    primarykey
    data
    text
    <p>Is it a good idea to have more than one comet actor on a page? </p> <p>I've currently got a simple chat box like the one in the Lift docs and a simple webcam stream handler.</p> <p>I'm experiencing locks when both are activated, e.g I type a message into the chat, all is well, but when I start a camera feed the chat box no longer works.</p> <p>What is best practice for this kind of setup? I aim to have alot more than two on a page, but was wondering if it would be better to have a single actor that dispatches the results to the page for both chat and streams etc.</p> <p>Code is posted below:</p> <p><strong>CHAT</strong></p> <pre><code>case class ChatMessage(name: String, text: String) class ChatComet extends CometActor with CometListener { private var messages: List[ChatMessage] = Nil def registerWith = ChatServer override def lowPriority = { case v: List[ChatMessage] =&gt; messages = v; reRender() } def render = { "li *" #&gt; messages.map(message =&gt; ".name *" #&gt; message.name &amp; ".text *" #&gt; message.text ) } } object ChatServer extends LiftActor with ListenerManager { private var messages: List[ChatMessage] = Nil def createUpdate = messages override def lowPriority = { case message: String if message.length &gt; 0 =&gt; messages :+= ChatMessage("Anon", message); updateListeners() } } </code></pre> <p><strong>STREAM (Webcam)</strong></p> <pre><code>case class StreamItem(name: String, path: String, level: String) class StreamComet extends CometActor with CometListener { private var streams: List[StreamItem] = Nil def registerWith = StreamServer override def lowPriority = { case v: List[StreamItem] =&gt; streams = v; reRender(); partialUpdate(Call("STREAMMOD.stream_view.add_stream({ path : '" + streams.reverse(0).path + "', level : '_1'})")); } def render = { "li *" #&gt; streams.map(stream =&gt; ".name *" #&gt; stream.name.toString &amp; ".stream [id]" #&gt; stream.path.toString ) } } object StreamServer extends LiftActor with ListenerManager { private var streams: List[StreamItem] = Nil def createUpdate = streams override def lowPriority = { case stream: String if stream.length &gt; 0 =&gt; streams :+= StreamItem("James", stream, "_1"); updateListeners() } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload