From 9d0026da41a6445d17c697683c7ad27eba6b6e73 Mon Sep 17 00:00:00 2001 From: gustavo Date: Sun, 3 Apr 2016 21:48:50 +0200 Subject: [PATCH] AngularJS: stomp client using SockJS --- .../src/stomp/app/example/example.controller.js | 35 +++++++-- angularjs/stomp/src/stomp/app/example/example.html | 83 +++++++++++----------- angularjs/stomp/src/stomp/index.html | 3 +- .../stomp/src/stomp/stubs/cars/cars.service.js | 27 ------- angularjs/stomp/src/stomp/stubs/stubs.config.js | 3 +- 5 files changed, 75 insertions(+), 76 deletions(-) delete mode 100644 angularjs/stomp/src/stomp/stubs/cars/cars.service.js diff --git a/angularjs/stomp/src/stomp/app/example/example.controller.js b/angularjs/stomp/src/stomp/app/example/example.controller.js index 79929cb..cdcfce8 100644 --- a/angularjs/stomp/src/stomp/app/example/example.controller.js +++ b/angularjs/stomp/src/stomp/app/example/example.controller.js @@ -2,7 +2,7 @@ 'use strict'; angular - .module('app.users') + .module('app.example') .controller('ExampleController', ExampleController); /** @@ -25,13 +25,21 @@ 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 () { @@ -39,6 +47,21 @@ 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); + } } })(); diff --git a/angularjs/stomp/src/stomp/app/example/example.html b/angularjs/stomp/src/stomp/app/example/example.html index ea77b29..b6797fd 100644 --- a/angularjs/stomp/src/stomp/app/example/example.html +++ b/angularjs/stomp/src/stomp/app/example/example.html @@ -1,67 +1,70 @@ - - - - - STOMP-Example - - - -