Support for async request-respond through post-message#2
Conversation
|
reqres seams non-intuitive namespace, maybe choose a better name (transport/messageBus etc?) - or remove the namespace. Can the ext plugin pass anything else than window to the request function? I see no reason for this first arg. |
|
Naming it a message bus is a bit overkill imo, in adherence to the messaging design pattern. The pluginAPI itself is a simple pub/sub system. This service however is more specialized and conforms to the request/response pattern (with an asynchronous response handler). I think that should be expressed in the API name. But yes, reqres might not be very intuitive. Maybe I shouldn't have abstracted out these two functions, but instead have them directly on the pluginApi. What do you think? request needs a window reference, because it depends on xde, which uses for post messaging. |
// host-plugin
pluginApi.respondToPostmessage('endPoint', function(payload, done) {
//data
done(Math.random());
});
// ext-plugin
pluginApi.postMessage('endPoint', {'foo': bar}, function(err, result) {
// error is e.g. reference error
// do something with the value that was passed down through evt.data
}, window); |
There are cases when banners need to communicate with the parent, and be notified when there is a response.
Example use: