kriskowal/q-comm — pull request #7 by johnjbarton (2012-02-07 23:04:51+00:00)
Title: Proposed fix for issue 5

First, I don't understand this pull UI in github. I want to send you just one patch, not 14 commits...

Second, this is imperfect because the original code had the addEventListener/postMessage bindings separate, but I need them together as you will see. It might be better to make the various adaptations into separate functions. Plus I only understand the iframe case...

Theory: Two windows want to communicate with addEventListener/postMessage. We don't know which one will start. So we issue 'introduction' sequence, an addEventListener followed immediately on the same turn by postMessage. If we are first up, the postMessage will be dropped; if not then we will trigger the event listener in the first up. The event listeners switch over to the regular listener cycle.