add setting for mouse polling interval
This commit is contained in:
parent
931dff5f04
commit
5ef0e86ab8
3 changed files with 30 additions and 6 deletions
File diff suppressed because one or more lines are too long
8
main.go
8
main.go
|
|
@ -43,6 +43,7 @@ const (
|
|||
authenticationRateLimit time.Duration = time.Second / 10
|
||||
authenticationRateBurst int = 10
|
||||
challengeLength int = 8
|
||||
defaultUpdateInterval int = 50
|
||||
defaultBind string = ":0"
|
||||
version string = "0.0.3"
|
||||
)
|
||||
|
|
@ -127,12 +128,15 @@ func secureRandBase64(length int) string {
|
|||
func main() {
|
||||
var bind, certFile, keyFile, secret string
|
||||
var showVersion, invert bool
|
||||
var updateInterval int
|
||||
flag.BoolVar(&showVersion, "version", false, "show program's version number and exit")
|
||||
flag.StringVar(&bind, "bind", defaultBind, "bind server to [IP]:PORT")
|
||||
flag.StringVar(&secret, "secret", "", "shared secret for client authentication")
|
||||
flag.StringVar(&certFile, "cert", "", "file containing TLS certificate")
|
||||
flag.StringVar(&keyFile, "key", "", "file containing TLS private key")
|
||||
flag.BoolVar(&invert, "invert", false, "use inverse colors for QR code")
|
||||
flag.IntVar(&updateInterval, "interval", defaultUpdateInterval,
|
||||
"mouse polling interval in milliseconds")
|
||||
flag.Parse()
|
||||
if showVersion {
|
||||
fmt.Println(version)
|
||||
|
|
@ -148,6 +152,9 @@ func main() {
|
|||
if secret == "" {
|
||||
secret = secureRandBase64(defaultSecretLength)
|
||||
}
|
||||
if updateInterval < 0 {
|
||||
log.Fatal("interval must be greater or equal to zero")
|
||||
}
|
||||
var plugin Plugin
|
||||
platformErrors := ""
|
||||
for _, f := range Plugins {
|
||||
|
|
@ -199,6 +206,7 @@ func main() {
|
|||
if !challenge.verify(message) {
|
||||
return
|
||||
}
|
||||
websocket.Message.Send(ws, fmt.Sprintf("i%d", updateInterval))
|
||||
for {
|
||||
if err := websocket.Message.Receive(ws, &message); err != nil {
|
||||
return
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ const MOVE_MULT = 1;
|
|||
const SCROLL_MULT = 0.05;
|
||||
// [[px/s, mult], ...]
|
||||
const POINTER_ACCELERATION = [[0, 0], [87, 1], [173, 1], [553, 2]];
|
||||
const UPDATE_INTERVAL = 50;
|
||||
const MAX_IDLE_UPDATES = 10;
|
||||
|
||||
var ws;
|
||||
|
|
@ -43,6 +42,7 @@ var scrollYSum = 0;
|
|||
var dragging = false;
|
||||
var draggingTimeout = null;
|
||||
var updateTimer = null;
|
||||
var updateInterval = 0;
|
||||
var idleUpdates = 0;
|
||||
|
||||
function fullscreenEnabled() {
|
||||
|
|
@ -147,8 +147,8 @@ function onDraggingTimeout() {
|
|||
function updateMoveAndScroll() {
|
||||
if (updateTimer == null) {
|
||||
onUpdateTimeout();
|
||||
if (UPDATE_INTERVAL > 0 && idleUpdates == 0) {
|
||||
updateTimer = setInterval(onUpdateTimeout, UPDATE_INTERVAL);
|
||||
if (updateInterval > 0 && idleUpdates == 0) {
|
||||
updateTimer = setInterval(onUpdateTimeout, updateInterval);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -298,6 +298,20 @@ function challengeResponse(message) {
|
|||
return btoa(shaObj.getHMAC("BYTES"));
|
||||
}
|
||||
|
||||
function processCommand(message) {
|
||||
if (message.charAt(0) == "i") {
|
||||
var x = parseInt(message.substr(1));
|
||||
if (isNaN(x) || x.toString() != message.substr(1) || x < 0) {
|
||||
return false;
|
||||
}
|
||||
updateInterval = x;
|
||||
clearInterval(updateTimer);
|
||||
updateTimer = null;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
window.addEventListener("load", function() {
|
||||
var authenticated = false;
|
||||
var opening = document.getElementById("opening");
|
||||
|
|
@ -322,7 +336,9 @@ window.addEventListener("load", function() {
|
|||
|
||||
ws.onmessage = function(event) {
|
||||
if (authenticated) {
|
||||
ws.close();
|
||||
if (!processCommand(event.data)) {
|
||||
ws.close();
|
||||
}
|
||||
return;
|
||||
}
|
||||
authenticated = true;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue