summaryrefslogtreecommitdiff
path: root/src/BeerDukeController.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/BeerDukeController.js')
-rw-r--r--src/BeerDukeController.js28
1 files changed, 24 insertions, 4 deletions
diff --git a/src/BeerDukeController.js b/src/BeerDukeController.js
index 48e9cd4..ac41c47 100644
--- a/src/BeerDukeController.js
+++ b/src/BeerDukeController.js
@@ -4,6 +4,29 @@
function BeerDukeControllerController($log, BeerDukeService, BeerDukeSettings) {
var ctrl = this;
+ ctrl.slots = {};
+
+ BeerDukeService.callbacks.onConnect = function () {
+ BeerDukeService.subscribe('/beer-duke/slot/#');
+ };
+ BeerDukeService.callbacks.onMessageArrived = function (m) {
+ $log.info('m.payloadString =', m.payloadString);
+
+ var slotNo = m.destinationName.match(/^\/beer-duke\/slot\/([0-9]+)$/);
+
+ if (slotNo && slotNo.length == 2) {
+ try {
+ $log.info('slot', slotNo[1]);
+ var slot = parseInt(slotNo[1]);
+ var count = parseInt(m.payloadString);
+ $log.info('slot ' + slot + ' = ' + count);
+ ctrl.slots[slot] = count;
+ } catch (e) {
+ $log.warn(e);
+ }
+ }
+ };
+
if (BeerDukeSettings.values.showSettings) {
ctrl.code = 123;
ctrl.email = 'foo@example.org';
@@ -19,13 +42,10 @@
BeerDukeService.submit('/beer-duke/give-beer', payload);
};
- BeerDukeService.callbacks.onMessageArrived = function (m) {
- ctrl.lastCode = m.code;
- }
+ BeerDukeService.connect('controller');
}
function run(BeerDukeService) {
- BeerDukeService.connect('controller');
}
function config($routeProvider) {