Class: ExpoTurbo::Rails::Cable::ProtectedStreamsChannel

Inherits:
ActionCable::Channel::Base
  • Object
show all
Defined in:
lib/expo_turbo/rails/cable/protected_streams_channel.rb

Constant Summary collapse

CALLBACK_FAILURE =
Object.new.freeze

Instance Method Summary collapse

Instance Method Details

#subscribedObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/expo_turbo/rails/cable/protected_streams_channel.rb', line 9

def subscribed
  return reject unless ExpoTurbo::Rails::Cable.configured?

  token = params[:signed_stream_name]
  stream_name = ExpoTurbo::Rails::Cable.verified_protected_stream_name(token)
  return reject unless stream_name && valid_grant?(params[:grant])

  subject = resolved_subject
  return if subject.equal?(CALLBACK_FAILURE)
  return reject unless subject.present?

  authorized = subscription_authorized?(subject, stream_name, params[:grant])
  return if authorized.equal?(CALLBACK_FAILURE)
  return reject unless authorized

  stream_from token
end