@@ -5,6 +5,7 @@ block title
5
5
6
6
block content
7
7
h1 #[ span.mega-octicon.octicon-device-desktop ] Machine: #{machine .hostname } #[ small.text-muted (#{machine ._id })]
8
+ h2 Status #[ span#machine-status .mega-octicon.octicon-device-desktop ]
8
9
h2 Specifications
9
10
dl.dl-horizontal
10
11
dt.col-sm-3 Hostname
@@ -29,3 +30,38 @@ block content
29
30
ul.list-unstyled
30
31
- each project in projects
31
32
li #[ a( href ="/projects/" + project ._id ) #{project .name }]
33
+
34
+ block scripts
35
+ script .
36
+ var host = " #{machine.address}" .replace (/ ^ http/ , ' ws' ); // WebSocket server address
37
+ var ws = null ; // WebSocket
38
+ var $status = $ (" #machine-status" ); // Machine status icon
39
+
40
+ // Connects to WebSocket server
41
+ var wsConnect = function () {
42
+ ws = new WebSocket (host); // Attempt to connect
43
+
44
+ // Set server status as on
45
+ ws .onopen = function (event ) {
46
+ $status .removeClass (" text-danger" );
47
+ $status .addClass (" text-success" );
48
+ };
49
+ // Set server status as off
50
+ ws .onclose = function (event ) {
51
+ // Set status
52
+ $status .removeClass (" text-success" );
53
+ $status .addClass (" text-danger" );
54
+ };
55
+ };
56
+
57
+ // Reconnects to WebSocket server if needed
58
+ var wsReconnect = function () {
59
+ if (! ws || ws .readyState === WebSocket .CLOSED ) {
60
+ wsConnect ();
61
+ }
62
+ };
63
+
64
+ // Connect
65
+ wsConnect ();
66
+ // Attempt to reconnect every 5s if necessary
67
+ setInterval (wsReconnect, 5000 );
0 commit comments