From 9c1bc39bc473e28ec86095f0f125ef8cc308cb33 Mon Sep 17 00:00:00 2001 From: Maik Hummel Date: Wed, 25 Jan 2017 11:53:25 +0100 Subject: [PATCH 1/4] Ignore .idea folder --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 5d94447..65246d3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ bower_components/ node_modules/ npm-debug.log +.idea/ \ No newline at end of file From 1a6883243abdc60fc645677b30883e478317bf3f Mon Sep 17 00:00:00 2001 From: Maik Hummel Date: Wed, 25 Jan 2017 11:58:44 +0100 Subject: [PATCH 2/4] Add eslint for CodeClimate support --- .eslintrc.yml | 1 + package.json | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 .eslintrc.yml diff --git a/.eslintrc.yml b/.eslintrc.yml new file mode 100644 index 0000000..413f14b --- /dev/null +++ b/.eslintrc.yml @@ -0,0 +1 @@ +extends: standard \ No newline at end of file diff --git a/package.json b/package.json index ab4dee9..5469fd2 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,11 @@ "grunt": "^1.0.1", "grunt-contrib-uglify": "^2.0.0", "grunt-file-exists": "^0.1.4", - "grunt-standard": "^2.0.0" + "grunt-standard": "^2.0.0", + "eslint": "3.14.0", + "eslint-config-standard": "6.2.1", + "eslint-plugin-promise": "3.4.0", + "eslint-plugin-standard": "2.0.1" }, "scripts": { "test": "grunt --verbose" From e67bebc4239aea4fe72b31d9008c592f70224d12 Mon Sep 17 00:00:00 2001 From: Maik Hummel Date: Wed, 25 Jan 2017 11:58:59 +0100 Subject: [PATCH 3/4] Fix minor eslint issue --- src/ng-stomp.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ng-stomp.js b/src/ng-stomp.js index ffcfc3f..2ce2948 100644 --- a/src/ng-stomp.js +++ b/src/ng-stomp.js @@ -6,7 +6,7 @@ * @license MIT */ -/*global +/* global angular, SockJS, Stomp */ angular From 18b73fa16b8acb07b0e25cb743af60ceb2afd37a Mon Sep 17 00:00:00 2001 From: Maik Hummel Date: Wed, 25 Jan 2017 15:12:58 +0100 Subject: [PATCH 4/4] Use provider to make incoming / outgoing heartbeat configurable --- src/ng-stomp.js | 147 +++++++++++++++++++++++++++--------------------- 1 file changed, 82 insertions(+), 65 deletions(-) diff --git a/src/ng-stomp.js b/src/ng-stomp.js index 93377db..5519fe0 100644 --- a/src/ng-stomp.js +++ b/src/ng-stomp.js @@ -7,84 +7,101 @@ */ /* global - angular, SockJS, Stomp */ + angular, SockJS, Stomp */ + (function () { angular .module('ngStomp', []) - .service('$stomp', [ - '$rootScope', '$q', - function ($rootScope, $q) { - this.sock = null - this.stomp = null - this.debug = null + .provider('$stomp', [ + function () { + var outgoingHeartbeat = 1000 + var incomingHeartbeat = 1000 - this.setDebug = function (callback) { - this.debug = callback - } + return { + setOutgoingHeartbeat: function (interval) { + outgoingHeartbeat = interval + }, + setIncomingHeartbeat: function (interval) { + incomingHeartbeat = interval + }, + $get: [ + '$rootScope', '$q', + function ($rootScope, $q) { + this.sock = null + this.stomp = null + this.debug = null - this.connect = function (endpoint, headers, errorCallback, sockjsOpts) { - headers = headers || {} - sockjsOpts = sockjsOpts || {} + this.setDebug = function (callback) { + this.debug = callback + } - var dfd = $q.defer() + this.connect = function (endpoint, headers, errorCallback, sockjsOpts) { + headers = headers || {} + sockjsOpts = sockjsOpts || {} - this.sock = new SockJS(endpoint, null, sockjsOpts) - this.sock.onclose = function () { - if (angular.isFunction(errorCallback)) { - errorCallback(new Error('Connection broken')) - } - } + var dfd = $q.defer() - this.stomp = Stomp.over(this.sock) - this.stomp.debug = this.debug - this.stomp.connect(headers, function (frame) { - dfd.resolve(frame) - }, function (err) { - dfd.reject(err) - if (angular.isFunction(errorCallback)) { - errorCallback(err) - } - }) + this.sock = new SockJS(endpoint, null, sockjsOpts) + this.sock.onclose = function () { + if (angular.isFunction(errorCallback)) { + errorCallback(new Error('Connection broken')) + } + } - return dfd.promise - } + this.stomp = Stomp.over(this.sock) + this.stomp.heartbeat.outgoing = outgoingHeartbeat + this.stomp.heartbeat.incoming = incomingHeartbeat + this.stomp.debug = this.debug + this.stomp.connect(headers, function (frame) { + dfd.resolve(frame) + }, function (err) { + dfd.reject(err) + if (angular.isFunction(errorCallback)) { + errorCallback(err) + } + }) - this.disconnect = function () { - var dfd = $q.defer() - this.stomp.disconnect(dfd.resolve) - return dfd.promise - } + return dfd.promise + } - this.subscribe = this.on = function (destination, callback, headers) { - headers = headers || {} - return this.stomp.subscribe(destination, function (res) { - var payload = null - try { - payload = JSON.parse(res.body) - } finally { - if (callback) { - callback(payload, res.headers, res) + this.disconnect = function () { + var dfd = $q.defer() + this.stomp.disconnect(dfd.resolve) + return dfd.promise } - } - }, headers) - } - this.unsubscribe = this.off = function (subscription) { - subscription.unsubscribe() - } + this.subscribe = this.on = function (destination, callback, headers) { + headers = headers || {} + return this.stomp.subscribe(destination, function (res) { + var payload = null + try { + payload = JSON.parse(res.body) + } finally { + if (callback) { + callback(payload, res.headers, res) + } + } + }, headers) + } - this.send = function (destination, body, headers) { - var dfd = $q.defer() - try { - var payloadJson = JSON.stringify(body) - headers = headers || {} - this.stomp.send(destination, headers, payloadJson) - dfd.resolve() - } catch (e) { - dfd.reject(e) - } - return dfd.promise + this.unsubscribe = this.off = function (subscription) { + subscription.unsubscribe() + } + + this.send = function (destination, body, headers) { + var dfd = $q.defer() + try { + var payloadJson = JSON.stringify(body) + headers = headers || {} + this.stomp.send(destination, headers, payloadJson) + dfd.resolve() + } catch (e) { + dfd.reject(e) + } + return dfd.promise + } + } ] } - }] - ) + } ] + ) })()