aboutsummaryrefslogtreecommitdiff
path: root/ext/mixed/js/comm.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-07-10 22:13:59 -0400
committerGitHub <noreply@github.com>2020-07-10 22:13:59 -0400
commit8389cd8ba27f328123fb73e72b24e69a4a6de2c1 (patch)
tree3d697dd1599415678dd708746cb2bdbcc43fd9cd /ext/mixed/js/comm.js
parent964f011409e824da52510c7de16a1c64ebae1787 (diff)
Popup crossFrame communication (#658)
* Add support for dynamic message handlers * Pass messages using crossFrame.invoke instead of contentWindow.postMessage * Set up async handlers * Simplify configure call and response
Diffstat (limited to 'ext/mixed/js/comm.js')
-rw-r--r--ext/mixed/js/comm.js33
1 files changed, 13 insertions, 20 deletions
diff --git a/ext/mixed/js/comm.js b/ext/mixed/js/comm.js
index 0d6b8695..182400e3 100644
--- a/ext/mixed/js/comm.js
+++ b/ext/mixed/js/comm.js
@@ -172,29 +172,22 @@ class CrossFrameAPIPort extends EventDispatcher {
return;
}
- const {handler, async} = messageHandler;
+ let {handler, async} = messageHandler;
this._sendAck(id);
- if (async) {
- this._invokeHandlerAsync(id, handler, params);
- } else {
- this._invokeHandler(id, handler, params);
- }
- }
-
- _invokeHandler(id, handler, params) {
- try {
- const result = handler(params);
- this._sendResult(id, result);
- } catch (error) {
- this._sendError(id, error);
- }
- }
-
- async _invokeHandlerAsync(id, handler, params) {
try {
- const result = await handler(params);
- this._sendResult(id, result);
+ let result = handler(params);
+ if (async === 'dynamic') {
+ ({async, result} = result);
+ }
+ if (async) {
+ result.then(
+ (result2) => this._sendResult(id, result2),
+ (error2) => this._sendError(id, error2)
+ );
+ } else {
+ this._sendResult(id, result);
+ }
} catch (error) {
this._sendError(id, error);
}