Class: EventMachine::RTMP::Request
- Inherits:
-
ConnectionDelegate
- Object
- ConnectionDelegate
- EventMachine::RTMP::Request
- Includes:
- Deferrable
- Defined in:
- lib/em-rtmp/request.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#body ⇒ Object
The request implementation here references a Header object and a message body.
-
#header ⇒ Object
The request implementation here references a Header object and a message body.
-
#message ⇒ Object
The request implementation here references a Header object and a message body.
Attributes inherited from ConnectionDelegate
Instance Method Summary collapse
-
#chunk_count ⇒ Object
Determines the number of chunks we will send.
-
#chunk_size ⇒ Object
Determines the proper chunk size for each packet we will send.
-
#chunks ⇒ Object
Splits the body into chunks for sending.
-
#header_length_for_chunk(offset) ⇒ Object
Determine the proper header length for a given chunk.
-
#initialize(connection) ⇒ Request
constructor
Initialize, setting attributes.
-
#send ⇒ Object
Update the header and send each chunk with an appropriate header.
-
#send_chunk(chunk) ⇒ Object
Send a chunk to the stream.
-
#update_header ⇒ Object
Updates the header to reflect the actual length of the body.
Methods inherited from ConnectionDelegate
#bytes_waiting, #change_state, #read, #write
Methods included from IOHelpers
#read_bitfield, #read_double_be, #read_int29, #read_safe, #read_uint16_be, #read_uint24_be, #read_uint32_be, #read_uint32_le, #read_uint8, #write_bitfield, #write_double_be, #write_int29, #write_uint16_be, #write_uint24_be, #write_uint32_be, #write_uint32_le, #write_uint8
Constructor Details
Instance Attribute Details
#body ⇒ Object
The request implementation here references a Header object and a message body. The body can be any object that responds to to_s.
16 17 18 |
# File 'lib/em-rtmp/request.rb', line 16 def body @body end |
#header ⇒ Object
The request implementation here references a Header object and a message body. The body can be any object that responds to to_s.
16 17 18 |
# File 'lib/em-rtmp/request.rb', line 16 def header @header end |
#message ⇒ Object
The request implementation here references a Header object and a message body. The body can be any object that responds to to_s.
16 17 18 |
# File 'lib/em-rtmp/request.rb', line 16 def @message end |
Instance Method Details
#chunk_count ⇒ Object
Determines the number of chunks we will send
Returns the chunk count as an Integer
47 48 49 |
# File 'lib/em-rtmp/request.rb', line 47 def chunk_count (body.length / chunk_size.to_f).ceil end |
#chunk_size ⇒ Object
Determines the proper chunk size for each packet we will send
Returns the chunk size as an Integer
40 41 42 |
# File 'lib/em-rtmp/request.rb', line 40 def chunk_size @connection.chunk_size end |
#chunks ⇒ Object
Splits the body into chunks for sending
Returns an Array of Strings, each a chunk to send
54 55 56 57 58 59 60 |
# File 'lib/em-rtmp/request.rb', line 54 def chunks (0...chunk_count).map do |chunk| offset_start = chunk_size * chunk offset_end = [offset_start + chunk_size, body.length].min - 1 body[offset_start..offset_end] end end |
#header_length_for_chunk(offset) ⇒ Object
Determine the proper header length for a given chunk
Returns an Integer
65 66 67 |
# File 'lib/em-rtmp/request.rb', line 65 def header_length_for_chunk(offset) offset == 0 ? 12 : 1 end |
#send ⇒ Object
Update the header and send each chunk with an appropriate header.
Returns the number of bytes written
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/em-rtmp/request.rb', line 72 def send bytes_sent = 0 update_header Logger.info "head: #{header.inspect}" Logger.info "body: #{.inspect}" for i in 0..(chunk_count-1) self.header.header_length = header_length_for_chunk(i) bytes_sent += send_chunk chunks[i] end PendingRequest.create self, @connection bytes_sent end |
#send_chunk(chunk) ⇒ Object
Send a chunk to the stream
body - Body string to write
Returns the number of bytes written
94 95 96 97 |
# File 'lib/em-rtmp/request.rb', line 94 def send_chunk(chunk) Logger.debug "sending chunk (#{chunk.length})", indent: 1 write(header.encode) + write(chunk) end |
#update_header ⇒ Object
Updates the header to reflect the actual length of the body
Returns nothing
33 34 35 |
# File 'lib/em-rtmp/request.rb', line 33 def update_header header.body_length = body.length end |