Sorry hit send too soon ... continuation below

On Jun 1, 10:42 am, "marius d." <marius.dan...@gmail.com> wrote:
> On Jun 1, 2:59 am, Xavi Ramirez <xavi....@gmail.com> wrote:
>
>
>
> > Thanks for pointing me into the right direction.  I've created a
> > simple example (see attachment).  In my example, the user can drag a
> > div around the screen.  Every time the div moves, the browser sends a
> > json object with the x and y coordinates to the comet steam.
> > Unfortunately I've ran into a couple of usability and performance
> > problems.
>
> > Assume the following set up: two browses are open (browser A and B)
> > are all listening to comet stream K.  Comet stream K broadcasts
> > commands that update the position of a div.
>
> > It seems that whenever browser A notifies comet stream K about an
> > update to the div's position, stream K broadcasts the message to all
> > its listeners, including browser A.  In other words, browser A
> > essentially hears its own echo.  For the user of browser A, this
> > causes the div to constantly jump between where the user actually
> > dragged it and the position that comet stream K is currently
> > broadcasting.
>
> This is something your app must handle. Your ShapeTracker actor is
> notified by all CometActor with AddListener hence your ShapeActor is
> sending messages to all running actors. Your app needs to discriminate
> the actors such that to not send the Comet response back if the
> notification request pertains to the same session.
>
> BTW Lift has ListenerManager trait such as:

 class ShapeDisplay extends CometActor with CometListenee {

   override def registerWith = ShapeTracker
   ...

 }

 object ShapeTracked extends Actor with ListenerManager {
   var msg: MoveShape = _

   override def createUpdate = msg

   override lowPriority = {
    case m @ MoveShape(x, y) => msg = chat; updateListeners
 }

    ...

 }

This is just a mechanism for your actor to interract with CometActors
but you still need to determine to which actor you don't want to send
the message. You could probably use a SessionVar to set some value
before notifying the CometActors and in CometActor you could probably
check if this SessionVar has the right value. If it does it would mean
that the CometActor pertains to the same session and you wont send
down any message back to the client. You would nee to unset this value
once you determined that. There are probably better ways to do it ...
but I'm thinking now that maybe we should do something inside
ListenerManager to allow the users to send messages only to
CometActors pertaining to other sessions only.

I'll look more into this and see if/how we can provide something out
of the box.

>
> > Also there does not seem to be any throttling mechanism for
> > client-side comet calls.  In my attached example, even a very simple
> > drag action creates dozens of ajax calls at once.  Firefox does not
> > handle this well.
>
> This is an on purpose Lift mechanism that avoids Ajax connections
> starvation. For instance I assume that you opened 2 firefox instances
> and tried it out. Well there is not difference between opening a new
> browser tab or a new browser window and Ajax parallel connections are
> shared among all instances. If you open one FF instance and oen IE
> instance you will not see this behavior anymore.
>
>
>
> > I'd greatly appreciate any tips or suggestions.
>
> > Thanks,
> > Xavi
>
> > P.S. Random question: Is there a CometActor instance for every browser
> > viewing a comet stream?
>
> > P.P.S.S.  I feel there's some utility in a JsCometActor.  If you all
> > are amenable, I'd love to write up a proposal and maybe even lend a
> > hand with implementing it.
>
> > On Sun, May 31, 2009 at 4:07 AM, marius d. <marius.dan...@gmail.com> wrote:
>
> > > Yes looks like this is exactly what you would need. Please see
> > > partialUpdate from CometActor. As an example you can see sites/example/
> > > src/main/scala/net/liftweb/example/comet/Clock.scala. partialUPdate
> > > function returns a JsCmd but there are of course implicit conversions
> > > between JsExp and JsCmd.
>
> > > What you're trying to do seems like an interesting thing for a Lift
> > > demo app in the sense that it would provide an interesting visual
> > > effect through CometActor.
>
> > > Br's,
> > > Marius
>
> > > On May 31, 4:46 am, Xavi Ramirez <xavi....@gmail.com> wrote:
> > >> I'm trying add some comet features to an existing JS app. Essentially,
> > >> I want to drag/drop a widget and have my movements reflected on other
> > >> user's browsers.
>
> > >> You mentioned that a CometActor can cause JsExp to be executed.  This
> > >> might be what I'm looking for.  How does that work?
>
> > >> Thanks,
> > >> Xavi
>
> > >> On Sat, May 30, 2009 at 5:02 PM, marius d. <marius.dan...@gmail.com> 
> > >> wrote:
>
> > >> > Lift generates the JavaScript for Comet so you essentially don't have
> > >> > to worry about it. From a CometActor you just provide the markup that
> > >> > you need to render asynchronously or just the JsExp to be executed by
> > >> > browser.
>
> > >> > However could you please provide an overview of what you're trying to
> > >> > achieve?
>
> > >> > P.S.
> > >> > By default Lift's Ajax/Comet support works against JavaScript content
> > >> > type responses and not JSON. However you can use JSON as well.
>
> > >> > Br's,
> > >> > Marius
>
> > >> > On May 30, 3:12 pm, Xavi Ramirez <xavi....@gmail.com> wrote:
> > >> >> Hello,
>
> > >> >> I was wondering if Lift provides a javascript interface to comet?
> > >> >> Ideally it would look something like this:
>
> > >> >> lift.getComet("comet-name").addListener(callback); // callback takes a
> > >> >> json object
> > >> >> lift.getComet("comet-name").postMessage(jsonObj);
>
> > >> >> Thanks,
> > >> >> Xavi
>
> >  cometmove.zip
> > 64KViewDownload
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to liftweb@googlegroups.com
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to