Last active
April 9, 2019 01:43
-
-
Save mouWorks/0af99347dd81bc62aeb4208b1bdbcef4 to your computer and use it in GitHub Desktop.
timeSync
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##PseudoCode - Just an example | |
## TBD - Not complete yet. | |
var mountAdjustDiff = function(start) { | |
if(start == 'undefined'){ | |
return; | |
} | |
var getTimeUrl = 'http://localhost:8080/index.php/time'; //ServerTime url | |
beforeTime = Date.now(); //送出Request之前先記一個 timestamp //t1 | |
$.ajax(getTimeUrl, { | |
type: 'GET', | |
success: function(response) { | |
response = JSON.parse(response); | |
var clientTime, timeDiff, serverTime; | |
// Get offset | |
clientTime = Date.now(); //Ajax Call 結束後再記一個 timestamp (t4) | |
timeDiff = (clientTime-beforeTime)/2; //ClientEnd - Client Begin = 去程 t4-t1/2 | |
serverReplyTime = response.body.time; //t3 -> Call Server時, Server傳回的時間 | |
//This is the answer | |
// t3 + (t4-t1) / 2 | |
adjustValue = response.body.time + timeDiff; | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment