stomp shared worker improvements
authorgustavo <gu.martinm@gmail.com>
Sun, 28 Aug 2016 23:00:18 +0000 (01:00 +0200)
committergustavo <gu.martinm@gmail.com>
Sun, 28 Aug 2016 23:00:18 +0000 (01:00 +0200)
angularjs/stomp/src/stomp/app/shared-stomp/shared-stomp.controller.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 1f7ee75..7bc47f7 100644 (file)
       alert('got connection');
     }
 
-    function connectErrorCallback(jsonConnectErrorAsString) {
+    function connectErrorCallback(error) {
       // display the error's message header:
-      alert('error call back: \n' + jsonConnectErrorAsString);
+      alert('error call back: \n' + JSON.stringify(error, null, 4));
     }
 
-    function subscribeCallback(jsonMessageAsString) {
+    function subscribeCallback(message) {
       // called when the client receives a STOMP message from the server
-      alert('subscribe message: \n' + jsonMessageAsString);
+      alert('subscribe message: \n' + JSON.stringify(message, null, 4));
     }
 
     function disconnectCallback() {
index d6f0c11..fdc0988 100644 (file)
@@ -72,7 +72,7 @@
 
       _connectSuccessCallback = connectSuccessCallback;
       _connectErrorCallback = connectErrorCallback;
-      _messagePort.postMessage(message);
+      doPostMessage(message);
     }
 
     function subscribe(clientDestination, subscribeCallback, subscribeHeaders) {
@@ -83,7 +83,7 @@
       };
 
       _subscribeCallback = subscribeCallback;
-      _messagePort.postMessage(message);
+      doPostMessage(message);
     }
 
     function unSubscribe() {
@@ -91,7 +91,7 @@
         command: 'unSubscribe'
       };
 
-      _messagePort.postMessage(message);
+      doPostMessage(message);
     }
 
     function send(serverDestination, sendHeaders, payload) {
         payload: payload
       };
 
-      _messagePort.postMessage(message);
+      doPostMessage(message);
     }
 
     function disconnect(disconnectCallback) {
       };
 
       _disconnectCallback = disconnectCallback;
-      _messagePort.postMessage(message);
+      doPostMessage(message);
     }
 
+    function doPostMessage(message) {
+      _messagePort.postMessage(JSON.stringify(message, null, 4));
+    }
 
     function onMessage(event) {
       if (event.data.error) {
         // Error
       } else {
-        callBack(event.data);
+        callBack(JSON.parse(event.data));
       }
     }
     // var send {
     // }
     // var result {
     //     command:
-    //     connectError:
+    //     error:
     //     message:
     // };
     function callBack(data) {
-
       switch(data.command) {
         case 'connectSuccessCallback':
           _connectSuccessCallback();
           break;
         case 'connectErrorCallback':
-          _connectErrorCallback(data.jsonConnectErrorAsString);
+          _connectErrorCallback(data.error);
           break;
         case 'subscribeCallback':
-          _subscribeCallback(data.jsonMessageAsString);
+          _subscribeCallback(data.message);
           break;
         case 'disconnectCallback':
           _disconnectCallback();
index fdd6587..185172d 100644 (file)
     <!-- Custom JavaScript -->
     <!-- build:js(.) js/app.min.js -->
     <!-- inject:js -->
+    <script src="/src/stomp/app/widgets/widgets.module.js"></script>
+    <script src="/src/stomp/app/widgets/auto-height.directive.js"></script>
     <script src="/src/stomp/app/shared-stomp/shared-stomp.module.js"></script>
     <script src="/src/stomp/app/shared-stomp/shared-worker.service.js"></script>
     <script src="/src/stomp/app/shared-stomp/shared-stomp.route.js"></script>
     <script src="/src/stomp/app/shared-stomp/shared-stomp.controller.js"></script>
-    <script src="/src/stomp/app/widgets/widgets.module.js"></script>
-    <script src="/src/stomp/app/widgets/auto-height.directive.js"></script>
     <script src="/src/stomp/app/example/example.module.js"></script>
     <script src="/src/stomp/app/example/example.route.js"></script>
     <script src="/src/stomp/app/example/example.controller.js"></script>
index a5c96b0..fba6a8a 100644 (file)
@@ -34,12 +34,13 @@ self.onerror = function (msg, url, lineNo, columnNo, error) {
 };
 
 function onMessage(event) {
-  callCommand(event.data);
+  callCommand(JSON.parse(event.data));
 }
 
 function postMessage(message) {
+  var jsonMessageAsString = JSON.stringify(message, null, 4);
   messagePorts.forEach(function (messagePort) {
-    messagePort.postMessage(message);
+    messagePort.postMessage(jsonMessageAsString);
   });
 }
 
@@ -115,18 +116,16 @@ function connectSuccessCallback() {
 
 function connectErrorCallback(error) {
   isConnected = false;
-  var jsonConnectErrorAsString = JSON.stringify(error, null, 4);
   postMessage({
     command: 'connectErrorCallback',
-    jsonConnectErrorAsString: jsonConnectErrorAsString
+    error: error
   });
 }
 
 function subscribeCallback(message) {
-  var jsonMessageAsString = JSON.stringify(message, null, 4);
   postMessage({
     command: 'subscribeCallback',
-    jsonMessageAsString: jsonMessageAsString
+    message: message
   });
 }