Class: RubyRabbitmqJanus::RRJ
- Inherits:
-
Object
- Object
- RubyRabbitmqJanus::RRJ
- Defined in:
- lib/rrj/init.rb
Overview
# RubyRabbitmqJanus - RRJ
Initialize RRJ gem and create automatically a session with janus and sending a keepalive message. The Time To Live is configured in yaml configuration file config/default.yml or if you a customize config in config/ruby-rabbitmq-janus.yml.
Instance Attribute Summary collapse
-
#session ⇒ Fixnum
readonly
Return an session number created when this gem is instanciate.
Instance Method Summary collapse
-
#cleanup_connection ⇒ Object
Delete all resources to JanusInstance reference.
-
#handle_endpoint_private(options = {}) ⇒ Object
Create a transaction between Apps and Janus.
-
#handle_endpoint_public(options = {}) ⇒ Object
Create a transaction between Apps and Janus in private queue.
-
#initialize ⇒ RRJ
constructor
Return a new instance of RubyRabbitmqJanus.
-
#session_endpoint_private(options = {}) ⇒ Object
Create a transaction between Apps and Janus in queue private.
-
#session_endpoint_public(options = {}) ⇒ Object
Create a transaction between Apps and Janus in queue public.
-
#start_transaction(exclusive = true, options = {}) ⇒ Object
deprecated
Deprecated.
Use #session_endpoint_public or #session_endpoint_private instead.
-
#start_transaction_handle(exclusive = true, options = {}) ⇒ Fixnum
deprecated
Deprecated.
Use #handle_endpoint_public or #handle_endpoint_private instead.
Constructor Details
Instance Attribute Details
#session ⇒ Fixnum (readonly)
Return an session number created when this gem is instanciate. It’s janus who creates the number of the session.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
# File 'lib/rrj/init.rb', line 37 class RRJ attr_reader :session # Return a new instance of RubyRabbitmqJanus. # # @example Create a instance to this gem # @rrj = RubyRabbitmqJanus::RRJ.new # => #<RubyRabbitmqJanus::RRJ:0x007 @session=123> def initialize @option = Tools::Option.new rescue => exception raise Errors::RRJ::InstanciateGem, exception end # Start a transaction with Janus. Request use session_id information. # # @param [Boolean] exclusive Choose if message is storage in exclusive queue # @param [Hash] options # Give a session number for use another session in Janus # # @example Get Janus information # @rrj.start_transaction do |transaction| # response = transaction.publish_message('base::info').to_hash # end # # @since 2.0.0 # @deprecated Use {#session_endpoint_public} or # {#session_endpoint_private} instead. def start_transaction(exclusive = true, = {}) session = @option.use_current_session?() transaction = Janus::Transactions::Session.new(exclusive, session) transaction.connect { yield(transaction) } rescue raise Errors::RRJ::StartTransaction.new(exclusive, ) end # Create a transaction between Apps and Janus in queue public # # @params [Hash] options # @options [String] :instance (mandatory id cluster is enabled) # @options [Integer] :session_id # @options [Hash] :replace # @options [Hash] :add # # @example Create a session # instance : { 'instance' => 42 } # @rrj.session_endpoint_public(instance) do |transaction| # transaction.publish_message('base::create') # end # # @example Destroy session in instance # options = { 'instance' => 42, 'session_id' => 71984735765 } # @rrj.session_endpoint_public(options) do |transaction| # transaction.publish_message('base::destroy', options) # end # # @since 2.7.0 def session_endpoint_public( = {}) session = @option.use_current_session?() transaction = Janus::Transactions::Session.new(false, session) transaction.connect { yield(transaction) } end # Create a transaction between Apps and Janus in queue private # # @params [Hash] options # @options [String] :instance (mandatory id cluster is enabled) # @options [Integer] :session_id # @options [Hash] :replace # @options [Hash] :add # # @example Create a session # instance : { 'instance' => 42 } # @rrj.session_endpoint_public(instance) do |transaction| # transaction.publish_message('base::create') # end # # @example Destroy session in instance # options = { 'instance' => 42, 'session_id' => 71984735765 } # @rrj.session_endpoint_public(options) do |transaction| # transaction.publish_message('base::destroy', options) # end # # @since 2.7.0 def session_endpoint_private( = {}) session = @option.use_current_session?() transaction = Janus::Transactions::Session.new(true, session) transaction.connect { yield(transaction) } end # Start a transaction with Janus. Request used session_id/handle_id # information. # # @param [Boolean] exclusive Choose if message is storage in exclusive queue # @param [Hash] options # Give a session number for use another session in Janus # # @note Use transaction.detach for closing handle in Janus # # @example Send request trickles for exclusive queue # @cde = { 'sdpMid' => '...', sdpMLineIndex => 0, 'candidate' => '...' } # @rrj.start_transaction_handle do |transaction| # transaction.publish_message('base::trickle', @cde) # end # # @example Send request trickles for non exclusive queue # @cde = { 'sdpMid' => '...', sdpMLineIndex => 0, 'candidate' => '...' } # @rrj.start_transaction_handle(false) do |transaction| # transaction.publish_message('base::trickle', @cde) # end # # @return [Fixnum] Handle used for transaction # # @since 2.0.0 # @deprecated Use {#handle_endpoint_public} # or {#handle_endpoint_private} instead. def start_transaction_handle(exclusive = true, = {}) session = @option.use_current_session?() handle = @option.use_current_handle?() instance = ['instance'] || 1 transaction = Janus::Transactions::Handle.new(exclusive, session, handle, instance) transaction.connect { yield(transaction) } rescue raise Errors::RRJ::StartTransactionHandle, exclusive, end # Create a transaction between Apps and Janus in private queue # # @param [Hash] options # @options [String] :instance (mandatory id cluster is enabled) # @options [Integer] :session_id (mandatory) # @options [Integer] :handle_id # @options [Hash] :replace # @options [Hash] :add # # @example Post a offer # options = { # 'instance' => 42, # 'session_id' => 71984735765, # 'handle_id' => 56753748917, # 'replace' => { # 'sdp' => 'v=0\r\no=[..more sdp stuff..]' # } # } # @rrj.handle_endpoint_public(options) do |transaction| # transaction.publish_message('peer::offer', options) # end # # @since 2.7.0 def handle_endpoint_public( = {}) session = @option.use_current_session?() handle = @option.use_current_handle?() instance = ['instance'] || 1 transaction = Janus::Transactions::Handle.new(false, session, handle, instance) transaction.connect { yield(transaction) } end # Create a transaction between Apps and Janus # # @param [Hash] options # @options [String] :instance (mandatory id cluster is enabled) # @options [Integer] :session_id (mandatory) # @options [Integer] :handle_id # @options [Hash] :replace # @options [Hash] :add # # @example Post a answer # options = { # 'instance' => 42, # 'session_id' => 71984735765, # 'handle_id' => 56753748917, # 'replace' => { # 'sdp' => 'v=0\r\no=[..more sdp stuff..]' # } # } # @rrj.handle_endpoint_private(options) do |transaction| # transaction.publish_message('peer::answer', options) # end # # @since 2.7.0 def handle_endpoint_private( = {}) session = @option.use_current_session?() handle = @option.use_current_handle?() instance = ['instance'] || 1 transaction = Janus::Transactions::Handle.new(true, session, handle, instance) transaction.connect { yield(transaction) } end # Delete all resources to JanusInstance reference. # Warning: All data in database and Janus Instance is delete # # @since 2.1.0 def cleanup_connection Models::JanusInstance.destroys rescue raise Errors::RRJ::CleanupConnection end private attr_reader :option end |
Instance Method Details
#cleanup_connection ⇒ Object
Delete all resources to JanusInstance reference. Warning: All data in database and Janus Instance is delete
238 239 240 241 242 |
# File 'lib/rrj/init.rb', line 238 def cleanup_connection Models::JanusInstance.destroys rescue raise Errors::RRJ::CleanupConnection end |
#handle_endpoint_private(options = {}) ⇒ Object
Create a transaction between Apps and Janus
223 224 225 226 227 228 229 230 231 232 |
# File 'lib/rrj/init.rb', line 223 def handle_endpoint_private( = {}) session = @option.use_current_session?() handle = @option.use_current_handle?() instance = ['instance'] || 1 transaction = Janus::Transactions::Handle.new(true, session, handle, instance) transaction.connect { yield(transaction) } end |
#handle_endpoint_public(options = {}) ⇒ Object
Create a transaction between Apps and Janus in private queue
189 190 191 192 193 194 195 196 197 198 |
# File 'lib/rrj/init.rb', line 189 def handle_endpoint_public( = {}) session = @option.use_current_session?() handle = @option.use_current_handle?() instance = ['instance'] || 1 transaction = Janus::Transactions::Handle.new(false, session, handle, instance) transaction.connect { yield(transaction) } end |
#session_endpoint_private(options = {}) ⇒ Object
Create a transaction between Apps and Janus in queue private
121 122 123 124 125 |
# File 'lib/rrj/init.rb', line 121 def session_endpoint_private( = {}) session = @option.use_current_session?() transaction = Janus::Transactions::Session.new(true, session) transaction.connect { yield(transaction) } end |
#session_endpoint_public(options = {}) ⇒ Object
Create a transaction between Apps and Janus in queue public
94 95 96 97 98 |
# File 'lib/rrj/init.rb', line 94 def session_endpoint_public( = {}) session = @option.use_current_session?() transaction = Janus::Transactions::Session.new(false, session) transaction.connect { yield(transaction) } end |
#start_transaction(exclusive = true, options = {}) ⇒ Object
Use #session_endpoint_public or #session_endpoint_private instead.
Start a transaction with Janus. Request use session_id information.
65 66 67 68 69 70 71 |
# File 'lib/rrj/init.rb', line 65 def start_transaction(exclusive = true, = {}) session = @option.use_current_session?() transaction = Janus::Transactions::Session.new(exclusive, session) transaction.connect { yield(transaction) } rescue raise Errors::RRJ::StartTransaction.new(exclusive, ) end |
#start_transaction_handle(exclusive = true, options = {}) ⇒ Fixnum
Use #handle_endpoint_public or #handle_endpoint_private instead.
Use transaction.detach for closing handle in Janus
Start a transaction with Janus. Request used session_id/handle_id information.
153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/rrj/init.rb', line 153 def start_transaction_handle(exclusive = true, = {}) session = @option.use_current_session?() handle = @option.use_current_handle?() instance = ['instance'] || 1 transaction = Janus::Transactions::Handle.new(exclusive, session, handle, instance) transaction.connect { yield(transaction) } rescue raise Errors::RRJ::StartTransactionHandle, exclusive, end |