Class: Cloudflare::RealtimeKit::Recording

Inherits:
Cloudflare::Resource show all
Defined in:
lib/cloudflare/realtime_kit/recording.rb

Overview

A meeting recording. The platform supports composite recordings (one MP4 of the whole meeting, via Recording.create) and per-track recordings (one file per participant audio/video track, via Recording.start_track).

rec = Recording.create(meeting_id: "mtg-1", app_id: "app-1")

# State transitions hit one upstream endpoint with a
# body-discriminated +action+. The canonical form is +#transition+;
# +#pause+, +#resume+, +#stop+ are 1-line forwarders.
rec.transition(action: :pause)
rec.pause
rec.resume
rec.stop

Recording.active_for(meeting_id: "mtg-1", app_id: "app-1")

Constant Summary collapse

TRANSITIONS =

Spec-enumerated values for #transition. Exposed so callers can iterate, validate, or build CLI flags from the canonical list.

%i[pause resume stop].freeze

Constants inherited from Cloudflare::Resource

Cloudflare::Resource::ENVELOPE_KEYS

Instance Attribute Summary

Attributes inherited from Cloudflare::Resource

#scope

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Cloudflare::Resource

#==, #[], all, attribute, attributes, #attributes, collection_path, create, #destroy, find, has_many, has_one, #hash, #id, #initialize, member_path, read_only, read_only?, #reload, scope_params, scope_required, #set_attrs_from_response, #to_h, to_wire_keys, unwrap_envelope, #update, wire_kwarg, wire_name_for_request, wire_name_for_response

Constructor Details

This class inherits a constructor from Cloudflare::Resource

Class Method Details

.active_for(meeting_id:, app_id:, account_id: nil) ⇒ Object

GET /recordings/active-recording/meeting_id — fetch the recording currently in progress for a meeting (404 if none).



51
52
53
54
55
56
57
# File 'lib/cloudflare/realtime_kit/recording.rb', line 51

def active_for(meeting_id:, app_id:, account_id: nil)
  scope    = build_scope(account_id: , app_id: app_id)
  path     = interpolate("/accounts/{account_id}/realtime/kit/{app_id}/recordings/active-recording/{meeting_id}",
                         scope.merge(meeting_id: meeting_id))
  response = Connection.instance.request(:get, path)
  new(response, scope: scope)
end

.start_track(meeting_id:, layers:, app_id:, account_id: nil, max_seconds: nil) ⇒ Object

POST /recordings/track — start a multi-file (per-track) recording. Different upstream endpoint than create; use this when you need one media file per participant track.



41
42
43
44
45
46
47
# File 'lib/cloudflare/realtime_kit/recording.rb', line 41

def start_track(meeting_id:, layers:, app_id:, account_id: nil, max_seconds: nil)
  scope    = build_scope(account_id: , app_id: app_id)
  path     = interpolate("/accounts/{account_id}/realtime/kit/{app_id}/recordings/track", scope)
  response = Connection.instance.request(:post, path,
    body: { meeting_id: meeting_id, layers: layers, max_seconds: max_seconds })
  new(response, scope: scope)
end

Instance Method Details

#pauseObject

Convenience verbs — each forwards to #transition with a fixed action. The wire mapping lives in #transition; these exist for readability at call sites.



80
# File 'lib/cloudflare/realtime_kit/recording.rb', line 80

def pause  = transition(action: :pause)

#resumeObject



81
# File 'lib/cloudflare/realtime_kit/recording.rb', line 81

def resume = transition(action: :resume)

#stopObject



82
# File 'lib/cloudflare/realtime_kit/recording.rb', line 82

def stop   = transition(action: :stop)

#transition(action:) ⇒ Object

PUT /recordings/Cloudflare::Resource#id — body-discriminated transition. Canonical 1:1 mapping to the upstream operation. Validates action against TRANSITIONS so a typo fails at the call site, not in the upstream 422.

recording.transition(action: :pause)
recording.transition(action: "stop")


67
68
69
70
71
72
73
74
75
# File 'lib/cloudflare/realtime_kit/recording.rb', line 67

def transition(action:)
  sym = action.to_sym
  unless TRANSITIONS.include?(sym)
    raise ArgumentError, "action must be one of #{TRANSITIONS.inspect}, got #{action.inspect}"
  end
  response = Connection.instance.request(:put, member_path, body: { action: sym.to_s })
  set_attrs_from_response(response)
  self
end