简体   繁体   中英

Pusher Heroku Add-on error

so I'm using the Pusher Heroku Add-on for my application. The application has live notifications, so when a user receives a message he will see a pop up notification saying "new message". However, In production I am getting the below error:

Firefox can't establish a connection to the server at ws://ws.pusherapp.com/app/b1cc5d4f400faddcb40b?protocol=7&client=js&version=2.1.6&flash=false.
Reload the page to get source for: http://js.pusher.com/2.1/pusher.min.js

And here's the Pusher controller:

class PusherController < ApplicationController
  protect_from_forgery :except => :auth # stop rails CSRF protection for this action

  def auth
    Pusher.app_id = ENV['PUSHER_APP_ID']
    Pusher.key = ENV['PUSHER_KEY']
    Pusher.secret = ENV['PUSHER_SECRET']



    if current_user && params[:channel_name] == "private-user-#{current_user.id}"
      response = Pusher[params[:channel_name]].authenticate(params[:socket_id])
      render :json => response
    else
      render :text => "Not authorized", :status => '403'
    end
  end
end

And I'm using the figaro gem to push the keys to heroku.

What am I doing wrong?

Kind regards

JS

That looks like a problem with Javascript, rather than Rails

We've got pusher working very well with one of our production apps, and it works by firstly having the pusher gem installed, allowing you to call the pusher JS files from your layout:

#app/views/layouts/application.html.erb
<%= javascript_include_tag "http://js.pusher.com/2.1/pusher.min.js" %>

Rails

You may also wish to put the pusher initialization code into an initializer:

#config/initializers/pusher.rb
Pusher.url = ENV["PUSHER_URL"]

Pusher.app_id = ENV["PUSHER_APP_ID"]
Pusher.key = ENV["PUSHER_KEY"]
Pusher.secret = ENV["PUSHER_SECRET"]

This will ensure app-wide connectivity, rather than controller-specific (allowing for greater flexibility)

Firefox can't establish a connection to the server at ws://ws.pusherapp.com/app/b1cc5d4f400faddcb40b?protocol=7&client=js&version=2.1.6&flash=false. Reload the page to get source for: http://js.pusher.com/2.1/pusher.min.js

This doesn't necessarily mean anything is wrong. it just means that an unsecured WebSocket connection couldn't be established. Pusher's fallback strategy should result in a successful connection being established via either HTTP fallback (HTTP or HTTPS) or via WSS (a secure WebSocket connection).

Failed connection attempts are logged as console errors. There's nothing that can be done about that.

To test this you can bind to connection events and ensure that you are indeed connecting. The pusher-js JavaScript logging will also help determine what's happening.

You can also try http://test.pusher.com/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM