From: gustavo Date: Sun, 3 Apr 2016 19:48:50 +0000 (+0200) Subject: AngularJS: stomp client using SockJS X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=9d0026da41a6445d17c697683c7ad27eba6b6e73;p=JavaScriptForFun AngularJS: stomp client using SockJS --- 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 - - - -