Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 0.7.2
    • Fix Version/s: 0.7.2
    • Component/s: runtime
    • Labels:
      None
    • Environment:

      Grails / Atmosphere 0.7.2 snapshot / jquery.atmosphere.js / Firefox 4 on MacOS

      Description

      When I broadcast to a client who has firefox 4, every 3/4 messages, the next one is not receive by the client.

      Sample jquery :

      function callback(response){
          $.jqotetag('**');
      
          var message = $.parseJSON(response.responseBody);
      
          switch(message.call){
              case "add-actor":
              $('#backlog-layout-window-actor').jqotepre('#postit-actor-tmpl', message.object);
              $('#backlog-layout-widget-actor').jqotepre('#postit-row-actor-tmpl', message.object);
              $('#actor-table').jqotepre('#table-row-actor-tmpl', message.object);
              break;
      
              case "update-actor":
              $('div.postit-actor[elemid='+this+']').jqotesub('#postit-actor-tmpl', message.object);
              $('div.postit-row-actor[elemid='+this+']').jqotesub('#postit-row-actor-tmpl', message.object);
              $('#actor-table tr[elemid='+this+']').jqotesub('#table-row-actor-tmpl', message.object);
              break;
      
              case "remove-actor":
              $(message.object).each(function(){
                  $('div.postit-actor[elemid='+this+']').remove();
                  $('div.postit-row-actor[elemid='+this+']').remove();
                  $('#actor-table tr[elemid='+this+']').remove();
              });
              break;
          }
        }
        var url = $.icescrum.o.baseUrl + 'push/app?${params.product ? 'product='+params.product : params.team ? 'team='+params.team :'' }';
        $.atmosphere.subscribe(url,callback, $.atmosphere.request = {transport:'streaming'});
      

      IceScrumAtmosphereHandler.groovy :

      package org.icescrum.atmosphere
      
      import org.atmosphere.cpr.AtmosphereHandler
      import org.atmosphere.cpr.AtmosphereResource
      import org.atmosphere.cpr.AtmosphereResourceEvent
      import javax.servlet.http.HttpServletRequest
      import javax.servlet.http.HttpServletResponse
      import org.atmosphere.cpr.BroadcasterFactory
      import org.atmosphere.cpr.DefaultBroadcaster
      import org.icescrum.core.domain.Product
      import org.icescrum.core.domain.Team
      import org.apache.commons.logging.LogFactory
      import org.springframework.security.web.context.HttpSessionSecurityContextRepository
      import org.springframework.security.core.context.SecurityContext
      import org.icescrum.core.domain.User
      import org.atmosphere.util.XSSHtmlFilter
      
      
      class IceScrumAtmosphereHandler implements AtmosphereHandler<HttpServletRequest, HttpServletResponse> {
      
          private static final log = LogFactory.getLog(this)
      
          void onRequest(AtmosphereResource<HttpServletRequest, HttpServletResponse> event) throws IOException {
      
              event.response.setContentType("text/html;charset=ISO-8859-1");
      		event.response.addHeader("Cache-Control", "private");
      		event.response.addHeader("Pragma", "no-cache");
              event.suspend()
      
              def productID = event.request.getParameterValues("product") ? event.request.getParameterValues("product")[0] : null
              def teamID = event.request.getParameterValues("team") ? event.request.getParameterValues("team")[0] : null
              def user = getUserFromAtmosphereResource(event.request)
      
              def channel = null
              if (productID){
                  channel = Product.load(productID.toLong()) ? "product-${productID}" : null
      
              }else if(teamID){
                  channel = Team.load(teamID.toLong()) ? "team-${teamID}" : null
              }
              if (channel){
                  def broadcaster = BroadcasterFactory.default.lookup(DefaultBroadcaster.class,channel,true)
                  broadcaster.broadcasterConfig.addFilter(new XSSHtmlFilter())
                  broadcaster.addAtmosphereResource(event)
                  if (log.isDebugEnabled()){
                      log.debug("add user ${user?.username?:'anonymous'} to broadcaster: ${channel}")
                      log.debug(broadcaster)
                  }
              }
      
              if (log.isDebugEnabled()){
                  log.debug("add user ${user?.username?:'anonymous'} to app broadcaster")
              }
          }
      
          void onStateChange(AtmosphereResourceEvent<HttpServletRequest, HttpServletResponse> event) throws IOException {
      
              def user = getUserFromAtmosphereResource(event.resource.request)
              if (!event.message){
                  return
              }
      
              if (event.cancelled){
                  if (log.isDebugEnabled()){
                      log.debug("user ${user?.username?:'anonymous'} disconnected")
                      return
                  }
              }
      
              if (log.isDebugEnabled()){
                  log.debug("send message to user ${user?.username?:'anonymous'}")
              }
      
              event.resource.response.writer.with {
                  write "${event.message}"
                  flush()
              }
          }
          void destroy() {}
      
          private User getUserFromAtmosphereResource(def request){
              def httpSession = request.session;
              def user = null
              if (httpSession != null) {
                  def context = (SecurityContext)httpSession.getAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY);
                  if (context?.authentication?.isAuthenticated()){
                      user = User.get(context.authentication.principal.id)
                  }
              }
              user
          }
      }
      

      Broadcast example :

      def broadcaster = BroadcasterFactory.default.lookup(DefaultBroadcaster.class,'product-'+params.product)
      broadcaster?.broadcast([call:'add-actor',object:actor] as JSON)
      

        Activity

        Hide
        jfarcand added a comment -
        Show
        jfarcand added a comment - Fixed by http://java.net/jira/browse/ATMOSPHERE-116

          People

          • Assignee:
            Unassigned
            Reporter:
            vbarrier
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: