1
|
define([
|
2
|
'dojo/_base/declare',
|
3
|
'steam2/stores',
|
4
|
'steam2/user'
|
5
|
], function(declare, stores, user){
|
6
|
|
7
|
var Channel = declare('steam2.Channel', null, {
|
8
|
|
9
|
wait: 500,
|
10
|
|
11
|
constructor: function(){
|
12
|
this.subscribe();
|
13
|
},
|
14
|
|
15
|
subscribe: function(){
|
16
|
var channel = "/stabile/ui_update/" + user.username + "~ui_update";
|
17
|
var self = this;
|
18
|
dojo.xhrGet({
|
19
|
handleAs:"json",
|
20
|
url:channel,
|
21
|
load: function(tasks){
|
22
|
self.wait = 500;
|
23
|
self.publish(tasks);
|
24
|
self.subscribe();
|
25
|
},
|
26
|
error: function(){
|
27
|
setTimeout(self.subscribe, self.wait);
|
28
|
self.wait = self.wait * 1.5;
|
29
|
}
|
30
|
});
|
31
|
},
|
32
|
|
33
|
publish: function(tasks){
|
34
|
dojo.forEach(tasks, function(ev){
|
35
|
console.log('steam2.channel.publish', ev);
|
36
|
if(ev.id == 'servers'){
|
37
|
var set = stores.servers.setValue;
|
38
|
var item = stores.servers.byId({identity:ev.uuid});
|
39
|
if(ev.status){
|
40
|
set(item, 'status', ev.status);
|
41
|
}
|
42
|
if(ev.displayip){
|
43
|
set(item, 'macip', ev.displayip);
|
44
|
}
|
45
|
if(ev.displayport){
|
46
|
set(item, 'port', ev.displayport);
|
47
|
}
|
48
|
}
|
49
|
});
|
50
|
}
|
51
|
});
|
52
|
|
53
|
// go ahead and create the channel
|
54
|
new Channel();
|
55
|
|
56
|
});
|