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')
// the randomly generated session UUID
......@@ -17,14 +16,14 @@ var socket;
* @param annotationMapper - The local annotation store
* @param groups - The local groups store
* @param session - Provides access to read and update the session state
* @param settings - Application settings
*
* @return An angular-websocket wrapper around the socket.
*/
// @ngInject
function connect($websocket, annotationMapper, groups, session) {
function connect($websocket, annotationMapper, groups, session, settings) {
// Get the socket URL
var url = new URL('/ws', baseURI);
url.protocol = url.protocol.replace('http', 'ws');
var url = settings.websocketUrl;
// Close any existing socket
if (socket) {
......@@ -32,7 +31,7 @@ function connect($websocket, annotationMapper, groups, session) {
}
// Open the socket
socket = $websocket(url.href, [], {
socket = $websocket(url, [], {
reconnectIfNotNormalClose: true
});
socket.send({
......
......@@ -34,6 +34,7 @@ describe('streamer', function () {
var fakeAnnotationMapper;
var fakeGroups;
var fakeSession;
var fakeSettings;
var socket;
beforeEach(function () {
......@@ -52,11 +53,16 @@ describe('streamer', function () {
update: sinon.stub(),
};
fakeSettings = {
websocketUrl: 'ws://example.com/ws',
};
socket = streamer.connect(
fakeSocketConstructor,
fakeAnnotationMapper,
fakeGroups,
fakeSession
fakeSession,
fakeSettings
);
});
......@@ -70,7 +76,9 @@ describe('streamer', function () {
var oldSocket = socket;
var newSocket = streamer.connect(fakeSocketConstructor,
fakeAnnotationMapper,
fakeGroups
fakeGroups,
fakeSession,
fakeSettings
);
assert.ok(oldSocket.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