* @name app.shared-stomp.sharedWorker
*
* @requires $window
+ * @requires $location
*
* <p>
* <br>
* {@link https://docs.angularjs.org/api/ng/service/$window $window} <br>
+ * {@link https://docs.angularjs.org/api/ng/service/$location $location}
* </p>
*
* @description
* sharedWorker service.
*/
/* @ngInject */
- function sharedWorker($window) {
+ function sharedWorker($window, $location) {
var _messagePort;
var _connectSuccessCallback;
var _connectErrorCallback;
var message = {
command: 'connect',
url: url,
+ urlImports: $location.protocol() + '://' + $location.host(),
connectHeaders: connectHeaders
};
}
function makeSharedWorker($window) {
+ var sharedWorkerName = 'shared-stomp';
var sharedWorker;
//Make sure blob and create object URL are supported
if (workers && $window.Blob && $window.URL.createObjectURL) {
//worker's string was loaded successfully
var blob = new Blob([workers['shared.js']], {type: 'application/javascript'});
- sharedWorker = new $window.SharedWorker($window.URL.createObjectURL(blob));
+ sharedWorker = new $window.SharedWorker($window.URL.createObjectURL(blob), sharedWorkerName);
} else {
//Fallback! Can be used for debugging purposes.
- sharedWorker = new $window.SharedWorker('scripts/workers/shared.js');
+ sharedWorker = new $window.SharedWorker('scripts/workers/shared.js', sharedWorkerName);
}
return sharedWorker;
'use strict';
-importScripts('sockjs.js');
-importScripts('stomp.min.js');
-
var messagePorts = [];
var client;
var subscription;
function callCommand(data) {
switch(data.command) {
case 'connect':
+ doImports(data.urlImports);
connect(data.url, data.connectHeaders);
break;
case 'subscribe':
command: 'disconnectCallback'
});
}
+
+function doImports(url) {
+ importScripts(url + '/stomp/js/sockjs.js');
+ importScripts(url + '/stomp/js/stomp.min.js');
+}