daepark / postmessage

window postmessage plugin for cross-window messaging
http://postmessage.freebaseapps.com
178 stars 55 forks source link

Messages without type not handled #12

Open goosewobbler opened 12 years ago

goosewobbler commented 12 years ago

If the message has no type then pm exits with a warning; could there be a better way to handle these messages?

It's not a problem for my own code, but this makes communicating with certain iframes (e.g. Vimeo universal embed) impossible using the plugin.

daepark commented 12 years ago

Is PM intercepting the postmessages sent by other means? Or are you actually invoking PM without a message type? How would you like it to be handled?

goosewobbler commented 12 years ago

PM is receiving messages sent by other means, so I am using it to send a message to my Vimeo embed frame but the response is sent without use of the plugin so is missing the type attribute. I don't mind the warning but I don't think the message should be discarded if there is no type.

daepark commented 12 years ago

Not quite sure how PM should handle messages that are not a request/response of PM because

  1. the message sent by other means are not JSON
  2. PM doesn't know how to dispatch the response. Consider if PM originally sends 2 messages of different types to your embedded iframe and your iframe does a native postMessage back (without PM). How should PM handle this? Which of the two original message callbacks should handle the message?

So if I understand you correctly, maybe you can use the native postMessage bindings to handle native postMessages from your embedded iframe.

goosewobbler commented 12 years ago

Ok, so:

  1. If a received mesage is not in JSON format then it would make a lot of sense to display an error and give up, but the messages in this case are JSON. See the "Events" section on http://vimeo.com/api/docs/player-js.
  2. I see your point here, although it could be sensible to handle the message (with warning) if there is only one callback, and error out if there is more than one?

I have used native postMessage to handle this case, but I just thought that the PM handling of the case could be improved for increasing the scope of usage of the plugin (which is great, by the way).