Commit 7919db62 authored by Robert Knight's avatar Robert Knight Committed by Nick Stenning

Do not try to setup communication to host frame on stream (#138)

This fixes an error when trying to load the Hypothesis client on the
stream or standalone annotation pages, caused by both the stream app and
the sidebar app trying to set up a 'Discovery' server for annotation
'guests' to connect to.

With this change, only the sidebar app will set up a Discovery server
and hence it is now possible to annotate the stream and standalone
annotation pages.
parent da9b4c6e
...@@ -24,7 +24,7 @@ function authStateFromUserID(userid) { ...@@ -24,7 +24,7 @@ function authStateFromUserID(userid) {
// @ngInject // @ngInject
module.exports = function AppController( module.exports = function AppController(
$controller, $document, $location, $rootScope, $route, $scope, $controller, $document, $location, $rootScope, $route, $scope,
$window, annotationUI, auth, drafts, features, groups, $window, annotationUI, auth, drafts, features, frameSync, groups,
serviceUrl, session, settings, streamer serviceUrl, session, settings, streamer
) { ) {
$controller('AnnotationUIController', {$scope: $scope}); $controller('AnnotationUIController', {$scope: $scope});
...@@ -51,6 +51,9 @@ module.exports = function AppController( ...@@ -51,6 +51,9 @@ module.exports = function AppController(
// Check to see if we're in the sidebar, or on a standalone page such as // Check to see if we're in the sidebar, or on a standalone page such as
// the stream page or an individual annotation page. // the stream page or an individual annotation page.
$scope.isSidebar = $window.top !== $window; $scope.isSidebar = $window.top !== $window;
if ($scope.isSidebar) {
frameSync.connect();
}
$scope.serviceUrl = serviceUrl; $scope.serviceUrl = serviceUrl;
......
...@@ -82,14 +82,6 @@ function configureRoutes($routeProvider) { ...@@ -82,14 +82,6 @@ function configureRoutes($routeProvider) {
}); });
} }
// @ngInject
function setupFrameSync(frameSync) {
// Setup the connection to the frame hosting the sidebar app.
// This should only be done if this is the sidebar app, not the stream or
// standalone annotation pages.
return frameSync.connect();
}
// @ngInject // @ngInject
function configureHttp($httpProvider, jwtInterceptorProvider) { function configureHttp($httpProvider, jwtInterceptorProvider) {
// Use the Pyramid XSRF header name // Use the Pyramid XSRF header name
...@@ -211,7 +203,6 @@ module.exports = angular.module('h', [ ...@@ -211,7 +203,6 @@ module.exports = angular.module('h', [
.config(configureLocation) .config(configureLocation)
.config(configureRoutes) .config(configureRoutes)
.run(setupFrameSync)
.run(setupHttp); .run(setupHttp);
processAppOpts(); processAppOpts();
......
...@@ -15,6 +15,7 @@ describe('AppController', function () { ...@@ -15,6 +15,7 @@ describe('AppController', function () {
var fakeAuth = null; var fakeAuth = null;
var fakeDrafts = null; var fakeDrafts = null;
var fakeFeatures = null; var fakeFeatures = null;
var fakeFrameSync = null;
var fakeLocation = null; var fakeLocation = null;
var fakeParams = null; var fakeParams = null;
var fakeSession = null; var fakeSession = null;
...@@ -76,6 +77,10 @@ describe('AppController', function () { ...@@ -76,6 +77,10 @@ describe('AppController', function () {
flagEnabled: sandbox.stub().returns(false), flagEnabled: sandbox.stub().returns(false),
}; };
fakeFrameSync = {
connect: sandbox.spy(),
};
fakeLocation = { fakeLocation = {
search: sandbox.stub().returns({}), search: sandbox.stub().returns({}),
}; };
...@@ -106,6 +111,7 @@ describe('AppController', function () { ...@@ -106,6 +111,7 @@ describe('AppController', function () {
$provide.value('auth', fakeAuth); $provide.value('auth', fakeAuth);
$provide.value('drafts', fakeDrafts); $provide.value('drafts', fakeDrafts);
$provide.value('features', fakeFeatures); $provide.value('features', fakeFeatures);
$provide.value('frameSync', fakeFrameSync);
$provide.value('serviceUrl', fakeServiceUrl); $provide.value('serviceUrl', fakeServiceUrl);
$provide.value('session', fakeSession); $provide.value('session', fakeSession);
$provide.value('settings', fakeSettings); $provide.value('settings', fakeSettings);
...@@ -142,6 +148,18 @@ describe('AppController', function () { ...@@ -142,6 +148,18 @@ describe('AppController', function () {
}); });
}); });
it('connects to host frame in the sidebar app', function () {
fakeWindow.top = {};
createController();
assert.called(fakeFrameSync.connect);
});
it('does not connect to the host frame in the stream', function () {
fakeWindow.top = fakeWindow;
createController();
assert.notCalled(fakeFrameSync.connect);
});
it('auth.status is "unknown" on startup', function () { it('auth.status is "unknown" on startup', function () {
createController(); createController();
assert.equal($scope.auth.status, 'unknown'); assert.equal($scope.auth.status, 'unknown');
......
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