Commit 896086a4 authored by Lyza Danger Gardner's avatar Lyza Danger Gardner Committed by Lyza Gardner

Update internal reference naming and comments pertaining to config types

parent e46c106c
...@@ -13,13 +13,13 @@ import * as postMessageJsonRpc from '../util/postmessage-json-rpc'; ...@@ -13,13 +13,13 @@ import * as postMessageJsonRpc from '../util/postmessage-json-rpc';
*/ */
/** /**
* Returns the global embedder ancestor frame. * Ascend `levels` from `window_` to find the designated embedder frame.
* *
* @param {number} levels - Number of ancestors levels to ascend. * @param {number} levels - Number of ancestors levels to ascend
* @param {Window=} window_ * @param {Window=} window_
* @return {Window} * @return {Window}
*/ */
function getAncestorFrame(levels, window_ = window) { function getEmbedderFrame(levels, window_ = window) {
let ancestorWindow = window_; let ancestorWindow = window_;
for (let i = 0; i < levels; i++) { for (let i = 0; i < levels; i++) {
if (ancestorWindow === ancestorWindow.top) { if (ancestorWindow === ancestorWindow.top) {
...@@ -73,14 +73,14 @@ function fetchServiceGroups(configFromHost, rpcSettings) { ...@@ -73,14 +73,14 @@ function fetchServiceGroups(configFromHost, rpcSettings) {
} }
/** /**
* Derive RPC settings from the provided `AnnotatorConfigFromHost`, if any are present. * Derive RPC settings from the provided `ConfigFromAnnotator`, if any are present.
* *
* @param {ConfigFromAnnotator} configFromHost * @param {ConfigFromAnnotator} configFromAnnotator
* @param {Window} window_ * @param {Window} window_
* @return {import('../../types/config').RPCSettings|null} * @return {import('../../types/config').RPCSettings|null}
*/ */
function buildRPCSettings(configFromHost, window_) { function buildRPCSettings(configFromAnnotator, window_) {
const rpcConfig = configFromHost.requestConfigFromFrame; const rpcConfig = configFromAnnotator.requestConfigFromFrame;
if (!rpcConfig) { if (!rpcConfig) {
return null; return null;
} else if ( } else if (
...@@ -92,21 +92,20 @@ function buildRPCSettings(configFromHost, window_) { ...@@ -92,21 +92,20 @@ function buildRPCSettings(configFromHost, window_) {
); );
} }
return { return {
targetFrame: getAncestorFrame(rpcConfig.ancestorLevel, window_), targetFrame: getEmbedderFrame(rpcConfig.ancestorLevel, window_),
origin: rpcConfig.origin, origin: rpcConfig.origin,
}; };
} }
/** /**
* Retrieve ConfigFromHost to use for settings from the ancestor frame indicated * Retrieve host configuration from embedder frame
* in `rpcSettings`
* *
* @param {ConfigFromAnnotator} hostConfigFromURL * @param {ConfigFromAnnotator} configFromAnnotator
* @param {RPCSettings} rpcSettings * @param {RPCSettings} rpcSettings
* @return {Promise<ConfigFromEmbedder>} * @return {Promise<ConfigFromEmbedder>}
*/ */
async function getEmbedderConfig(hostConfigFromURL, rpcSettings) { async function getEmbedderConfig(configFromAnnotator, rpcSettings) {
const hostConfigFromFrame = await postMessageJsonRpc.call( const configFromEmbedder = await postMessageJsonRpc.call(
rpcSettings.targetFrame, rpcSettings.targetFrame,
rpcSettings.origin, rpcSettings.origin,
'requestConfig', 'requestConfig',
...@@ -114,49 +113,47 @@ async function getEmbedderConfig(hostConfigFromURL, rpcSettings) { ...@@ -114,49 +113,47 @@ async function getEmbedderConfig(hostConfigFromURL, rpcSettings) {
3000 3000
); );
// In the case where the appropriate `ConfigFromHost` is sourced from another // In cases where host configuration is requested from the embedder frame
// frame by RPC, the original `ConfigFromHost` (`hostConfigFromURL`) is // (`ConfigFromEmbedder`), `ConfigFromAnnotator` values are discarded.
// discarded.
// //
// The `group` property, however, is currently not available in the remote // The `group` property, however, is currently not provided by
// `ConfigFromHost` and needs to be restored. This property is used by the // `ConfigFromEmbedder` and needs to be restored. This property is used by the
// Notebook. // Notebook.
// TODO: Notebook group should be set by alternate means
return { return {
...hostConfigFromFrame, ...configFromEmbedder,
...(hostConfigFromURL.group ? { group: hostConfigFromURL.group } : {}), ...(configFromAnnotator.group ? { group: configFromAnnotator.group } : {}),
}; };
} }
/** /**
* Build a `SidebarSettings` object by merging the provided `ConfigFromSidebar` * Build a `SidebarSettings` object by merging the provided `ConfigFromSidebar`
* with `ConfigFromHost` from an appropriate source. * with host configuration (`ConfigFromAnnotator` OR `ConfigFromEmbedder`).
* *
* `ConfigFromHost` may come from either: * @see {ConfigFromAnnotator}
* - The URL framgent of the sidebar's iframe src, written by the annotator * @see {ConfigFromEmbedder}
* when creating the sidebar's iframe, OR * @see {ConfigFromHost}
* - By sending an RPC request for host configuration to a designated ancestor
* frame (This is used in the LMS context)
* *
* @param {ConfigFromSidebar} configFromSidebar * @param {ConfigFromSidebar} configFromSidebar
* @param {Window} window_ - Test seam * @param {Window} window_ - Test seam
* @return {Promise<SidebarSettings>} - The merged settings * @return {Promise<SidebarSettings>} - The merged settings
*/ */
export async function buildSettings(configFromSidebar, window_ = window) { export async function buildSettings(configFromSidebar, window_ = window) {
const annotatorConfigFromHost = hostPageConfig(window); const configFromAnnotator = hostPageConfig(window);
const rpcSettings = buildRPCSettings(annotatorConfigFromHost, window_); const rpcSettings = buildRPCSettings(configFromAnnotator, window_);
let configFromHost; let configFromHost;
if (rpcSettings) { if (rpcSettings) {
// The presence of RPCSettings indicates that we should // The presence of RPCSettings indicates that we should
// source the ConfigFromHost from another frame, and potentially load // source the ConfigFromHost from another frame, and potentially load
// the correct groups asynchronously as well. // the correct groups asynchronously as well.
const hostConfigFromFrame = await getEmbedderConfig( const configFromEmbedder = await getEmbedderConfig(
annotatorConfigFromHost, configFromAnnotator,
rpcSettings rpcSettings
); );
configFromHost = fetchServiceGroups(hostConfigFromFrame, rpcSettings); configFromHost = fetchServiceGroups(configFromEmbedder, rpcSettings);
} else { } else {
configFromHost = annotatorConfigFromHost; configFromHost = configFromAnnotator;
} }
/** @type {SidebarSettings} */ /** @type {SidebarSettings} */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment