W3C home > Mailing lists > Public > whatwg@whatwg.org > February 2008

[whatwg] reply() extension to postMessage()

From: Anne van Kesteren <annevk@opera.com>
Date: Thu, 14 Feb 2008 17:58:11 +0100
Message-ID: <op.t6ixe9i564w2qv@annevk-t60.oslo.opera.com>
On Thu, 14 Feb 2008 17:30:15 +0100, Aaron Boodman <aa at google.com> wrote:
> If we're going to add reply, I would like to easily be able to get
> replies to a specific message. So extend postMessage to accept a
> callback, and then either have reply() call this callback. Like this:
>
> // sender:
> someWindow.postMessage("hello!", function(response) {
>   alert("got response: " + response);
> });
>
> // receiver
> window.addEventListener("message", function(e) {
>   alert("got message: " + e.message);
>   e.reply("good day");
> });

You really want reply() to have that callback too (for longer  
conversations) and at that point it starts getting icky.

I came up with another idea to address the issue you mention. We let  
postMessage() return a UUID and give MessageEvent an "id" attribute. When  
postMessage() is invoked a UUID is generated and returned. This same UUID  
is set on the event that is dispatched. When reply is invoked on that  
event object it creates an event that again has the same UUID. Both  
parties can have multiple conversations that way by checking the UUID of  
the message.


-- 
Anne van Kesteren
<http://annevankesteren.nl/>
<http://www.opera.com/>
Received on Thursday, 14 February 2008 08:58:11 UTC

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 16:59:00 UTC