Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions packages/@webex/internal-plugin-device/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,21 @@ export default {
* @type {boolean}
*/
energyForecast: false,
},

/**
* installationId is used exclusively as web client for fraud prevention,
* and is aliased to as machineId by CA.
*
* @alias device.machineId
* @type {string}
*/
installationId: undefined,
/**
* debugFeatureTogglesKey
* The session storage key for debug feature toggles
* @type {string}
*/
debugFeatureTogglesKey: undefined,

/**
* installationId is used exclusively as web client for fraud prevention,
* and is aliased to as machineId by CA.
*
* @alias device.machineId
* @type {string}
*/
installationId: undefined,
},
};
43 changes: 43 additions & 0 deletions packages/@webex/internal-plugin-device/src/device.js
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,34 @@ const Device = WebexPlugin.extend({
return Promise.reject(new Error('device: failed to get the current websocket url'));
},

/**
* Get sanitized processed debug features from session storage
* these should be JSON encoded and in the form {feature1: true, feature2: false}
*
* @returns {Array<Object>} - Array of sanitized debug feature toggles
*/
getDebugFeatures() {
const sanitizedDebugFeatures = [];
if (this.config.debugFeatureTogglesKey) {
const debugFeaturesString = this.webex
.getWindow()
.sessionStorage.getItem(this.config.debugFeatureTogglesKey);
if (debugFeaturesString) {
const debugFeatures = JSON.parse(debugFeaturesString);
Object.entries(debugFeatures).forEach(([key, value]) => {
sanitizedDebugFeatures.push({
key,
val: value ? 'true' : 'false',
mutable: true,
lastModified: new Date().toISOString(),
});
});
}
}

return sanitizedDebugFeatures;
},

/**
* Process a successful device registration.
*
Expand Down Expand Up @@ -814,6 +842,14 @@ const Device = WebexPlugin.extend({
// When using the etag feature cache, user and entitlement features are still returned
this.features.user.reset(features.user);
this.features.entitlement.reset(features.entitlement);
} else if (this.config.debugFeatureTogglesKey && body?.features?.developer) {
// Add the debug feature toggles from session storage if available
try {
const debugFeatures = this.getDebugFeatures();
body.features.developer.push(...debugFeatures);
} catch (error) {
this.logger.error('Failed to parse debug feature toggles from session storage:', error);
}
}

// Assign the recieved DTO from **WDM** to this device.
Expand Down Expand Up @@ -946,6 +982,13 @@ const Device = WebexPlugin.extend({
// Prototype the extended class in order to preserve the parent member.
Reflect.apply(WebexPlugin.prototype.initialize, this, args);

this.listenToOnce(this.webex, 'change:config', () => {
// If debug feature toggles exist, clear the etag to ensure developer feature toggles are fetched
if (this.getDebugFeatures(this.config.debugFeatureTogglesKey).length > 0) {
this.set('etag', undefined);
}
});

// Initialize feature events and listeners.
FEATURE_COLLECTION_NAMES.forEach((collectionName) => {
this.features.on(`change:${collectionName}`, (model, value, options) => {
Expand Down
Loading
Loading