/sub-projects/jquery-stream-atmosphere/trunk/src/main/webapp/jquery.stream.atmosphere.js
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 14 // Default configurations 15 $.stream.setup({ 16 17 // Atmosphere runs on any Java based web server maintaining session using JSESSIONID cookie 18 // and sets 'Access-Control-Allow-Origin' header to '*' unless 'enableAccessControl' option is not false 19 enableXDR: true, 20 21 // Atmosphere always prints junk padding ending with <!-- EOD --> wisely 22 // and there is no identifier concept 23 handleOpen: function(text, message) { 24 // 'Content-Type' header of the response must be set to 'text/plain' 25 // message.index = text.indexOf("<!-- EOD -->") + "<!-- EOD -->".length; 26 message.index = text.indexOf("<!-- EOD -->") + 12; 27 }, 28 29 // This plugin assumes that you can send message in accord with the default message format 30 // if not possible, you can parse the response chunks directly by implementing the following handler 31 // handleMessage: function(text, message, stream) {}, 32 33 // Atmosphere doesn't need metadata 34 handleSend: function(type) { 35 // All except send-type request will be canceled 36 if (type !== "send") { 37 return false; 38 } 39 } 40 41 }); 42 43})(jQuery);