Skip to content
This repository was archived by the owner on Jul 6, 2022. It is now read-only.

Commit 6a943dc

Browse files
committed
Making data client into parameters and moving it into Data.state.
1 parent aa24ebc commit 6a943dc

4 files changed

Lines changed: 23 additions & 14 deletions

File tree

‎app/js/Data.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ var Data = {
66
scans: [],
77

88
config: {
9+
data_client: 'http://127.0.0.1:44444/',
910
domain: 'https://standing-fleet.herokuapp.com/',
1011
apiUrl: '/api',
1112
alertStay: 5000,
@@ -29,6 +30,7 @@ var Data = {
2930
systemId: ''
3031
},
3132
alertCount: 0,
33+
data_client: null,
3234
dimmed: false,
3335
lastPollTs : Date.now(),
3436
memberSortOrder: {

‎app/js/Main.js‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@ $(function () {
22
UI.registerEventHandlers();
33
initialize();
44

5-
data_client = new Faye.Client('http://127.0.0.1:44444/');
6-
data_client.subscribe('/events', function(event) {
7-
console.log(event)
8-
EventList.addEvent(event);
9-
});
5+
try {
6+
Data.state.data_client = new Faye.Client(Data.config.data_client);
7+
Data.state.data_client.subscribe('/events', function(event) {
8+
EventList.addEvent(event);
9+
});
10+
} catch(err) {
11+
console.log('Unable to connect to local data client...')
12+
}
1013

1114
});
1215

‎app/js/client/Data.js‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@ var Data = {
55
alertStay: 5000,
66
maxEvents: 20,
77
uiSpeed: 400,
8+
local_dataport: 44444,
89
log: 'console'
910
},
1011

1112
state: {
1213
alertCount: 0,
1314
dimmed: false,
14-
pollLoop: 0
15+
pollLoop: 0,
16+
datasources: {
17+
local: null
18+
}
1519
},
1620

1721
build_ui: function() {

‎app/js/client/Main.js‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,22 @@ function initializeClient() {
1919
Data.templates = Data.build_templates();
2020

2121
log('Starting Server...')
22-
var server = http.createServer(),
23-
bayeux = new faye.NodeAdapter({mount: '/', timeout: 45});
22+
var server = http.createServer()
23+
Data.state.datasources.local = new faye.NodeAdapter({mount: '/', timeout: 45});
2424

25-
bayeux.attach(server);
26-
server.listen(44444);
25+
Data.state.datasources.local.attach(server);
26+
server.listen(Data.config.local_dataport);
2727

2828
UI.stopSpin();
2929
UI.registerEventHandlers();
3030

3131
log('Begin Polling...')
3232

33-
pollClipboard(bayeux);
33+
pollClipboard();
3434
gui.Window.get().show();
3535
};
3636

37-
function pollClipboard(bayeux) {
37+
function pollClipboard() {
3838
UI.startSpin();
3939
setTimeout(function() {
4040
var cb = gui.Clipboard.get();
@@ -43,11 +43,11 @@ function pollClipboard(bayeux) {
4343

4444
var renderedEvent = $(Templates.event(event))
4545
Data.ui.clipboard_list.prepend(renderedEvent);
46-
bayeux.getClient().publish('/events', event);
46+
Data.state.datasources.local.getClient().publish('/events', event);
4747

4848
UI.stopSpin();
4949

50-
pollClipboard(bayeux);
50+
pollClipboard();
5151
}, 7000);
5252
}
5353

0 commit comments

Comments
 (0)