Skip to content

Commit

Permalink
#1471: add server system date + time clock
Browse files Browse the repository at this point in the history
git-svn-id: https://xpra.org/svn/Xpra/trunk@18731 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Mar 16, 2018
1 parent 13d0aed commit 607c132
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 11 deletions.
9 changes: 6 additions & 3 deletions src/html5/connect.html
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@ <h4 class="panel-title">Advanced options</h4>
<li class="list-group-item">
<input type="checkbox" id="swap_keys"> <span>Swap command and control key</span>
</li>
<li class="list-group-item">
<input type="checkbox" id="clock"> <span>Show server clock</span>
</li>
<li class="list-group-item">
<input type="checkbox" id="video"> <span>Video (experimental) <input type="checkbox" id="mediasource_video"> Native decoding</span>
</li>
Expand Down Expand Up @@ -319,7 +322,7 @@ <h4 class="panel-title">Advanced options</h4>
"exit_with_children", "exit_with_client",
"sharing", "steal", "reconnect", "swap_keys",
"video", "mediasource_video",
"ssl", "insecure",
"ssl", "insecure", "clock",
"debug_main", "debug_keyboard", "debug_mouse", "debug_clipboard", "debug_draw", "debug_audio", "debug_network",
];
for (var i = 0; i < bool_props.length; i++) {
Expand Down Expand Up @@ -534,9 +537,9 @@ <h4 class="panel-title">Advanced options</h4>
var bool_props = ["clipboard", "printing", "file_transfer",
"exit_with_children", "exit_with_client",
"sharing", "steal", "reconnect", "swap_keys",
"video", "mediasource_video",
"video", "mediasource_video", "clock",
"debug_main", "debug_keyboard", "debug_mouse", "debug_clipboard", "debug_draw", "debug_audio", "debug_network"];
var default_on = ["steal", "clipboard", "printing", "file_transfer", "reconnect", "exit_with_children", "exit_with_client"];
var default_on = ["steal", "clipboard", "printing", "file_transfer", "reconnect", "clock", "exit_with_children", "exit_with_client"];
if (Utilities.isMacOS()) {
default_on.push("swap_keys");
}
Expand Down
10 changes: 10 additions & 0 deletions src/html5/css/client.css
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,16 @@ div.windowinfocus {
display: none;
}

.clock_block {
position: relative;
float: left;
padding-left: 100px;
}
#clock_text {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
color: #fff;
}

@media screen {
.notifications .alert.visible {
margin-top: 0;
Expand Down
51 changes: 44 additions & 7 deletions src/html5/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@
<a href="#" id="upload_link" onclick="upload_file(event); return false">Upload File</a>
</div>
</div>
<div class="clock_block">
<p id="clock_text"></p>
</div>
</div>
</div>

Expand Down Expand Up @@ -97,6 +100,8 @@ <h3>Version 2.3</h3>
</div>

<script>
var getparam = Utilities.getparam;
var getboolparam = Utilities.getboolparam;

// disable right click menu:
window.oncontextmenu = function(e) {
Expand All @@ -110,13 +115,13 @@ <h3>Version 2.3</h3>
function show_menu(menu_id, event) {
var menu = $("#"+menu_id);
if (menu.is(':visible')) {
menu.hide();
menu.slideUp();
}
else {
$('.menu-content').hide();
var left = $(event.target).offset().left;
menu.offset({left : left});
menu.show();
menu.slideDown();
}
event.stopPropagation();
}
Expand All @@ -128,18 +133,18 @@ <h3>Version 2.3</h3>
}

function upload_file(event) {
$('.menu-content').hide();
$('.menu-content').slideUp();
$('#upload').click();
}

$("body").click(function() {
$('.menu-content').hide();
$('.menu-content').slideUp();
$('#about').hide();
});

function show_about(event) {
$('.menu-content').slideUp();
$('#about').show();
$('.menu-content').hide();
event.stopPropagation();
}

Expand All @@ -150,8 +155,6 @@ <h3>Version 2.3</h3>
}
var https = document.location.protocol=="https:";

var getparam = Utilities.getparam;
var getboolparam = Utilities.getboolparam;
// look at url parameters
var username = getparam("username") || null;
var password = getparam("password") || null;
Expand Down Expand Up @@ -533,6 +536,37 @@ <h3>Version 2.3</h3>
});
}

function init_clock(client) {
function update_clock() {
var now = new Date().getTime();
var server_time = client.last_ping_server_time + (now - client.last_ping_local_time);
var date = new Date(server_time);
cdebug("update_clock() server_time=", server_time, "date=", date.toLocaleDateString());
$("#clock_text").text(date.toLocaleDateString()+" "+date.toLocaleTimeString());
//try to land at the half-second point,
//so that we never miss displaying a second:
var delay = (1500-(server_time % 1000)) % 1000;
if (delay<10) {
delay = 1000;
}
setTimeout(update_clock, delay);
}

function wait_for_time() {
cdebug("wait_for_time() last_ping_local_time=", client.last_ping_local_time);
if (client.last_ping_local_time>0) {
update_clock();
}
else {
//check again soon:
//(ideally, we should register a callback on the ping packet)
setTimeout(wait_for_time, 1000);
}
}
wait_for_time();
}


var client = null;
$(document).ready(function() {
client = init_client();
Expand All @@ -556,6 +590,9 @@ <h3>Version 2.3</h3>
else {
$('upload_link').removeAttr('href');
}
if (getboolparam("clock")) {
init_clock(client);
}
});
</script>
</body>
Expand Down
8 changes: 8 additions & 0 deletions src/html5/js/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ XpraClient.prototype.init_state = function(container) {
this.ping_timeout_timer = null;
this.ping_grace_timer = null;
this.ping_timer = null;
this.last_ping_server_time = 0
this.last_ping_local_time = 0
this.last_ping_echoed_time = 0;
this.server_ok = false;
//packet handling
Expand Down Expand Up @@ -1818,6 +1820,12 @@ XpraClient.prototype._gendigest = function(digest, password, salt) {

XpraClient.prototype._process_ping = function(packet, ctx) {
var echotime = packet[1];
ctx.last_ping_server_time = echotime;
if (packet.length>2) {
//prefer system time (packet[1] is monotonic)
ctx.last_ping_server_time = packet[2];
}
ctx.last_ping_local_time = new Date().getTime();
var l1=0, l2=0, l3=0;
ctx.send(["ping_echo", echotime, l1, l2, l3, 0]);
}
Expand Down
3 changes: 2 additions & 1 deletion src/xpra/server/source/networkstate_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ def ping(self):
#NOTE: all ping time/echo time/load avg values are in milliseconds
now_ms = int(1000*monotonic_time())
log("sending ping to %s with time=%s", self.protocol, now_ms)
self.send_async("ping", now_ms, will_have_more=False)
import time
self.send_async("ping", now_ms, int(time.time()*1000), will_have_more=False)
timeout = PING_TIMEOUT
self.check_ping_echo_timers[now_ms] = self.timeout_add(timeout*1000, self.check_ping_echo_timeout, now_ms, timeout)

Expand Down

0 comments on commit 607c132

Please sign in to comment.