An active constructor is called and only afterwards the event listeners are attached. Technically, it is possible for a message to arrive before the corresponding listener is attached.
One way to avoid this is to specify that the user agent should buffer incoming events until the event listener is attached. However, it seems advisable to avoid this altogether and redesign the API as in the following sudo-code example:
let pc = new LP2PConnection( peerA );
pc.addEventListener("message", function (event) { /* ... */ });
await pc.start({ /* ... */ });
In the current API design, many objects are constructed as follows:
An active constructor is called and only afterwards the event listeners are attached. Technically, it is possible for a message to arrive before the corresponding listener is attached.
One way to avoid this is to specify that the user agent should buffer incoming events until the event listener is attached. However, it seems advisable to avoid this altogether and redesign the API as in the following sudo-code example:
Examples of related APIs that do this include the Presentation, ORTC and p2p-webtransport APIs.