lib/pusher/client.rb
def authenticate(channel_name, socket_id, custom_data = nil)
      channel_instance = channel(channel_name)
      r = channel_instance.authenticate(socket_id, custom_data)
      if channel_name.match(/^private-encrypted-/)
        r[:shared_secret] = Base64.strict_encode64(
          channel_instance.shared_secret(encryption_master_key)
        )
      end
      r
    end
# Generate the expected response for an authentication endpoint.
# See http://pusher.com/docs/authenticating_users for details.
#
# @example Private channels
#   render :json => Pusher.authenticate('private-my_channel', params[:socket_id])
#
# @example Presence channels
#   render :json => Pusher.authenticate('presence-my_channel', params[:socket_id], {
#     :user_id => current_user.id, # => required
#     :user_info => { # => optional - for example
#       :name => current_user.name,
#       :email => current_user.email
#     }
#   })
#
# @param socket_id [String]
# @param custom_data [Hash] used for example by private channels
#
# @return [Hash]
#
# @raise [Pusher::Error] if channel_name or socket_id are invalid
#
# @private Custom data is sent to server as JSON-encoded string
#
Generate the expected response for an authentication endpoint.
Generate the expected response for an authentication endpoint .
def authenticate(channel_name, socket_id, custom_data = nil)
      channel_instance = channel(channel_name)
      r = channel_instance.authenticate(socket_id, custom_data)
      if channel_name.match(/^private-encrypted-/)
        r[:shared_secret] = Base64.strict_encode64(
          channel_instance.shared_secret(encryption_master_key)
        )
      end
      r
    end
def authenticate ( channel_name , socket_id , custom_data = nil ) channel_instance = channel ( channel_name ) r = channel_instance . authenticate ( socket_id , custom_data ) if channel_name . match ( / ^private-encrypted- / ) r [ :shared_secret ] = Base64 . strict_encode64 ( channel_instance . shared_secret ( encryption_master_key ) ) end r end
Generate the expected response for an authentication endpoint.
Generate the expected response for an authentication endpoint .
None
Hash
[Pusher::Error] if channel_name or socket_id are invalid
[ Pusher :: Error ] if channel_name or socket_id are invalid
channel_name
socket_id
custom_data
used for example by private channels
used for example by private channels
None
example
Private channels render :json => Pusher.authenticate('private-my_channel', params[:socket_id])
Private channels render : json = > Pusher . authenticate ( ' private - my_channel ' params [ : socket_id ] )
example
Presence channels render :json => Pusher.authenticate('presence-my_channel', params[:socket_id], { :user_id => current_user.id, # => required :user_info => { # => optional - for example :name => current_user.name, :email => current_user.email } })
Presence channels render : json = > Pusher . authenticate ( ' presence - my_channel ' params [ : socket_id ] { : user_id = > current_user . id # = > required : user_info = > { # = > optional - for example : name = > current_user . name : email = > current_user . email } } )
private
Custom data is sent to server as JSON-encoded string
Custom data is sent to server as JSON - encoded string