stomp: automated shared workers
authorgustavo <gu.martinm@gmail.com>
Sun, 22 May 2016 20:13:06 +0000 (22:13 +0200)
committergustavo <gu.martinm@gmail.com>
Sun, 22 May 2016 20:13:06 +0000 (22:13 +0200)
angularjs/stomp/src/stomp/app/shared-stomp/shared-stomp.html
angularjs/stomp/src/stomp/app/shared-stomp/shared-stomp.route.js
angularjs/stomp/src/stomp/app/shared-stomp/shared-worker.service.js
angularjs/stomp/src/stomp/index.html
angularjs/stomp/src/stomp/workers/shared.js

index 1d2c3ea..b0d92c6 100644 (file)
@@ -1,5 +1,5 @@
 <!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>
index 1e8c8ac..afce62c 100644 (file)
    * @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>
    *
    *
@@ -23,7 +21,7 @@
    * Router configuration for Shared Worker STOMP application.
    */
   /* @ngInject */
-  function route($stateProvider, $urlRouterProvider) {
+  function route($stateProvider) {
     var state = 'shared-stomp';
     var config = {
       abstract: false,
@@ -31,7 +29,6 @@
       templateUrl: 'app/shared-stomp/shared-stomp.html'
     };
 
-    $urlRouterProvider.otherwise(state);
     $stateProvider.state(state, config);
   }
 }());
index 1727b34..8ec3f6b 100644 (file)
     };
 
     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;
+  }
+
 }());
index b5609ad..ee42a42 100644 (file)
     <!-- AngularJS templates -->
     <!-- inject:templates:js -->
     <!-- endinject -->
+
+    <!-- Workers and shared workers -->
+    <!-- inject:workers:js -->
+    <!-- endinject -->
     <!-- endbuild -->
   </head>
 
index a56f571..85f7edb 100644 (file)
@@ -1,7 +1,7 @@
 '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;