Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'failed' connection state is not triggered #21

Closed
zinkkrysty opened this issue May 15, 2012 · 14 comments
Closed

'failed' connection state is not triggered #21

zinkkrysty opened this issue May 15, 2012 · 14 comments

Comments

@zinkkrysty
Copy link

When I test my application in IE with flash disabled, the 'failed' connection state is not triggered, which doesn't allow me to display a sympathy message for my users that don't have Flash (or wrong version) or WebSockets.

The code I was using at the beginning is this:

pusher.connection.bind('failed', function() {
  alert('not supported');
});

And when I was trying to debug a little further I tried to bind the 'state_change' event:

pusher.connection.bind('state_change', function(states) {
  // states = {previous: 'oldState', current: 'newState'}
  alert("Pusher's current state is " + states.current);
});

Which does what is suppose in Safari or IE with Flash but doesn't output anything in IE without Flash.

Does anyone have a working example that the 'failed' state is triggered?

@zinkkrysty
Copy link
Author

I just tried this now:

alert("Final pusher state: " + pusher.connection.state);

and outputs 'failed'. But the event is not triggered...

@maryrosecook
Copy link
Contributor

Hiya. Thanks a lot for reporting this. I'm looking into it.

@maryrosecook
Copy link
Contributor

By the way, which version of IE are you using?

@zinkkrysty
Copy link
Author

I think I tried it with both IE9 and IE8 (flash enabled: works; flash disabled: doesn't) through browserstack.com

@maryrosecook
Copy link
Contributor

Could you tell me which version of the Pusher JavaScript library you are using? Also, are there any error messages displayed in your browser console?

@maryrosecook
Copy link
Contributor

Sorry. Another question: when do you bind to the failed state? Would you mind posting a little more of your code? It would be useful to see the code from the Pusher object instantiation to the bind?

@zinkkrysty
Copy link
Author

Hi, I use CoffeeScript and have a static object that holds a method to start listening to different pusher events.

@CarHistoryLookupForm =
  messages_received: 0
  received_anything: false
  pusher: null
  channel: null

  start_listening: (channel_id) ->
    @pusher = new Pusher('xxxxxxx')
    @pusher.connection.bind 'failed', @unsupported
    @channel = @pusher.subscribe(channel_id)
    @channel.bind 'start', (data) => @handle_start(data)
    @channel.bind 'success', (data) => @handle_succes(data)
    @channel.bind 'failure', (data) => @handle_failure(data)
    @channel.bind 'failure_unknown_reg_number', (data) => @handle_reg_number_failure(data)

  # ....

  handle_failure: (data={}) ->
    @disconnect_pusher
    @hide_loader()
    @show_failure()

I call the method from an AJAX response that gets executed (Rails remote form)

CarHistoryLookupForm.start_listening('<%=@channel%>')

if you're not familiar with CoffeeScript, please note that @ means this. and -> or => is similar to function() {

@maryrosecook
Copy link
Contributor

Great - thank you. Which version of the Pusher JavaScript library are you on?

@zinkkrysty
Copy link
Author

I was using this one: "http://js.pusher.com/1.11/pusher.min.js"
but I also tried with latest, 1.12 and had the same issue

@maryrosecook
Copy link
Contributor

Great - thank you. I'll be in touch after I've investigated further.

@maryrosecook
Copy link
Contributor

Hmm. I'm a bit baffled. I tried a test with the following code:

var pusher = new Pusher('insertkeyhere');
pusher.connection.bind("failed", function() {
    console.log("failed!");
});

in IE8 running both on a local VM and in browserstack.com and the failed event was emitted correctly. I can't see any important differences between your code and my test code. Is there any way you could send me the URL of your page so I can look at the page source and view any debug console errors that might be getting thrown?

Thanks.

@maryrosecook
Copy link
Contributor

As we agreed via email, I'm going to close this because we can't reproduce it in isolation from your app.

@jesussobrino
Copy link

Hello!

I have exactly the same problem. I can read in docs (https://pusher.com/docs/client_api_guide/client_connect) I should bind 'error'

So I do the following:

   pusher.connection.bind('error', function (error) {
      console.log('Service error');
    });

    pusher.connection.bind('failed', function (error) {
      console.log('service failed');
    });

    pusher.connection.bind('state_change', function(states) {
      console.log("Pusher's current state is " + states.current);
    });

And when I connect / disconnect my internet connection the only console log I can see is "Pusher's current state is ...". Should I do something else?

Thanks in advance!

@leggetter
Copy link
Contributor

From https://pusher.com/docs/client_api_guide/client_connect:

A state of failed means:

Pusher is not supported by the browser. This implies that WebSockets are not natively available, Flash is not available, and an HTTP-based transport could not be found.

This will only every happy at the very start of the connection/Pusher instantiation process.

A state of error occurs:

When connection limits are reached additional connections over the limit will be rejected

Additionally, this may happen if you provide the incorrect application key. This also only happens at the very start of the connection/Pusher instantiation process.

when I connect / disconnect my internet connection the only console log I can see is "Pusher's current state is ..."

As above, this is because both failed and error are initial failure states and you shouldn't expect to see them during the reconnection cycle.

I hope this clarifies things.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants