Code review re. dynamically loaded vapi-client-extra.js

Related commit:
- 87d0e456f1

Ensure that the code which depends on extending
`vapi-client.js` is ready to deal with
`vapi-client-extra.js` failing to load.
This commit is contained in:
Raymond Hill 2019-09-26 15:57:55 -04:00
parent e97ab16a54
commit efa4ff3bcf
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
3 changed files with 34 additions and 23 deletions

View File

@ -79,6 +79,7 @@ vAPI.messaging = {
port: null,
portTimer: null,
portTimerDelay: 10000,
extended: undefined,
extensions: [],
msgIdGenerator: 1,
pending: new Map(),
@ -219,6 +220,19 @@ vAPI.messaging = {
port.postMessage({ channel, msgId, msg });
return promise;
},
// Dynamically extend capabilities.
extend: function() {
if ( this.extended === undefined ) {
this.extended = vAPI.messaging.send('vapi', {
what: 'extendClient'
}).then(( ) => {
return vAPI instanceof Object && this.extensions.length !== 0;
}).catch(( ) => {
});
}
return this.extended;
},
};
vAPI.shutdown.add(( ) => {

View File

@ -303,11 +303,8 @@ const handlers = {
/******************************************************************************/
(async ( ) => {
// Dynamically add broadcast listening abilities.
if ( vAPI.broadcastListener instanceof Object === false ) {
await vAPI.messaging.send('vapi', { what: 'extendClient' });
}
vAPI.messaging.extend().then(extended => {
if ( extended !== true ) { return; }
const broadcastListener = msg => {
if ( msg.what === 'loggerDisabled' ) {
processTimer.clear();
@ -318,7 +315,7 @@ const handlers = {
}
};
vAPI.broadcastListener.add(broadcastListener);
})();
});
vAPI.domWatcher.addListener(handlers);

View File

@ -884,7 +884,7 @@ const onMessage = function(request) {
// Install DOM inspector widget
const bootstrap = async function(ev) {
const bootstrap = function(ev) {
if ( ev ) {
pickerRoot.removeEventListener(ev.type, bootstrap);
}
@ -934,9 +934,8 @@ const bootstrap = async function(ev) {
// Dynamically add direct connection abilities so that we can establish
// a direct, fast messaging connection to the logger.
if ( vAPI.MessagingConnection instanceof Function === false ) {
await vAPI.messaging.send('vapi', { what: 'extendClient' });
}
vAPI.messaging.extend().then(extended => {
if ( extended !== true ) { return; }
vAPI.MessagingConnection.connectTo('domInspector', 'loggerUI', msg => {
switch ( msg.what ) {
case 'connectionAccepted':
@ -951,6 +950,7 @@ const bootstrap = async function(ev) {
break;
}
});
});
};
pickerRoot = document.createElement('iframe');