<!DOCTYPE html>
-<div class="container" ng-controller="ExampleController as vm">
+<div class="container" ng-controller="SharedStompController as vm">
<div>
<span>1. Connect</span><br>
<button ng-click="vm.connect()">Connect to Endpoint</button>
* @name app.shared-stomp.route
*
* @requires $stateProvider
- * @requires $urlRouterProvider
*
* <p>
* <br>
* {@link http://angular-ui.github.io/ui-router/site/#/api/ui.router.state.$stateProvider $stateProvider} <br>
- * {@link http://angular-ui.github.io/ui-router/site/#/api/ui.router.router.$urlRouterProvider $urlRouterProvider}
* </p>
*
*
* Router configuration for Shared Worker STOMP application.
*/
/* @ngInject */
- function route($stateProvider, $urlRouterProvider) {
+ function route($stateProvider) {
var state = 'shared-stomp';
var config = {
abstract: false,
templateUrl: 'app/shared-stomp/shared-stomp.html'
};
- $urlRouterProvider.otherwise(state);
$stateProvider.state(state, config);
}
}());
};
function init() {
- if (!!$window.SharedWorker) {
- var sharedWorker = new $window.SharedWorker('scripts/workers/shared.js');
- _messagePort = sharedWorker.port;
- _messagePort.onmessage = onMessage;
- } else {
+ if (!$window.SharedWorker) {
throw new Error('Shared Web Workers not supported. Try with a modern browser');
}
+ var sharedWorker = makeSharedWorker($window);
+ _messagePort = sharedWorker.port;
+ _messagePort.onmessage = onMessage;
}
/**
}
}
+ function makeSharedWorker($window) {
+ 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));
+ } else {
+ //Fallback! Can be used for debugging purposes.
+ sharedWorker = new $window.SharedWorker('scripts/workers/shared.js');
+ }
+
+ return sharedWorker;
+ }
+
}());
<!-- AngularJS templates -->
<!-- inject:templates:js -->
<!-- endinject -->
+
+ <!-- Workers and shared workers -->
+ <!-- inject:workers:js -->
+ <!-- endinject -->
<!-- endbuild -->
</head>
'use strict';
-importScripts('/bower_components/sockjs/sockjs.js');
-importScripts('/bower_components/stomp-websocket/lib/stomp.min.js');
+importScripts('sockjs.js');
+importScripts('stomp.min.js');
var messagePorts = [];
var client;