dariocravero / padrino-websockets

Agnostic websockets support for Padrino
MIT License
14 stars 9 forks source link

Can't access authentication helpers inside websocket #8

Open kethomassen opened 8 years ago

kethomassen commented 8 years ago

Currently calling any padrino helper functions, e.g. logged_in? or current_account throws a method not found error. Is there any way to bypass or fix this problem?

dariocravero commented 8 years ago

Sorry about that, would you have an example to work with? What version of Padrino are you using? Thanks

kethomassen commented 8 years ago

@dariocravero Hmmm, weird. They have decided to randomly start working again, however now when I try to broadcast I get an error.

DEBUG -  {"some"=>"data"}
  DEBUG -  Broadcasting message on channel: ping. Message:
  DEBUG -  {:pong=>true, :data=>{"some"=>"data"}}
  ERROR -  Error while running the event handler
  ERROR -  undefined method `each' for nil:NilClass
  ERROR -  /Users/kristianthomassen/.rvm/gems/ruby-2.2.3/gems/padrino-websockets-0.1.1/lib/padrino-websockets/base-event-manager.rb:138:in `broadcast'
/Users/kristianthomassen/.rvm/gems/ruby-2.2.3/gems/padrino-websockets-0.1.1/lib/padrino-websockets/faye/helpers.rb:10:in `broadcast'
/Users/kristianthomassen/Desktop/SkinNetwork.xyz/Skinpot/site/app/app.rb:148:in `block (2 levels) in <class:Skinpot>'
/Users/kristianthomassen/.rvm/gems/ruby-2.2.3/gems/padrino-websockets-0.1.1/lib/padrino-websockets/base-event-manager.rb:95:in `instance_exec'
/Users/kristianthomassen/.rvm/gems/ruby-2.2.3/gems/padrino-websockets-0.1.1/lib/padrino-websockets/base-event-manager.rb:95:in `on_message'
/Users/kristianthomassen/.rvm/gems/ruby-2.2.3/gems/padrino-websockets-0.1.1/lib/padrino-websockets/faye/event-manager.rb:10:in `block in initialize'

using only this now and still getting the error

    websocket :channel do
        on :ping do |message|
            broadcast(:ping, {pong: true, data: message })
        end
    end

seems to be something to do with the @@connections variable in base-event-manager.rb

jaybeecave commented 8 years ago
websocket :channel do
  on :ping do |message|
    send_message(:ping, session['websocket_user'], {pong: true, data: message})
    broadcast(:ping, {pong: true, data: message, broadcast: true})
  end
end

should actually be

websocket :channel do
  on :ping do |message|
    send_message(:channel, session['websocket_user'], {pong: true, data: message})
    broadcast(:channel, {pong: true, data: message, broadcast: true})
  end
end

The example is just a bit wrong

jaybeecave commented 8 years ago

replace :ping with :channel except for on :ping which is essentially on event...