AngularJS: stomp client using SockJS
authorgustavo <gu.martinm@gmail.com>
Sun, 3 Apr 2016 19:48:50 +0000 (21:48 +0200)
committergustavo <gu.martinm@gmail.com>
Sun, 3 Apr 2016 19:48:50 +0000 (21:48 +0200)
angularjs/stomp/src/stomp/app/example/example.controller.js
angularjs/stomp/src/stomp/app/example/example.html
angularjs/stomp/src/stomp/index.html
angularjs/stomp/src/stomp/stubs/cars/cars.service.js [deleted file]
angularjs/stomp/src/stomp/stubs/stubs.config.js

index 79929cb..cdcfce8 100644 (file)
@@ -2,7 +2,7 @@
   'use strict';
 
   angular
-    .module('app.users')
+    .module('app.example')
     .controller('ExampleController', ExampleController);
 
   /**
   function ExampleController() {
     var vm = this;
 
-    vm.connectHeaders = {};
-    vm.clientDestination = {};
-    vm.serverDestination = {};
-    vm.payload = {};
-    vm.headers = {};
+    var client;
+
+    // vm.connectHeaders = {};
+    // vm.clientDestination = {};
+    // vm.serverDestination = {};
+    // vm.payload = {};
+    // vm.headers = {};
 
     vm.connect = function () {
+      // use SockJS implementation instead of the browser's native implementation
+      var ws = new SockJS(vm.url);
+      client = Stomp.over(ws);
+      client.heartbeat.outgoing = 20000; // client will send heartbeats every 20000ms
+      client.heartbeat.incoming = 0;     // client does not want to receive heartbeats from the server
+      client.connect(vm.connectHeaders, connectCallback, errorCallback);
     };
 
     vm.subscribe = function () {
 
     vm.send = function () {
     };
+
+    vm.disconnect = function() {
+      client.disconnect(function() {
+        alert('See you next time!');
+      });
+    };
+
+    function connectCallback() {
+      // called back after the client is connected and authenticated to the STOMP server
+    }
+
+    function errorCallback(error) {
+      // display the error's message header:
+      alert(error.headers.message);
+    }
   }
 
 })();
index ea77b29..b6797fd 100644 (file)
@@ -1,67 +1,70 @@
 <!DOCTYPE html>
-<html lang="en">
-<head>
-  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
-  <meta charset="UTF-8">
-  <title>STOMP-Example</title>
-</head>
-<body class="ng-scope" ng-app="stomp-ui" ng-controller="ExampleController as vm">
-
-<div class="sidebar">
-  <div class="box">
-    <span class="up">1. Connect</span>
-    <button class="up-right" ng-click="vm.connect()">Connect to Endpoint</button>
+<div class="container" ng-controller="ExampleController as vm">
+  <div>
+    <span>1. Connect</span><br>
+    <button ng-click="vm.connect()">Connect to Endpoint</button>
+    <br>
 
     <label>
-      Endpoint:
-      <input value="http://localhost:8080" class="ng-pristine ng-untouched ng-valid" ng-model="vm.url" placeholder="url">
+      Endpoint:<br>
+      <input value="http://localhost:8080" ng-model="vm.url" placeholder="url">
     </label>
-    <hr>
+    <br>
     <label>
-      Headers:
-      <textarea class="ng-pristine ng-valid ng-touched" ng-model="vm.connectHeaders" placeholder="headers">
+      Headers:<br>
+      <textarea ng-model="vm.connectHeaders" placeholder="headers">
         {"login":"superadmin","passcode":"12345678"}
       </textarea>
     </label>
   </div>
-  <div class="box">
-    <span class="up">2. Subscribe</span>
-    <button class="up-right" ng-click="vm.subscribe()">Subscribe to destination</button>
+
+  <hr>
+
+  <div>
+    <span>2. Disconnect</span><br>
+    <button ng-click="vm.disconnect()">Disconnect from Endpoint</button>
+  </div>
+
+  <hr>
+
+  <div>
+    <span>3. Subscribe</span><br>
+    <button ng-click="vm.subscribe()">Subscribe to destination</button>
+    <br>
 
     <label>
-      Queue:
-      <input value="/rpc/" class="ng-pristine ng-untouched ng-valid" ng-model="vm.clientDestination"
-             placeholder="Client-Destination">
+      Queue:<br>
+      <input value="/rpc/" ng-model="vm.clientDestination" placeholder="Client-Destination">
     </label><br>
   </div>
-  <div class="box">
-    <span class="up">3. Send</span>
-    <button class="up-right" ng-click="vm.send()">Send message to server</button>
+
+  <hr>
+
+  <div>
+    <span>4. Send</span><br>
+    <button ng-click="vm.send()">Send message to server</button>
+    <br>
 
     <label>
-      Server-Destination:
-      <input value="/dest" class="ng-pristine ng-untouched ng-valid" ng-model="vm.serverDestination" placeholder="channel">
+      Server-Destination:<br>
+      <input value="/dest" ng-model="vm.serverDestination" placeholder="channel">
     </label>
-    <hr>
+    <br>
     <label>
-      Body / Payload
-      <textarea ng-model="vm.payload" size="50" class="full ng-pristine ng-untouched ng-valid" placeholder="payload">
+      Body / Payload:<br>
+      <textarea ng-model="vm.payload" size="50" placeholder="payload">
         {"key":"value"}
       </textarea>
     </label>
-    <hr>
+    <br>
     <label>
-      Headers
-      <textarea ng-model="vm.headers" size="50" class="full ng-pristine ng-untouched ng-valid" placeholder="headers">
+      Headers:<br>
+      <textarea ng-model="vm.headers" size="50" placeholder="headers">
         {"rid": 1234}
       </textarea>
     </label>
   </div>
 
-</div>
-
-<textarea id="log"></textarea>
-
-</body>
+  <textarea id="log"></textarea>
 
-</html>
+</div>
index 2b71a4e..20c4fff 100644 (file)
@@ -2,7 +2,8 @@
 <html lang="en">
 
   <head>
-    <meta charset="utf-8" />
+    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
+    <meta charset="UTF-8">
     <title>STOMP client with SockJS</title>
     <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
 
diff --git a/angularjs/stomp/src/stomp/stubs/cars/cars.service.js b/angularjs/stomp/src/stomp/stubs/cars/cars.service.js
deleted file mode 100644 (file)
index a7b563b..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-(function () {
-  'use strict';
-
-  angular
-    .module('app.stubs')
-    .factory('carsStub', carsStub);
-
-  /* @ngInject */
-  function carsStub($httpBackend, API) {
-    return {
-      register: register
-    };
-
-    function register() {
-      $httpBackend.whenGET(API.CARS).respond(getAll);
-
-      function getAll() {
-        return [
-          {id:1, content: 'Car: 1'},
-          {id:2, content: 'Car: 2'},
-          {id:3, content: 'Car: 3'}
-        ];
-      }
-    }
-  }
-
-}());
index 5b31132..46d5669 100644 (file)
@@ -7,8 +7,7 @@
     .run('register', register);
 
   /* @ngInject */
-  function register(carsStub) {
-    carsStub.register();
+  function register() {
   }
 
 }());