Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

updated jetty to version 7.5.4, updated atmosphere to 0.8.4

  • Loading branch information...
commit 7c44267b81fcfeb332a5b2276d7569cffc49a930 1 parent 25bac38
@haed authored
Showing with 301 additions and 330 deletions.
  1. +4 −4 src/java/haed/notification/NotificationAPI.java
  2. +44 −59 src/java/haed/notification/NotificationBroadcaster.java
  3. +3 −12 src/java/haed/notification/NotificationMgr.java
  4. BIN  webroot/WEB-INF/lib.src/atmosphere-annotations-0.8.4-sources.jar
  5. BIN  webroot/WEB-INF/lib.src/atmosphere-compat-jbossweb-0.8.4-sources.jar
  6. BIN  webroot/WEB-INF/lib.src/atmosphere-compat-tomcat-0.8.4-sources.jar
  7. BIN  webroot/WEB-INF/lib.src/atmosphere-compat-tomcat7-0.8.4-sources.jar
  8. BIN  webroot/WEB-INF/lib.src/atmosphere-compat-weblogic-0.8.4-sources.jar
  9. BIN  webroot/WEB-INF/lib.src/atmosphere-jersey-0.8.4-sources.jar
  10. BIN  webroot/WEB-INF/lib.src/atmosphere-runtime-0.8.4-sources.jar
  11. BIN  webroot/WEB-INF/lib/atmosphere-annotations-0.8.1.jar
  12. BIN  webroot/WEB-INF/lib/atmosphere-annotations-0.8.4.jar
  13. BIN  webroot/WEB-INF/lib/atmosphere-compat-jbossweb-0.8.1.jar
  14. BIN  webroot/WEB-INF/lib/atmosphere-compat-jbossweb-0.8.4.jar
  15. BIN  webroot/WEB-INF/lib/{atmosphere-compat-jetty-0.8.1.jar → atmosphere-compat-jetty-0.8.4.jar}
  16. BIN  webroot/WEB-INF/lib/atmosphere-compat-tomcat-0.8.1.jar
  17. BIN  webroot/WEB-INF/lib/atmosphere-compat-tomcat-0.8.4.jar
  18. BIN  webroot/WEB-INF/lib/atmosphere-compat-tomcat7-0.8.4.jar
  19. BIN  webroot/WEB-INF/lib/atmosphere-compat-weblogic-0.8.1.jar
  20. BIN  webroot/WEB-INF/lib/atmosphere-compat-weblogic-0.8.4.jar
  21. BIN  webroot/WEB-INF/lib/atmosphere-jersey-0.8.1.jar
  22. BIN  webroot/WEB-INF/lib/atmosphere-jersey-0.8.4.jar
  23. BIN  webroot/WEB-INF/lib/atmosphere-runtime-0.8.1.jar
  24. BIN  webroot/WEB-INF/lib/atmosphere-runtime-0.8.4.jar
  25. BIN  webroot/WEB-INF/lib/jetty-ajp-7.4.2.v20110526.jar
  26. BIN  webroot/WEB-INF/lib/jetty-ajp-7.5.4.v20111024.jar
  27. BIN  webroot/WEB-INF/lib/jetty-all-7.5.4.v20111024-javadoc.jar
  28. BIN  webroot/WEB-INF/lib/jetty-annotations-7.4.2.v20110526.jar
  29. BIN  webroot/WEB-INF/lib/jetty-annotations-7.5.4.v20111024.jar
  30. BIN  webroot/WEB-INF/lib/jetty-client-7.4.2.v20110526.jar
  31. BIN  webroot/WEB-INF/lib/jetty-client-7.5.4.v20111024.jar
  32. BIN  webroot/WEB-INF/lib/{jetty-continuation-7.4.2.v20110526.jar → jetty-continuation-7.5.4.v20111024.jar}
  33. BIN  webroot/WEB-INF/lib/jetty-deploy-7.4.2.v20110526.jar
  34. BIN  webroot/WEB-INF/lib/jetty-deploy-7.5.4.v20111024.jar
  35. BIN  webroot/WEB-INF/lib/jetty-http-7.4.2.v20110526.jar
  36. BIN  webroot/WEB-INF/lib/jetty-http-7.5.4.v20111024.jar
  37. BIN  webroot/WEB-INF/lib/jetty-io-7.4.2.v20110526.jar
  38. BIN  webroot/WEB-INF/lib/jetty-io-7.5.4.v20111024.jar
  39. BIN  webroot/WEB-INF/lib/jetty-jmx-7.4.2.v20110526.jar
  40. BIN  webroot/WEB-INF/lib/jetty-jmx-7.5.4.v20111024.jar
  41. BIN  webroot/WEB-INF/lib/jetty-jndi-7.4.2.v20110526.jar
  42. BIN  webroot/WEB-INF/lib/jetty-jndi-7.5.4.v20111024.jar
  43. BIN  .../WEB-INF/lib/{jetty-overlay-deployer-7.4.2.v20110526.jar → jetty-overlay-deployer-7.5.4.v20111024.jar}
  44. BIN  webroot/WEB-INF/lib/jetty-plus-7.4.2.v20110526.jar
  45. BIN  webroot/WEB-INF/lib/jetty-plus-7.5.4.v20111024.jar
  46. BIN  webroot/WEB-INF/lib/{jetty-policy-7.4.2.v20110526.jar → jetty-policy-7.5.4.v20111024.jar}
  47. BIN  webroot/WEB-INF/lib/jetty-rewrite-7.4.2.v20110526.jar
  48. BIN  webroot/WEB-INF/lib/jetty-rewrite-7.5.4.v20111024.jar
  49. BIN  webroot/WEB-INF/lib/jetty-security-7.4.2.v20110526.jar
  50. BIN  webroot/WEB-INF/lib/jetty-security-7.5.4.v20111024.jar
  51. BIN  webroot/WEB-INF/lib/jetty-server-7.4.2.v20110526.jar
  52. BIN  webroot/WEB-INF/lib/jetty-server-7.5.4.v20111024.jar
  53. BIN  webroot/WEB-INF/lib/jetty-servlet-7.4.2.v20110526.jar
  54. BIN  webroot/WEB-INF/lib/jetty-servlet-7.5.4.v20111024.jar
  55. BIN  webroot/WEB-INF/lib/jetty-servlets-7.4.2.v20110526.jar
  56. BIN  webroot/WEB-INF/lib/jetty-servlets-7.5.4.v20111024.jar
  57. BIN  webroot/WEB-INF/lib/jetty-util-7.4.2.v20110526.jar
  58. BIN  webroot/WEB-INF/lib/jetty-util-7.5.4.v20111024.jar
  59. BIN  webroot/WEB-INF/lib/jetty-webapp-7.4.2.v20110526.jar
  60. BIN  webroot/WEB-INF/lib/jetty-webapp-7.5.4.v20111024.jar
  61. BIN  webroot/WEB-INF/lib/jetty-websocket-7.4.2.v20110526.jar
  62. BIN  webroot/WEB-INF/lib/jetty-websocket-7.5.4.v20111024.jar
  63. BIN  webroot/WEB-INF/lib/jetty-xml-7.4.2.v20110526.jar
  64. BIN  webroot/WEB-INF/lib/jetty-xml-7.5.4.v20111024.jar
  65. +1 −2  webroot/WEB-INF/web.xml
  66. +3 −170 webroot/js/haed.notification.js
  67. +246 −83 webroot/js/jquery.atmosphere.js
View
8 src/java/haed/notification/NotificationAPI.java
@@ -102,8 +102,8 @@ public Response createChannel()
final NotificationBroadcaster _broadCaster = broadCaster;
final SuspendResponseBuilder<String> suspendResponseBuilder = new SuspendResponse.SuspendResponseBuilder<String>()
- .period(1, TimeUnit.MINUTES)
-// .period(20, TimeUnit.SECONDS) // stress test setting
+// .period(1, TimeUnit.MINUTES)
+ .period(20, TimeUnit.SECONDS) // stress test setting
.addListener(new AtmosphereResourceEventListener() {
@@ -120,7 +120,7 @@ public void onSuspend(final AtmosphereResourceEvent<HttpServletRequest, HttpServ
// // process queued notifications: re-check if broadcaster was absent (because of all resources were disconnected)
// notificationMgr.processQueue(channelID, _broadCaster);
- _broadCaster.processCache();
+// _broadCaster.processCache();
}
public void onResume(final AtmosphereResourceEvent<HttpServletRequest, HttpServletResponse> event) {
@@ -136,7 +136,7 @@ public void onDisconnect(final AtmosphereResourceEvent<HttpServletRequest, HttpS
// NOTE: disconnect also happens in "connected"-environments, e.g. on suspend timeout (after 5 minutes)
if (logger.isDebugEnabled())
- logger.debug("channel with id '" + channelID + "' disconnected");
+ logger.info("channel with id '" + channelID + "' disconnected");
// TODO [haed]: this is uncommented for testing, maybe a "buggy" destroy kills all subscriptions
// -> if this works, we do not need a scheduled destroy on suspend, we can use onDisconnect
View
103 src/java/haed/notification/NotificationBroadcaster.java
@@ -11,18 +11,10 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
-import javax.servlet.http.HttpServletRequest;
-
import org.apache.log4j.Logger;
import org.atmosphere.cpr.AtmosphereResource;
-import org.atmosphere.cpr.AtmosphereResourceEvent;
import org.atmosphere.cpr.AtmosphereServlet.AtmosphereConfig;
-import org.atmosphere.cpr.BroadcasterLifeCyclePolicyListener;
-import org.atmosphere.cpr.FrameworkConfig;
import org.atmosphere.jersey.JerseyBroadcaster;
-import org.atmosphere.jersey.util.JerseyBroadcasterUtil;
-
-import com.sun.jersey.spi.container.ContainerResponse;
public class NotificationBroadcaster extends JerseyBroadcaster {
@@ -44,7 +36,9 @@ public void run() {
if (logger.isDebugEnabled())
logger.debug("check destruction queue, " + destructionQueue.size() + " elements before check");
- final long t = System.currentTimeMillis() - (1000 * 60 * 5); // destroy all broadcaster which are more than 5 minutes in destruction queue
+// final long t = System.currentTimeMillis() - (1000 * 60 * 5); // destroy all broadcaster which are more than 5 minutes in destruction queue
+
+ final long t = System.currentTimeMillis() - (1000 * 10);
synchronized (destructionQueue) {
for (final Iterator<Map.Entry<String, Long>> iter = destructionQueue.entrySet().iterator(); iter.hasNext(); ) {
@@ -77,7 +71,7 @@ public void run() {
// overrides the underlying broadcaster cache
- private final NotificationBroadcasterCache broadcasterCache = new NotificationBroadcasterCache();
+// private final NotificationBroadcasterCache broadcasterCache = new NotificationBroadcasterCache();
// private boolean send = false;
@@ -123,39 +117,44 @@ public NotificationBroadcaster(final String id, final AtmosphereConfig config) {
return resource;
}
- @Override
- protected void checkCachedAndPush(final AtmosphereResource<?, ?> r, final AtmosphereResourceEvent e) {
-
- // make nothing
-
-// retrieveTrackedBroadcast(r, e);
-// if (e.getMessage() instanceof List && !((List) e.getMessage()).isEmpty()) {
-// HttpServletRequest.class.cast(r.getRequest()).setAttribute(CACHED, "true");
-// // Must make sure execute only one thread
-// synchronized (r) {
-// broadcast(r, e);
-// }
-// }
- }
- // TODO @haed [haed]: remove if long-polling bug is solved (issue https://github.com/Atmosphere/atmosphere/issues/81)
- @Override
- protected void broadcast(final AtmosphereResource<?, ?> r, final AtmosphereResourceEvent e) {
-
- final ContainerResponse containerResponse = (ContainerResponse) ((HttpServletRequest) r.getRequest()).getAttribute(FrameworkConfig.CONTAINER_RESPONSE);
- if (containerResponse == null || resources.isEmpty()) {
-
- if (logger.isInfoEnabled())
- logger.info("resource is not connected, re-add message to cache, channelID: " + getID() + ", message: " + e.getMessage());
-
- // resource is not connected, re-queue
- broadcasterCache.addToCache(null, e.getMessage());
-
- } else
- // resource is connected, go forward
- JerseyBroadcasterUtil.broadcast(r, e);
- }
+// @Override
+// protected void checkCachedAndPush(final AtmosphereResource<?, ?> r, final AtmosphereResourceEvent e) {
+//
+// // make nothing
+//
+//// retrieveTrackedBroadcast(r, e);
+//// if (e.getMessage() instanceof List && !((List) e.getMessage()).isEmpty()) {
+//// HttpServletRequest.class.cast(r.getRequest()).setAttribute(CACHED, "true");
+//// // Must make sure execute only one thread
+//// synchronized (r) {
+//// broadcast(r, e);
+//// }
+//// }
+// }
+
+
+// // TODO @haed [haed]: remove if long-polling bug is solved (issue https://github.com/Atmosphere/atmosphere/issues/81)
+// @Override
+// protected void broadcast(final AtmosphereResource<?, ?> r, final AtmosphereResourceEvent e) {
+//
+// final ContainerResponse containerResponse = (ContainerResponse) ((HttpServletRequest) r.getRequest()).getAttribute(FrameworkConfig.CONTAINER_RESPONSE);
+// if (containerResponse == null || resources.isEmpty()) {
+//
+// if (logger.isInfoEnabled())
+// logger.info("resource is not connected, re-add message to cache, channelID: " + getID() + ", message: " + e.getMessage());
+//
+// // resource is not connected, re-queue
+// broadcasterCache.addToCache(null, e.getMessage());
+//
+// } else
+// // resource is connected, go forward
+// JerseyBroadcasterUtil.broadcast(r, e, this);
+// }
+
+
+
private boolean send = false;
@@ -189,10 +188,10 @@ public void send(final Object message) {
}
}
- protected void processCache() {
- for (final Object message: broadcasterCache.retrieveFromCache(null))
- send(message);
- }
+// protected void processCache() {
+// for (final Object message: broadcasterCache.retrieveFromCache(null))
+// send(message);
+// }
// @Override
@@ -205,20 +204,6 @@ protected void processCache() {
// return false;
// }
-
- @Override
- public void destroy() {
-
- super.destroy();
-
- // TODO @haed [haed]: atmosphere does not call BroadcasterLifeCyclePolicyListener#onDestroy on explicitly calling broadcaster#destroy().
- // => we have to override to trigger custom logic
- // - remove if atmosphere works like expected
- // GitHub issue: https://github.com/Atmosphere/atmosphere/issues/83
- for (final BroadcasterLifeCyclePolicyListener b: lifeCycleListeners)
- b.onDestroy();
- }
-
public boolean addSubscription(final String notificationType) {
return subscribedNotificationTypes.add(notificationType);
}
View
15 src/java/haed/notification/NotificationMgr.java
@@ -5,7 +5,7 @@
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicLong;
import org.apache.log4j.Logger;
import org.atmosphere.cpr.BroadcasterFactory;
@@ -55,7 +55,7 @@ public static void useExecutorService(ScheduledExecutorService service) {
// */
// private final Map<String, LinkedList<Long>> queues = new HashMap<String, LinkedList<Long>>();
- private final AtomicInteger notificationID = new AtomicInteger(1);
+ private final AtomicLong notificationID = new AtomicLong(1);
// private final long time2NotificationIdThreshold = 1000;
// private long currentTime2NotificationId = 0;
@@ -69,16 +69,7 @@ private NotificationMgr() {
}
private long createNotificationID() {
-
- final long id = notificationID.incrementAndGet();
-
-// final long now = System.currentTimeMillis();
-// if (now - currentTime2NotificationId > time2NotificationIdThreshold) {
-// currentTime2NotificationId = now;
-// time2NotificationId.put(currentTime2NotificationId, id);
-// }
-
- return id;
+ return notificationID.incrementAndGet();
}
View
BIN  webroot/WEB-INF/lib.src/atmosphere-annotations-0.8.4-sources.jar
Binary file not shown
View
BIN  webroot/WEB-INF/lib.src/atmosphere-compat-jbossweb-0.8.4-sources.jar
Binary file not shown
View
BIN  webroot/WEB-INF/lib.src/atmosphere-compat-tomcat-0.8.4-sources.jar
Binary file not shown
View
BIN  webroot/WEB-INF/lib.src/atmosphere-compat-tomcat7-0.8.4-sources.jar
Binary file not shown
View
BIN  webroot/WEB-INF/lib.src/atmosphere-compat-weblogic-0.8.4-sources.jar
Binary file not shown
View
BIN  webroot/WEB-INF/lib.src/atmosphere-jersey-0.8.4-sources.jar
Binary file not shown
View
BIN  webroot/WEB-INF/lib.src/atmosphere-runtime-0.8.4-sources.jar
Binary file not shown
View
BIN  webroot/WEB-INF/lib/atmosphere-annotations-0.8.1.jar
Binary file not shown
View
BIN  webroot/WEB-INF/lib/atmosphere-annotations-0.8.4.jar
Binary file not shown
View
BIN  webroot/WEB-INF/lib/atmosphere-compat-jbossweb-0.8.1.jar
Binary file not shown
View
BIN  webroot/WEB-INF/lib/atmosphere-compat-jbossweb-0.8.4.jar
Binary file not shown
View
BIN  ...oot/WEB-INF/lib/atmosphere-compat-jetty-0.8.1.jar → ...oot/WEB-INF/lib/atmosphere-compat-jetty-0.8.4.jar
Binary file not shown
View
BIN  webroot/WEB-INF/lib/atmosphere-compat-tomcat-0.8.1.jar
Binary file not shown
View
BIN  webroot/WEB-INF/lib/atmosphere-compat-tomcat-0.8.4.jar
Binary file not shown
View
BIN  webroot/WEB-INF/lib/atmosphere-compat-tomcat7-0.8.4.jar
Binary file not shown
View
BIN  webroot/WEB-INF/lib/atmosphere-compat-weblogic-0.8.1.jar
Binary file not shown
View
BIN  webroot/WEB-INF/lib/atmosphere-compat-weblogic-0.8.4.jar
Binary file not shown
View
BIN  webroot/WEB-INF/lib/atmosphere-jersey-0.8.1.jar
Binary file not shown
View
BIN  webroot/WEB-INF/lib/atmosphere-jersey-0.8.4.jar
Binary file not shown
View
BIN  webroot/WEB-INF/lib/atmosphere-runtime-0.8.1.jar
Binary file not shown
View
BIN  webroot/WEB-INF/lib/atmosphere-runtime-0.8.4.jar
Binary file not shown
View
BIN  webroot/WEB-INF/lib/jetty-ajp-7.4.2.v20110526.jar
Binary file not shown
View
BIN  webroot/WEB-INF/lib/jetty-ajp-7.5.4.v20111024.jar
Binary file not shown
View
BIN  webroot/WEB-INF/lib/jetty-all-7.5.4.v20111024-javadoc.jar
Binary file not shown
View
BIN  webroot/WEB-INF/lib/jetty-annotations-7.4.2.v20110526.jar
Binary file not shown
View
BIN  webroot/WEB-INF/lib/jetty-annotations-7.5.4.v20111024.jar
Binary file not shown
View
BIN  webroot/WEB-INF/lib/jetty-client-7.4.2.v20110526.jar
Binary file not shown
View
BIN  webroot/WEB-INF/lib/jetty-client-7.5.4.v20111024.jar
Binary file not shown
View
BIN  ...EB-INF/lib/jetty-continuation-7.4.2.v20110526.jar → ...EB-INF/lib/jetty-continuation-7.5.4.v20111024.jar
Binary file not shown
View
BIN  webroot/WEB-INF/lib/jetty-deploy-7.4.2.v20110526.jar
Binary file not shown
View
BIN  webroot/WEB-INF/lib/jetty-deploy-7.5.4.v20111024.jar
Binary file not shown
View
BIN  webroot/WEB-INF/lib/jetty-http-7.4.2.v20110526.jar
Binary file not shown
View
BIN  webroot/WEB-INF/lib/jetty-http-7.5.4.v20111024.jar
Binary file not shown
View
BIN  webroot/WEB-INF/lib/jetty-io-7.4.2.v20110526.jar
Binary file not shown
View
BIN  webroot/WEB-INF/lib/jetty-io-7.5.4.v20111024.jar
Binary file not shown
View
BIN  webroot/WEB-INF/lib/jetty-jmx-7.4.2.v20110526.jar
Binary file not shown
View
BIN  webroot/WEB-INF/lib/jetty-jmx-7.5.4.v20111024.jar
Binary file not shown
View
BIN  webroot/WEB-INF/lib/jetty-jndi-7.4.2.v20110526.jar
Binary file not shown
View
BIN  webroot/WEB-INF/lib/jetty-jndi-7.5.4.v20111024.jar
Binary file not shown
View
BIN  ...NF/lib/jetty-overlay-deployer-7.4.2.v20110526.jar → ...NF/lib/jetty-overlay-deployer-7.5.4.v20111024.jar
Binary file not shown
View
BIN  webroot/WEB-INF/lib/jetty-plus-7.4.2.v20110526.jar
Binary file not shown
View
BIN  webroot/WEB-INF/lib/jetty-plus-7.5.4.v20111024.jar
Binary file not shown
View
BIN  webroot/WEB-INF/lib/jetty-policy-7.4.2.v20110526.jar → webroot/WEB-INF/lib/jetty-policy-7.5.4.v20111024.jar
Binary file not shown
View
BIN  webroot/WEB-INF/lib/jetty-rewrite-7.4.2.v20110526.jar
Binary file not shown
View
BIN  webroot/WEB-INF/lib/jetty-rewrite-7.5.4.v20111024.jar
Binary file not shown
View
BIN  webroot/WEB-INF/lib/jetty-security-7.4.2.v20110526.jar
Binary file not shown
View
BIN  webroot/WEB-INF/lib/jetty-security-7.5.4.v20111024.jar
Binary file not shown
View
BIN  webroot/WEB-INF/lib/jetty-server-7.4.2.v20110526.jar
Binary file not shown
View
BIN  webroot/WEB-INF/lib/jetty-server-7.5.4.v20111024.jar
Binary file not shown
View
BIN  webroot/WEB-INF/lib/jetty-servlet-7.4.2.v20110526.jar
Binary file not shown
View
BIN  webroot/WEB-INF/lib/jetty-servlet-7.5.4.v20111024.jar
Binary file not shown
View
BIN  webroot/WEB-INF/lib/jetty-servlets-7.4.2.v20110526.jar
Binary file not shown
View
BIN  webroot/WEB-INF/lib/jetty-servlets-7.5.4.v20111024.jar
Binary file not shown
View
BIN  webroot/WEB-INF/lib/jetty-util-7.4.2.v20110526.jar
Binary file not shown
View
BIN  webroot/WEB-INF/lib/jetty-util-7.5.4.v20111024.jar
Binary file not shown
View
BIN  webroot/WEB-INF/lib/jetty-webapp-7.4.2.v20110526.jar
Binary file not shown
View
BIN  webroot/WEB-INF/lib/jetty-webapp-7.5.4.v20111024.jar
Binary file not shown
View
BIN  webroot/WEB-INF/lib/jetty-websocket-7.4.2.v20110526.jar
Binary file not shown
View
BIN  webroot/WEB-INF/lib/jetty-websocket-7.5.4.v20111024.jar
Binary file not shown
View
BIN  webroot/WEB-INF/lib/jetty-xml-7.4.2.v20110526.jar
Binary file not shown
View
BIN  webroot/WEB-INF/lib/jetty-xml-7.5.4.v20111024.jar
Binary file not shown
View
3  webroot/WEB-INF/web.xml
@@ -18,11 +18,10 @@
<param-value>haed.notification.NotificationApplication</param-value>
</init-param>
- <!--
<init-param>
<param-name>org.atmosphere.cpr.broadcasterCacheClass</param-name>
<param-value>haed.notification.NotificationBroadcasterCache</param-value>
- </init-param>-->
+ </init-param>
<load-on-startup>1</load-on-startup>
</servlet>
View
173 webroot/js/haed.notification.js
@@ -87,26 +87,6 @@ haed.notification = (function() {
return function(response) {
-// console.log("response.responseBody: " + response.responseBody);
-// console.log("lastResponseBody: " + lastResponseBody);
-
-
- // HOTFIX (for 0.7.2, still in 0.8): atmosphere do not cut chunks out of the response body on polling (but in streaming it does)
- // => so we have to do it manually
- if (lastResponseBody.length > 0 && response.responseBody.indexOf(lastResponseBody) === 0) {
-
-// console.log("BUG");
-// console.log("response.responseBody: " + response.responseBody);
-// console.log("lastResponseBody: " + lastResponseBody);
-
-
- response.responseBody = response.responseBody.substring(lastResponseBody.length);
- lastResponseBody += response.responseBody;
- } else {
- lastResponseBody = response.responseBody;
- }
-
-
if (response.state === "messageReceived" && response.responseBody && response.responseBody.length > 0) {
stream += response.responseBody;
@@ -147,9 +127,10 @@ haed.notification = (function() {
jQuery.atmosphere.subscribe(baseURL + "notification/v1/openChannel?channelID=" + channelID + "&outputComments=true", null, {
-
+
// some stress test settings
- timeout: 1000 * 60 * 60, // 1 hour, server timeout must be lower
+ timeout: 1000 * 60 * 60, // 1 hour, server timeout must be lower
+// timeout: 1000 * 1, // stress test: 1sec
// suspend: false,
callback: callback,
@@ -287,12 +268,6 @@ haed.notification = (function() {
subscribe: function(notificationType, callback) {
-// haed.notification.subscribe(baseURL, channelID, notificationType, callback);
-
-// channels[baseURL] = channels[_baseURL] || {};
-// channels[baseURL][channelID] = channels[baseURL][channelID] || {};
-// channels[baseURL][channelID].subscriptions = channels[baseURL][channelID].subscriptions || {};
-
// TODO @haed subscriptions should be part of the channel instance
channels[baseURL][channelID].subscriptions = channels[baseURL][channelID].subscriptions || {};
var subscriptions = channels[baseURL][channelID].subscriptions;
@@ -326,163 +301,21 @@ haed.notification = (function() {
getDefaultChannel: function(baseURL) {
-// var deferred = new jQuery.Deferred();
-
var _baseURL = validateBaseURL(baseURL);
channels[_baseURL] = channels[_baseURL] || {};
-// channels[_baseURL]["default"] = channels[_baseURL]["default"] || {};
-
if (channels[_baseURL]["default"] === undefined) {
channels[_baseURL]["default"] = { deferred: haed.notification.createChannel(_baseURL) };
-
-// return haed.notification.createChannel(_baseURL)
-// .done(function(channel) {
-//// var p = channels[_baseURL]["default"].deferred;
-// channels[_baseURL]["default"] = channels[_baseURL][channel.getID()];
-//// channels[_baseURL]["default"].deferred = p;
-// });
}
return channels[_baseURL]["default"].deferred;
-
-// if (channels[_baseURL]["default"]) {
-// return channels[_baseURL]["default"].deferred;
-// } else {
-//// channels[_baseURL]["default"] = { deferred: new jQuery.Deferred() };
-// return haed.notification.createChannel(_baseURL)
-// .done(function(channel) {
-//
-// channels[_baseURL]["default"] = channels[_baseURL][channel.getID()];
-//
-//// channels[_baseURL][channel.getID()] = channels[_baseURL]["default"];
-//// channels[_baseURL][channel.getID()].channel = channel;
-//
-//// haed.notification.openChannel(_baseURL, channel.getID());
-//
-//// deferred.resolve(channel);
-// });
-//// .fail(deferred.reject);
-// }
-//
-//// return deferred.promise();
},
-
-// openChannel: function() {
-//
-// var createCallback = function(baseURL, channelID) {
-//
-// var lastResponseBody = "";
-//
-// var stream = "";
-//
-// return function(response) {
-//
-// // HOTFIX (for 0.7.2, still in 0.8): atmosphere do not cut chunks out of the response body on polling (but in streaming it does)
-// // => so we have to do it manually
-// if (response.responseBody.indexOf(lastResponseBody) === 0) {
-// response.responseBody = response.responseBody.substring(lastResponseBody.length);
-// lastResponseBody += response.responseBody;
-// } else {
-// lastResponseBody = response.responseBody;
-// }
-//
-//
-// if (response.state === "messageReceived" && response.responseBody && response.responseBody.length > 0) {
-//
-// stream += response.responseBody;
-//
-// var idx = stream.indexOf(":");
-// while (idx > -1) {
-// var l = parseInt(stream.substring(0, idx));
-// if (stream.length > (l + idx)) {
-//
-// // parse notification
-// var notification;
-// try {
-// notification = JSON.parse(stream.substring(idx + 1, idx + 1 + l));
-// } catch (error) {
-// // TODO: handle and log
-// console.log("error: " + error);
-// }
-//
-// // notify listeners
-// if (notification) {
-// notify(baseURL, channelID, notification);
-// }
-//
-// // finally cut stream and get next index
-// stream = stream.substring(idx + 1 + l);
-// idx = stream.indexOf(":");
-//
-// } else {
-// idx = -1;
-// }
-// }
-// }
-// };
-// };
-//
-// return function(baseURL, channelID) {
-//
-// var _baseURL = validateBaseURL(baseURL);
-//
-// channels[_baseURL] = channels[_baseURL] || {};
-// channels[_baseURL][channelID] = channels[_baseURL][channelID] || {};
-//
-// if (channels[_baseURL][channelID].open === undefined) {
-//
-// channels[_baseURL][channelID].id = channelID;
-// channels[_baseURL][channelID].baseURL = _baseURL;
-//
-// channels[_baseURL][channelID].open = true;
-// jQuery.atmosphere.subscribe(_baseURL + "notification/v1/openChannel?channelID=" + channelID + "&outputComments=true", null, {
-//
-// callback: createCallback(_baseURL, channelID),
-//
-//// transport: 'long-polling',
-//// fallbackTransport: 'long-polling',
-//
-// // TODO [haed]: check: ie does not support streaming, also fallback will be ignored ...
-// // TODO [haed]: streaming over vodafone stick usb does not work (lost some packages)
-//// transport: 'streaming',
-//// fallbackTransport: 'long-polling',
-//
-//// transport: 'websocket',
-//// fallbackTransport: 'polling',
-//
-//
-//
-// contentType: 'text/plain;charset=utf-8',
-// maxRequest: Math.pow(2, 53)
-// });
-// }
-//
-// return channels[_baseURL][channelID];
-// };
-// }(),
// TODO [scthi]: there should be a more convenient configure method
setDefaultBaseURL: function(url) {
defaultBaseURL = url;
}
-
-// subscribe: function(baseURL, channelID, notificationType, func) {
-//
-// var _baseURL = validateBaseURL(baseURL);
-//
-// channels[_baseURL] = channels[_baseURL] || {};
-// channels[_baseURL][channelID] = channels[_baseURL][channelID] || {};
-// channels[_baseURL][channelID].subscriptions = channels[_baseURL][channelID].subscriptions || {};
-//
-// var subscriptions = channels[_baseURL][channelID].subscriptions;
-// if (subscriptions[notificationType]) {
-// subscriptions[notificationType].push(func);
-// } else {
-// subscriptions[notificationType] = [func];
-// }
-// }
};
View
329 webroot/js/jquery.atmosphere.js
@@ -39,6 +39,7 @@ jQuery.atmosphere = function() {
headers : [],
state : "messageReceived",
transport : "polling",
+
push : [],
error: null,
id : 0
@@ -101,14 +102,14 @@ jQuery.atmosphere = function() {
}
if (jQuery.atmosphere.request.transport != 'websocket') {
- jQuery.atmosphere.executeRequest();
+ jQuery.atmosphere.executeRequest(jQuery.atmosphere.request);
} else if (jQuery.atmosphere.request.transport == 'websocket') {
if (jQuery.atmosphere.request.webSocketImpl == null && !window.WebSocket && !window.MozWebSocket) {
jQuery.atmosphere.log(logLevel, ["Websocket is not supported, using request.fallbackTransport ("
+ jQuery.atmosphere.request.fallbackTransport + ")"]);
jQuery.atmosphere.request.transport = jQuery.atmosphere.request.fallbackTransport;
jQuery.atmosphere.response.transport = jQuery.atmosphere.request.fallbackTransport;
- jQuery.atmosphere.executeRequest();
+ jQuery.atmosphere.executeRequest(jQuery.atmosphere.request);
}
else {
jQuery.atmosphere.executeWebSocket();
@@ -133,22 +134,36 @@ jQuery.atmosphere = function() {
},
- jsonp: function() {
- var request = jQuery.atmosphere.request;
-
- jQuery.atmosphere.request.attachHeadersAsQueryString = true;
+ jsonp: function(aRequest) {
+ var request = aRequest || jQuery.atmosphere.request;
jQuery.atmosphere.response.push = function(url) {
jQuery.atmosphere.request.callback = null;
jQuery.atmosphere.publish(url, null, jQuery.atmosphere.request);
};
+ var url = request.url;
+ var data = request.data;
+ if (jQuery.atmosphere.request.attachHeadersAsQueryString) {
+ url = jQuery.atmosphere.attachHeaders(request);
+ if (data != "") {
+ if (data != '') {
+ url += "&X-Atmosphere-Post-Body=" + data;
+ }
+ }
+ data = '';
+ }
+
var jqxhr = jQuery.ajax({
- url : request.url ,
+ url : url,
type : request.method,
dataType: "jsonp",
error : function(jqXHR, textStatus, errorThrown) {
- jQuery.atmosphere.ieCallback(textStatus, "error", jqXHR.status, request.transport);
+ if (jqXHR.status < 300) {
+ jQuery.atmosphere.reconnect(jqxhr, request);
+ } else {
+ jQuery.atmosphere.ieCallback(textStatus, "error", jqXHR.status, request.transport);
+ }
},
jsonp : "jsonpTransport",
success: function(json) {
@@ -156,34 +171,46 @@ jQuery.atmosphere = function() {
jQuery.atmosphere.reconnect(jqxhr, request);
}
- jQuery.atmosphere.ieCallback(json.message, "messageReceived", 200, request.transport);
+ var msg = json.message;
+ if (msg != null && typeof msg != 'string') {
+ msg = jQuery.stringifyJSON(msg);
+ }
+ jQuery.atmosphere.ieCallback(msg, "messageReceived", 200, request.transport);
if (!request.executeCallbackBeforeReconnect) {
jQuery.atmosphere.reconnect(jqxhr, request);
}
},
data : request.data,
- beforeSend : function(jqXHR){
+ beforeSend : function(jqXHR) {
jQuery.atmosphere.doRequest(jqXHR, request, false);
}});
},
- checkCORSSupport : function(){
+ checkCORSSupport : function() {
if (jQuery.browser.msie && !window.XDomainRequest) {
return true;
} else if (jQuery.browser.opera) {
return true;
}
+ // Force Android to use CORS as some version like 2.2.3 fail otherwise
+ var ua = navigator.userAgent.toLowerCase();
+ var isAndroid = ua.indexOf("android") > -1;
+ if (isAndroid) {
+ return true;
+ }
return false;
},
- executeRequest: function() {
- var request = jQuery.atmosphere.request;
+
+ executeRequest: function(aRequest) {
+ var request = aRequest || jQuery.atmosphere.request;
// CORS fake using JSONP
- if (jQuery.atmosphere.request.transport == 'jsonp' || (jQuery.atmosphere.request.enableXDR && jQuery.atmosphere.request.checkCORSSupport())) {
- jQuery.atmosphere.jsonp();
+ if (jQuery.atmosphere.request.transport == 'jsonp' || (jQuery.atmosphere.checkCORSSupport())) {
+ request.attachHeadersAsQueryString = true;
+ jQuery.atmosphere.jsonp(request);
return;
}
@@ -256,9 +283,17 @@ jQuery.atmosphere = function() {
var update = false;
// Remote server disconnected us, reconnect.
- if (request.transport != 'polling' && request.transport != 'long-polling' && (request.readyState == 2 && ajaxRequest.readyState == 4)) {
- jQuery.atmosphere.reconnect(ajaxRequest, request);
+ if (request.transport == 'streaming'
+ && (request.readyState > 2
+ && ajaxRequest.readyState == 4)) {
+
+ request.readyState = 0;
+ request.lastIndex = 0;
+
+ jQuery.atmosphere.reconnect(ajaxRequest, jQuery.atmosphere.request, true);
+ return;
}
+ request.readyState = ajaxRequest.readyState;
if (ajaxRequest.readyState == 4) {
if (jQuery.browser.msie) {
@@ -346,7 +381,7 @@ jQuery.atmosphere = function() {
}
if (request.executeCallbackBeforeReconnect) {
- jQuery.atmosphere.reconnect(ajaxRequest, request);
+ jQuery.atmosphere.reconnect(ajaxRequest, request, false);
}
// For backward compatibility with Atmosphere < 0.8
@@ -356,9 +391,8 @@ jQuery.atmosphere = function() {
jQuery.atmosphere.invokeCallback(response);
if (!request.executeCallbackBeforeReconnect) {
- jQuery.atmosphere.reconnect(ajaxRequest, request);
+ jQuery.atmosphere.reconnect(ajaxRequest, request, false);
}
- request.readyState = ajaxRequest.readyState;
if ((request.transport == 'streaming') && (responseText.length > jQuery.atmosphere.request.maxStreamingLength)) {
// Close and reopen connection on large data received
@@ -385,10 +419,10 @@ jQuery.atmosphere = function() {
doRequest : function(ajaxRequest, request, create) {
// Prevent Android to cache request
var url = jQuery.atmosphere.prepareURL(request.url);
-
if (create) {
ajaxRequest.open(request.method, url, true);
}
+
ajaxRequest.setRequestHeader("X-Atmosphere-Framework", jQuery.atmosphere.version);
ajaxRequest.setRequestHeader("X-Atmosphere-Transport", request.transport);
ajaxRequest.setRequestHeader("X-Cache-Date", new Date().getTime());
@@ -403,20 +437,26 @@ jQuery.atmosphere = function() {
}
},
- reconnect : function (ajaxRequest, request) {
+ reconnect : function (ajaxRequest, request, force) {
jQuery.atmosphere.request = request;
- if (request.suspend && ajaxRequest.status == 200 && request.transport != 'streaming') {
+ if (force || (request.suspend && ajaxRequest.status == 200 && request.transport != 'streaming' && jQuery.atmosphere.subscribed)) {
jQuery.atmosphere.request.method = 'GET';
jQuery.atmosphere.request.data = "";
- jQuery.atmosphere.executeRequest();
+ jQuery.atmosphere.executeRequest(jQuery.atmosphere.request);
}
},
attachHeaders : function(request) {
var url = request.url;
+ // If not enabled
if (!request.attachHeadersAsQueryString) return url;
+ // If already added
+ if (url.indexOf("X-Atmosphere-Framework") != -1) {
+ return url;
+ }
+
url += "?X-Atmosphere-tracking-id=" + jQuery.atmosphere.uuid;
url += "&X-Atmosphere-Framework=" + jQuery.atmosphere.version;
url += "&X-Atmosphere-Transport=" + request.transport;
@@ -440,8 +480,7 @@ jQuery.atmosphere = function() {
},
configureIE : function() {
- var stop,
- doc = new window.ActiveXObject("htmlfile");
+ var stop, doc = new window.ActiveXObject("htmlfile");
doc.open();
doc.close();
@@ -461,7 +500,9 @@ jQuery.atmosphere = function() {
var iframe = doc.createElement("iframe");
if (request.method == 'POST') {
url = jQuery.atmosphere.attachHeaders(request);
- url += "&X-Atmosphere-Post-Body=" + jQuery.atmosphere.request.data;
+ if (jQuery.atmosphere.request.data != '') {
+ url += "&X-Atmosphere-Post-Body=" + jQuery.atmosphere.request.data;
+ }
}
// Finally attach a timestamp to prevent Android and IE caching.
@@ -488,38 +529,36 @@ jQuery.atmosphere = function() {
}
}
- var res = cdoc.body ? cdoc.body.lastChild : cdoc,
- readResponse = function() {
- // Clones the element not to disturb the original one
- var clone = res.cloneNode(true);
+ var res = cdoc.body ? cdoc.body.lastChild : cdoc, readResponse = function() {
+ // Clones the element not to disturb the original one
+ var clone = res.cloneNode(true);
- // If the last character is a carriage return or a line feed, IE ignores it in the innerText property
- // therefore, we add another non-newline character to preserve it
- clone.appendChild(cdoc.createTextNode("."));
+ // If the last character is a carriage return or a line feed, IE ignores it in the innerText property
+ // therefore, we add another non-newline character to preserve it
+ clone.appendChild(cdoc.createTextNode("."));
- var text = clone.innerText;
- var isJunkEnded = true;
+ var text = clone.innerText;
+ var isJunkEnded = true;
- if (text.indexOf("<!-- Welcome to the Atmosphere Framework.") == -1) {
- isJunkEnded = false;
- }
+ if (text.indexOf("<!-- Welcome to the Atmosphere Framework.") == -1) {
+ isJunkEnded = false;
+ }
- if (isJunkEnded) {
- var endOfJunk = "<!-- EOD -->";
- var endOfJunkLenght = endOfJunk.length;
- var junkEnd = text.indexOf(endOfJunk) + endOfJunkLenght;
+ if (isJunkEnded) {
+ var endOfJunk = "<!-- EOD -->";
+ var endOfJunkLenght = endOfJunk.length;
+ var junkEnd = text.indexOf(endOfJunk) + endOfJunkLenght;
- text = text.substring(junkEnd);
- }
- return text.substring(0, text.length - 1);
- };
+ text = text.substring(junkEnd);
+ }
+ return text.substring(0, text.length - 1);
+ };
//To support text/html content type
if (!jQuery.nodeName(res, "pre")) {
// Injects a plaintext element which renders text without interpreting the HTML and cannot be stopped
// it is deprecated in HTML5, but still works
- var head = cdoc.head || cdoc.getElementsByTagName("head")[0] || cdoc.documentElement || cdoc,
- script = cdoc.createElement("script");
+ var head = cdoc.head || cdoc.getElementsByTagName("head")[0] || cdoc.documentElement || cdoc, script = cdoc.createElement("script");
script.text = "document.write('<plaintext>')";
@@ -589,8 +628,12 @@ jQuery.atmosphere = function() {
var lastMessage = "";
var transport = jQuery.atmosphere.request.transport;
var lastIndex = 0;
+ var request = jQuery.atmosphere.request;
jQuery.atmosphere.response.push = function(url) {
+ jQuery.atmosphere.request.method = 'POST';
+ jQuery.atmosphere.request.enableXDR = true;
+ jQuery.atmosphere.request.attachHeadersAsQueryString = true;
jQuery.atmosphere.request.callback = null;
jQuery.atmosphere.publish(url, null, jQuery.atmosphere.request);
};
@@ -615,33 +658,33 @@ jQuery.atmosphere = function() {
jQuery.atmosphere.ieCallback(responseBody, "messageReceived", 200, transport);
};
- var xdr = new window.XDomainRequest(),
- rewriteURL = jQuery.atmosphere.request.rewriteURL || function(url) {
- // Maintaining session by rewriting URL
- // http://stackoverflow.com/questions/6453779/maintaining-session-by-rewriting-url
- var rewriters = {
- JSESSIONID: function(sid) {
- return url.replace(/;jsessionid=[^\?]*|(\?)|$/, ";jsessionid=" + sid + "$1");
- },
- PHPSESSID: function(sid) {
- return url.replace(/\?PHPSESSID=[^&]*&?|\?|$/, "?PHPSESSID=" + sid + "&").replace(/&$/, "");
- }
- };
+ var xdr = new window.XDomainRequest(), rewriteURL = jQuery.atmosphere.request.rewriteURL || function(url) {
+ // Maintaining session by rewriting URL
+ // http://stackoverflow.com/questions/6453779/maintaining-session-by-rewriting-url
+ var rewriters = {
+ JSESSIONID: function(sid) {
+ return url.replace(/;jsessionid=[^\?]*|(\?)|$/, ";jsessionid=" + sid + "$1");
+ },
+ PHPSESSID: function(sid) {
+ return url.replace(/\?PHPSESSID=[^&]*&?|\?|$/, "?PHPSESSID=" + sid + "&").replace(/&$/, "");
+ }
+ };
- for (var name in rewriters) {
- // Finds session id from cookie
- var matcher = new RegExp("(?:^|;\\s*)" + encodeURIComponent(name) + "=([^;]*)").exec(document.cookie);
- if (matcher) {
- return rewriters[name](matcher[1]);
- }
+ for (var name in rewriters) {
+ // Finds session id from cookie
+ var matcher = new RegExp("(?:^|;\\s*)" + encodeURIComponent(name) + "=([^;]*)").exec(document.cookie);
+ if (matcher) {
+ return rewriters[name](matcher[1]);
}
+ }
- return url;
- };
+ return url;
+ };
// Handles open and message event
xdr.onprogress = function() {
xdrCallback(xdr);
+ lastMessage = xdr.responseText;
};
// Handles error event
xdr.onerror = function() {
@@ -653,14 +696,21 @@ jQuery.atmosphere = function() {
xdrCallback(xdr);
}
- jQuery.atmosphere.reconnect(xdr, jQuery.atmosphere.request);
+ if (transport == "long-polling") {
+ jQuery.atmosphere.request.method = 'GET';
+ jQuery.atmosphere.request.data = "";
+ jQuery.atmosphere.request.transport = transport;
+ jQuery.atmosphere.executeRequest(jQuery.atmosphere.request);
+ }
};
return {
open: function() {
var url = jQuery.atmosphere.attachHeaders(jQuery.atmosphere.request);
if (jQuery.atmosphere.request.method == 'POST') {
- url += "&X-Atmosphere-Post-Body=" + jQuery.atmosphere.request.data;
+ if (jQuery.atmosphere.request.data != '') {
+ url += "&X-Atmosphere-Post-Body=" + jQuery.atmosphere.request.data;
+ }
}
xdr.open(jQuery.atmosphere.request.method, rewriteURL(url));
xdr.send();
@@ -675,8 +725,7 @@ jQuery.atmosphere = function() {
executeWebSocket : function() {
var request = jQuery.atmosphere.request;
var webSocketSupported = false;
- var url = jQuery.atmosphere.request.url;
- url = jQuery.atmosphere.attachHeaders(jQuery.atmosphere.request);
+ var url = jQuery.atmosphere.attachHeaders(jQuery.atmosphere.request);
var callback = jQuery.atmosphere.request.callback;
jQuery.atmosphere.log(logLevel, ["Invoking executeWebSocket"]);
@@ -722,7 +771,7 @@ jQuery.atmosphere = function() {
request.data = data;
jQuery.atmosphere.response.transport = request.fallbackTransport;
jQuery.atmosphere.request = request;
- jQuery.atmosphere.executeRequest();
+ jQuery.atmosphere.executeRequest(jQuery.atmosphere.request);
websocket.onclose = function(message) {
};
@@ -735,6 +784,8 @@ jQuery.atmosphere = function() {
jQuery.atmosphere.debug("Websocket successfully opened");
webSocketSupported = true;
jQuery.atmosphere.response.state = 'opening';
+ jQuery.atmosphere.response.status = 200;
+
jQuery.atmosphere.invokeCallback(jQuery.atmosphere.response);
if (jQuery.atmosphere.request.method == 'POST') {
@@ -751,6 +802,7 @@ jQuery.atmosphere = function() {
}
jQuery.atmosphere.response.state = 'messageReceived';
jQuery.atmosphere.response.responseBody = message.data;
+ jQuery.atmosphere.response.status = 200;
jQuery.atmosphere.invokeCallback(jQuery.atmosphere.response);
};
@@ -793,8 +845,14 @@ jQuery.atmosphere = function() {
break;
}
}
- jQuery.atmosphere.warn("Websocket closed, reason: " + reason);
- jQuery.atmosphere.warn("Websocket closed, wasClean: " + message.wasClean);
+
+ jQuery.atmosphere.log(logLevel, ["Websocket closed, reason: " + reason]);
+ jQuery.atmosphere.log(logLevel, ["Websocket closed, wasClean: " + message.wasClean]);
+
+ jQuery.atmosphere.response.state = 'closed';
+ jQuery.atmosphere.response.responseBody = "";
+ jQuery.atmosphere.response.status = 200;
+ jQuery.atmosphere.invokeCallback(jQuery.atmosphere.response);
if (!webSocketSupported) {
var data = jQuery.atmosphere.request.data;
@@ -806,14 +864,15 @@ jQuery.atmosphere = function() {
jQuery.atmosphere.response.transport = request.fallbackTransport;
jQuery.atmosphere.request = request;
- jQuery.atmosphere.executeRequest();
+ jQuery.atmosphere.executeRequest(jQuery.atmosphere.request);
} else if (jQuery.atmosphere.subscribed && jQuery.atmosphere.response.transport == 'websocket') {
if (request.requestCount++ < request.maxRequest) {
jQuery.atmosphere.request.requestCount = request.requestCount;
jQuery.atmosphere.request.maxRequest = request.maxRequest;
+ jQuery.atmosphere.request.method = request.method;
- jQuery.atmosphere.request.url = request.url;
+ jQuery.atmosphere.request.url = jQuery.atmosphere.attachHeaders(request);
jQuery.atmosphere.response.responseBody = "";
jQuery.atmosphere.executeWebSocket();
@@ -876,7 +935,16 @@ jQuery.atmosphere = function() {
maxRequest : 60,
logLevel : 'info',
requestCount : 0,
- transport: 'polling'
+ transport: 'polling',
+ webSocketImpl: null,
+ webSocketUrl: null,
+ webSocketPathDelimiter: "@@",
+ enableXDR : false,
+ rewriteURL : false,
+ attachHeadersAsQueryString : false,
+ executeCallbackBeforeReconnect : true,
+ readyState : 0
+
}, request);
if (callback != null) {
@@ -889,7 +957,7 @@ jQuery.atmosphere = function() {
jQuery.atmosphere.request.transport = 'polling';
if (jQuery.atmosphere.request.transport != 'websocket') {
- jQuery.atmosphere.executeRequest();
+ jQuery.atmosphere.executeRequest(jQuery.atmosphere.request);
} else if (jQuery.atmosphere.request.transport == 'websocket') {
if (!window.WebSocket && !window.MozWebSocket) {
alert("WebSocket not supported by this browser");
@@ -943,6 +1011,12 @@ jQuery.atmosphere = function() {
,
unsubscribe : function() {
+ logLevel = 'info';
+ jQuery.atmosphere.response.state = 'unsubscribe';
+ jQuery.atmosphere.response.responseBody = "";
+ jQuery.atmosphere.response.status = 408;
+ jQuery.atmosphere.invokeCallback(jQuery.atmosphere.response);
+
jQuery.atmosphere.subscribed = false;
jQuery.atmosphere.closeSuspendedConnection();
jQuery.atmosphere.callbacks = [];
@@ -961,8 +1035,7 @@ jQuery.atmosphere = function() {
// From jQuery-Stream
prepareURL: function(url) {
// Attaches a time stamp to prevent caching
- var ts = jQuery.now(),
- ret = url.replace(/([?&])_=[^&]*/, "$1_=" + ts);
+ var ts = jQuery.now(), ret = url.replace(/([?&])_=[^&]*/, "$1_=" + ts);
return ret + (ret === url ? (/\?/.test(url) ? "&" : "?") + "_=" + ts : "");
},
@@ -1076,4 +1149,94 @@ jQuery.atmosphere = function() {
}
-}();
+}();
+
+/*
+ * jQuery stringifyJSON
+ * http://github.com/flowersinthesand/jquery-stringifyJSON
+ *
+ * Copyright 2011, Donghwan Kim
+ * Licensed under the Apache License, Version 2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
+ */
+// This plugin is heavily based on Douglas Crockford's reference implementation
+(function($) {
+
+ var escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, meta = {
+ '\b' : '\\b',
+ '\t' : '\\t',
+ '\n' : '\\n',
+ '\f' : '\\f',
+ '\r' : '\\r',
+ '"' : '\\"',
+ '\\' : '\\\\'
+ };
+
+ function quote(string) {
+ return '"' + string.replace(escapable, function(a) {
+ var c = meta[a];
+ return typeof c === "string" ? c : "\\u" + ("0000" + a.charCodeAt(0).toString(16)).slice(-4);
+ }) + '"';
+ }
+
+ function f(n) {
+ return n < 10 ? "0" + n : n;
+ }
+
+ function str(key, holder) {
+ var i, v, len, partial, value = holder[key], type = typeof value;
+
+ if (value && typeof value === "object" && typeof value.toJSON === "function") {
+ value = value.toJSON(key);
+ type = typeof value;
+ }
+
+ switch (type) {
+ case "string":
+ return quote(value);
+ case "number":
+ return isFinite(value) ? String(value) : "null";
+ case "boolean":
+ return String(value);
+ case "object":
+ if (!value) {
+ return "null";
+ }
+
+ switch (Object.prototype.toString.call(value)) {
+ case "[object Date]":
+ return isFinite(value.valueOf()) ? '"' + value.getUTCFullYear() + "-" + f(value.getUTCMonth() + 1) + "-" + f(value.getUTCDate()) + "T" +
+ f(value.getUTCHours()) + ":" + f(value.getUTCMinutes()) + ":" + f(value.getUTCSeconds()) + "Z" + '"' : "null";
+ case "[object Array]":
+ len = value.length;
+ partial = [];
+ for (i = 0; i < len; i++) {
+ partial.push(str(i, value) || "null");
+ }
+
+ return "[" + partial.join(",") + "]";
+ default:
+ partial = [];
+ for (i in value) {
+ if (Object.prototype.hasOwnProperty.call(value, i)) {
+ v = str(i, value);
+ if (v) {
+ partial.push(quote(i) + ":" + v);
+ }
+ }
+ }
+
+ return "{" + partial.join(",") + "}";
+ }
+ }
+ }
+
+ $.stringifyJSON = function(value) {
+ if (window.JSON && window.JSON.stringify) {
+ return window.JSON.stringify(value);
+ }
+
+ return str("", {"": value});
+ };
+
+}(jQuery));
Please sign in to comment.
Something went wrong with that request. Please try again.