6
6
. controller ( 'HyperdecksCtrl' , controller ) ;
7
7
8
8
/* @ngInject */
9
- function controller ( hyperdecks , Hyperdeck ) {
9
+ function controller ( hyperdecks , Hyperdeck , $websocket ) {
10
10
var vm = this ;
11
11
12
12
init ( ) ;
@@ -20,12 +20,33 @@ function controller(hyperdecks, Hyperdeck) {
20
20
vm . getSlotInfo = getSlotInfo ;
21
21
22
22
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
+
23
40
vm . hyperdecks = hyperdecks ;
24
41
_ . map ( vm . hyperdecks , getEvents ) ;
25
42
_ . map ( vm . hyperdecks , getConfiguration ) ;
26
43
_ . map ( vm . hyperdecks , getTransportInfo ) ;
27
44
}
28
45
46
+ function findDeck ( id ) {
47
+ return _ . findWhere ( vm . hyperdecks , { '_id' : id } ) ;
48
+ }
49
+
29
50
function connect ( hyperdeck ) {
30
51
Hyperdeck . connect ( hyperdeck . _id ) ;
31
52
}
@@ -45,24 +66,30 @@ function controller(hyperdecks, Hyperdeck) {
45
66
}
46
67
47
68
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
+ }
51
74
}
52
75
53
76
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
+ }
57
82
}
58
83
59
84
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
+ }
66
93
}
67
94
}
68
95
} ) ( ) ;
0 commit comments