Class: WebRTC::RTCSessionDescription

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

Constant Summary collapse

TYPES =
%i[offer answer pranswer rollback].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(init = {}) ⇒ RTCSessionDescription

Returns a new instance of RTCSessionDescription.



9
10
11
12
13
14
15
16
# File 'lib/webrtc/session_description.rb', line 9

def initialize(init = {})
  init = init.to_h if init.respond_to?(:to_h)
  @type = normalize_type(init[:type])
  @sdp = init[:sdp] || ''
  @ptr = nil

  validate!
end

Instance Attribute Details

#sdpObject (readonly)

Returns the value of attribute sdp.



7
8
9
# File 'lib/webrtc/session_description.rb', line 7

def sdp
  @sdp
end

#typeObject (readonly)

Returns the value of attribute type.



7
8
9
# File 'lib/webrtc/session_description.rb', line 7

def type
  @type
end

Class Method Details

.from_ptr(ptr) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/webrtc/session_description.rb', line 18

def self.from_ptr(ptr)
  return nil if ptr.nil? || ptr.null?

  type_str = FFI.webrtc_session_description_get_type(ptr)
  sdp_str = FFI.webrtc_session_description_get_sdp(ptr)

  desc = new(type: type_str&.to_sym, sdp: sdp_str)
  desc.instance_variable_set(:@ptr, ptr)
  desc
end

Instance Method Details

#releaseObject



43
44
45
46
47
48
# File 'lib/webrtc/session_description.rb', line 43

def release
  return unless @ptr && !@ptr.null?

  FFI.webrtc_session_description_destroy(@ptr)
  @ptr = nil
end

#to_hObject



39
40
41
# File 'lib/webrtc/session_description.rb', line 39

def to_h
  { type: type, sdp: sdp }
end

#to_ptrObject

Raises:



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

def to_ptr
  return @ptr if @ptr && !@ptr.null?

  error = FFI::Error.new
  @ptr = FFI.webrtc_session_description_create(type.to_s, sdp, error)
  raise OperationError, error[:message] if error[:code] != 0

  @ptr
end