0

In my grails 2.3.7 application, I am using atmosphere-meteor 0.8.3.

On my home page load, I subscribe the client. And by default I run long-polling; and it works fine. On page refresh, I unsubscribe the client.

However, if I refresh the page; then some of the JS and CSS fails to load. It happens 5 out of 10 times of refresh.

Am I doing anything wrong? (As I subscribe on document.ready()). Or do I need to do anything else?

Any help is appreciated.

Update:

Code inside gsp for subscription:

$('body').bind('beforeunload',function(){
    Jabber.unsubscribe();
});
$(document).ready(function () { 
    if (typeof atmosphere == 'undefined') {
        Jabber.socket = $.atmosphere;
    } else {
        Jabber.socket = atmosphere;
    }
    var atmosphereRequest = {
        type: 'public',
        url: 'atmosphere/public',
        trackMessageLength: false
    };
    //setTimeout(function(){
        Jabber.subscribe(atmosphereRequest);
    //}, 10000);
});

And the Jabber variable

var Jabber = {
    socket: null,
    publicSubscription: null,
    transport: null,

    subscribe: function (options) {
        var defaults = {
            type: '',
            contentType: "application/json",
            shared: false,
            //transport: 'websocket',
            transport: 'long-polling',
            fallbackTransport: 'long-polling',
            trackMessageLength: true
        },
        atmosphereRequest = $.extend({}, defaults, options);
        console.log(atmosphereRequest);
        atmosphereRequest.onOpen = function (response) {
            console.log('atmosphereOpen transport: ' + response.transport);
        };
        atmosphereRequest.onReconnect = function (request, response) {
            console.log("atmosphereReconnect");
        };
        atmosphereRequest.onMessage = function (response) {
            console.log("on message");
            Jabber.onMessage(response);
        };
        atmosphereRequest.onError = function (response) {
            console.log('atmosphereError: ' + response);
        };
        atmosphereRequest.onTransportFailure = function (errorMsg, request) {
            console.log('atmosphereTransportFailure: ' + errorMsg);
        };
        atmosphereRequest.onClose = function (response) {
            console.log('atmosphereClose: ' + response);
        };

        switch (options.type) {
        case 'public':
            Jabber.publicSubscription = Jabber.socket.subscribe(atmosphereRequest);
            break;
        default:
            return false;
        }
        //Jabber.publicSubscription = Jabber.socket.subscribe(atmosphereRequest);

    },

    unsubscribe: function () {
        if (Jabber.socket)
            Jabber.socket.unsubscribe();
    },

    onMessage:function(response){....}
}
sSaroj
  • 268
  • 4
  • 18

1 Answers1

0

I'm the plugin author. Please update to version 1.0.1. If you still have trouble after updating the plugin, create a new issue. We can work through the problem then. However, I do have a question. When you say the JS fails to load, do you mean the atmosphere JavaScript or your own? There is no plugin related CSS.

Ken
  • 685
  • 2
  • 5
  • 11
  • Hey Ken, thank you for replying. I have upgraded to version 1.0.1. But still it is not helping. At times it is my application JavaScript files and at times it is the atmosphere JavaScript file which fails to load. – sSaroj Sep 11 '14 at 08:13
  • Are you using the resources or asset-pipeline plugin to manage your JavaScript? Maybe you should try updating that one as well. The asset-pipeline plugin is updated at least once a week it seems. I don't think this is an atmosphere-meteor plugin problem. I'll try and help, but I'm not an expert on those other two plugins. – Ken Sep 11 '14 at 17:24
  • @aSaroj Did you get your problem fixed? If so, what was causing it? – Ken Sep 14 '14 at 12:45
  • Nope @Ken . I have tried lot of alternatives but still it is not fixed. Actually my application is in a two node environment hosted in Linux and the tomcat is being proxied through apache(httpd) server. Is that going to make any difference? – sSaroj Sep 14 '14 at 14:06
  • Sorry, I can't help you with proxying. However, if you're using the resources plugin, you might want to try running it in [debug mode](http://grails-plugins.github.io/grails-resources/guide/8.%20Debugging.html). Then you can see exactly which files are making it to the browser. – Ken Sep 15 '14 at 17:06
  • Thank you for your reply. I am not using resources plugin at all now. The moment I comment out the subscribe code in my gsp file everything works fine. So, m still wondering what could be the problem? – sSaroj Sep 15 '14 at 18:09
  • Please update your question and insert your subscribe code. It's probably something you've overlooked. – Ken Sep 15 '14 at 19:36
  • I have updated the code for your reference. Please have a look at it. – sSaroj Sep 15 '14 at 19:48
  • You need either the resources or asset-pipeline plugin to get the one of the Atmosphere JavaScript libraries in the client. See the [JavaScript section](https://github.com/kensiprell/grails-atmosphere-meteor/blob/master/README.md#javascript) in the README. – Ken Sep 15 '14 at 20:11
  • Can the Atmosphere plugin be used in multi-node environment. Lets' say there are two tomcat servers for the application, and the load balancer decides to which server the client needs to connect. If I subscribe from one tomcat server, will I get broadcasted message done from the other tomcat server. – sSaroj Oct 03 '14 at 15:10
  • That won't work out of the box. You'd need a message broker or an [atmosphere extension](https://github.com/Atmosphere/atmosphere/wiki/Atmosphere-PlugIns-and-Extensions). One plugin user wrote a Wiki page on [how to use Hazelcast](https://github.com/kensiprell/grails-atmosphere-meteor/wiki/Hazelcast-Broadcaster). – Ken Oct 03 '14 at 17:01
  • I am trying two options here. RMI and REST service call to each of the nodes. I have a question on fallbacktransport. If the default is WebSocket and fallback is long-polling, on what scenario it will start using the fallback? If the server doesn't support websocket or if websocket fails due to some problem. – sSaroj Oct 07 '14 at 20:23
  • It will use the fallback if either the client or server does not support websocket. – Ken Oct 08 '14 at 03:57