From c937a3ceaa53c650421d87232880c99d55986872 Mon Sep 17 00:00:00 2001 From: gustavo Date: Sun, 22 May 2016 22:13:06 +0200 Subject: [PATCH] stomp: automated shared workers --- .../src/stomp/app/shared-stomp/shared-stomp.html | 2 +- .../stomp/app/shared-stomp/shared-stomp.route.js | 5 +---- .../app/shared-stomp/shared-worker.service.js | 25 +++++++++++++++++----- angularjs/stomp/src/stomp/index.html | 4 ++++ angularjs/stomp/src/stomp/workers/shared.js | 4 ++-- 5 files changed, 28 insertions(+), 12 deletions(-) diff --git a/angularjs/stomp/src/stomp/app/shared-stomp/shared-stomp.html b/angularjs/stomp/src/stomp/app/shared-stomp/shared-stomp.html index 1d2c3ea..b0d92c6 100644 --- a/angularjs/stomp/src/stomp/app/shared-stomp/shared-stomp.html +++ b/angularjs/stomp/src/stomp/app/shared-stomp/shared-stomp.html @@ -1,5 +1,5 @@ -
+
1. Connect
diff --git a/angularjs/stomp/src/stomp/app/shared-stomp/shared-stomp.route.js b/angularjs/stomp/src/stomp/app/shared-stomp/shared-stomp.route.js index 1e8c8ac..afce62c 100644 --- a/angularjs/stomp/src/stomp/app/shared-stomp/shared-stomp.route.js +++ b/angularjs/stomp/src/stomp/app/shared-stomp/shared-stomp.route.js @@ -10,12 +10,10 @@ * @name app.shared-stomp.route * * @requires $stateProvider - * @requires $urlRouterProvider * *

*
* {@link http://angular-ui.github.io/ui-router/site/#/api/ui.router.state.$stateProvider $stateProvider}
- * {@link http://angular-ui.github.io/ui-router/site/#/api/ui.router.router.$urlRouterProvider $urlRouterProvider} *

* * @@ -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); } }()); diff --git a/angularjs/stomp/src/stomp/app/shared-stomp/shared-worker.service.js b/angularjs/stomp/src/stomp/app/shared-stomp/shared-worker.service.js index 1727b34..8ec3f6b 100644 --- a/angularjs/stomp/src/stomp/app/shared-stomp/shared-worker.service.js +++ b/angularjs/stomp/src/stomp/app/shared-stomp/shared-worker.service.js @@ -38,13 +38,12 @@ }; 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; } /** @@ -151,4 +150,20 @@ } } + 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; + } + }()); diff --git a/angularjs/stomp/src/stomp/index.html b/angularjs/stomp/src/stomp/index.html index b5609ad..ee42a42 100644 --- a/angularjs/stomp/src/stomp/index.html +++ b/angularjs/stomp/src/stomp/index.html @@ -72,6 +72,10 @@ + + + + diff --git a/angularjs/stomp/src/stomp/workers/shared.js b/angularjs/stomp/src/stomp/workers/shared.js index a56f571..85f7edb 100644 --- a/angularjs/stomp/src/stomp/workers/shared.js +++ b/angularjs/stomp/src/stomp/workers/shared.js @@ -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; -- 2.1.4