ruby_rabbitmq_janus 1.2.9 → 2.0.0.pre.42
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/Gemfile +2 -0
- data/README.md +145 -32
- data/config/default.yml +2 -0
- data/config/requests.md +2 -1
- data/config/requests/admin/add_token.json +6 -0
- data/config/requests/admin/allow_token.json +6 -0
- data/config/requests/admin/disallow_token.json +6 -0
- data/config/requests/admin/handle_info.json +1 -1
- data/config/requests/admin/handles.json +1 -1
- data/config/requests/admin/remove_token.json +6 -0
- data/config/requests/admin/sessions.json +1 -1
- data/config/requests/admin/set_locking_debug.json +6 -0
- data/config/requests/admin/{log_level.json → set_log_level.json} +1 -1
- data/config/requests/admin/tokens.json +5 -0
- data/config/requests/base/attach.json +1 -1
- data/config/requests/base/create.json +1 -1
- data/config/requests/base/destroy.json +1 -1
- data/config/requests/base/detach.json +1 -1
- data/config/requests/base/info.json +1 -1
- data/config/requests/base/keepalive.json +1 -1
- data/config/requests/peer/answer.json +1 -1
- data/config/requests/peer/offer.json +1 -1
- data/config/requests/peer/trickle.json +1 -1
- data/lib/generators/ruby_rabbitmq_janus/initializer_generator.rb +3 -0
- data/lib/rrj/admin.rb +34 -0
- data/lib/rrj/errors/error.rb +2 -1
- data/lib/rrj/errors/init.rb +6 -0
- data/lib/rrj/errors/janus/janus.rb +1 -0
- data/lib/rrj/errors/janus/janus_message.rb +8 -4
- data/lib/rrj/errors/janus/janus_processus_keepalive.rb +1 -0
- data/lib/rrj/errors/janus/janus_response.rb +27 -6
- data/lib/rrj/errors/janus/janus_transaction.rb +4 -0
- data/lib/rrj/errors/rabbit/rabbit.rb +3 -1
- data/lib/rrj/errors/tools/config.rb +1 -0
- data/lib/rrj/info.rb +1 -1
- data/lib/rrj/init.rb +37 -169
- data/lib/rrj/janus/messages/admin.rb +1 -2
- data/lib/rrj/janus/messages/message.rb +4 -4
- data/lib/rrj/janus/messages/standard.rb +3 -5
- data/lib/rrj/janus/processus/concurrency.rb +1 -1
- data/lib/rrj/janus/processus/keepalive.rb +10 -4
- data/lib/rrj/janus/responses/admin.rb +31 -0
- data/lib/rrj/janus/responses/event.rb +23 -5
- data/lib/rrj/janus/responses/response.rb +2 -0
- data/lib/rrj/janus/responses/standard.rb +26 -5
- data/lib/rrj/janus/transactions/admin.rb +22 -26
- data/lib/rrj/janus/transactions/handle.rb +13 -8
- data/lib/rrj/janus/transactions/session.rb +25 -7
- data/lib/rrj/janus/transactions/transaction.rb +2 -1
- data/lib/rrj/rabbit/connect.rb +2 -3
- data/lib/rrj/rabbit/publish/admin.rb +1 -6
- data/lib/rrj/rabbit/publish/base_publisher.rb +6 -11
- data/lib/rrj/rabbit/publish/exclusive.rb +1 -0
- data/lib/rrj/rabbit/publish/listener.rb +10 -27
- data/lib/rrj/rabbit/publish/non_exclusive.rb +2 -6
- data/lib/rrj/rabbit/publish/publisher.rb +4 -17
- data/lib/rrj/tools/{config.rb → gem/config.rb} +5 -5
- data/lib/rrj/tools/{log.rb → gem/log.rb} +21 -6
- data/lib/rrj/tools/gem/option.rb +57 -0
- data/lib/rrj/tools/{requests.rb → gem/requests.rb} +0 -0
- data/lib/rrj/tools/replaces/admin.rb +7 -13
- data/lib/rrj/tools/replaces/handle.rb +61 -0
- data/lib/rrj/tools/replaces/replace.rb +57 -27
- data/lib/rrj/tools/replaces/session.rb +34 -0
- data/lib/rrj/tools/replaces/type.rb +63 -11
- data/lib/rrj/tools/tools.rb +4 -3
- data/lib/ruby_rabbitmq_janus.rb +1 -0
- data/spec/request/admin/request_handle_info_spec.rb +13 -7
- data/spec/request/admin/request_handles_spec.rb +20 -0
- data/spec/request/admin/request_sessions_spec.rb +5 -4
- data/spec/request/admin/request_set_locking_debug_spec.rb +16 -0
- data/spec/request/admin/request_set_log_level_spec.rb +16 -0
- data/spec/request/admin/request_tokens_spec.rb +13 -0
- data/spec/request/base/request_attach_spec.rb +6 -9
- data/spec/request/base/request_create_spec.rb +5 -3
- data/spec/request/base/request_destroy_spec.rb +5 -3
- data/spec/request/base/request_detach_spec.rb +6 -7
- data/spec/request/base/request_info_spec.rb +5 -3
- data/spec/request/base/request_keepalive_spec.rb +5 -3
- data/spec/request/peer/request_offer_spec.rb +18 -92
- data/spec/request/peer/request_trickle_spec.rb +9 -28
- data/spec/request/peer/request_trickles_spec.rb +23 -0
- data/spec/rrj/responses/responses_admin_spec.rb +39 -0
- data/spec/rrj/responses/responses_event_spec.rb +25 -0
- data/spec/rrj/responses/responses_response_spec.rb +31 -0
- data/spec/rrj/responses/responses_standard_spec.rb +43 -0
- data/spec/rrj/rrj_config_spec.rb +7 -7
- data/spec/rrj/rrj_rabbitmq_spec.rb +1 -1
- data/spec/rrj/tools/replace_admin_spec.rb +86 -0
- data/spec/rrj/tools/replace_handle_spec.rb +78 -0
- data/spec/rrj/tools/replace_session_spec.rb +66 -0
- data/spec/rrj/tools/replace_spec.rb +69 -0
- data/spec/rrj/tools/type_spec.rb +150 -0
- data/spec/spec_helper.rb +46 -7
- data/spec/support/examples_request.rb +33 -61
- data/spec/support/examples_response.rb +30 -0
- data/spec/support/schemas/request/admin/handles.json +15 -0
- data/spec/support/schemas/request/admin/set_locking_debug.json +13 -0
- data/spec/support/schemas/request/admin/set_log_level.json +11 -0
- data/spec/support/schemas/request/admin/tokens.json +13 -0
- data/spec/support/type.rb +66 -0
- metadata +41 -69
- data/config/requests/peer/trickles.json +0 -7
- data/lib/rrj/tools/replaces/standard.rb +0 -101
- data/spec/fixtures/config/requests/admin/handle_info.json +0 -3
- data/spec/fixtures/config/requests/admin/handles.json +0 -3
- data/spec/fixtures/config/requests/admin/log_level.json +0 -3
- data/spec/fixtures/config/requests/admin/sessions.json +0 -3
- data/spec/fixtures/config/requests/base/attach.json +0 -3
- data/spec/fixtures/config/requests/base/create.json +0 -4
- data/spec/fixtures/config/requests/base/destroy.json +0 -3
- data/spec/fixtures/config/requests/base/detach.json +0 -3
- data/spec/fixtures/config/requests/base/info.json +0 -3
- data/spec/fixtures/config/requests/base/keepalive.json +0 -3
- data/spec/fixtures/config/requests/peer/answer.json +0 -3
- data/spec/fixtures/config/requests/peer/offer.json +0 -3
- data/spec/fixtures/config/requests/peer/trickle.json +0 -3
@@ -5,8 +5,9 @@ module RubyRabbitmqJanus
|
|
5
5
|
# Define an module for manipulate messages between apps and Janus
|
6
6
|
module Transactions
|
7
7
|
# @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
|
8
|
-
|
8
|
+
#
|
9
9
|
# # Manage a transactions
|
10
|
+
#
|
10
11
|
# This class work with Janus and send a series of message
|
11
12
|
class Transaction
|
12
13
|
# Initialize a transaction
|
data/lib/rrj/rabbit/connect.rb
CHANGED
@@ -3,7 +3,8 @@
|
|
3
3
|
module RubyRabbitmqJanus
|
4
4
|
module Rabbit
|
5
5
|
# @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
|
6
|
-
#
|
6
|
+
#
|
7
|
+
# Class for manage connection with RabbitMQ
|
7
8
|
class Connect
|
8
9
|
# Initialize connection to server RabbitMQ
|
9
10
|
def initialize
|
@@ -48,7 +49,6 @@ module RubyRabbitmqJanus
|
|
48
49
|
|
49
50
|
private
|
50
51
|
|
51
|
-
# Read option for bunny instance (connection with rabbitmq)
|
52
52
|
def read_options_server
|
53
53
|
cfg = Tools::Config.instance.options['rabbit']
|
54
54
|
opts = {}
|
@@ -58,7 +58,6 @@ module RubyRabbitmqJanus
|
|
58
58
|
opts
|
59
59
|
end
|
60
60
|
|
61
|
-
# Define option logs for bunny
|
62
61
|
def option_log_rabbit
|
63
62
|
if Tools::Log.instance.level.zero?
|
64
63
|
{
|
@@ -10,7 +10,7 @@ module RubyRabbitmqJanus
|
|
10
10
|
#
|
11
11
|
# @param [String] exchange Exchange used for the transaction
|
12
12
|
def initialize(exchange)
|
13
|
-
@reply = exchange.queue(
|
13
|
+
@reply = exchange.queue(Tools::Config.instance.queue_admin_from)
|
14
14
|
super(exchange)
|
15
15
|
subscribe_to_queue
|
16
16
|
end
|
@@ -29,11 +29,6 @@ module RubyRabbitmqJanus
|
|
29
29
|
private
|
30
30
|
|
31
31
|
attr_reader :reply
|
32
|
-
|
33
|
-
# Define queue used for posting a message to API admin
|
34
|
-
def queue_from
|
35
|
-
Tools::Config.instance.queue_admin_from
|
36
|
-
end
|
37
32
|
end
|
38
33
|
end
|
39
34
|
end
|
@@ -1,5 +1,4 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
require 'semaphore'
|
3
2
|
|
4
3
|
module RubyRabbitmqJanus
|
5
4
|
module Rabbit
|
@@ -16,13 +15,13 @@ module RubyRabbitmqJanus
|
|
16
15
|
#
|
17
16
|
# @abstract Publish message in RabbitMQ
|
18
17
|
class BasePublisher
|
19
|
-
attr_reader :
|
18
|
+
attr_reader :response
|
20
19
|
|
21
20
|
# Define a base publisher
|
22
21
|
def initialize
|
23
22
|
Tools::Log.instance.debug 'Create an publisher'
|
24
|
-
@
|
25
|
-
@
|
23
|
+
@response = nil
|
24
|
+
@condition = ConditionVariable.new
|
26
25
|
@lock = Mutex.new
|
27
26
|
end
|
28
27
|
|
@@ -30,16 +29,12 @@ module RubyRabbitmqJanus
|
|
30
29
|
|
31
30
|
attr_accessor :condition, :lock
|
32
31
|
|
33
|
-
# return an response when signal is trigger
|
34
32
|
def return_response
|
35
|
-
Tools::Log.instance.debug 'Waiting response...'
|
36
|
-
@semaphore.wait
|
37
|
-
Tools::Log.instance.debug 'Response received'
|
38
|
-
response = nil
|
39
33
|
@lock.synchronize do
|
40
|
-
|
34
|
+
Tools::Log.instance.debug 'Response received'
|
35
|
+
@condition.wait(@lock)
|
36
|
+
@response
|
41
37
|
end
|
42
|
-
response
|
43
38
|
end
|
44
39
|
end
|
45
40
|
end
|
@@ -4,6 +4,7 @@ module RubyRabbitmqJanus
|
|
4
4
|
module Rabbit
|
5
5
|
module Publisher
|
6
6
|
# @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
|
7
|
+
#
|
7
8
|
# This publisher don't post message. Is listen just an standard queue to
|
8
9
|
# Janus. By default is "from-janus". It's a parameter in config to this
|
9
10
|
# gem.
|
@@ -13,62 +14,44 @@ module RubyRabbitmqJanus
|
|
13
14
|
# @param [String] rabbit Information connection to rabbitmq server
|
14
15
|
def initialize(rabbit)
|
15
16
|
super()
|
16
|
-
@responses = []
|
17
17
|
@rabbit = rabbit.channel
|
18
|
+
@response = nil
|
18
19
|
subscribe_queue
|
19
20
|
end
|
20
21
|
|
21
22
|
# Listen a queue and return a body response
|
22
23
|
def listen_events
|
23
|
-
Tools::Log.instance.debug 'Waiting event...'
|
24
|
-
@semaphore.wait
|
25
|
-
Tools::Log.instance.info 'Janus event received .. treatment ..'
|
26
|
-
response = nil
|
27
24
|
lock.synchronize do
|
28
|
-
|
25
|
+
condition.wait(lock)
|
26
|
+
Tools::Log.instance.info 'Janus event received .. treatment ..'
|
27
|
+
yield @response.event, @response
|
29
28
|
end
|
30
|
-
yield response.event, response
|
31
29
|
end
|
32
30
|
|
33
31
|
private
|
34
32
|
|
35
|
-
def queue_name
|
36
|
-
Tools::Config.instance.queue_from
|
37
|
-
end
|
38
|
-
|
39
|
-
# Subscribe queue
|
40
33
|
def subscribe_queue
|
41
|
-
reply = @rabbit.queue(
|
34
|
+
reply = @rabbit.queue(Tools::Config.instance.queue_from)
|
42
35
|
@rabbit.prefetch(1)
|
43
36
|
reply.bind(binding).subscribe(opts_subs) do |info, prop, payload|
|
44
|
-
|
37
|
+
Tools::Log.instance.info \
|
38
|
+
"[X] Message reading ##{prop['correlation_id']}"
|
45
39
|
synchronize_response(info, payload)
|
46
40
|
end
|
47
41
|
end
|
48
42
|
|
49
|
-
# Define type binding used for subscriber
|
50
43
|
def binding
|
51
44
|
@rabbit.direct('amq.direct')
|
52
45
|
end
|
53
46
|
|
54
|
-
# Options subscribe
|
55
47
|
def opts_subs
|
56
48
|
{ block: false, manual_ack: true, arguments: { 'x-priority': 2 } }
|
57
49
|
end
|
58
50
|
|
59
|
-
# Counts transmitted messages
|
60
|
-
def log_message_id(propertie)
|
61
|
-
message_id = propertie.message_id
|
62
|
-
Tools::Log.instance.info "[X] Message reading with ID #{message_id}"
|
63
|
-
end
|
64
|
-
|
65
|
-
# Sending an signal when an response is reading in queue
|
66
51
|
def synchronize_response(info, payload)
|
67
|
-
|
68
|
-
@responses.push(Janus::Responses::Event.new(JSON.parse(payload)))
|
69
|
-
end
|
52
|
+
@response = Janus::Responses::Event.new(JSON.parse(payload))
|
70
53
|
@rabbit.acknowledge(info.delivery_tag, false)
|
71
|
-
|
54
|
+
lock.synchronize { condition.signal }
|
72
55
|
end
|
73
56
|
end
|
74
57
|
end
|
@@ -4,12 +4,13 @@ module RubyRabbitmqJanus
|
|
4
4
|
module Rabbit
|
5
5
|
module Publisher
|
6
6
|
# @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
|
7
|
+
#
|
7
8
|
# Publish message in queue non exclusive. By default "to-janus".
|
8
9
|
# This an option in config to this gem.
|
9
10
|
class PublishNonExclusive < Publisher
|
10
11
|
# Define an publisher for create non exclusive queue
|
11
12
|
def initialize(exchange)
|
12
|
-
@reply = exchange.queue(queue_from)
|
13
|
+
@reply = exchange.queue(Tools::Config.instance.queue_from)
|
13
14
|
super(exchange)
|
14
15
|
end
|
15
16
|
|
@@ -23,11 +24,6 @@ module RubyRabbitmqJanus
|
|
23
24
|
private
|
24
25
|
|
25
26
|
attr_reader :reply
|
26
|
-
|
27
|
-
# Define queue used for posting a message to API public
|
28
|
-
def queue_from
|
29
|
-
Tools::Config.instance.queue_from
|
30
|
-
end
|
31
27
|
end
|
32
28
|
end
|
33
29
|
end
|
@@ -4,7 +4,7 @@ module RubyRabbitmqJanus
|
|
4
4
|
module Rabbit
|
5
5
|
module Publisher
|
6
6
|
# @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
|
7
|
-
|
7
|
+
#
|
8
8
|
# This publisher send and read an message in queues
|
9
9
|
class Publisher < BasePublisher
|
10
10
|
# Intialize a publisher for sending and reading a message
|
@@ -28,35 +28,22 @@ module RubyRabbitmqJanus
|
|
28
28
|
Tools::Log.instance.info "Send request type : #{request.type}"
|
29
29
|
@message = request
|
30
30
|
@exchange.publish(@message.to_json,
|
31
|
-
request.options.merge!(reply_to:
|
31
|
+
request.options.merge!(reply_to: reply.name))
|
32
32
|
rescue => error
|
33
33
|
raise Errors::RabbitPublishMessage, error, request
|
34
34
|
end
|
35
35
|
|
36
36
|
private
|
37
37
|
|
38
|
-
# Subscribe to queue selectd with a message
|
39
38
|
def subscribe_to_queue
|
40
39
|
reply.subscribe do |_delivery_info, propertie, payload|
|
41
40
|
if @message.correlation.eql?(propertie.correlation_id)
|
42
|
-
|
43
|
-
lock.synchronize
|
44
|
-
@responses.push(JSON.parse payload)
|
45
|
-
end
|
46
|
-
Tools::Log.instance.debug "Response payload is: #{payload}"
|
47
|
-
@semaphore.signal
|
48
|
-
else
|
49
|
-
Tools::Log.instance.error "Response correlation ID mismatch (#{@message.correlation}!=#{propertie.correlation_id})"
|
41
|
+
@response = JSON.parse payload
|
42
|
+
lock.synchronize { condition.signal }
|
50
43
|
end
|
51
44
|
end
|
52
45
|
end
|
53
46
|
|
54
|
-
# Name to queue used for this publisher
|
55
|
-
# @return [String] Name to queue used
|
56
|
-
def queue_name
|
57
|
-
reply.name
|
58
|
-
end
|
59
|
-
|
60
47
|
attr_accessor :message
|
61
48
|
end
|
62
49
|
end
|
@@ -32,8 +32,8 @@ module RubyRabbitmqJanus
|
|
32
32
|
# Initialize configuration file default or customize if exist
|
33
33
|
def initialize
|
34
34
|
@options = @configuration = nil
|
35
|
-
|
36
|
-
|
35
|
+
loading_configuration_customize
|
36
|
+
loading_configuration_default
|
37
37
|
Tools::Log.instance.save_level(log_level)
|
38
38
|
end
|
39
39
|
|
@@ -86,17 +86,17 @@ module RubyRabbitmqJanus
|
|
86
86
|
def load_configuration
|
87
87
|
log_message = "Loading configuration file : #{@configuration}"
|
88
88
|
Tools::Log.instance.info(log_message)
|
89
|
-
YAML.
|
89
|
+
YAML.safe_load(ERB.new(File.read(@configuration)).result)
|
90
90
|
rescue
|
91
91
|
raise Errors::FileNotFound, @configuration
|
92
92
|
end
|
93
93
|
|
94
|
-
def
|
94
|
+
def loading_configuration_customize
|
95
95
|
@configuration = File.join(Dir.pwd, CONF_CUSTOM)
|
96
96
|
@options = load_configuration if File.exist?(@configuration)
|
97
97
|
end
|
98
98
|
|
99
|
-
def
|
99
|
+
def loading_configuration_default
|
100
100
|
@configuration = PATH_DEFAULT
|
101
101
|
@options ||= load_configuration
|
102
102
|
end
|
@@ -23,6 +23,9 @@ module RubyRabbitmqJanus
|
|
23
23
|
UNKNOWN: Logger::UNKNOWN
|
24
24
|
}.freeze
|
25
25
|
|
26
|
+
# Sensitive data
|
27
|
+
SENSITIVES = %i(admin_secret apisecret).freeze
|
28
|
+
|
26
29
|
attr_reader :level
|
27
30
|
|
28
31
|
# Returns a new instance to Log and use `Tag` element for each line
|
@@ -43,41 +46,41 @@ module RubyRabbitmqJanus
|
|
43
46
|
#
|
44
47
|
# @param message [String] Message writing in warning level in log
|
45
48
|
def unknown(message)
|
46
|
-
write_tag { @logs.unknown(message) }
|
49
|
+
write_tag { @logs.unknown(filter(message)) }
|
47
50
|
end
|
48
51
|
|
49
52
|
# Write a message in log with a `FATAL` level
|
50
53
|
#
|
51
54
|
# @param message [String] Message writing in warning level in log
|
52
55
|
def fatal(message)
|
53
|
-
write_tag { @logs.fatal(message) } if test_level?(Logger::FATAL)
|
56
|
+
write_tag { @logs.fatal(filter(message)) } if test_level?(Logger::FATAL)
|
54
57
|
end
|
55
58
|
|
56
59
|
# Write a message in log with a `ERROR` level
|
57
60
|
#
|
58
61
|
# @param message [String] Message writing in warning level in log
|
59
62
|
def error(message)
|
60
|
-
write_tag { @logs.error(message) } if test_level?(Logger::ERROR)
|
63
|
+
write_tag { @logs.error(filter(message)) } if test_level?(Logger::ERROR)
|
61
64
|
end
|
62
65
|
|
63
66
|
# Write a message in log with a `WARN` level
|
64
67
|
# @param message [String] Message writing in warning level in log
|
65
68
|
def warn(message)
|
66
|
-
write_tag { @logs.warn(message) } if test_level?(Logger::WARN)
|
69
|
+
write_tag { @logs.warn(filter(message)) } if test_level?(Logger::WARN)
|
67
70
|
end
|
68
71
|
|
69
72
|
# Write a message in log with a `INFO` level
|
70
73
|
#
|
71
74
|
# @param message [String] Message writing in info level in log
|
72
75
|
def info(message)
|
73
|
-
write_tag { @logs.info(message) } if test_level?(Logger::INFO)
|
76
|
+
write_tag { @logs.info(filter(message)) } if test_level?(Logger::INFO)
|
74
77
|
end
|
75
78
|
|
76
79
|
# Write a message in log with a `DEBUG` level
|
77
80
|
#
|
78
81
|
# @param message [String] Message writing in debug level in log
|
79
82
|
def debug(message)
|
80
|
-
write_tag { @logs.debug(message) } if test_level?(Logger::DEBUG)
|
83
|
+
write_tag { @logs.debug(filter(message)) } if test_level?(Logger::DEBUG)
|
81
84
|
end
|
82
85
|
|
83
86
|
# @return [RubyRabbitmqJanus::Tools::Log] the instance to logger
|
@@ -118,6 +121,18 @@ module RubyRabbitmqJanus
|
|
118
121
|
def write_tag
|
119
122
|
@logs.tagged(@logs.progname) { yield }
|
120
123
|
end
|
124
|
+
|
125
|
+
# @todo fix replace
|
126
|
+
def filter_sensitive_data(log)
|
127
|
+
msg = log
|
128
|
+
SENSITIVES.each do |word|
|
129
|
+
msg = log.gsub(/\"#{word}\".*\".*\"/, "\"#{word}\":\"[FILTERED]\"") \
|
130
|
+
if log.include?(word.to_s)
|
131
|
+
end
|
132
|
+
msg
|
133
|
+
end
|
134
|
+
|
135
|
+
alias filter filter_sensitive_data
|
121
136
|
end
|
122
137
|
end
|
123
138
|
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# :reek:FeatureEnvy :reek:UtilityFunction
|
4
|
+
|
5
|
+
module RubyRabbitmqJanus
|
6
|
+
module Tools
|
7
|
+
# @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
|
8
|
+
|
9
|
+
# # Utility for manage option to this gem.
|
10
|
+
#
|
11
|
+
# This class start all singleton, Log, Config, Request and Keepalice
|
12
|
+
# instance. It's alos used for testing session/handle used in request.
|
13
|
+
class Option
|
14
|
+
def initialize
|
15
|
+
Log.instance
|
16
|
+
Config.instance
|
17
|
+
Requests.instance
|
18
|
+
@session = Janus::Concurrencies::Keepalive.instance.session
|
19
|
+
end
|
20
|
+
|
21
|
+
# Give number session to keepalive
|
22
|
+
#
|
23
|
+
# @return [Fixnum] Session ID
|
24
|
+
#
|
25
|
+
# @since 2.0.0
|
26
|
+
def keepalive
|
27
|
+
@session
|
28
|
+
end
|
29
|
+
|
30
|
+
# Determine session_id used
|
31
|
+
#
|
32
|
+
# @param [Hash] options Read options used in request
|
33
|
+
#
|
34
|
+
# @return [Fixnum] Session ID
|
35
|
+
#
|
36
|
+
# @since 2.0.0
|
37
|
+
def use_current_session?(options)
|
38
|
+
hash = options
|
39
|
+
hash['session_id'] = @session unless hash.key?('session_id')
|
40
|
+
hash['session_id']
|
41
|
+
end
|
42
|
+
|
43
|
+
# Determine handle_id used
|
44
|
+
#
|
45
|
+
# @param [Hash] options Read options used in request
|
46
|
+
#
|
47
|
+
# @return [Fixnum] Handle ID
|
48
|
+
#
|
49
|
+
# @since 2.0.0
|
50
|
+
def use_current_handle?(options)
|
51
|
+
hash = options
|
52
|
+
hash['handle_id'] = 0 unless hash.key?('handle_id')
|
53
|
+
hash['handle_id']
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
File without changes
|
@@ -3,54 +3,48 @@
|
|
3
3
|
module RubyRabbitmqJanus
|
4
4
|
module Tools
|
5
5
|
module Replaces
|
6
|
-
# Format message request with good data to HASH format for Admin request
|
6
|
+
# Format message request with good data to HASH format for Admin request.
|
7
|
+
# Manage level, debug and admin_secret
|
8
|
+
#
|
7
9
|
# @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
|
8
|
-
class Admin <
|
10
|
+
class Admin < Handle
|
9
11
|
private
|
10
12
|
|
11
|
-
|
12
|
-
def replace_classic
|
13
|
+
def replace_element_classic
|
13
14
|
super
|
14
15
|
replace_admins if request.key?('admin_secret')
|
15
16
|
add_secret if opts.key?('add')
|
16
17
|
end
|
17
18
|
|
18
|
-
# Add string secret for admin request
|
19
19
|
def add_secret
|
20
20
|
values = opts['add']
|
21
|
-
Tools::Log.instance.debug "Values add : #{values}"
|
22
21
|
request.merge!(values)
|
23
22
|
end
|
24
23
|
|
25
|
-
# Replace elements admins if present
|
26
24
|
def replace_admins
|
27
25
|
replace_admin
|
28
26
|
replace_level if request.key?('level')
|
29
27
|
replace_debug if request.key?('debug')
|
30
28
|
end
|
31
29
|
|
32
|
-
# Replace admin secret in request
|
33
30
|
def replace_admin
|
34
31
|
request['admin_secret'] = admin_pass
|
35
32
|
rescue => message
|
36
33
|
Tools::Log.instance.warn "Error replace admin_secret : #{message}"
|
37
34
|
end
|
38
35
|
|
39
|
-
# Replace level element
|
40
36
|
def replace_level
|
41
|
-
request['level'] =
|
37
|
+
request['level'] = type.convert('level', opts)
|
42
38
|
rescue => message
|
43
39
|
Tools::Log.instance.warn "Error replace level : #{message}"
|
44
40
|
end
|
45
41
|
|
46
|
-
# Replace debug element
|
47
42
|
def replace_debug
|
48
|
-
request['debug'] =
|
43
|
+
request['debug'] = type.convert('debug', opts)
|
49
44
|
rescue => message
|
50
45
|
Tools::Log.instance.warn "Error replace debug : #{message}"
|
51
46
|
end
|
52
47
|
|
53
|
-
# Given a admin pass for request
|
54
48
|
def admin_pass
|
55
49
|
Tools::Config.instance.options['rabbit']['admin_pass']
|
56
50
|
end
|