/sub-projects/jquery-stream-atmosphere/trunk/src/main/webapp/jquery.stream.atmosphere.js

http://jquery-stream.googlecode.com/ · JavaScript · 43 lines · 13 code · 7 blank · 23 comment · 1 complexity · 0b72ece2bc15a2304ce69c6a3d30e1f5 MD5 · raw file

  1. /*
  2. * Atmosphere plugin for jQuery Stream
  3. * http://atmosphere.java.net/
  4. * http://code.google.com/p/jquery-stream/
  5. *
  6. * Copyright 2011, Donghwan Kim
  7. * Licensed under the Apache License, Version 2.0
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Compatible with jQuery Stream 1.2+
  11. */
  12. (function($) {
  13. // Default configurations
  14. $.stream.setup({
  15. // Atmosphere runs on any Java based web server maintaining session using JSESSIONID cookie
  16. // and sets 'Access-Control-Allow-Origin' header to '*' unless 'enableAccessControl' option is not false
  17. enableXDR: true,
  18. // Atmosphere always prints junk padding ending with <!-- EOD --> wisely
  19. // and there is no identifier concept
  20. handleOpen: function(text, message) {
  21. // 'Content-Type' header of the response must be set to 'text/plain'
  22. // message.index = text.indexOf("<!-- EOD -->") + "<!-- EOD -->".length;
  23. message.index = text.indexOf("<!-- EOD -->") + 12;
  24. },
  25. // This plugin assumes that you can send message in accord with the default message format
  26. // if not possible, you can parse the response chunks directly by implementing the following handler
  27. // handleMessage: function(text, message, stream) {},
  28. // Atmosphere doesn't need metadata
  29. handleSend: function(type) {
  30. // All except send-type request will be canceled
  31. if (type !== "send") {
  32. return false;
  33. }
  34. }
  35. });
  36. })(jQuery);