mirror of https://github.com/nealey/vail.git
Fix to clock skew bug
This commit is contained in:
parent
bbc788d829
commit
dcf10eb123
|
@ -294,6 +294,7 @@ class Vail {
|
||||||
this.clockOffset = 0 // How badly our clock is off of the server's
|
this.clockOffset = 0 // How badly our clock is off of the server's
|
||||||
this.rxDelay = 0 // Milliseconds to add to incoming timestamps
|
this.rxDelay = 0 // Milliseconds to add to incoming timestamps
|
||||||
this.beginTxTime = null // Time when we began transmitting
|
this.beginTxTime = null // Time when we began transmitting
|
||||||
|
this.debug = localStorage.debug
|
||||||
|
|
||||||
this.openSocket()
|
this.openSocket()
|
||||||
|
|
||||||
|
@ -460,7 +461,7 @@ class Vail {
|
||||||
}
|
}
|
||||||
|
|
||||||
wsSend(time, duration) {
|
wsSend(time, duration) {
|
||||||
let msg = [time + this.clockOffset, duration]
|
let msg = [time - this.clockOffset, duration]
|
||||||
let jmsg = JSON.stringify(msg)
|
let jmsg = JSON.stringify(msg)
|
||||||
this.socket.send(jmsg)
|
this.socket.send(jmsg)
|
||||||
this.sent.push(jmsg)
|
this.sent.push(jmsg)
|
||||||
|
@ -480,14 +481,8 @@ class Vail {
|
||||||
let beginTxTime = msg[0]
|
let beginTxTime = msg[0]
|
||||||
let durations = msg.slice(1)
|
let durations = msg.slice(1)
|
||||||
|
|
||||||
// Server is telling us the current time
|
if (this.debug) {
|
||||||
if (durations.length == 0) {
|
console.log("recv", beginTxTime, durations)
|
||||||
let offset = now - beginTxTime
|
|
||||||
if (this.clockOffset == 0) {
|
|
||||||
this.clockOffset = offset
|
|
||||||
this.updateReadings()
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let sent = this.sent.filter(e => e != jmsg)
|
let sent = this.sent.filter(e => e != jmsg)
|
||||||
|
@ -500,9 +495,25 @@ class Vail {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Server is telling us the current time
|
||||||
|
if (durations.length == 0) {
|
||||||
|
let offset = now - beginTxTime
|
||||||
|
if (this.clockOffset == 0) {
|
||||||
|
this.clockOffset = offset
|
||||||
|
this.updateReadings()
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Why is this happening?
|
||||||
|
if (beginTxTime == 0) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add rxDelay
|
||||||
let adjustedTxTime = beginTxTime+this.rxDelay
|
let adjustedTxTime = beginTxTime+this.rxDelay
|
||||||
if (adjustedTxTime < now) {
|
if (adjustedTxTime < now) {
|
||||||
|
console.log("adjustedTxTime: ", adjustedTxTime, " now: ", now)
|
||||||
this.error("Packet requested playback " + (now - adjustedTxTime) + "ms in the past. Increase receive delay!")
|
this.error("Packet requested playback " + (now - adjustedTxTime) + "ms in the past. Increase receive delay!")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue