lundi 28 septembre 2015

Rails web socket - authorization

I have Ember.js client and RoR server side with gem "websocket-rails".

I need to get private channel with authorization to send messages only for one user.

This is how I try:

class AuthorizationController < WebsocketRails::BaseController

    before_action :require_login

    def authorize_channels
        # The channel name will be passed inside the message Hash
        puts '*'*400
        ap current_user//Here I see the user

        channel = WebsocketRails[message[:channel]]
        accept_channel current_user

    end


    def require_login

        sign_in(User.find(4))

    end
end

My events.rb is:

WebsocketRails::EventMap.describe do
    namespace :websocket_rails do
        subscribe :subscribe, :to => AuthorizationController, :with_method => :authorize_channels
    end

end

But when I try to send message with:

WebsocketRails.users[4].trigger(:test_event, { message: 'This is a private message from WebSocket Rails' } )

I get error "#>"

And if I try to print WebsocketRails.users I see:

#<WebsocketRails::UserManager:0x007ff5bb617d68 @users={}>

What is wrong? Thx a lot!




Aucun commentaire:

Enregistrer un commentaire