access-point-client.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. FS.HTTP.setHeadersForGet = function setHeadersForGet() {
  2. // Client Stub
  3. };
  4. FS.HTTP.now = function() {
  5. return new Date(new Date() + FS.HTTP._serverTimeDiff);
  6. };
  7. // Returns the localstorage if its found and working
  8. // TODO: check if this works in IE
  9. // could use Meteor._localStorage - just needs a rewrite
  10. FS.HTTP._storage = function() {
  11. var storage,
  12. fail,
  13. uid;
  14. try {
  15. uid = "test";
  16. (storage = window.localStorage).setItem(uid, uid);
  17. fail = (storage.getItem(uid) !== uid);
  18. storage.removeItem(uid);
  19. if (fail) {
  20. storage = false;
  21. }
  22. } catch(e) {
  23. console.log("Error initializing storage for FS.HTTP");
  24. console.log(e);
  25. }
  26. return storage;
  27. };
  28. // get our storage if found
  29. FS.HTTP.storage = FS.HTTP._storage();
  30. FS.HTTP._prefix = 'fsHTTP.';
  31. FS.HTTP._serverTimeDiff = 0; // Time difference in ms
  32. if (FS.HTTP.storage) {
  33. // Initialize the FS.HTTP._serverTimeDiff
  34. FS.HTTP._serverTimeDiff = (1*FS.HTTP.storage.getItem(FS.HTTP._prefix+'timeDiff')) || 0;
  35. // At client startup we figure out the time difference between server and
  36. // client time - this includes lag and timezone
  37. Meteor.startup(function() {
  38. // Call the server method an get server time
  39. HTTP.get(rootUrlPathPrefix + '/cfs/servertime', function(error, result) {
  40. if (!error) {
  41. // Update our server time diff
  42. var dateNew = new Date(+result.content);
  43. FS.HTTP._serverTimeDiff = dateNew - new Date();// - lag or/and timezone
  44. // Update the localstorage
  45. FS.HTTP.storage.setItem(FS.HTTP._prefix + 'timeDiff', FS.HTTP._serverTimeDiff);
  46. } else {
  47. console.log(error.message);
  48. }
  49. }); // EO Server call
  50. });
  51. }