Class: RubyRabbitmqJanus::RRJ
- Inherits:
-
Object
- Object
- RubyRabbitmqJanus::RRJ
- Defined in:
- lib/rrj/init.rb
Overview
Initialize gem and create automatically an session with Janus :reek:BooleanParameter
Instance Attribute Summary collapse
-
#event ⇒ Object
readonly
Returns the value of attribute event.
-
#session ⇒ Object
readonly
Initialize gem and create automatically an session with Janus :reek:BooleanParameter.
-
#transaction ⇒ Object
private
Returns the value of attribute transaction.
Instance Method Summary collapse
-
#handle_message_simple(type, replace = {}, add = {}) ⇒ Object
Start an short transaction, this queue is not exclusive.
-
#initialize(listen_queue_classic = true) ⇒ RRJ
constructor
Returns a new instance of RubyRabbitmqJanus.
-
#message_admin(type, options = {}) ⇒ RubyRabbitmqJanus::Janus::Response
Send a message simple for admin Janus.
-
#message_handle(type, replace = {}, add = {}) ⇒ RubyRabbitmqJanus::Janus::Response
Send an message in handle session in current session.
-
#message_session(type, options = {}, exclusive = false) ⇒ RubyRabbitmqJanus::Janus::Response
Send an message simple in current session.
-
#message_simple(type = 'base::info', exclusive = false) ⇒ RubyRabbitmqJanus::Janus::Response
Send an simple message to janus.
-
#start_handle(exclusive = false) ⇒ Object
Define an handle transaction and establish connection with janus.
-
#start_handle_admin ⇒ Object
Define an handle admin transaction and establish connection with janus.
-
#start_instances_tools ⇒ Object
private
Start singleton instances.
-
#stop_handle ⇒ Object
Stop an handle existing in session running.
-
#use_current_session?(option) ⇒ Boolean
private
Return a current session if not specified.
Constructor Details
#initialize(listen_queue_classic = true) ⇒ RRJ
Returns a new instance of RubyRabbitmqJanus
23 24 25 26 27 28 29 30 |
# File 'lib/rrj/init.rb', line 23 def initialize(listen_queue_classic = true) start_instances_tools @session = Janus::Keepalive.instance.session Janus::Event.instance if listen_queue_classic @transaction = nil rescue => error raise Errors::RRJErrorInit, error end |
Instance Attribute Details
#event ⇒ Object (readonly)
Returns the value of attribute event.
20 21 22 |
# File 'lib/rrj/init.rb', line 20 def event @event end |
#session ⇒ Object (readonly)
Initialize gem and create automatically an session with Janus :reek:BooleanParameter
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 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 |
# File 'lib/rrj/init.rb', line 19 class RRJ attr_reader :session, :event # Returns a new instance of RubyRabbitmqJanus def initialize(listen_queue_classic = true) start_instances_tools @session = Janus::Keepalive.instance.session Janus::Event.instance if listen_queue_classic @transaction = nil rescue => error raise Errors::RRJErrorInit, error end # Send an simple message to janus. No options in request with this method. # @param [String] type # Given a type to request. JSON request writing in 'config/requests/' # @param [Bollean] exclusive # Use an exclusive queue or not # @example Sending an message info # RubyRabbitmqJanus::RRJ.new.message_simple('base::info') # #=> {"janus":"server_info","name":"Janus WebRTC Gateway" ... } # @return [RubyRabbitmqJanus::Janus::Response] Give an object response to janus server def (type = 'base::info', exclusive = false) Janus::Transaction.new(@session).connect(exclusive) do Janus::Message.new(type) end end # Send an message simple in current session. # @param [String] type # Given a type to request. JSON request writing in 'config/requests/' # @param [Hash] options Options update in request # @param [Bollean] exclusive # Use an exclusive queue or not # @example Sending an message create # RubyRabbitmqJanus::RRJ.new.message_session('base::create') # #=> {"janus":"server_info","name":"Janus WebRTC Gateway" ... } # @return [RubyRabbitmqJanus::Janus::Response] Give an object response to janus server def (type, = {}, exclusive = false) Janus::TransactionSession.new(@session).session_connect(exclusive) do Janus::Message.new(type, use_current_session?()) end rescue => error raise Errors::RRJErrorPost, error end # Send a message simple for admin Janus # @param [String] type # Given a type to request. JSON request writing in 'config/requests/' # @param [Hash] options Options update in request # @example Sending an message create # RubyRabbitmqJanus::RRJ.new.message_admin('admin::sessions') # #=> {"janus":"success","sessions": [12345, 8786567465465, ...] } # @return [RubyRabbitmqJanus::Janus::Response] Give an object response to janus server def (type, = {}) Janus::TransactionAdmin.new(@session).connect do Janus::MessageAdmin.new(type, .merge!('session_id' => @session)) end end # Send an message in handle session in current session. # @param [String] type # Given a type to request. JSON request writing in 'config/requests/' # @param [Hash] replace Options update in request # @param [Hash] add Elements adding to request # @example Sending an message create # RubyRabbitmqJanus::RRJ.new.message_session('base::create') # #=> {"janus":"server_info","name":"Janus WebRTC Gateway" ... } # @return [RubyRabbitmqJanus::Janus::Response] Give an object response to janus server def (type, replace = {}, add = {}) = { 'replace' => replace, 'add' => add } @transaction.(type, ) end # Define an handle transaction and establish connection with janus def start_handle(exclusive = false) @transaction ||= Janus::TransactionHandle.new(@session) @transaction.handle_connect(exclusive) { yield } rescue => error raise Errors::RRJErrorHandle, error end # Define an handle admin transaction and establish connection with janus def start_handle_admin @transaction ||= Janus::TransactionAdmin.new(@session) @transaction.handle_connect { yield } rescue => error raise Errors::RRJErrorHandle, error end # Stop an handle existing in session running def stop_handle @transaction.handle_running_stop end # Start an short transaction, this queue is not exclusive def (type, replace = {}, add = {}) @transaction ||= Janus::TransactionHandle.new(@session) @transaction.handle_connect_and_stop(false) do (type, replace, add).for_plugin end rescue => error raise Errors::RRJErrorHandle, error end private attr_accessor :transaction # Start singleton instances def start_instances_tools Tools::Env.instance Tools::Log.instance Tools::Config.instance Tools::Requests.instance end # Return a current session if not specified def use_current_session?(option) { 'session_id' => @session } unless option.key?('session_id') end end |
#transaction ⇒ Object (private)
Returns the value of attribute transaction.
126 127 128 |
# File 'lib/rrj/init.rb', line 126 def transaction @transaction end |
Instance Method Details
#handle_message_simple(type, replace = {}, add = {}) ⇒ Object
Start an short transaction, this queue is not exclusive
115 116 117 118 119 120 121 122 |
# File 'lib/rrj/init.rb', line 115 def (type, replace = {}, add = {}) @transaction ||= Janus::TransactionHandle.new(@session) @transaction.handle_connect_and_stop(false) do (type, replace, add).for_plugin end rescue => error raise Errors::RRJErrorHandle, error end |
#message_admin(type, options = {}) ⇒ RubyRabbitmqJanus::Janus::Response
Send a message simple for admin Janus
73 74 75 76 77 |
# File 'lib/rrj/init.rb', line 73 def (type, = {}) Janus::TransactionAdmin.new(@session).connect do Janus::MessageAdmin.new(type, .merge!('session_id' => @session)) end end |
#message_handle(type, replace = {}, add = {}) ⇒ RubyRabbitmqJanus::Janus::Response
Send an message in handle session in current session.
88 89 90 91 |
# File 'lib/rrj/init.rb', line 88 def (type, replace = {}, add = {}) = { 'replace' => replace, 'add' => add } @transaction.(type, ) end |
#message_session(type, options = {}, exclusive = false) ⇒ RubyRabbitmqJanus::Janus::Response
Send an message simple in current session.
57 58 59 60 61 62 63 |
# File 'lib/rrj/init.rb', line 57 def (type, = {}, exclusive = false) Janus::TransactionSession.new(@session).session_connect(exclusive) do Janus::Message.new(type, use_current_session?()) end rescue => error raise Errors::RRJErrorPost, error end |
#message_simple(type = 'base::info', exclusive = false) ⇒ RubyRabbitmqJanus::Janus::Response
Send an simple message to janus. No options in request with this method.
41 42 43 44 45 |
# File 'lib/rrj/init.rb', line 41 def (type = 'base::info', exclusive = false) Janus::Transaction.new(@session).connect(exclusive) do Janus::Message.new(type) end end |
#start_handle(exclusive = false) ⇒ Object
Define an handle transaction and establish connection with janus
94 95 96 97 98 99 |
# File 'lib/rrj/init.rb', line 94 def start_handle(exclusive = false) @transaction ||= Janus::TransactionHandle.new(@session) @transaction.handle_connect(exclusive) { yield } rescue => error raise Errors::RRJErrorHandle, error end |
#start_handle_admin ⇒ Object
Define an handle admin transaction and establish connection with janus
102 103 104 105 106 107 |
# File 'lib/rrj/init.rb', line 102 def start_handle_admin @transaction ||= Janus::TransactionAdmin.new(@session) @transaction.handle_connect { yield } rescue => error raise Errors::RRJErrorHandle, error end |
#start_instances_tools ⇒ Object (private)
Start singleton instances
129 130 131 132 133 134 |
# File 'lib/rrj/init.rb', line 129 def start_instances_tools Tools::Env.instance Tools::Log.instance Tools::Config.instance Tools::Requests.instance end |
#stop_handle ⇒ Object
Stop an handle existing in session running
110 111 112 |
# File 'lib/rrj/init.rb', line 110 def stop_handle @transaction.handle_running_stop end |
#use_current_session?(option) ⇒ Boolean (private)
Return a current session if not specified
137 138 139 |
# File 'lib/rrj/init.rb', line 137 def use_current_session?(option) { 'session_id' => @session } unless option.key?('session_id') end |