Skip to content

Commit c6e01a5

Browse files
committed
added websocket connection
1 parent 72a38a5 commit c6e01a5

File tree

4 files changed

+79
-15
lines changed

4 files changed

+79
-15
lines changed

Diff for: bower.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"moment": "~2.10.3",
1515
"animate.css": "~3.3.0",
1616
"angular": "~1.4.0",
17-
"lodash": "~3.9.3"
17+
"lodash": "~3.9.3",
18+
"angular-websocket": "~1.0.13"
1819
},
1920
"devDependencies": {
2021
"angular-mocks": "~1.4.0"

Diff for: src/app/components/hyperdecks/hyperdecks.controller.js

+40-13
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ angular
66
.controller('HyperdecksCtrl', controller);
77

88
/* @ngInject */
9-
function controller(hyperdecks, Hyperdeck) {
9+
function controller(hyperdecks, Hyperdeck, $websocket) {
1010
var vm = this;
1111

1212
init();
@@ -20,12 +20,33 @@ function controller(hyperdecks, Hyperdeck) {
2020
vm.getSlotInfo = getSlotInfo;
2121

2222
function init() {
23+
var dataStream = $websocket('ws://localhost:8888');
24+
dataStream.onMessage(function(message) {
25+
var data = JSON.parse(message.data);
26+
var deck;
27+
if (_.has(data, 'connectionStatus')) {
28+
deck = findDeck(data._id);
29+
if (deck) {
30+
deck.connectionStatus = data.connectionStatus;
31+
}
32+
} else if (_.has(data, 'event')) {
33+
deck = findDeck(data._id);
34+
if (deck) {
35+
deck.events.unshift(data.event);
36+
}
37+
}
38+
});
39+
2340
vm.hyperdecks = hyperdecks;
2441
_.map(vm.hyperdecks, getEvents);
2542
_.map(vm.hyperdecks, getConfiguration);
2643
_.map(vm.hyperdecks, getTransportInfo);
2744
}
2845

46+
function findDeck(id) {
47+
return _.findWhere(vm.hyperdecks, {'_id': id});
48+
}
49+
2950
function connect(hyperdeck) {
3051
Hyperdeck.connect(hyperdeck._id);
3152
}
@@ -45,24 +66,30 @@ function controller(hyperdecks, Hyperdeck) {
4566
}
4667

4768
function getConfiguration(hyperdeck) {
48-
Hyperdeck.getConfiguration(hyperdeck._id).then(function (configuration) {
49-
hyperdeck.configuration = configuration;
50-
});
69+
if (hyperdeck.connectionStatus === 'Connected') {
70+
Hyperdeck.getConfiguration(hyperdeck._id).then(function (configuration) {
71+
hyperdeck.configuration = configuration;
72+
});
73+
}
5174
}
5275

5376
function getTransportInfo(hyperdeck) {
54-
Hyperdeck.getTransportInfo(hyperdeck._id).then(function (transportInfo) {
55-
hyperdeck.transportInfo = transportInfo;
56-
});
77+
if (hyperdeck.connectionStatus === 'Connected') {
78+
Hyperdeck.getTransportInfo(hyperdeck._id).then(function (transportInfo) {
79+
hyperdeck.transportInfo = transportInfo;
80+
});
81+
}
5782
}
5883

5984
function getSlotInfo(hyperdeck, slot) {
60-
Hyperdeck.getSlotInfo(hyperdeck._id, slot).then(function (slotInfo) {
61-
if (!_.has(hyperdeck, 'slotInfo')) {
62-
hyperdeck.slotInfo = {};
63-
}
64-
hyperdeck.slotInfo[slot] = slotInfo;
65-
});
85+
if (hyperdeck.connectionStatus === 'Connected') {
86+
Hyperdeck.getSlotInfo(hyperdeck._id, slot).then(function (slotInfo) {
87+
if (!_.has(hyperdeck, 'slotInfo')) {
88+
hyperdeck.slotInfo = {};
89+
}
90+
hyperdeck.slotInfo[slot] = slotInfo;
91+
});
92+
}
6693
}
6794
}
6895
})();

Diff for: src/app/index.module.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
'use strict';
33

44
angular
5-
.module('hyperdeckUi', ['ngAnimate', 'ngCookies', 'ngTouch', 'ngSanitize', 'ui.router', 'ui.bootstrap']);
5+
.module('hyperdeckUi', ['ngAnimate', 'ngCookies', 'ngTouch', 'ngSanitize', 'ui.router', 'ui.bootstrap', 'ngWebSocket']);
66

77
})();

Diff for: src/assets/require.js

+36
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)