Skip to content

Commit 042c28c

Browse files
committed
Add Socket.io alert
1 parent 88378ce commit 042c28c

File tree

5 files changed

+47
-6
lines changed

5 files changed

+47
-6
lines changed

public/themes/pterodactyl/js/frontend/server.socket.js

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,52 @@
1818
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1919
// SOFTWARE.
2020
(function initSocket() {
21+
if (typeof $.notifyDefaults !== 'function') {
22+
console.error('Notify does not appear to be loaded.');
23+
return;
24+
}
25+
2126
if (typeof io !== 'function') {
2227
console.error('Socket.io is reqired to use this panel.');
2328
return;
2429
}
2530

31+
$.notifyDefaults({
32+
placement: {
33+
from: 'bottom',
34+
align: 'right'
35+
},
36+
newest_on_top: true,
37+
delay: 2000,
38+
animate: {
39+
enter: 'animated zoomInDown',
40+
exit: 'animated zoomOutDown'
41+
}
42+
});
43+
44+
var notifySocketError = false;
45+
2646
window.Socket = io(Pterodactyl.node.scheme + '://' + Pterodactyl.node.fqdn + ':' + Pterodactyl.node.daemonListen + '/ws/' + Pterodactyl.server.uuid, {
2747
'query': 'token=' + Pterodactyl.server.daemonSecret,
2848
});
2949

3050
Socket.io.on('connect_error', function (err) {
31-
console.error('Could not connect to socket.io.', err);
51+
if(typeof notifySocketError !== 'object') {
52+
notifySocketError = $.notify({
53+
message: 'There was an error attempting to establish a WebSocket connection to the Daemon. This panel will not work as expected.<br /><br />' + err,
54+
}, {
55+
type: 'danger',
56+
delay: 0
57+
});
58+
}
3259
});
3360

3461
// Connected to Socket Successfully
3562
Socket.on('connect', function () {
36-
console.log('connected to socket');
63+
if (notifySocketError !== false) {
64+
notifySocketError.close();
65+
notifySocketError = false;
66+
}
3767
});
3868

3969
Socket.on('initial status', function (data) {

public/themes/pterodactyl/vendor/animate/animate.min.css

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/themes/pterodactyl/vendor/bootstrap-notify/bootstrap-notify.min.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/themes/pterodactyl/layouts/master.blade.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
{!! Theme::css('vendor/adminlte/admin.min.css') !!}
3131
{!! Theme::css('vendor/adminlte/colors/skin-blue.min.css') !!}
3232
{!! Theme::css('vendor/sweetalert/sweetalert.min.css') !!}
33+
{!! Theme::css('vendor/animate/animate.min.css') !!}
3334
{!! Theme::css('css/pterodactyl.css') !!}
3435
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
3536
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/ionicons/2.0.1/css/ionicons.min.css">
@@ -266,6 +267,7 @@ class="active"
266267
{!! Theme::js('vendor/slimscroll/jquery.slimscroll.min.js') !!}
267268
{!! Theme::js('vendor/adminlte/app.min.js') !!}
268269
{!! Theme::js('js/vendor/socketio/socket.io.min.js') !!}
270+
{!! Theme::js('vendor/bootstrap-notify/bootstrap-notify.min.js') !!}
269271
@show
270272
</body>
271273
</html>

resources/themes/pterodactyl/server/index.blade.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@
4444
<div id="terminal" style="width:100%;"></div>
4545
</div>
4646
<div class="box-footer text-center">
47-
@can('power-start', $server)<button class="btn btn-success" data-attr="power" data-action="start">Start</button>@endcan
48-
@can('power-off', $server)<button class="btn btn-primary" data-attr="power" data-action="restart">Restart</button>@endcan
49-
@can('power-restart', $server)<button class="btn btn-danger" data-attr="power" data-action="stop">Stop</button>@endcan
50-
@can('power-kill', $server)<button class="btn btn-danger" data-attr="power" data-action="kill">Kill</button>@endcan
47+
@can('power-start', $server)<button class="btn btn-success disabled" data-attr="power" data-action="start">Start</button>@endcan
48+
@can('power-off', $server)<button class="btn btn-primary disabled" data-attr="power" data-action="restart">Restart</button>@endcan
49+
@can('power-restart', $server)<button class="btn btn-danger disabled" data-attr="power" data-action="stop">Stop</button>@endcan
50+
@can('power-kill', $server)<button class="btn btn-danger disabled" data-attr="power" data-action="kill">Kill</button>@endcan
5151
</div>
5252
</div>
5353
</div>

0 commit comments

Comments
 (0)