[whatwg] reply() extension to postMessage()

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