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.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +127 -0
  3. data/Rakefile +1 -3
  4. data/config/default.md +14 -14
  5. data/config/default.yml +12 -18
  6. data/config/requests.md +80 -0
  7. data/config/requests/{channel → peer}/answer.json +1 -1
  8. data/config/requests/{channel → peer}/offer.json +0 -0
  9. data/lib/generators/ruby_rabbitmq_janus/install_generator.rb +1 -0
  10. data/lib/rrj/errors/config.rb +8 -1
  11. data/lib/rrj/errors/error.rb +18 -5
  12. data/lib/rrj/errors/janus.rb +4 -2
  13. data/lib/rrj/errors/janus_message.rb +19 -15
  14. data/lib/rrj/errors/janus_response.rb +13 -26
  15. data/lib/rrj/errors/janus_transaction.rb +7 -13
  16. data/lib/rrj/errors/rabbit.rb +3 -9
  17. data/lib/rrj/info.rb +1 -1
  18. data/lib/rrj/init.rb +118 -68
  19. data/lib/rrj/janus/processus/concurrency.rb +8 -22
  20. data/lib/rrj/janus/processus/event.rb +13 -15
  21. data/lib/rrj/janus/processus/keepalive.rb +20 -15
  22. data/lib/rrj/janus/responses/response.rb +0 -1
  23. data/lib/rrj/janus/transactions/admin.rb +14 -22
  24. data/lib/rrj/janus/transactions/handle.rb +19 -33
  25. data/lib/rrj/janus/transactions/session.rb +13 -6
  26. data/lib/rrj/janus/transactions/transaction.rb +16 -24
  27. data/lib/rrj/rabbit/connect.rb +3 -4
  28. data/lib/rrj/rabbit/propertie.rb +6 -9
  29. data/lib/rrj/rabbit/publish/admin.rb +1 -1
  30. data/lib/rrj/rabbit/publish/base_publisher.rb +5 -0
  31. data/lib/rrj/rabbit/publish/listener.rb +1 -1
  32. data/lib/rrj/rabbit/publish/non_exclusive.rb +1 -1
  33. data/lib/rrj/tools/config.rb +44 -18
  34. data/lib/rrj/tools/log.rb +30 -15
  35. data/lib/rrj/tools/replaces/admin.rb +1 -3
  36. data/lib/rrj/tools/replaces/replace.rb +1 -6
  37. data/lib/rrj/tools/requests.rb +8 -8
  38. data/lib/rrj/tools/tools.rb +0 -1
  39. data/lib/ruby_rabbitmq_janus.rb +1 -0
  40. data/spec/request/admin/request_handle_info_spec.rb +3 -3
  41. data/spec/request/base/request_attach_spec.rb +7 -10
  42. data/spec/request/base/request_detach_spec.rb +6 -9
  43. data/spec/request/peer/request_answer_spec.rb +66 -0
  44. data/spec/request/peer/request_offer_spec.rb +113 -0
  45. data/spec/request/peer/request_trickle_spec.rb +9 -11
  46. data/spec/rrj/rrj_log_spec.rb +1 -6
  47. data/spec/spec_helper.rb +0 -1
  48. data/spec/support/examples.rb +6 -9
  49. data/spec/support/schemas/config/config.json +20 -32
  50. data/spec/support/schemas/request/peer/answer.json +15 -0
  51. data/spec/support/schemas/request/peer/offer.json +15 -0
  52. data/spec/support/schemas/request/peer/trickle.json +4 -12
  53. metadata +10 -19
  54. data/config/requests/channel/README.md +0 -29
  55. data/config/requests/channel/create.json +0 -9
  56. data/config/requests/channel/describe.json +0 -10
  57. data/config/requests/channel/destroy.json +0 -10
  58. data/config/requests/channel/exists.json +0 -10
  59. data/config/requests/channel/join.json +0 -11
  60. data/config/requests/channel/leave.json +0 -11
  61. data/config/requests/channel/list.json +0 -9
  62. data/config/requests/channel/select.json +0 -11
  63. data/config/requests/channel/trickle.json +0 -10
  64. data/config/requests/videocast/join.json +0 -12
  65. data/config/requests/videocast/leave.json +0 -11
  66. data/config/ruby-rabbitmq-janus.yml +0 -27
  67. data/lib/rrj/errors/request.rb +0 -21
  68. data/lib/rrj/tools/env.rb +0 -22
@@ -3,6 +3,10 @@
3
3
  module RubyRabbitmqJanus
4
4
  module Rabbit
5
5
  # @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
6
+
7
+ # @!attribute [r] correlation
8
+ # @return [String] Is a string uniq generated by SecureRandom
9
+ #
6
10
  # Manage properties to message sending in rabbitmq queue
7
11
  class Propertie
8
12
  attr_reader :correlation
@@ -17,7 +21,7 @@ module RubyRabbitmqJanus
17
21
  def options
18
22
  Tools::Log.instance.debug 'Add options to propertie to message'
19
23
  {
20
- routing_key: Tools::Config.instance.options['queues']['queue_to'],
24
+ routing_key: Tools::Config.instance.queue_to,
21
25
  correlation_id: @correlation,
22
26
  content_type: 'application/json'
23
27
  }
@@ -27,18 +31,11 @@ module RubyRabbitmqJanus
27
31
  def options_admin
28
32
  Tools::Log.instance.debug 'Add options to propertie to message'
29
33
  {
30
- routing_key: routing_key,
34
+ routing_key: Tools::Config.instance.queue_admin_to,
31
35
  correlation_id: @correlation,
32
36
  content_type: 'application/json'
33
37
  }
34
38
  end
35
-
36
- private
37
-
38
- # Read configuration file to gem for reading a admin queue name
39
- def routing_key
40
- Tools::Config.instance.options['queues']['admin']['queue_to']
41
- end
42
39
  end
43
40
  end
44
41
  end
@@ -25,7 +25,7 @@ module RubyRabbitmqJanus
25
25
 
26
26
  # Define queue used for posting a message to API admin
27
27
  def queue_from
28
- Tools::Config.instance.options['queues']['admin']['queue_from']
28
+ Tools::Config.instance.queue_admin_from
29
29
  end
30
30
  end
31
31
  end
@@ -5,6 +5,11 @@ module RubyRabbitmqJanus
5
5
  # Define an module for create an publisher
6
6
  module Publisher
7
7
  # @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
8
+
9
+ # @!attribute [r] response
10
+ # @return [RubyRabbitmqJanus::Janus::Responses::Response]
11
+ # Given a Janus response
12
+ #
8
13
  # @abstract Publish message in RabbitMQ
9
14
  class BasePublisher
10
15
  attr_reader :response
@@ -28,7 +28,7 @@ module RubyRabbitmqJanus
28
28
  private
29
29
 
30
30
  def queue_name
31
- Tools::Config.instance.options['queues']['queue_from']
31
+ Tools::Config.instance.queue_from
32
32
  end
33
33
 
34
34
  # Subscribe queue
@@ -24,7 +24,7 @@ module RubyRabbitmqJanus
24
24
 
25
25
  # Define queue used for posting a message to API public
26
26
  def queue_from
27
- Tools::Config.instance.options['queues']['queue_from']
27
+ Tools::Config.instance.queue_from
28
28
  end
29
29
  end
30
30
  end
@@ -3,13 +3,18 @@
3
3
  module RubyRabbitmqJanus
4
4
  module Tools
5
5
  # @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
6
- # Loading a yaml file for apply a configuration to gem.
6
+
7
+ # # Manage configuration file
8
+ # Singleton object for reading configuration file
9
+ #
10
+ # @!attribute [r] options
11
+ # @return [Hash] Return all options to configured in config file.
7
12
  class Config
8
13
  include Singleton
9
14
 
10
15
  attr_reader :options
11
16
 
12
- # Define HOME RRJ
17
+ # Define HOME RRJ gem
13
18
  RRJ_HOME = File.realpath(File.join(File.dirname(__FILE__),
14
19
  '..', '..', '..'))
15
20
 
@@ -19,7 +24,7 @@ module RubyRabbitmqJanus
19
24
  # Define a default override file configuration
20
25
  CONF_CUSTOM = 'config/ruby-rabbitmq-janus.yml'
21
26
 
22
- # Define a default path to file configuration
27
+ # Define a default path to file configuration to gem
23
28
  PATH_DEFAULT = File.join(RRJ_HOME, CONF_DEFAULT)
24
29
 
25
30
  # Initialize configuration file default or customize if exist
@@ -27,40 +32,61 @@ module RubyRabbitmqJanus
27
32
  @options = nil
28
33
  conf_customize
29
34
  conf_default
30
- define_log_level_used
35
+ Tools::Log.instance.save_level(log_level)
36
+ end
37
+
38
+ # @return [String] read configuration for queue `from`
39
+ def queue_from
40
+ @options['queues']['standard']['from']
41
+ end
42
+
43
+ # @return [String] read configuration for queue `to`
44
+ def queue_to
45
+ @options['queues']['standard']['to']
46
+ end
47
+
48
+ # @return [String] read configuration for queue admin `from`
49
+ def queue_admin_from
50
+ @options['queues']['admin']['from']
51
+ end
52
+
53
+ # @return [String] read configuration for queue admin `to`
54
+ def queue_admin_to
55
+ @options['queues']['admin']['to']
56
+ end
57
+
58
+ # @return [Symbol] read configuration for log level used in this gem
59
+ def log_level
60
+ @options['gem']['log']['level'].upcase.to_sym
61
+ rescue
62
+ raise Errors::LevelNotDefine
63
+ end
64
+
65
+ # @param [Fixnum] index determine what field is readint in array plugins
66
+ # in configuration file
67
+ # @return [String] read configuration for plugin with index
68
+ def plugin_at(index = 0)
69
+ @options['janus']['plugins'][index].to_s
31
70
  end
32
71
 
33
72
  private
34
73
 
35
- # Load configuration file yaml
36
- # @return [Yaml] Configuration file
37
- # @param file [String] Path to configuration file (with name)
38
74
  def load_configuration(file)
39
75
  Tools::Log.instance.info("Loading configuration file : #{file}")
40
- YAML.load(File.read(file))
76
+ YAML.load(ERB.new(File.read(file)).result)
41
77
  rescue
42
78
  raise Errors::ConfigFileNotFound, file
43
79
  end
44
80
 
45
- # Load customize configuration file if exist
46
81
  def conf_customize
47
82
  file = File.join(Dir.pwd, CONF_CUSTOM)
48
83
  @options = load_configuration(file) if File.exist?(file)
49
84
  end
50
85
 
51
- # Load default configuration if customize configuration doesn't exist
52
86
  def conf_default
53
87
  file = PATH_DEFAULT
54
88
  @options ||= load_configuration(file)
55
89
  end
56
-
57
- # Define log lvel used in this gem
58
- def define_log_level_used
59
- Tools::Log.instance.level = \
60
- Tools::Log::LEVELS[@options['gem']['log']['level'].upcase.to_sym]
61
- rescue
62
- raise Errors::LevelNotDefine
63
- end
64
90
  end
65
91
  end
66
92
  end
data/lib/rrj/tools/log.rb CHANGED
@@ -1,10 +1,15 @@
1
1
  # frozen_string_literal: true
2
- # :reek:Attribute and :reek:UtilityFunction
3
2
 
4
3
  module RubyRabbitmqJanus
5
4
  module Tools
6
5
  # @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
7
- # Class for wrtting logs.
6
+
7
+ # # Manage log in this gem
8
+ #
9
+ # Singleton object for manipulate logs in this gem
10
+ #
11
+ # @!attribute [r] level
12
+ # @return [Fixnum] Return a number to log level.
8
13
  class Log
9
14
  include Singleton
10
15
 
@@ -18,9 +23,12 @@ module RubyRabbitmqJanus
18
23
  UNKNOWN: Logger::UNKNOWN
19
24
  }.freeze
20
25
 
21
- attr_accessor :level, :progname
26
+ attr_reader :level
22
27
 
23
- # Returns a new instance to Log
28
+ # Returns a new instance to Log and use `Tag` element for each line
29
+ # writing in log with name to gem.
30
+ #
31
+ # @see http://api.rubyonrails.org/classes/ActiveSupport/TaggedLogging.html
24
32
  def initialize
25
33
  logs = defined?(Rails) ? logger_rails : logger_develop
26
34
  logs.progname = RubyRabbitmqJanus.name
@@ -31,60 +39,68 @@ module RubyRabbitmqJanus
31
39
  @logs = ActiveSupport::TaggedLogging.new(logs)
32
40
  end
33
41
 
34
- # Write a message in log with a UNKNOWN level
42
+ # Write a message in log with a `UNKNOWN` level
43
+ #
35
44
  # @param message [String] Message writing in warning level in log
36
45
  def unknown(message)
37
46
  write_tag { @logs.unknown(message) }
38
47
  end
39
48
 
40
- # Write a message in log with a FATAL level
49
+ # Write a message in log with a `FATAL` level
50
+ #
41
51
  # @param message [String] Message writing in warning level in log
42
52
  def fatal(message)
43
53
  write_tag { @logs.fatal(message) } if test_level?(Logger::FATAL)
44
54
  end
45
55
 
46
- # Write a message in log with a ERROR level
56
+ # Write a message in log with a `ERROR` level
57
+ #
47
58
  # @param message [String] Message writing in warning level in log
48
59
  def error(message)
49
60
  write_tag { @logs.error(message) } if test_level?(Logger::ERROR)
50
61
  end
51
62
 
52
- # Write a message in log with a warn level
63
+ # Write a message in log with a `WARN` level
53
64
  # @param message [String] Message writing in warning level in log
54
65
  def warn(message)
55
66
  write_tag { @logs.warn(message) } if test_level?(Logger::WARN)
56
67
  end
57
68
 
58
- # Write a message in log with a info level
69
+ # Write a message in log with a `INFO` level
70
+ #
59
71
  # @param message [String] Message writing in info level in log
60
72
  def info(message)
61
73
  write_tag { @logs.info(message) } if test_level?(Logger::INFO)
62
74
  end
63
75
 
64
- # Write a message in log with a debug level
76
+ # Write a message in log with a `DEBUG` level
77
+ #
65
78
  # @param message [String] Message writing in debug level in log
66
79
  def debug(message)
67
80
  write_tag { @logs.debug(message) } if test_level?(Logger::DEBUG)
68
81
  end
69
82
 
70
- # Return instance logger
83
+ # @return [RubyRabbitmqJanus::Tools::Log] the instance to logger
71
84
  def logger
72
85
  @logs
73
86
  end
74
87
 
75
- # Return device to log is writing
88
+ # @return [String] name of file to lgger used
76
89
  def logdev
77
90
  @logs.instance_variable_get(:'@logdev').filename
78
91
  end
79
92
 
93
+ # Save log level used in this gem
94
+ def save_level(gem_level)
95
+ @level = LEVELS[gem_level]
96
+ end
97
+
80
98
  private
81
99
 
82
- # Define instance logger with rails
83
100
  def logger_rails
84
101
  Rails.logger
85
102
  end
86
103
 
87
- # Define instance logger wiptout rails
88
104
  def logger_develop
89
105
  log = Logger.new('log/rails-rabbit-janus.log')
90
106
  log.formatter = proc do |severity, _datetime, _progname, msg|
@@ -97,7 +113,6 @@ module RubyRabbitmqJanus
97
113
  this_level >= Log.instance.level ? true : false
98
114
  end
99
115
 
100
- # Write a log with an tag
101
116
  def write_tag
102
117
  @logs.tagged(@logs.progname) { yield }
103
118
  end
@@ -52,9 +52,7 @@ module RubyRabbitmqJanus
52
52
 
53
53
  # Given a admin pass for request
54
54
  def admin_pass
55
- cfg = Tools::Config.instance.options['rabbit']
56
- key = 'admin_pass'
57
- Tools::Env.instance.test_env_var(cfg, key)
55
+ Tools::Config.instance.options['rabbit']['admin_pass']
58
56
  end
59
57
  end
60
58
  end
@@ -56,15 +56,10 @@ module RubyRabbitmqJanus
56
56
 
57
57
  # Replace plugin string
58
58
  def replace_plugin
59
- @request['plugin'] = plugin
59
+ @request['plugin'] = Tools::Config.instance.plugin_at
60
60
  rescue => message
61
61
  Tools::Log.instance.warn "Error plugin replace : #{message}"
62
62
  end
63
-
64
- # Return a first plugin to array in config gem
65
- def plugin
66
- Tools::Config.instance.options['janus']['plugins'][0]
67
- end
68
63
  end
69
64
  end
70
65
  end
@@ -3,9 +3,15 @@
3
3
  module RubyRabbitmqJanus
4
4
  module Tools
5
5
  # @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
6
- # Load files json in config/request.
7
- # This file is used for sending a request to RabbitMQ
6
+
7
+ # # Load files json in `config/request/**/*`.
8
+ #
9
+ # This file is used for sending a request to Janus
10
+ #
8
11
  # @!attribute [r] requests
12
+ # @return [Hash] It's a hash with name and path to request.
13
+ #
14
+ # @see file:/config/requests.md For more information to type requests used.
9
15
  class Requests
10
16
  include Singleton
11
17
 
@@ -29,7 +35,6 @@ module RubyRabbitmqJanus
29
35
 
30
36
  private
31
37
 
32
- # Run folder contains templates json
33
38
  def each_folder(subfolder)
34
39
  Dir[File.join(PATH_REQUEST + subfolder, '*')].count do |file|
35
40
  if File.file?(file)
@@ -40,15 +45,10 @@ module RubyRabbitmqJanus
40
45
  end
41
46
  end
42
47
 
43
- # Add template json to requests array
44
- # @param file [File]
45
48
  def read_file(file)
46
49
  @requests[File.basename(file, '.json').to_s] = File.path(file)
47
50
  end
48
51
 
49
- # Add template json to requests array with a path
50
- # @param folder [Dir]
51
- # @param file [File]
52
52
  def read_folder(folder, file)
53
53
  @requests[folder + File.basename(file, '.json').to_s] = File.path(file)
54
54
  end
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'rrj/tools/log'
4
- require 'rrj/tools/env'
5
4
  require 'rrj/tools/config'
6
5
  require 'rrj/tools/requests'
7
6
  require 'rrj/tools/replaces/type'
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # Load all tools necessary to good functionlaty to this gem
3
4
  require 'rrj/init'
4
5
 
5
6
  # Define tools for this gems
@@ -5,10 +5,10 @@ require 'spec_helper'
5
5
  describe 'RubyRabbitmqJanus::RRJ -- message type handle_info' do
6
6
  before(:example) { @type = 'admin::handle_info' }
7
7
 
8
- describe '#message_admin', type: :request,
9
- level: :admin, name: :handle_info do
8
+ describe '#message_admin', type: :request, level: :admin,
9
+ name: :handle_info, broken: true do
10
10
  include_examples 'message_handle_admin should match json schema'
11
11
  end
12
12
 
13
- # after(:example) { @gateway.stop_handle }
13
+ # after(:example) { @gateway.handle_message_simple('base::detach') }
14
14
  end
@@ -3,23 +3,20 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe 'RubyRabbitmqJanus::RRJ -- message type attach' do
6
- before(:example) { @type = 'base::attach' }
6
+ before(:example) do
7
+ @type = 'base::attach'
8
+ @options = { 'replace' => {}, 'add' => {} }
9
+ end
7
10
 
8
11
  describe '#message_handle', type: :request, level: :base, name: :attach do
9
12
  context 'when queue is exclusive' do
10
- it_behaves_like 'message_handle should match json schema' do
11
- let(:replace) { {} }
12
- let(:add) { {} }
13
- end
13
+ it_behaves_like 'message_handle should match json schema'
14
14
  end
15
15
 
16
16
  context 'when queue is not exclusive' do
17
- it_behaves_like 'message_handle should match json empty' do
18
- let(:replace) { {} }
19
- let(:add) { {} }
20
- end
17
+ it_behaves_like 'message_handle should match json empty'
21
18
  end
22
19
  end
23
20
 
24
- after(:example) { @gateway.stop_handle }
21
+ after(:example) { @gateway.handle_message_simple('base::detach') }
25
22
  end
@@ -3,21 +3,18 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe 'RubyRabbitmqJanus::RRJ -- mesage type detach' do
6
- before(:example) { @type = 'base::detach' }
6
+ before(:example) do
7
+ @type = 'base::detach'
8
+ @options = { 'replace' => {}, 'add' => {} }
9
+ end
7
10
 
8
11
  describe '#message_handle', type: :request, level: :base, name: :detach do
9
12
  context 'when queue is exclusive' do
10
- it_behaves_like 'message_handle should match json schema' do
11
- let(:replace) { {} }
12
- let(:add) { {} }
13
- end
13
+ it_behaves_like 'message_handle should match json schema'
14
14
  end
15
15
 
16
16
  context 'when queue is not exclusive' do
17
- it_behaves_like 'message_handle should match json empty' do
18
- let(:replace) { {} }
19
- let(:add) { {} }
20
- end
17
+ it_behaves_like 'message_handle should match json empty'
21
18
  end
22
19
  end
23
20
  end