ping.html:
<html>
<head><title>PingPong SharedWorker</title></head>
<body>
<script type="text/javascript">
var worker = new SharedWorker("pong.js",'pingpong')
worker.onerror = function(err) {
document.write("[problem "+err+"]")
}
var count = 4;
worker.port.addEventListener('message', function(e) {
document.write("[data: "+e.data+"]")
if(--count)
worker.port.postMessage("ping")
},false)
worker.port.postMessage("ping")
</script>
begin<br/>
</body>
</html>
pong.js:
var messageHandler = function(event) {
event.ports[0].postMessage("pong")
};
onconnect = function(event) {
event.ports[0].onmessage = messageHandler
event.ports[0].postMessaage("connect")
};
Please help me use this incredible feature. I have no idea what I'm
doing wrong.
-rektide
--
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.
I tried your example in some older build of Chromium I had installed
(around 39330) and it was working nicely. However, the example from
Simon Peters on the WHATWG mailing list [1] was crashing - Chromium
showed an exception that a HTML SharedWorker crashed (in the yellow
notification bar below the bookmarks bar, nothing was alerted in the
console). That example differs from this one in basically one thing -
the shared worker is instantiated in two places (in a window context
and in a child iframe context). Notice, however, that the workers are
not given a name in Simon's example. Anyway - the Chromium version I
had installed crashed when a SharedWorker was created in both contexts
from the same JavaScript source, but worked fine when created in only
one context (no matter which one).
Hoping that it was a bug which had been resolved in never versions, I
did an update of Chromium and am now running 40217. However, now I
can't even get your example running (which, as I said, worked in the
older version). No exceptions are thrown, but from what I can tell -
Chromium breaks when instantiating a SharedWorker. Did anything
SharedWorker-wise change in the last ~800 versions that would cause
the example to stop working? Possibly helpful debugging info: windows
xp OS and I'm running the example from the local filesystem, they're
not online. Any ideas? :)
I think Workers and SharedWorkers are awesome and can't wait to see
all the cool things people will be doing with them. That's one reason
why I developed the pmrpc library [2] which is essentially a RPC
mechanism built on top of cross-document messaging APIs (for inter-
window/iframe communication) and web workers (for communication
between workers and windows/iframes). The library currently supports
regular Workers but has been waiting on a full SharedWorker
implementation in Chromium so I can test, debug and rejoice :).
Thanks,
Ivan
[1] http://www.mail-archive.com/wha...@lists.whatwg.org/msg20329.html
[2] http://code.google.com/p/pmrpc/
On Feb 23, 10:27 pm, Drew Wilson <atwil...@chromium.org> wrote:
> Following up on this - for #2, I believe that MessageEvent.target == the
> port. So your messageHandler() function could be:
>
> messageHandler = function(event) {
> event.target.postMessage("pong");
>
> }
>
> You don't have to use a closure.
>
> -atw
>
>
>
> On Tue, Feb 23, 2010 at 11:12 AM, Drew Wilson <atwil...@chromium.org> wrote:
> > First off, I'm really happy to see developers starting to use
> > SharedWorkers! I'm sorry you ran into problems, but the debugger support for
> > SharedWorkers is still a work in progress.
>
> > Anyhow, there are several issues, most of which are fairly
> > non-obvious/obscure, so don't feel bad for stubbing your toe on them - I've
> > run into every single one of these myself at one time or another:
>
> > 1) Your onconnect handler in pong.js has a typo:
>
> > event.ports[0].postMess*aa*ge("connect")
>
> > Note the double "a" in postMessaage(). It turns out that parse exceptions
> > generated within workers are not always logged to the developers console,
> > which makes errors like this really hard to track down. I've logged bug
> >http://code.google.com/p/chromium/issues/detail?id=36577to track this
> > *worker.port.start();*
> > log("begin");
> > </script>
>
> > </body>
> > </html>
>
> > pong.js:
>
> > onconnect = function(event) {
> > * event.ports[0].onmessage = function(e) {
> > event.ports[0].postMessage("pong"); };
> > * event.ports[0].*postMessage*("connect")
> > };
>
> > -atw
> >> 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<chromium-html5%2Bunsubscr...@chromium.org>
Everything seems to be working now, including the example from Simon.
Cheers,
Ivan
On Sat, Feb 27, 2010 at 17:59, Nico Weber <tha...@google.com> wrote:
> There was a recent change that disallows local html files to access other
> local files. That might be the cause. Check the googlechromereleasenotes
> blog for a flag that gives you the old behavior.
>
> Nico
>> Following up on this - for #2, I ...
>
>> On Tue, Feb 23, 2010 at 11:12 AM, Drew Wilson <atwil...@chromium.org>
>> wrote:
>> > First off, I'm re...
>
>> > event.ports[0].postMess*aa*ge("connect")
>
>>
>> > Note the double "a" in postMessaage(). It turns out that parse
>> > exceptions
>> > generated within...
>
>> >http://code.google.com/p/chromium/issues/detail?id=36577to track this
>
>> > issue.
>>
>> > 2) The messageHandler function won't work, because MessageEvent won't
>> > have
>> > even...
>
>> > On Mon, Feb 22, 2010 at 8:34 PM, rektide <rekt...@voodoowarez.com>
>> > wrote:
>>
>> >> I'm trying to u...
>
>> >> 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<chromium-html5%2Bunsubscr...@chromium.org>
>
>> >> .
>> >> For more options, visit this group at
To post to this group, send email to chromiu...@chromium.org.
To unsubscribe from this group, send email to chromium-html...@chromium.org.
Thanks anyway! Now I'm cheering for supporting logging of worker
exceptions in the console :).
Ivan