PageRenderTime 25ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/js/lib/Socket.IO-node/support/socket.io-client/lib/transports/xhr-polling.js

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
JavaScript | 62 lines | 45 code | 10 blank | 7 comment | 8 complexity | ad825fe5b88319a77a1a50cda00c9dbf MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, MPL-2.0-no-copyleft-exception, BSD-3-Clause
  1. /**
  2. * Socket.IO client
  3. *
  4. * @author Guillermo Rauch <guillermo@learnboost.com>
  5. * @license The MIT license.
  6. * @copyright Copyright (c) 2010 LearnBoost <dev@learnboost.com>
  7. */
  8. (function(){
  9. var io = this.io;
  10. var empty = new Function(),
  11. XHRPolling = io.Transport['xhr-polling'] = function(){
  12. io.Transport.XHR.apply(this, arguments);
  13. };
  14. io.util.inherit(XHRPolling, io.Transport.XHR);
  15. XHRPolling.prototype.type = 'xhr-polling';
  16. XHRPolling.prototype.connect = function(){
  17. if (io.util.ios || io.util.android){
  18. var self = this;
  19. io.util.load(function(){
  20. setTimeout(function(){
  21. io.Transport.XHR.prototype.connect.call(self);
  22. }, 10);
  23. });
  24. } else {
  25. io.Transport.XHR.prototype.connect.call(this);
  26. }
  27. };
  28. XHRPolling.prototype._get = function(){
  29. var self = this;
  30. this._xhr = this._request(+ new Date, 'GET');
  31. this._xhr.onreadystatechange = function(){
  32. var status;
  33. if (self._xhr.readyState == 4){
  34. self._xhr.onreadystatechange = empty;
  35. try { status = self._xhr.status; } catch(e){}
  36. if (status == 200){
  37. self._onData(self._xhr.responseText);
  38. self._get();
  39. } else {
  40. self._onDisconnect();
  41. }
  42. }
  43. };
  44. this._xhr.send(null);
  45. };
  46. XHRPolling.check = function(){
  47. return io.Transport.XHR.check();
  48. };
  49. XHRPolling.xdomainCheck = function(){
  50. return io.Transport.XHR.xdomainCheck();
  51. };
  52. })();