Class: Librtmp::Streamer

Inherits:
Object
  • Object
show all
Defined in:
lib/librtmp/streamer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStreamer

Returns a new instance of Streamer.



9
10
11
# File 'lib/librtmp/streamer.rb', line 9

def initialize()
  @session = nil
end

Instance Attribute Details

#sessionObject (readonly)

Returns the value of attribute session.



7
8
9
# File 'lib/librtmp/streamer.rb', line 7

def session
  @session
end

#urlObject (readonly)

Returns the value of attribute url.



5
6
7
# File 'lib/librtmp/streamer.rb', line 5

def url
  @url
end

#writableObject (readonly)

Returns the value of attribute writable.



6
7
8
# File 'lib/librtmp/streamer.rb', line 6

def writable
  @writable
end

Instance Method Details

#connect(connection_url, connection_writable = false) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/librtmp/streamer.rb', line 17

def connect(connection_url, connection_writable = false)
  @url = connection_url
  @writable = connection_writable

  setup_session

  FFI::RTMP_EnableWrite(@session_ptr) if writable?

  unless FFI::RTMP_Connect(@session_ptr, nil)
    raise 'Unable to connect to RTMP server'
  end

  unless FFI::RTMP_ConnectStream(@session_ptr, 0)
    raise 'Unable to connect to RTMP stream'
  end
end

#disconnectObject



44
45
46
47
# File 'lib/librtmp/streamer.rb', line 44

def disconnect
  FFI::RTMP_Close(@session_ptr)
  FFI::RTMP_Free(@session_ptr)
end

#send(data) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/librtmp/streamer.rb', line 34

def send(data)
  return if data.nil? || data == ''

  if data.is_a?(Hash)
    (data)
  elsif is_flv?(data)
    FFI::RTMP_Write(@session_ptr, data, data.size)
  end
end

#writable?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/librtmp/streamer.rb', line 13

def writable?
  @writable
end