* @ngdoc controller
* @name app.example.controller:ExampleController
*
- * @requires $rootScope
- * @requires $scope
+ * @requires $location
*
* <p>
* <br>
- * {@link https://docs.angularjs.org/api/ng/service/$rootScope $rootScope}
- * {@link https://docs.angularjs.org/api/ng/type/$rootScope.Scope $scope}
+ * {@link https://docs.angularjs.org/api/ng/service/$location $location}
* </p>
*
* @description
* ExampleController controller.
*/
/* @ngInject */
- function ExampleController() {
+ function ExampleController($location) {
var vm = this;
-
var client;
var subscription;
- // vm.serverDestination = {};
- // vm.payload = {};
- // vm.headers = {};
+ vm.url = $location.protocol() + '://' + $location.host() + '/spring-stomp-server/portfolio';
+ vm.clientDestination = '/topic/greeting';
+ vm.serverDestination = '/app/greeting';
+ vm.connectHeaders = JSON.stringify({
+ login: 'mylogin',
+ passcode: 'mypasscode',
+ // User defined headers
+ 'client-id': 'gumartin-id'
+ }, null, 4);
+ // User defined headers
+ vm.sendHeaders = JSON.stringify({
+ priority: 9
+ }, null, 4);
+ // User defined headers
+ vm.subscribeHeaders = JSON.stringify({
+ id: 123456
+ }, null, 4);
+
+
vm.connect = function () {
// use SockJS implementation instead of the browser's native implementation
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);
+ client.connect(JSON.parse(vm.connectHeaders), connectCallback, errorCallback);
};
vm.subscribe = function () {
- subscription = client.subscribe(vm.clientDestination, subscribeCallback);
+ subscription = client.subscribe(vm.clientDestination, subscribeCallback, JSON.parse(vm.subscribeHeaders));
};
vm.unsubscribe = function () {
};
vm.send = function () {
- client.send(vm.serverDestination, vm.headers, vm.payload);
+ client.send(vm.serverDestination, JSON.parse(vm.sendHeaders), vm.payload);
};
vm.disconnect = function() {
function subscribeCallback(message) {
// called when the client receives a STOMP message from the server
if (message.body) {
- alert('got message with body ' + message.body)
+ alert('got message with body ' + message.body);
} else {
alert('got empty message');
}
<br>
<label>
Headers:<br>
- <textarea ng-model="vm.connectHeaders" placeholder="headers">
+ <textarea style="width: 200%; border: none" auto-height
+ ng-model="vm.connectHeaders" placeholder="headers">
{"login":"superadmin","passcode":"12345678"}
</textarea>
</label>
<label>
Queue:<br>
<input value="/rpc/" ng-model="vm.clientDestination" placeholder="Client-Destination">
- </label><br>
+ </label>
+ <br>
+ <label>
+ Headers:<br>
+ <textarea style="width: 200%; border: none" auto-height
+ ng-model="vm.subscribeHeaders" placeholder="headers">
+ {"rid": 1234}
+ </textarea>
+ </label>
</div>
<hr>
<br>
<label>
Body / Payload:<br>
- <textarea ng-model="vm.payload" size="50" placeholder="payload">
+ <textarea style="width: 200%; border: none" auto-height
+ ng-model="vm.payload" placeholder="payload">
{"key":"value"}
</textarea>
</label>
<br>
<label>
Headers:<br>
- <textarea ng-model="vm.headers" size="50" placeholder="headers">
+ <textarea style="width: 200%; border: none" auto-height
+ ng-model="vm.sendHeaders" size="50" placeholder="headers">
{"rid": 1234}
</textarea>
</label>
--- /dev/null
+(function () {
+ 'use strict';
+
+ angular
+ .module('app.widgets')
+ .directive('autoHeight', autoHeight);
+
+ /**
+ * @ngdoc directive
+ * @name app.widgets.directive:autoHeight
+ * @restrict EA
+ *
+ *
+ * @description
+ * Controller child directive example.
+ *
+ * @element auto-height-directive
+ *
+ * @example
+ <example name="auto-height" module="app.widgets">
+ <file name="index.html">
+ <textarea auto-height> </textarea>
+ </file>
+ </example>
+ */
+ function autoHeight() {
+ return {
+ restrict: 'EA',
+ link: linkFunc,
+ scope: {}
+ };
+
+ function linkFunc(scope, el, attr, ctrl) {
+ var height = (el[0].scrollHeight < 30) ? 80 : el[0].scrollHeight;
+
+ height = height + 80;
+ el[0].style.height = height + 'px';
+ }
+ }
+
+})();