Commit 68b55c2b authored by Eduardo's avatar Eduardo

Revert "Rename bridge to contain the frame target"

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