Class: Librtmp::Streamer
- Inherits:
-
Object
- Object
- Librtmp::Streamer
- Defined in:
- lib/librtmp/streamer.rb
Instance Attribute Summary collapse
-
#session ⇒ Object
readonly
Returns the value of attribute session.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
-
#writable ⇒ Object
readonly
Returns the value of attribute writable.
Instance Method Summary collapse
- #connect(connection_url, connection_writable = false) ⇒ Object
- #disconnect ⇒ Object
-
#initialize ⇒ Streamer
constructor
A new instance of Streamer.
- #send(data) ⇒ Object
- #writable? ⇒ Boolean
Constructor Details
#initialize ⇒ Streamer
Returns a new instance of Streamer.
9 10 11 |
# File 'lib/librtmp/streamer.rb', line 9 def initialize() @session = nil end |
Instance Attribute Details
#session ⇒ Object (readonly)
Returns the value of attribute session.
7 8 9 |
# File 'lib/librtmp/streamer.rb', line 7 def session @session end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
5 6 7 |
# File 'lib/librtmp/streamer.rb', line 5 def url @url end |
#writable ⇒ Object (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 |
#disconnect ⇒ Object
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
13 14 15 |
# File 'lib/librtmp/streamer.rb', line 13 def writable? @writable end |