Class: RTSP::Message
Overview
This class is responsible for building a single RTSP message that can be used by both clients and servers.
Only message types defined in RFC 2326 are implemented, however if you need to add a new message type (perhaps for some custom server implementation?), you can simply add to the supported list by:
RTSP::Message. << :barrel_roll
You can then build it like a standard message:
= RTSP::Message.("192.168.1.10").with_headers({
cseq: 123, content_type: "video/x-m4v" })
Constant Summary collapse
- RTSP_ACCEPT_TYPE =
"application/sdp"
- RTSP_DEFAULT_NPT =
"0.000-"
- RTSP_DEFAULT_SEQUENCE_NUMBER =
1
- USER_AGENT =
"RubyRTSP/#{RTSP::VERSION} (Ruby #{RUBY_VERSION}-p#{RUBY_PATCHLEVEL})"
Constants included from Global
Global::DEFAULT_RTSP_PORT, Global::DEFAULT_VERSION
Class Attribute Summary collapse
-
.message_types ⇒ Array<Symbol>
Lists the method/message types this class can create.
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#method_type ⇒ Object
readonly
Returns the value of attribute method_type.
-
#request_uri ⇒ Object
readonly
Returns the value of attribute request_uri.
-
#rtsp_version ⇒ Object
writeonly
Sets the attribute rtsp_version.
Attributes included from Global
#log, #log_level, #logger, #raise_errors
Class Method Summary collapse
-
.method_missing(method, *args) ⇒ RTSP::Message
Creates a new message based on the given method type and URI.
-
.respond_to?(method) ⇒ Boolean
Make sure the class responds to our message types.
Instance Method Summary collapse
- #add_body(new_body) ⇒ Object
- #add_headers(new_headers) ⇒ Object
-
#header(type, value) ⇒ Object
Adds the header and its value to the list of headers for the message.
-
#initialize(method_type, request_uri) ⇒ Message
constructor
A new instance of Message.
-
#to_s ⇒ String
The message as a String.
-
#with_body(new_body) ⇒ Object
Use when creating a new Message to add body you want.
-
#with_headers(new_headers) ⇒ RTSP::Message
Use to message-chain with one of the method types; used when creating a new Message to add headers you want.
Methods included from Helpers
Methods included from Global
#log?, #raise_errors?, #reset_config!, #rtsp_version
Constructor Details
#initialize(method_type, request_uri) ⇒ Message
Returns a new instance of Message.
80 81 82 83 84 85 86 |
# File 'lib/rtsp/message.rb', line 80 def initialize(method_type, request_uri) @method_type = method_type @request_uri = build_resource_uri_from request_uri @headers = default_headers @body = "" @version = DEFAULT_VERSION end |
Class Attribute Details
.message_types ⇒ Array<Symbol>
Lists the method/message types this class can create.
47 48 49 |
# File 'lib/rtsp/message.rb', line 47 def @message_types end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
75 76 77 |
# File 'lib/rtsp/message.rb', line 75 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
74 75 76 |
# File 'lib/rtsp/message.rb', line 74 def headers @headers end |
#method_type ⇒ Object (readonly)
Returns the value of attribute method_type.
72 73 74 |
# File 'lib/rtsp/message.rb', line 72 def method_type @method_type end |
#request_uri ⇒ Object (readonly)
Returns the value of attribute request_uri.
73 74 75 |
# File 'lib/rtsp/message.rb', line 73 def request_uri @request_uri end |
#rtsp_version=(value) ⇒ Object (writeonly)
Sets the attribute rtsp_version
76 77 78 |
# File 'lib/rtsp/message.rb', line 76 def rtsp_version=(value) @rtsp_version = value end |
Class Method Details
.method_missing(method, *args) ⇒ RTSP::Message
Creates a new message based on the given method type and URI.
61 62 63 64 65 66 67 68 69 |
# File 'lib/rtsp/message.rb', line 61 def method_missing(method, *args) request_uri = args.first if @message_types.include? method self.new(method, request_uri) else super end end |
.respond_to?(method) ⇒ Boolean
Make sure the class responds to our message types.
52 53 54 |
# File 'lib/rtsp/message.rb', line 52 def respond_to?(method) @message_types.include?(method) || super end |
Instance Method Details
#add_body(new_body) ⇒ Object
135 136 137 138 |
# File 'lib/rtsp/message.rb', line 135 def add_body new_body add_headers({ content_length: new_body.length }) @body = new_body end |
#add_headers(new_headers) ⇒ Object
119 120 121 |
# File 'lib/rtsp/message.rb', line 119 def add_headers(new_headers) @headers.merge! new_headers end |
#header(type, value) ⇒ Object
Adds the header and its value to the list of headers for the message.
92 93 94 95 96 97 98 |
# File 'lib/rtsp/message.rb', line 92 def header(type, value) if type.is_a? Symbol headers[type] = value else raise RTSP::Error, "Header type must be a Symbol (i.e. :cseq)." end end |
#to_s ⇒ String
Returns The message as a String.
148 149 150 |
# File 'lib/rtsp/message.rb', line 148 def to_s .to_s end |
#with_body(new_body) ⇒ Object
Use when creating a new Message to add body you want.
129 130 131 132 133 |
# File 'lib/rtsp/message.rb', line 129 def with_body(new_body) add_body new_body self end |
#with_headers(new_headers) ⇒ RTSP::Message
Use to message-chain with one of the method types; used when creating a new Message to add headers you want.
113 114 115 116 117 |
# File 'lib/rtsp/message.rb', line 113 def with_headers(new_headers) add_headers new_headers self end |