'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);
+ }
}
})();
<!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>
+++ /dev/null
-(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'}
- ];
- }
- }
- }
-
-}());