lib/junkie/webinterface/public/js/index.js in junkie-0.1.0 vs lib/junkie/webinterface/public/js/index.js in junkie-0.1.1
- old
+ new
@@ -53,15 +53,16 @@
var time = new Date().toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, "$1");
$("#last_update").text(time);
}
$(function () {
- var ws = new WebSocket('ws://' + window.location.host + window.location.pathname);
- ws.onopen = function() {
+ var protocol = (window.location.protocol === "https:") ? "wss:" : "ws:";
+ var ws = new WebSocket(protocol + '//' + window.location.host + window.location.pathname);
+ ws.onopen = function() {
console.log('websocket opened');
$('#connection_status').text('connected');
};
- ws.onclose = function() {
+ ws.onclose = function() {
console.log('websocket closed');
$('#connection_status').text('disconnected');
};
ws.onmessage = function(m) {
console.log(m);