Class: WebRTC::MediaStreamTrack

Inherits:
Object
  • Object
show all
Defined in:
lib/webrtc/media_stream_track.rb

Direct Known Subclasses

AudioTrackInterface, VideoTrackInterface

Constant Summary collapse

KINDS =
%i[audio video].freeze
READY_STATES =
%i[live ended].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ MediaStreamTrack

Returns a new instance of MediaStreamTrack.



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/webrtc/media_stream_track.rb', line 11

def initialize(options = {})
  @id = options[:id] || generate_id
  @kind = options[:kind]&.to_sym
  @label = options[:label] || ''
  @enabled = options.fetch(:enabled, true)
  @muted = options.fetch(:muted, false)
  @ready_state = :live
  @content_hint = options[:content_hint] || ''
  @callbacks = {}
  @ptr = options[:ptr]

  validate!
end

Instance Attribute Details

#content_hintObject

Returns the value of attribute content_hint.



9
10
11
# File 'lib/webrtc/media_stream_track.rb', line 9

def content_hint
  @content_hint
end

#enabledObject

Returns the value of attribute enabled.



9
10
11
# File 'lib/webrtc/media_stream_track.rb', line 9

def enabled
  @enabled
end

#idObject (readonly)

Returns the value of attribute id.



8
9
10
# File 'lib/webrtc/media_stream_track.rb', line 8

def id
  @id
end

#kindObject (readonly)

Returns the value of attribute kind.



8
9
10
# File 'lib/webrtc/media_stream_track.rb', line 8

def kind
  @kind
end

#labelObject (readonly)

Returns the value of attribute label.



8
9
10
# File 'lib/webrtc/media_stream_track.rb', line 8

def label
  @label
end

#mutedObject

Returns the value of attribute muted.



9
10
11
# File 'lib/webrtc/media_stream_track.rb', line 9

def muted
  @muted
end

#ready_stateObject (readonly)

Returns the value of attribute ready_state.



8
9
10
# File 'lib/webrtc/media_stream_track.rb', line 8

def ready_state
  @ready_state
end

Instance Method Details

#apply_constraints(_constraints = {}) ⇒ Object



55
56
57
# File 'lib/webrtc/media_stream_track.rb', line 55

def apply_constraints(_constraints = {})
  Promise.resolve(nil)
end

#cloneObject



30
31
32
33
34
35
36
37
38
# File 'lib/webrtc/media_stream_track.rb', line 30

def clone
  MediaStreamTrack.new(
    kind: kind,
    label: label,
    enabled: enabled,
    muted: muted,
    content_hint: content_hint
  )
end

#get_capabilitiesObject



44
45
46
# File 'lib/webrtc/media_stream_track.rb', line 44

def get_capabilities
  {}
end

#get_constraintsObject



40
41
42
# File 'lib/webrtc/media_stream_track.rb', line 40

def get_constraints
  {}
end

#get_settingsObject



48
49
50
51
52
53
# File 'lib/webrtc/media_stream_track.rb', line 48

def get_settings
  {
    device_id: '',
    group_id: ''
  }
end

#on_ended(&block) ⇒ Object



59
60
61
# File 'lib/webrtc/media_stream_track.rb', line 59

def on_ended(&block)
  @callbacks[:ended] = block
end

#on_mute(&block) ⇒ Object



63
64
65
# File 'lib/webrtc/media_stream_track.rb', line 63

def on_mute(&block)
  @callbacks[:mute] = block
end

#on_unmute(&block) ⇒ Object



67
68
69
# File 'lib/webrtc/media_stream_track.rb', line 67

def on_unmute(&block)
  @callbacks[:unmute] = block
end

#stopObject



25
26
27
28
# File 'lib/webrtc/media_stream_track.rb', line 25

def stop
  @ready_state = :ended
  @callbacks[:ended]&.call
end