From 8389cd8ba27f328123fb73e72b24e69a4a6de2c1 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Fri, 10 Jul 2020 22:13:59 -0400 Subject: 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 --- ext/mixed/js/comm.js | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) (limited to 'ext/mixed/js') 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); } -- cgit v1.2.3