Commit 8334e2f7 authored by Nick Stenning's avatar Nick Stenning

Use websocket URL provided in settings

Rather than constructing a URL from hard-coded defaults in the streamer
service, we pass the websocket URL from the backend in the settings
object and use this when opening the websocket.
parent c1d03a03
var baseURI = require('document-base-uri')
var uuid = require('node-uuid') var uuid = require('node-uuid')
// the randomly generated session UUID // the randomly generated session UUID
...@@ -17,14 +16,14 @@ var socket; ...@@ -17,14 +16,14 @@ var socket;
* @param annotationMapper - The local annotation store * @param annotationMapper - The local annotation store
* @param groups - The local groups store * @param groups - The local groups store
* @param session - Provides access to read and update the session state * @param session - Provides access to read and update the session state
* @param settings - Application settings
* *
* @return An angular-websocket wrapper around the socket. * @return An angular-websocket wrapper around the socket.
*/ */
// @ngInject // @ngInject
function connect($websocket, annotationMapper, groups, session) { function connect($websocket, annotationMapper, groups, session, settings) {
// Get the socket URL // Get the socket URL
var url = new URL('/ws', baseURI); var url = settings.websocketUrl;
url.protocol = url.protocol.replace('http', 'ws');
// Close any existing socket // Close any existing socket
if (socket) { if (socket) {
...@@ -32,7 +31,7 @@ function connect($websocket, annotationMapper, groups, session) { ...@@ -32,7 +31,7 @@ function connect($websocket, annotationMapper, groups, session) {
} }
// Open the socket // Open the socket
socket = $websocket(url.href, [], { socket = $websocket(url, [], {
reconnectIfNotNormalClose: true reconnectIfNotNormalClose: true
}); });
socket.send({ socket.send({
......
...@@ -34,6 +34,7 @@ describe('streamer', function () { ...@@ -34,6 +34,7 @@ describe('streamer', function () {
var fakeAnnotationMapper; var fakeAnnotationMapper;
var fakeGroups; var fakeGroups;
var fakeSession; var fakeSession;
var fakeSettings;
var socket; var socket;
beforeEach(function () { beforeEach(function () {
...@@ -52,11 +53,16 @@ describe('streamer', function () { ...@@ -52,11 +53,16 @@ describe('streamer', function () {
update: sinon.stub(), update: sinon.stub(),
}; };
fakeSettings = {
websocketUrl: 'ws://example.com/ws',
};
socket = streamer.connect( socket = streamer.connect(
fakeSocketConstructor, fakeSocketConstructor,
fakeAnnotationMapper, fakeAnnotationMapper,
fakeGroups, fakeGroups,
fakeSession fakeSession,
fakeSettings
); );
}); });
...@@ -70,7 +76,9 @@ describe('streamer', function () { ...@@ -70,7 +76,9 @@ describe('streamer', function () {
var oldSocket = socket; var oldSocket = socket;
var newSocket = streamer.connect(fakeSocketConstructor, var newSocket = streamer.connect(fakeSocketConstructor,
fakeAnnotationMapper, fakeAnnotationMapper,
fakeGroups fakeGroups,
fakeSession,
fakeSettings
); );
assert.ok(oldSocket.didClose); assert.ok(oldSocket.didClose);
assert.ok(!newSocket.didClose); assert.ok(!newSocket.didClose);
......
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