Commit 520b5c50 authored by Eduardo Sanz García's avatar Eduardo Sanz García Committed by Eduardo

Rename bridge to contain the frame target

In future PR, `Guest` will contain two bridges (like `FrameSync`).
Naming them by the destination frame will help identify the purpose of
it.

It seems that the convention for this `Bridge`s is to contain the word
`RPC` to indicate that it is a remote (inter-frame) procedure.
parent 2957944d
......@@ -28,11 +28,11 @@
export class AnnotationSync {
/**
* @param {EventBus} eventBus - Event bus for communicating with the annotator code (eg. the Guest)
* @param {SidebarBridge} bridge - Channel for communicating with the sidebar
* @param {SidebarBridge} sidebarRPC - Channel for communicating with the sidebar
*/
constructor(eventBus, bridge) {
constructor(eventBus, sidebarRPC) {
this._emitter = eventBus.createEmitter();
this._sidebar = bridge;
this._sidebarRPC = sidebarRPC;
/**
* Mapping from annotation tags to annotation objects for annotations which
......@@ -45,7 +45,7 @@ export class AnnotationSync {
this.destroyed = false;
// Relay events from the sidebar to the rest of the annotator.
this._sidebar.on('deleteAnnotation', (body, callback) => {
this._sidebarRPC.on('deleteAnnotation', (body, callback) => {
if (this.destroyed) {
callback(null);
return;
......@@ -57,7 +57,7 @@ export class AnnotationSync {
callback(null);
});
this._sidebar.on('loadAnnotations', (bodies, callback) => {
this._sidebarRPC.on('loadAnnotations', (bodies, callback) => {
if (this.destroyed) {
callback(null);
return;
......@@ -72,7 +72,7 @@ export class AnnotationSync {
if (annotation.$tag) {
return;
}
this._sidebar.call('createAnnotation', this._format(annotation));
this._sidebarRPC.call('createAnnotation', this._format(annotation));
});
}
......@@ -89,7 +89,7 @@ export class AnnotationSync {
return;
}
this._sidebar.call(
this._sidebarRPC.call(
'syncAnchoringStatus',
annotations.map(ann => this._format(ann))
);
......
......@@ -177,12 +177,12 @@ export default class Guest {
*
* @type {Bridge<GuestToSidebarEvent,SidebarToGuestEvent>}
*/
this._bridge = new Bridge();
this._sidebarRPC = new Bridge();
this._connectSidebarEvents();
// Set up listeners for when the sidebar asks us to add or remove annotations
// in this frame.
this._annotationSync = new AnnotationSync(eventBus, this._bridge);
this._annotationSync = new AnnotationSync(eventBus, this._sidebarRPC);
this._connectAnnotationSync();
// Set up automatic and integration-triggered injection of client into
......@@ -229,7 +229,7 @@ export default class Guest {
// Don't hide the sidebar if the event comes from an element that contains a highlight
return;
}
this._bridge.call('closeSidebar');
this._sidebarRPC.call('closeSidebar');
};
this._listeners.add(this.element, 'mouseup', event => {
......@@ -318,7 +318,7 @@ export default class Guest {
async _connectSidebarEvents() {
// Handlers for events sent when user hovers or clicks on an annotation card
// in the sidebar.
this._bridge.on('focusAnnotations', (tags = []) => {
this._sidebarRPC.on('focusAnnotations', (tags = []) => {
this._focusedAnnotations.clear();
tags.forEach(tag => this._focusedAnnotations.add(tag));
......@@ -330,7 +330,7 @@ export default class Guest {
}
});
this._bridge.on('scrollToAnnotation', tag => {
this._sidebarRPC.on('scrollToAnnotation', tag => {
const anchor = this.anchors.find(a => a.annotation.$tag === tag);
if (!anchor?.highlights) {
return;
......@@ -356,21 +356,21 @@ export default class Guest {
});
// Handler for when sidebar requests metadata for the current document
this._bridge.on('getDocumentInfo', cb => {
this._sidebarRPC.on('getDocumentInfo', cb => {
this.getDocumentInfo()
.then(info => cb(null, info))
.catch(reason => cb(reason));
});
// Handler for controls on the sidebar
this._bridge.on('setHighlightsVisible', showHighlights => {
this._sidebarRPC.on('setHighlightsVisible', showHighlights => {
this.setHighlightsVisible(showHighlights);
});
// Discover and connect to the sidebar frame. All RPC events must be
// registered before creating the channel.
const sidebarPort = await this._portFinder.discover('sidebar');
this._bridge.createChannel(sidebarPort);
this._sidebarRPC.createChannel(sidebarPort);
}
destroy() {
......@@ -387,7 +387,7 @@ export default class Guest {
this._integration.destroy();
this._emitter.destroy();
this._annotationSync.destroy();
this._bridge.destroy();
this._sidebarRPC.destroy();
}
/**
......@@ -585,7 +585,7 @@ export default class Guest {
*/
_focusAnnotations(annotations) {
const tags = annotations.map(a => a.$tag);
this._bridge.call('focusAnnotations', tags);
this._sidebarRPC.call('focusAnnotations', tags);
}
/**
......@@ -636,11 +636,11 @@ export default class Guest {
selectAnnotations(annotations, toggle = false) {
const tags = annotations.map(a => a.$tag);
if (toggle) {
this._bridge.call('toggleAnnotationSelection', tags);
this._sidebarRPC.call('toggleAnnotationSelection', tags);
} else {
this._bridge.call('showAnnotations', tags);
this._sidebarRPC.call('showAnnotations', tags);
}
this._bridge.call('openSidebar');
this._sidebarRPC.call('openSidebar');
}
/**
......
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