HTML5 SSE test on Chrome 17

347 views
Skip to first unread message

Raul Parra

unread,
Mar 3, 2012, 1:56:08 AM3/3/12
to Chromium HTML5
Hi there.
I was making an html5 page for sse protocol testing using Chrome 17
version on Windows 7.
I've created an EventSource object and add a function to the listener
on this way:

var source = new EventSource('stream.php');
source.addEventListener('message', function(e) {
console.log(e.data);
}, false);

The question is: how can unregister the function?
What I have observed is that even if you call to:

source.close();

the function is still registered.
Let's say you have this code:

var source = new EventSource('stream.php');
source.addEventListener('message', function(e) {
console.log(e.data);
}, false);

source.close();

// create an EventSource again

source = new EventSource('stream2.php');
source.addEventListener('message', function(e) {
console.log(e.data);
}, false);

what I am observing in console log is that the registered function is
called 2 times...seems like if the first event registered was not
removed even if source.close() was called.( I've even tried to make a
"delete source" object after the call to close without success)

Is there something I am missing?

Regards.

PhistucK

unread,
Mar 3, 2012, 10:42:58 AM3/3/12
to Raul Parra, Chromium HTML5
Sounds like a weird bug. In my testing, it does not happen for me with the "error" event (I do not have a real EventSource sample at hand).
You can search crbug.com for an existing issue and star it. If you cannot find one, file a new issue at new.crbug.com.
Please, do not add a "+1" or "Me too" or "Confirmed" (or similar) comment. It just wastes the time of Chrome engineers and sends unnecessary e-mails to all of the people who starred the issue.

Thank you.




PhistucK




--
You received this message because you are subscribed to the Google Groups "Chromium HTML5" group.
To post to this group, send email to chromiu...@chromium.org.
To unsubscribe from this group, send email to chromium-html...@chromium.org.
For more options, visit this group at http://groups.google.com/a/chromium.org/group/chromium-html5/?hl=en.


Rick Waldron

unread,
Mar 3, 2012, 12:29:47 PM3/3/12
to PhistucK, Raul Parra, Chromium HTML5
Hey all - I haven't posted here before, usually just a reader...

You can "unregister" the handler by using removeEventListener


var source = new EventSource('stream.php'),
    handler = function(e) {
      console.log(e.data);
    };
    
source.addEventListener('message', handler, false);

// removal...

source.removeEventListener('message', handler);



Rick

PhistucK

unread,
Mar 3, 2012, 12:42:42 PM3/3/12
to Rick Waldron, Raul Parra, Chromium HTML5
Yes, but why would a new EventSource instance fire events on a previous (as well as the current) EventSource instance?
This is why it sounds like a bug.

PhistucK

Raul Parra

unread,
Mar 3, 2012, 1:13:08 PM3/3/12
to Chromium HTML5
Hi there.
Actually my testing was not as easy like I have showed in the example.
I have just tested an example exactly like the one I posted and it is
working (with chromium on ubuntu this time).
The testing which did not work was using jquerymobile.
Let's me reformat the jquery mobile example and I will post if I
reproduce the bug. But once I have seen that a regular html sample
works...I would like first to do more testing to avoid losing your
time with a not real bug.

Raul

On Mar 3, 6:42 pm, PhistucK <phist...@gmail.com> wrote:
> Yes, but why would a new EventSource instance fire events on a previous (as
> well as the current) EventSource instance?
> This is why it sounds like a bug.
>
> ☆*PhistucK*
>
>
>
>
>
>
>
> On Sat, Mar 3, 2012 at 19:29, Rick Waldron <waldron.r...@gmail.com> wrote:
> > Hey all - I haven't posted here before, usually just a reader...
>
> > You can "unregister" the handler by using removeEventListener
>
> > var source = new EventSource('stream.php'),
> >     handler = function(e) {
> >       console.log(e.data);
> >     };
>
> > source.addEventListener('message', handler, false);
>
> > // removal...
>
> > source.removeEventListener('message', handler);
>
> > Rick
>
> > On Sat, Mar 3, 2012 at 10:42 AM, PhistucK <phist...@gmail.com> wrote:
>
> >> Sounds like a weird bug. In my testing, it does not happen for me with
> >> the "error" event (I do not have a real EventSource sample at hand).
> >>  You can search crbug.com for an existing issue and star it. If you
> >> cannot find one, file a new issue at new.crbug.com.
> >> Please, do not add a "+1" or "Me too" or "Confirmed" (or similar)
> >> comment. It just wastes the time of Chrome engineers and sends unnecessary
> >> e-mails to all of the people who starred the issue.
>
> >> Thank you.
>
> >> ☆*PhistucK*
> >>> To post to this group, send email to chromium-ht...@chromium.org.
> >>> To unsubscribe from this group, send email to
> >>> chromium-html5+unsubscr...@chromium.org.
> >>> For more options, visit this group at
> >>>http://groups.google.com/a/chromium.org/group/chromium-html5/?hl=en.
>
> >>  --
> >> You received this message because you are subscribed to the Google Groups
> >> "Chromium HTML5" group.
> >> To post to this group, send email to chromium-ht...@chromium.org.
> >> To unsubscribe from this group, send email to
> >> chromium-html5+unsubscr...@chromium.org.

Rick Waldron

unread,
Mar 3, 2012, 1:56:55 PM3/3/12
to PhistucK, Raul Parra, Chromium HTML5
On Sat, Mar 3, 2012 at 12:42 PM, PhistucK <phis...@gmail.com> wrote:
Yes, but why would a new EventSource instance fire events on a previous (as well as the current) EventSource instance?
This is why it sounds like a bug.

That would indeed sound like and be a bug, but it's not reproducible with the code above or in any contrived tests I've tried.

Rick

Raul Parra

unread,
Mar 3, 2012, 2:58:24 PM3/3/12
to Chromium HTML5
Hi there
Finally i guess it is an jquery mobile error.
I show you the example, i have 2 html files and 1 php file:

index.html:

<html>
<head>
<title>TEST</title>
<meta name="viewport" content="width=device-width, initial-
scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0/
jquery.mobile-1.0.min.css" />
<script type="text/javascript" src="http://code.jquery.com/
jquery-1.6.4.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/
mobile/1.0/jquery.mobile-1.0.min.js"></script>
</head>
<body>

<div data-role="page" id="principal">

<div data-role="header">
<h1>TEST</h1>
</div><!-- /header -->

<div data-role="content">
<ul id="listado" data-role="listview" data-
inset="true" data-filter="true">
<li><a href="estacion.html?id=1">Elemento 1</
a></li>
<li><a href="estacion.html?id=2">Elemento 2</
a></li>
</ul>

</div><!-- /content -->

</div><!-- /page -->

</body>
</html>


estacion.html:

<html>
<head>
<title>Test</title>
<meta name="viewport" content="width=device-width, initial-
scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0/
jquery.mobile-1.0.min.css" />
<script type="text/javascript" src="http://code.jquery.com/
jquery-1.6.4.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/
mobile/1.0/jquery.mobile-1.0.min.js"></script>
</head>
<body>

<div data-role="page" id="linea">

<div data-role="header">
<h1 id="cabecera">TEST</h1>
</div><!-- /header -->

<div data-role="content">
<h3>Data</h3>
<p id="datos">No data</p>
<a href="index.html" data-
role="button">Volver</a>

</div><!-- /content -->
<script>
var evento;

$('#linea').live('pagehide',function (event, ui) {
console.log("closing sse");
evento.close();
delete evento;
});

$('#linea').live('pageinit',function (event1) {
var query = $(this).data("url").split("?")[1];
var id = query.replace("id=","");
console.log ("id whith value "+id);
$('#cabecera').html("TEST - "+id);
evento = new EventSource ("ejemplo.php?
id="+id);
evento.onmessage= function (e) {
console.log (e.data);
$('#datos').html(e.data);
};
});

</script>

</div><!-- /page -->
</body>
</html>

ejemplo.php:

<?php
header ("Content-Type: text/event-stream\n\n");
echo "retry: 10000".PHP_EOL;
echo "data: Tiempo: ".time().' Id: '.$_GET['id'].PHP_EOL;
echo PHP_EOL;
flush();

?>


In the above example i guess the error appears on jquery mobile call
to pageinit. It looks like everytime i access estacion.html the
pageinit add a new function to the listener. Even if you go back (with
volver button), the function registered with pageinit (which contains
the eventSource code) it is not unregistered...
In other words...everytime i click an item in the list going to the
second page, jquery mobile execute the pageinit event registering the
function one more time.

So my conclusion is that sse is working fine.

regards.



On Mar 3, 7:56 pm, Rick Waldron <waldron.r...@gmail.com> wrote:
> On Sat, Mar 3, 2012 at 12:42 PM, PhistucK <phist...@gmail.com> wrote:
> > Yes, but why would a new EventSource instance fire events on a previous
> > (as well as the current) EventSource instance?
> > This is why it sounds like a bug.
>
> That would indeed sound like and be a bug, but it's not reproducible with
> the code above or in any contrived tests I've tried.
>
> Rick
>
>
>
>
>
>
>
>
>
> > ☆*PhistucK*
>
> > On Sat, Mar 3, 2012 at 19:29, Rick Waldron <waldron.r...@gmail.com> wrote:
>
> >> Hey all - I haven't posted here before, usually just a reader...
>
> >> You can "unregister" the handler by using removeEventListener
>
> >> var source = new EventSource('stream.php'),
> >>     handler = function(e) {
> >>       console.log(e.data);
> >>     };
>
> >> source.addEventListener('message', handler, false);
>
> >> // removal...
>
> >> source.removeEventListener('message', handler);
>
> >> Rick
>
> >> On Sat, Mar 3, 2012 at 10:42 AM, PhistucK <phist...@gmail.com> wrote:
>
> >>> Sounds like a weird bug. In my testing, it does not happen for me with
> >>> the "error" event (I do not have a real EventSource sample at hand).
> >>>  You can search crbug.com for an existing issue and star it. If you
> >>> cannot find one, file a new issue at new.crbug.com.
> >>> Please, do not add a "+1" or "Me too" or "Confirmed" (or similar)
> >>> comment. It just wastes the time of Chrome engineers and sends unnecessary
> >>> e-mails to all of the people who starred the issue.
>
> >>> Thank you.
>
> >>> ☆*PhistucK*
> >>>> To post to this group, send email to chromium-ht...@chromium.org.
> >>>> To unsubscribe from this group, send email to
> >>>> chromium-html5+unsubscr...@chromium.org.
> >>>> For more options, visit this group at
> >>>>http://groups.google.com/a/chromium.org/group/chromium-html5/?hl=en.
>
> >>>  --
> >>> You received this message because you are subscribed to the Google
> >>> Groups "Chromium HTML5" group.
> >>> To post to this group, send email to chromium-ht...@chromium.org.
> >>> To unsubscribe from this group, send email to
> >>> chromium-html5+unsubscr...@chromium.org.
Reply all
Reply to author
Forward
0 new messages