Module: AnyCable::Rails::Helper

Defined in:
lib/anycable/rails/helper.rb

Instance Method Summary collapse

Instance Method Details

#action_cable_with_jwt_meta_tag(**identifiers) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/anycable/rails/helper.rb', line 8

def action_cable_with_jwt_meta_tag(**identifiers)
  # From: https://github.com/rails/rails/blob/main/actioncable/lib/action_cable/helpers/action_cable_helper.rb
  base_url = ActionCable.server.config.url ||
    ActionCable.server.config.mount_path ||
    raise("No Action Cable URL configured -- please configure this at config.action_cable.url")

  token = JWT.encode(identifiers)

  parts = [base_url, "#{AnyCable.config.jwt_param}=#{token}"]

  uri = URI.parse(base_url)

  url = parts.join(uri.query ? "&" : "?")

  tag "meta", name: "action-cable-url", content: url
end

#anycable_token_meta_tag(**identifiers) ⇒ Object



25
26
27
28
29
# File 'lib/anycable/rails/helper.rb', line 25

def anycable_token_meta_tag(**identifiers)
  token = JWT.encode(identifiers)

  tag "meta", name: "cable-token", content: token
end

#signed_stream_name(streamables) ⇒ Object



31
32
33
# File 'lib/anycable/rails/helper.rb', line 31

def signed_stream_name(streamables)
  Rails.signed_stream_name(streamables)
end