ruby_rabbitmq_janus 1.1.12 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +127 -0
- data/Rakefile +1 -3
- data/config/default.md +14 -14
- data/config/default.yml +12 -18
- data/config/requests.md +80 -0
- data/config/requests/{channel → peer}/answer.json +1 -1
- data/config/requests/{channel → peer}/offer.json +0 -0
- data/lib/generators/ruby_rabbitmq_janus/install_generator.rb +1 -0
- data/lib/rrj/errors/config.rb +8 -1
- data/lib/rrj/errors/error.rb +18 -5
- data/lib/rrj/errors/janus.rb +4 -2
- data/lib/rrj/errors/janus_message.rb +19 -15
- data/lib/rrj/errors/janus_response.rb +13 -26
- data/lib/rrj/errors/janus_transaction.rb +7 -13
- data/lib/rrj/errors/rabbit.rb +3 -9
- data/lib/rrj/info.rb +1 -1
- data/lib/rrj/init.rb +118 -68
- data/lib/rrj/janus/processus/concurrency.rb +8 -22
- data/lib/rrj/janus/processus/event.rb +13 -15
- data/lib/rrj/janus/processus/keepalive.rb +20 -15
- data/lib/rrj/janus/responses/response.rb +0 -1
- data/lib/rrj/janus/transactions/admin.rb +14 -22
- data/lib/rrj/janus/transactions/handle.rb +19 -33
- data/lib/rrj/janus/transactions/session.rb +13 -6
- data/lib/rrj/janus/transactions/transaction.rb +16 -24
- data/lib/rrj/rabbit/connect.rb +3 -4
- data/lib/rrj/rabbit/propertie.rb +6 -9
- data/lib/rrj/rabbit/publish/admin.rb +1 -1
- data/lib/rrj/rabbit/publish/base_publisher.rb +5 -0
- data/lib/rrj/rabbit/publish/listener.rb +1 -1
- data/lib/rrj/rabbit/publish/non_exclusive.rb +1 -1
- data/lib/rrj/tools/config.rb +44 -18
- data/lib/rrj/tools/log.rb +30 -15
- data/lib/rrj/tools/replaces/admin.rb +1 -3
- data/lib/rrj/tools/replaces/replace.rb +1 -6
- data/lib/rrj/tools/requests.rb +8 -8
- data/lib/rrj/tools/tools.rb +0 -1
- data/lib/ruby_rabbitmq_janus.rb +1 -0
- data/spec/request/admin/request_handle_info_spec.rb +3 -3
- data/spec/request/base/request_attach_spec.rb +7 -10
- data/spec/request/base/request_detach_spec.rb +6 -9
- data/spec/request/peer/request_answer_spec.rb +66 -0
- data/spec/request/peer/request_offer_spec.rb +113 -0
- data/spec/request/peer/request_trickle_spec.rb +9 -11
- data/spec/rrj/rrj_log_spec.rb +1 -6
- data/spec/spec_helper.rb +0 -1
- data/spec/support/examples.rb +6 -9
- data/spec/support/schemas/config/config.json +20 -32
- data/spec/support/schemas/request/peer/answer.json +15 -0
- data/spec/support/schemas/request/peer/offer.json +15 -0
- data/spec/support/schemas/request/peer/trickle.json +4 -12
- metadata +10 -19
- data/config/requests/channel/README.md +0 -29
- data/config/requests/channel/create.json +0 -9
- data/config/requests/channel/describe.json +0 -10
- data/config/requests/channel/destroy.json +0 -10
- data/config/requests/channel/exists.json +0 -10
- data/config/requests/channel/join.json +0 -11
- data/config/requests/channel/leave.json +0 -11
- data/config/requests/channel/list.json +0 -9
- data/config/requests/channel/select.json +0 -11
- data/config/requests/channel/trickle.json +0 -10
- data/config/requests/videocast/join.json +0 -12
- data/config/requests/videocast/leave.json +0 -11
- data/config/ruby-rabbitmq-janus.yml +0 -27
- data/lib/rrj/errors/request.rb +0 -21
- data/lib/rrj/tools/env.rb +0 -22
@@ -5,7 +5,11 @@ module RubyRabbitmqJanus
|
|
5
5
|
# Modules for create autonomous processus
|
6
6
|
module Concurrencies
|
7
7
|
# @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
|
8
|
-
|
8
|
+
|
9
|
+
# # Class for manage threads
|
10
|
+
#
|
11
|
+
# @abstract Manage thread in this gem for keepalive message and listen
|
12
|
+
# standard queue.
|
9
13
|
class Concurrency
|
10
14
|
# Initialize class with elements for thread communication
|
11
15
|
def initialize
|
@@ -14,37 +18,19 @@ module RubyRabbitmqJanus
|
|
14
18
|
@lock = Mutex.new
|
15
19
|
@condition = ConditionVariable.new
|
16
20
|
@thread = Thread.new { initialize_thread }
|
17
|
-
@thread.abort_on_exception = true
|
18
21
|
end
|
19
22
|
|
20
23
|
private
|
21
24
|
|
22
|
-
# Initialize a thread
|
23
25
|
def initialize_thread
|
24
|
-
rabbit.transaction_long { transaction_running }
|
26
|
+
@rabbit.transaction_long { transaction_running }
|
25
27
|
rescue Interrupt
|
26
28
|
Tools::Log.instance.info "Stop transaction #{self.class.name}"
|
27
|
-
rabbit.close
|
28
|
-
end
|
29
|
-
|
30
|
-
# Wait an signal
|
31
|
-
def wait
|
32
|
-
@lock.synchronize do
|
33
|
-
@condition.wait(@lock)
|
34
|
-
Tools::Log.instance.info 'Waitting signal'
|
35
|
-
yield
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
# Send and signal
|
40
|
-
def signal
|
41
|
-
@lock.synchronize do
|
42
|
-
Tools::Log.instance.info 'Sending signal'
|
43
|
-
@condition.signal
|
44
|
-
end
|
29
|
+
@rabbit.close
|
45
30
|
end
|
46
31
|
|
47
32
|
attr_accessor :rabbit, :publish
|
33
|
+
attr_reader :thread, :lock, :condition
|
48
34
|
end
|
49
35
|
end
|
50
36
|
end
|
@@ -1,33 +1,31 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
# :reek:InstanceVariableAssumption and :reek:NilCheck
|
3
|
-
# :reek:TooManyInstanceVariables and :reek:TooManyStatements
|
4
2
|
|
5
3
|
module RubyRabbitmqJanus
|
6
|
-
# @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
|
7
4
|
module Janus
|
8
5
|
module Concurrencies
|
9
|
-
#
|
6
|
+
# @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
|
7
|
+
|
8
|
+
# # Listen standar queue
|
9
|
+
#
|
10
|
+
# Listen standard queue and sending a block code to thread listen.
|
11
|
+
# The default queue is configured in config file.
|
12
|
+
#
|
13
|
+
# @see file:/config/default.md For more information to config file used.
|
10
14
|
class Event < Concurrency
|
11
15
|
include Singleton
|
12
16
|
|
13
|
-
#
|
14
|
-
#
|
15
|
-
|
16
|
-
super
|
17
|
-
@publish = @response = nil
|
18
|
-
end
|
19
|
-
|
20
|
-
# Execute an block code in a thread
|
17
|
+
# Create a thred for execute a block code in a thread
|
18
|
+
#
|
19
|
+
# @yield Send to publisher the actions when a Janus event is received
|
21
20
|
def run(&block)
|
22
|
-
|
21
|
+
thread.join
|
23
22
|
Thread.new do
|
24
|
-
loop {
|
23
|
+
loop { thread.thread_variable_get(:publish).listen_events(&block) }
|
25
24
|
end
|
26
25
|
end
|
27
26
|
|
28
27
|
private
|
29
28
|
|
30
|
-
# Initialize a thread
|
31
29
|
def transaction_running
|
32
30
|
publisher = Rabbit::Publisher::Listener.new(rabbit)
|
33
31
|
Thread.current.thread_variable_set(:publish, publisher)
|
@@ -4,59 +4,64 @@ module RubyRabbitmqJanus
|
|
4
4
|
module Janus
|
5
5
|
module Concurrencies
|
6
6
|
# @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
|
7
|
-
|
7
|
+
|
8
|
+
# # Manage sending keepalive message
|
9
|
+
#
|
10
|
+
# Create a thread for sending keepalive to session created by this
|
11
|
+
# instanciate gem
|
8
12
|
class Keepalive < Concurrency
|
9
13
|
include Singleton
|
10
14
|
|
11
|
-
#
|
15
|
+
# Create a thread
|
12
16
|
def initialize
|
13
|
-
@
|
17
|
+
@response = nil
|
14
18
|
super
|
15
19
|
end
|
16
20
|
|
17
|
-
#
|
21
|
+
# @return [Fixnum] Identifier to session created by Janus
|
18
22
|
def session
|
19
|
-
|
23
|
+
lock.synchronize do
|
24
|
+
condition.wait(lock)
|
25
|
+
Tools::Log.instance.info 'Waitting signal'
|
26
|
+
running_session
|
27
|
+
end
|
20
28
|
end
|
21
29
|
|
22
30
|
private
|
23
31
|
|
24
|
-
# Star an session with janus and waiting an signal for saving session_id
|
25
32
|
def transaction_running
|
26
33
|
@response = Janus::Responses::Standard.new(create_session)
|
27
|
-
|
34
|
+
lock.synchronize do
|
35
|
+
Tools::Log.instance.info 'Sending signal'
|
36
|
+
condition.signal
|
37
|
+
end
|
28
38
|
session_keepalive(ttl)
|
29
39
|
end
|
30
40
|
|
31
|
-
# Create an loop for sending a keepalive message
|
32
41
|
def session_keepalive(time_to_live)
|
33
42
|
loop do
|
34
43
|
sleep time_to_live
|
35
|
-
|
44
|
+
publish.send_a_message(message_keepalive)
|
36
45
|
end
|
37
46
|
rescue => message
|
38
47
|
Tools::Log.instance.debug "Error keepalive : #{message}"
|
39
48
|
end
|
40
49
|
|
41
|
-
# Define a Time To Live between each request sending to janus
|
42
50
|
def ttl
|
43
51
|
Tools::Config.instance.options['gem']['session']['keepalive'].to_i
|
44
52
|
rescue => error
|
45
53
|
Tools::Log.instance.debug "TTL Not loading - #{error}"
|
46
54
|
end
|
47
55
|
|
48
|
-
# Create an message and publish for create session in Janus
|
49
56
|
def create_session
|
50
|
-
|
51
|
-
|
57
|
+
publish = Rabbit::Publisher::PublishExclusive.new(rabbit.channel, '')
|
58
|
+
publish.send_a_message(Janus::Messages::Standard.new('base::create'))
|
52
59
|
end
|
53
60
|
|
54
|
-
# Return session_id
|
55
61
|
def running_session
|
56
62
|
@response.session
|
57
63
|
end
|
58
64
|
|
59
|
-
# Create an message with type keepalive
|
60
65
|
def message_keepalive
|
61
66
|
Janus::Messages::Standard.new('base::keepalive',
|
62
67
|
'session_id' => running_session)
|
@@ -4,43 +4,37 @@ module RubyRabbitmqJanus
|
|
4
4
|
module Janus
|
5
5
|
module Transactions
|
6
6
|
# @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
|
7
|
+
|
7
8
|
# This class work with janus and send a series of message
|
8
9
|
class Admin < Handle
|
9
|
-
#
|
10
|
+
# Opening a long transaction with rabbitmq. If handle is equal to 0
|
11
|
+
# create an handle, send request 'type::atach' before message.
|
12
|
+
#
|
13
|
+
# @yield Send a message to Janus
|
14
|
+
#
|
15
|
+
# @return [Fixnum] Sender using in current transaction
|
10
16
|
def connect
|
11
17
|
rabbit.transaction_short do
|
12
18
|
choose_queue
|
13
|
-
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
# Choose queue, create an handle, connect to rabbitmq server and send
|
18
|
-
# messages
|
19
|
-
def handle_connect
|
20
|
-
rabbit.transaction_long do
|
21
|
-
choose_queue
|
22
|
-
create_handle
|
19
|
+
create_handle if handle.eql?(0)
|
23
20
|
yield
|
24
21
|
end
|
22
|
+
handle
|
25
23
|
end
|
26
24
|
|
27
25
|
# Publish an message in handle
|
28
|
-
def publish_message_handle(type, options
|
26
|
+
def publish_message_handle(type, options)
|
29
27
|
opts = {
|
30
28
|
'session_id' => session,
|
31
29
|
'handle_id' => handle,
|
32
|
-
'
|
33
|
-
'admin_secret' => admin_secret
|
34
|
-
}
|
30
|
+
'admin_secret' => admin_secret
|
35
31
|
}
|
36
32
|
msg = Janus::Messages::Admin.new(type, opts.merge!(options))
|
37
|
-
|
33
|
+
publisher = publish.send_a_message(msg)
|
34
|
+
Janus::Responses::Standard.new(read_response(publisher))
|
38
35
|
end
|
39
36
|
|
40
|
-
|
41
|
-
def handle_running_stop
|
42
|
-
publish_message_handle('base::detach')
|
43
|
-
end
|
37
|
+
private
|
44
38
|
|
45
39
|
# Define queue used for admin message
|
46
40
|
def choose_queue
|
@@ -48,8 +42,6 @@ module RubyRabbitmqJanus
|
|
48
42
|
@publish = Rabbit::Publisher::PublisherAdmin.new(chan)
|
49
43
|
end
|
50
44
|
|
51
|
-
private
|
52
|
-
|
53
45
|
# Override method for publishing an message and reading a response
|
54
46
|
def send_a_message
|
55
47
|
Tools::Log.instance.info 'Publish a message ...'
|
@@ -4,48 +4,40 @@ module RubyRabbitmqJanus
|
|
4
4
|
module Janus
|
5
5
|
module Transactions
|
6
6
|
# @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
|
7
|
+
|
7
8
|
# This class work with janus and send a series of message
|
8
|
-
# :reek:TooManyStatements
|
9
9
|
class Handle < Session
|
10
|
-
#
|
11
|
-
|
10
|
+
# Initialize a transaction with handle
|
11
|
+
#
|
12
|
+
# @param [Fixnum] session
|
13
|
+
# Use a session identifier for created message
|
14
|
+
def initialize(session, exclusive, handle = 0)
|
12
15
|
super(session)
|
13
|
-
@exclusive = nil
|
14
|
-
end
|
15
|
-
|
16
|
-
# Initialize connection to Rabbit and Janus
|
17
|
-
def handle_connect(exclusive)
|
18
16
|
@exclusive = exclusive
|
19
|
-
|
20
|
-
choose_queue(exclusive)
|
21
|
-
create_handle
|
22
|
-
yield
|
23
|
-
end
|
24
|
-
handle
|
17
|
+
@handle = handle
|
25
18
|
end
|
26
19
|
|
27
|
-
#
|
28
|
-
#
|
29
|
-
|
30
|
-
|
20
|
+
# Opening a long transaction with rabbitmq and is ending closing
|
21
|
+
# transaction, so delete exclusive queue
|
22
|
+
#
|
23
|
+
# @yield Send a message to Janus
|
24
|
+
#
|
25
|
+
# @return [Fixnum] Sender using in current transaction
|
26
|
+
def connect
|
31
27
|
rabbit.transaction_short do
|
32
|
-
choose_queue
|
33
|
-
|
28
|
+
choose_queue
|
29
|
+
create_handle
|
34
30
|
yield
|
35
31
|
end
|
36
|
-
|
37
|
-
|
38
|
-
# Stop an handle running
|
39
|
-
def handle_running_stop
|
40
|
-
publish_message_handle('base::detach')
|
32
|
+
handle
|
41
33
|
end
|
42
34
|
|
43
35
|
# Publish an message in handle
|
44
|
-
def publish_message_handle(type, options
|
36
|
+
def publish_message_handle(type, options)
|
45
37
|
opts = { 'session_id' => session, 'handle_id' => handle }
|
46
38
|
msg = Janus::Messages::Standard.new(type, opts.merge!(options))
|
47
39
|
publisher = publish.send_a_message(msg)
|
48
|
-
Janus::Responses::Standard.new(read_response(publisher
|
40
|
+
Janus::Responses::Standard.new(read_response(publisher))
|
49
41
|
end
|
50
42
|
|
51
43
|
private
|
@@ -58,12 +50,6 @@ module RubyRabbitmqJanus
|
|
58
50
|
@handle = send_a_message_exclusive { msg }
|
59
51
|
end
|
60
52
|
|
61
|
-
# Connect to handle
|
62
|
-
def connect_handle(sender)
|
63
|
-
Tools::Log.instance.info 'Connect an handle'
|
64
|
-
@handle = sender
|
65
|
-
end
|
66
|
-
|
67
53
|
# Send a messaeg in exclusive queue
|
68
54
|
def send_a_message_exclusive
|
69
55
|
Janus::Responses::Standard.new(read_response_exclusive do
|
@@ -4,14 +4,21 @@ module RubyRabbitmqJanus
|
|
4
4
|
module Janus
|
5
5
|
module Transactions
|
6
6
|
# @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
|
7
|
-
|
8
|
-
#
|
7
|
+
|
8
|
+
# # Manage a transaction
|
9
|
+
# Manage a transaction with message if contains a session identifier
|
9
10
|
class Session < Transaction
|
10
|
-
#
|
11
|
-
|
11
|
+
# Opening a short transaction with rabbitmq and close when is ending
|
12
|
+
#
|
13
|
+
# @param [Boolean] exclusive
|
14
|
+
# Determine if the message is sending to a exclusive queue or not
|
15
|
+
#
|
16
|
+
# @yield Send a message to Janus
|
17
|
+
def connect(exclusive)
|
18
|
+
@exclusive = exclusive
|
12
19
|
rabbit.transaction_short do
|
13
|
-
choose_queue
|
14
|
-
send_a_message
|
20
|
+
choose_queue
|
21
|
+
send_a_message { yield }
|
15
22
|
end
|
16
23
|
end
|
17
24
|
end
|
@@ -1,39 +1,33 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
# :reek:TooManyInstanceVariables and :reek:ControlParameter
|
3
|
-
# :reek:ControlParameter and :reek:BooleanParameter
|
4
2
|
|
5
3
|
module RubyRabbitmqJanus
|
6
4
|
module Janus
|
7
|
-
# Define an module for manipulate
|
5
|
+
# Define an module for manipulate messages between apps and Janus
|
8
6
|
module Transactions
|
9
7
|
# @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
|
10
|
-
|
8
|
+
|
9
|
+
# # Manage a transactions
|
10
|
+
# This class work with Janus and send a series of message
|
11
11
|
class Transaction
|
12
|
-
# Initialize
|
12
|
+
# Initialize a transaction
|
13
|
+
#
|
14
|
+
# @param [Fixnum] session
|
15
|
+
# Use a session identifier for created message
|
13
16
|
def initialize(session)
|
14
17
|
@rabbit = Rabbit::Connect.new
|
15
18
|
@session = session
|
16
|
-
@
|
19
|
+
@publish = @exclusive = nil
|
17
20
|
rescue => error
|
18
21
|
raise Errors::JanusTransaction, error
|
19
22
|
end
|
20
23
|
|
21
|
-
# Opening a short transaction with rabbitmq and close when is ending
|
22
|
-
def connect(exclusive)
|
23
|
-
@rabbit.transaction_short do
|
24
|
-
choose_queue(exclusive)
|
25
|
-
send_a_message(exclusive) { yield }
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
24
|
private
|
30
25
|
|
31
|
-
attr_reader :rabbit, :session, :response, :handle, :publish
|
26
|
+
attr_reader :rabbit, :session, :response, :handle, :publish, :exclusive
|
32
27
|
|
33
|
-
|
34
|
-
def choose_queue(exclusive)
|
28
|
+
def choose_queue
|
35
29
|
chan = @rabbit.channel
|
36
|
-
@publish = if exclusive
|
30
|
+
@publish = if @exclusive
|
37
31
|
Tools::Log.instance.debug \
|
38
32
|
'Choose an queue Exclusive : ampq.gen-xxx'
|
39
33
|
Rabbit::Publisher::PublishExclusive.new(chan, '')
|
@@ -44,16 +38,14 @@ module RubyRabbitmqJanus
|
|
44
38
|
end
|
45
39
|
end
|
46
40
|
|
47
|
-
|
48
|
-
def send_a_message(exclusive)
|
41
|
+
def send_a_message
|
49
42
|
Tools::Log.instance.info 'Publish a message ...'
|
50
43
|
publish = @publish.send_a_message(yield)
|
51
|
-
Janus::Responses::Standard.new(read_response(publish
|
44
|
+
Janus::Responses::Standard.new(read_response(publish))
|
52
45
|
end
|
53
46
|
|
54
|
-
|
55
|
-
|
56
|
-
if exclusive
|
47
|
+
def read_response(publish)
|
48
|
+
if @exclusive
|
57
49
|
Tools::Log.instance.info '... and read a janus response'
|
58
50
|
publish
|
59
51
|
else
|
data/lib/rrj/rabbit/connect.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
# :reek:FeatureEnvy
|
3
2
|
|
4
3
|
module RubyRabbitmqJanus
|
5
4
|
module Rabbit
|
@@ -9,7 +8,7 @@ module RubyRabbitmqJanus
|
|
9
8
|
# Initialize connection to server RabbitMQ
|
10
9
|
def initialize
|
11
10
|
Tools::Log.instance.debug 'Initialize connection with RabbitMQ'
|
12
|
-
@rabbit = Bunny.new(read_options_server)
|
11
|
+
@rabbit = Bunny.new(read_options_server.merge!(option_log_rabbit))
|
13
12
|
end
|
14
13
|
|
15
14
|
# Create an transaction with rabbitmq and close after response is received
|
@@ -54,9 +53,9 @@ module RubyRabbitmqJanus
|
|
54
53
|
cfg = Tools::Config.instance.options['rabbit']
|
55
54
|
opts = {}
|
56
55
|
%w(host port pass user vhost).each do |val|
|
57
|
-
opts.merge!(val.to_sym =>
|
56
|
+
opts.merge!(val.to_sym => cfg[val])
|
58
57
|
end
|
59
|
-
opts
|
58
|
+
opts
|
60
59
|
end
|
61
60
|
|
62
61
|
# Define option logs for bunny
|