Class: RubyRabbitmqJanus::RRJ

Inherits:
Object
  • Object
show all
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.

Direct Known Subclasses

RRJAdmin, RRJTask

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRRJ

Return a new instance of RubyRabbitmqJanus.

Examples:

Create a instance to this gem

@rrj = RubyRabbitmqJanus::RRJ.new
=> #<RubyRabbitmqJanus::RRJ:0x007 @session=123>


44
45
46
47
48
# File 'lib/rrj/init.rb', line 44

def initialize
  @option = Tools::Option.new
rescue => exception
  raise Errors::RRJ::InstanciateGem, exception
end

Instance Attribute Details

#sessionFixnum (readonly)

Return an session number created when this gem is instanciate. It’s janus who creates the number of the session.

Returns:

  • (Fixnum)

    Return an session number created when this gem is instanciate. It’s janus who creates the number of the session.



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
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
# File 'lib/rrj/init.rb', line 36

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, options = {})
    session = @option.use_current_session?(options)
    transaction = Janus::Transactions::Session.new(exclusive, session)
    transaction.connect { yield(transaction) }
  rescue
    raise Errors::RRJ::StartTransaction.new(exclusive, options)
  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(options = {})
    session = @option.use_current_session?(options)
    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(options = {})
    session = @option.use_current_session?(options)
    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, options = {})
    session = @option.use_current_session?(options)
    handle = @option.use_current_handle?(options)
    instance = options['instance'] || 1
    transaction = Janus::Transactions::Handle.new(exclusive,
                                                  session,
                                                  handle,
                                                  instance)
    transaction.connect { yield(transaction) }
  rescue
    raise Errors::RRJ::StartTransactionHandle, exclusive, options
  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(options = {})
    session = @option.use_current_session?(options)
    handle = @option.use_current_handle?(options)
    instance = options['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(options = {})
    session = @option.use_current_session?(options)
    handle = @option.use_current_handle?(options)
    instance = options['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_connectionObject

Delete all resources to JanusInstance reference. Warning: All data in database and Janus Instance is delete

Since:

  • 2.1.0



237
238
239
240
241
# File 'lib/rrj/init.rb', line 237

def cleanup_connection
  Models::JanusInstance.destroys
rescue
  raise Errors::RRJ::CleanupConnection
end

#handle_endpoint_private(options = {}) ⇒ Object

Create a transaction between Apps and Janus

Examples:

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

Parameters:

  • options (Hash) (defaults to: {})

Since:

  • 2.7.0



222
223
224
225
226
227
228
229
230
231
# File 'lib/rrj/init.rb', line 222

def handle_endpoint_private(options = {})
  session = @option.use_current_session?(options)
  handle = @option.use_current_handle?(options)
  instance = options['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

Examples:

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

Parameters:

  • options (Hash) (defaults to: {})

Since:

  • 2.7.0



188
189
190
191
192
193
194
195
196
197
# File 'lib/rrj/init.rb', line 188

def handle_endpoint_public(options = {})
  session = @option.use_current_session?(options)
  handle = @option.use_current_handle?(options)
  instance = options['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

Examples:

Create a session

instance : { 'instance' => 42 }
@rrj.session_endpoint_public(instance) do |transaction|
  transaction.publish_message('base::create')
end

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



120
121
122
123
124
# File 'lib/rrj/init.rb', line 120

def session_endpoint_private(options = {})
  session = @option.use_current_session?(options)
  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

Examples:

Create a session

instance : { 'instance' => 42 }
@rrj.session_endpoint_public(instance) do |transaction|
  transaction.publish_message('base::create')
end

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



93
94
95
96
97
# File 'lib/rrj/init.rb', line 93

def session_endpoint_public(options = {})
  session = @option.use_current_session?(options)
  transaction = Janus::Transactions::Session.new(false, session)
  transaction.connect { yield(transaction) }
end

#start_transaction(exclusive = true, options = {}) ⇒ Object

Start a transaction with Janus. Request use session_id information.

Examples:

Get Janus information

@rrj.start_transaction do |transaction|
  response = transaction.publish_message('base::info').to_hash
end

Parameters:

  • exclusive (Boolean) (defaults to: true)

    Choose if message is storage in exclusive queue

  • options (Hash) (defaults to: {})

    Give a session number for use another session in Janus

Since:

  • 2.0.0



64
65
66
67
68
69
70
# File 'lib/rrj/init.rb', line 64

def start_transaction(exclusive = true, options = {})
  session = @option.use_current_session?(options)
  transaction = Janus::Transactions::Session.new(exclusive, session)
  transaction.connect { yield(transaction) }
rescue
  raise Errors::RRJ::StartTransaction.new(exclusive, options)
end

#start_transaction_handle(exclusive = true, options = {}) ⇒ Fixnum

Note:

Use transaction.detach for closing handle in Janus

Start a transaction with Janus. Request used session_id/handle_id information.

Examples:

Send request trickles for exclusive queue

@cde = { 'sdpMid' => '...', sdpMLineIndex => 0, 'candidate' => '...' }
@rrj.start_transaction_handle do |transaction|
  transaction.publish_message('base::trickle', @cde)
end

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

Parameters:

  • exclusive (Boolean) (defaults to: true)

    Choose if message is storage in exclusive queue

  • options (Hash) (defaults to: {})

    Give a session number for use another session in Janus

Returns:

  • (Fixnum)

    Handle used for transaction

Since:

  • 2.0.0



152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/rrj/init.rb', line 152

def start_transaction_handle(exclusive = true, options = {})
  session = @option.use_current_session?(options)
  handle = @option.use_current_handle?(options)
  instance = options['instance'] || 1
  transaction = Janus::Transactions::Handle.new(exclusive,
                                                session,
                                                handle,
                                                instance)
  transaction.connect { yield(transaction) }
rescue
  raise Errors::RRJ::StartTransactionHandle, exclusive, options
end