ruby_rabbitmq_janus 1.1.9 → 1.1.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e3153d60baafdf940b9b95b691e9a96db5ddbb14
4
- data.tar.gz: d55879f82f8a52e4dd17834de27b70f19b6a371c
3
+ metadata.gz: e43decf663e6b315b6bfa75620e9bc85023a0812
4
+ data.tar.gz: 67843fec8156528f645869d2628661fc419cf8f7
5
5
  SHA512:
6
- metadata.gz: cc3ff0b7f739fbc25f1a253940f67305ccb8faa8208f60456fb3643c4ab3fc0cb524c42adb81f6e7b4557c72f8e115edc750dea301b4fe76a8ec830765871397
7
- data.tar.gz: 72925fdbfee645bd0666faf7ca86877afc9a5f8d7b7a0f280385cc43030672b7a7fa2f2a18fca4ed1eb71276dffdac932ce451d4d28ddfe2663da993931865c4
6
+ metadata.gz: e4e212150e1e13db4a301f6b432938a061d82f29753086499343c6692ee0a9935ef4b56815304fb6f3e8cc6750ecefc437c0d3004d7a0e0506a895212832458a
7
+ data.tar.gz: 6ad38904fda8373e035c4520924e28630088e59be4c36d4dfe00a8870cc65c0d22589c153b00e37c31cbf78e5beb6d5460e8f2c365cba5e11ccf2302cf9e4d32
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Module contains all lib to this gem
4
3
  module RubyRabbitmqJanus
5
4
  # Module for generators
6
5
  module Generators
@@ -10,7 +9,7 @@ module RubyRabbitmqJanus
10
9
 
11
10
  # Define root path for original file a copied
12
11
  def self.source_root
13
- root_path = File.realpath(File.join(File.dirname(__FILE__), '..', '..', '..'))
12
+ root_path = File.realpath(root_path_gem)
14
13
  @_rrj_source_root ||= File.join(root_path, 'config')
15
14
  end
16
15
 
@@ -18,6 +17,13 @@ module RubyRabbitmqJanus
18
17
  def copy_configuration
19
18
  template 'default.yml', 'config/ruby-rabbitmq-janus.yml'
20
19
  end
20
+
21
+ private
22
+
23
+ # Define a root path
24
+ def root_path_gem
25
+ File.join(File.dirname(__FILE__), '..', '..', '..')
26
+ end
21
27
  end
22
28
  end
23
29
  end
@@ -3,15 +3,16 @@
3
3
  # Override String class
4
4
  class String
5
5
  # Character used for delimited an line
6
- SEPARATOR_LINE = ','
6
+ SEP_LINE = ','
7
7
  # Character used for delimited an key and this value
8
- SEPARATOR_KEY_VALUE = ':'
8
+ SEP_KEY = ':'
9
9
 
10
10
  # Converting a string with a format special to hash
11
11
  def converting_to_hash
12
12
  hash = {}
13
- split(SEPARATOR_LINE).each do |couple_hash|
14
- hash.merge! HashString.new(couple_hash.split(SEPARATOR_KEY_VALUE)).convert_in_hash
13
+ split(SEP_LINE).each do |couple_hash|
14
+ hash.merge! \
15
+ HashString.new(couple_hash.split(SEP_KEY)).convert_in_hash
15
16
  end
16
17
  hash
17
18
  end
@@ -35,12 +36,16 @@ class HashString
35
36
 
36
37
  # Test if string is hash
37
38
  def test_string_hash
38
- value.include?('{') ? HashString.new(format_hash_string).convert_in_hash : value
39
+ if value.include?('{')
40
+ HashString.new(format_hash_string).convert_in_hash
41
+ else
42
+ value
43
+ end
39
44
  end
40
45
 
41
46
  # Transform string to hash
42
47
  def format_hash_string
43
- @array.drop(1).join(':').sub('{', '').sub('}', '').split(String::SEPARATOR_KEY_VALUE)
48
+ @array.drop(1).join(':').sub('{', '').sub('}', '').split(String::SEP_KEY)
44
49
  end
45
50
 
46
51
  # Return the value for hash object
@@ -58,7 +63,8 @@ module RubyRabbitmqJanus
58
63
  argument :janus_type, type: :string, default: ''
59
64
  argument :content, type: :string, default: ''
60
65
 
61
- # Create an file to json format in folder 'config/request/' to you Rails apps
66
+ # Create an file to json format in folder 'config/request/' to you
67
+ # Rails apps
62
68
  def create_request
63
69
  create_file file_json, write_json
64
70
  end
@@ -67,7 +73,11 @@ module RubyRabbitmqJanus
67
73
 
68
74
  # Create a path and name file
69
75
  def file_json
70
- base_file = type_name.empty? ? 'config/requests' : create_folder?(type_name)
76
+ base_file = if type_name.empty?
77
+ 'config/requests'
78
+ else
79
+ create_folder?(type_name)
80
+ end
71
81
  "#{base_file}/#{janus_type}.json"
72
82
  end
73
83
 
@@ -8,7 +8,7 @@ module RubyRabbitmqJanus
8
8
 
9
9
  # Define root path for original file a copied
10
10
  def self.source_root
11
- root_path = File.realpath(File.join(File.dirname(__FILE__), '..', '..', '..'))
11
+ root_path = File.realpath(root_path_gem)
12
12
  @_rrj_source_root ||= File.join(root_path, 'config')
13
13
  end
14
14
 
@@ -16,6 +16,13 @@ module RubyRabbitmqJanus
16
16
  def copy_default_request
17
17
  directory 'requests', 'config/requests'
18
18
  end
19
+
20
+ private
21
+
22
+ # Define a root path
23
+ def root_path_gem
24
+ File.join(File.dirname(__FILE__), '..', '..', '..')
25
+ end
19
26
  end
20
27
  end
21
28
  end
@@ -6,7 +6,8 @@ module RubyRabbitmqJanus
6
6
  # Define an error if the configuration file is not here
7
7
  class ConfigFileNotFound < Errors::RRJError
8
8
  def initialize(file)
9
- super "Error for configuration file (#{file}), does on exist.", :error
9
+ super \
10
+ "Error for configuration file (#{file}), does on exist.", :error
10
11
  end
11
12
  end
12
13
 
@@ -14,7 +15,8 @@ module RubyRabbitmqJanus
14
15
  # Define and error if rubrik level is not present
15
16
  class LevelNotDefine < Errors::RRJError
16
17
  def initialize
17
- super 'Error in configuration file : option level is not present.', :warn
18
+ super \
19
+ 'Error in configuration file : option level is not present.', :warn
18
20
  end
19
21
  end
20
22
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+ # rubocop:disable Metrics/LineLength
2
3
 
3
4
  module RubyRabbitmqJanus
4
5
  # Define all error in gem
@@ -45,6 +46,7 @@ module RubyRabbitmqJanus
45
46
  end
46
47
  end
47
48
  end
49
+ # rubocop:enable Metrics/LineLength
48
50
 
49
51
  require 'rrj/errors/janus'
50
52
  require 'rrj/errors/janus_message'
@@ -40,7 +40,8 @@ module RubyRabbitmqJanus
40
40
  # Define an exception for json
41
41
  class JanusResponseJson < JanusResponse
42
42
  def initialize(message)
43
- super "Error transform to JSON : #{message[0]} -- message : #{message[1]}"
43
+ super \
44
+ "Error transform to JSON : #{message[0]} -- message : #{message[1]}"
44
45
  end
45
46
  end
46
47
 
@@ -56,7 +57,8 @@ module RubyRabbitmqJanus
56
57
  # Define an exception for hash
57
58
  class JanusResponseHash < JanusResponse
58
59
  def initialize(message)
59
- super "Error transform to Hash : #{message[0]} -- message : #{message[1]}"
60
+ super \
61
+ "Error transform to Hash : #{message[0]} -- message : #{message[1]}"
60
62
  end
61
63
  end
62
64
 
data/lib/rrj/info.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  # Define constant to gem.
4
4
  module RubyRabbitmqJanus
5
5
  # Define version to gem
6
- VERSION = '1.1.9'
6
+ VERSION = '1.1.10'
7
7
 
8
8
  # Define a summary description to gem
9
9
  SUMMARY = 'Ruby RabbitMQ Janus'
@@ -16,10 +16,11 @@ module RubyRabbitmqJanus
16
16
 
17
17
  private
18
18
 
19
- # Transform raw request in request to janus, so replace element <string>, <number>
20
- # and other with real value
19
+ # Transform raw request in request to janus, so replace element
20
+ # <string>, <number> and other with real value
21
21
  def prepare_request(options)
22
- @request = Tools::Replaces::Admin.new(request, options).transform_request
22
+ @request = Tools::Replaces::Admin.new(request,
23
+ options).transform_request
23
24
  super
24
25
  end
25
26
  end
@@ -11,10 +11,10 @@ module RubyRabbitmqJanus
11
11
 
12
12
  # Instanciate an message
13
13
  # @param template_request [String] Name of request prepare
14
- # @param [Hash] options Options to request (replace element or add in body)
14
+ # @param [Hash] options Options to request
15
15
  # @option options [String] :session_id Identifier to session
16
16
  # @option options [String] :handle_id Identifier to session manipulate
17
- # @option options [Hash] :other Element contains in request sending to janus
17
+ # @option options [Hash] :other Element contains in request sending
18
18
  # @example Initialize a message
19
19
  # Message.new('test', {
20
20
  # "session_id": 42,
@@ -68,7 +68,7 @@ module RubyRabbitmqJanus
68
68
 
69
69
  # Load raw request
70
70
  def load_request_file
71
- @request = JSON.parse File.read Tools::Requests.instance.requests[@type]
71
+ @request = request_instance
72
72
  Tools::Log.instance.debug "Opening request : #{to_json}"
73
73
  end
74
74
 
@@ -76,6 +76,11 @@ module RubyRabbitmqJanus
76
76
  def prepare_request(_options)
77
77
  Tools::Log.instance.debug "Prepare request for janus : #{to_json}"
78
78
  end
79
+
80
+ # Return request to json format
81
+ def request_instance
82
+ JSON.parse File.read Tools::Requests.instance.requests[@type]
83
+ end
79
84
  end
80
85
  end
81
86
  end
@@ -15,10 +15,12 @@ module RubyRabbitmqJanus
15
15
 
16
16
  private
17
17
 
18
- # Transform raw request in request to janus, so replace element <string>, <number>
18
+ # Transform raw request in request to janus, so replace element
19
+ # <string>, <number>
19
20
  # and other with real value
20
21
  def prepare_request(options)
21
- @request = Tools::Replaces::Standard.new(request, options).transform_request
22
+ @request = Tools::Replaces::Standard.new(request,
23
+ options).transform_request
22
24
  super
23
25
  end
24
26
  end
@@ -10,7 +10,8 @@ module RubyRabbitmqJanus
10
10
  class Event < Concurrency
11
11
  include Singleton
12
12
 
13
- # Initialize Event object. Is used for listen an standard out queue to Janus
13
+ # Initialize Event object. Is used for listen an standard out queue to
14
+ # Janus
14
15
  def initialize
15
16
  super
16
17
  @publish = @response = nil
@@ -28,8 +29,8 @@ module RubyRabbitmqJanus
28
29
 
29
30
  # Initialize a thread
30
31
  def transaction_running
31
- Thread.current.thread_variable_set(:publish,
32
- Rabbit::Publisher::Listener.new(rabbit))
32
+ publisher = Rabbit::Publisher::Listener.new(rabbit)
33
+ Thread.current.thread_variable_set(:publish, publisher)
33
34
  end
34
35
  end
35
36
  end
@@ -62,7 +62,8 @@ module RubyRabbitmqJanus
62
62
 
63
63
  # Test if message response contains an error in plugin
64
64
  def error_plugin?
65
- @request.key?('plugindata') && @request['plugindata']['data'].key?('error_code')
65
+ @request.key?('plugindata') && \
66
+ @request['plugindata']['data'].key?('error_code')
66
67
  end
67
68
  end
68
69
  end
@@ -14,7 +14,8 @@ module RubyRabbitmqJanus
14
14
  end
15
15
  end
16
16
 
17
- # Choose queue, create an handle, connect to rabbitmq server and send messages
17
+ # Choose queue, create an handle, connect to rabbitmq server and send
18
+ # messages
18
19
  def handle_connect
19
20
  rabbit.transaction_long do
20
21
  choose_queue
@@ -29,7 +30,7 @@ module RubyRabbitmqJanus
29
30
  'session_id' => session,
30
31
  'handle_id' => handle,
31
32
  'add' => {
32
- 'admin_secret' => Tools::Config.instance.options['rabbit']['admin_pass']
33
+ 'admin_secret' => admin_secret
33
34
  }
34
35
  }
35
36
  msg = Janus::Messages::Admin.new(type, opts.merge!(options))
@@ -54,6 +55,11 @@ module RubyRabbitmqJanus
54
55
  Tools::Log.instance.info 'Publish a message ...'
55
56
  Janus::Responses::Standard.new(publish.send_a_message(yield))
56
57
  end
58
+
59
+ # Read a admin pass in configuration file to this gem
60
+ def admin_secret
61
+ Tools::Config.instance.options['rabbit']['admin_pass']
62
+ end
57
63
  end
58
64
  end
59
65
  end
@@ -4,7 +4,8 @@ module RubyRabbitmqJanus
4
4
  module Janus
5
5
  module Transactions
6
6
  # @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
7
- # This class work with janus and send a series of message for session level
7
+ # This class work with janus and send a series of message for session
8
+ # level
8
9
  class Session < Transaction
9
10
  # Connect to session and post an message
10
11
  def session_connect(exclusive)
@@ -27,11 +27,18 @@ module RubyRabbitmqJanus
27
27
  def options_admin
28
28
  Tools::Log.instance.debug 'Add options to propertie to message'
29
29
  {
30
- routing_key: Tools::Config.instance.options['queues']['admin']['queue_to'],
30
+ routing_key: routing_key,
31
31
  correlation_id: @correlation,
32
32
  content_type: 'application/json'
33
33
  }
34
34
  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
35
42
  end
36
43
  end
37
44
  end
data/lib/rrj/tools/env.rb CHANGED
@@ -11,8 +11,8 @@ module RubyRabbitmqJanus
11
11
  # Test if a string contains a word ENV
12
12
  def test_env_var(configuration, key)
13
13
  test = configuration[key.to_s]
14
- if test.is_a?(String)
15
- test.include?('ENV') ? ENV[test.gsub("ENV['", '').gsub("']", '')] : test
14
+ if test.is_a?(String) && test.include?('ENV')
15
+ ENV[test.gsub("ENV['", '').gsub("']", '')]
16
16
  else
17
17
  test
18
18
  end
@@ -31,8 +31,7 @@ module RubyRabbitmqJanus
31
31
 
32
32
  # Replace admin secret in request
33
33
  def replace_admin
34
- cfg = Tools::Config.instance.options['rabbit']
35
- request['admin_secret'] = Tools::Env.instance.test_env_var(cfg, 'admin_pass')
34
+ request['admin_secret'] = admin_pass
36
35
  rescue => message
37
36
  Tools::Log.instance.warn "Error replace admin_secret : #{message}"
38
37
  end
@@ -50,6 +49,13 @@ module RubyRabbitmqJanus
50
49
  rescue => message
51
50
  Tools::Log.instance.warn "Error replace debug : #{message}"
52
51
  end
52
+
53
+ # Given a admin pass for request
54
+ def admin_pass
55
+ cfg = Tools::Config.instance.options['rabbit']
56
+ key = 'admin_pass'
57
+ Tools::Env.instance.test_env_var(cfg, key)
58
+ end
53
59
  end
54
60
  end
55
61
  end
@@ -14,7 +14,8 @@ module RubyRabbitmqJanus
14
14
  Tools::Log.instance.debug "Element to replace : #{@opts}"
15
15
  end
16
16
 
17
- # Replace element in hash request with information used for this transaction
17
+ # Replace element in hash request with information used for this
18
+ # transaction
18
19
  # @return HASH request with element replace
19
20
  def transform_request
20
21
  replace_classic
@@ -36,9 +37,11 @@ module RubyRabbitmqJanus
36
37
  replace_plugin if @request.key?('plugin')
37
38
  end
38
39
 
39
- # Create an transaction string and replace in request field with an String format
40
+ # Create an transaction string and replace in request field with an
41
+ # String format
40
42
  def replace_transaction
41
- @request['transaction'].replace [*('A'..'Z'), *('0'..'9')].sample(10).join
43
+ @request['transaction'].replace \
44
+ [*('A'..'Z'), *('0'..'9')].sample(10).join
42
45
  rescue => message
43
46
  Tools::Log.instance.warn "Error transaction replace : #{message}"
44
47
  end
@@ -52,10 +55,15 @@ module RubyRabbitmqJanus
52
55
 
53
56
  # Replace plugin string
54
57
  def replace_plugin
55
- @request['plugin'] = Tools::Config.instance.options['janus']['plugins'][0]
58
+ @request['plugin'] = plugin
56
59
  rescue => message
57
60
  Tools::Log.instance.warn "Error plugin replace : #{message}"
58
61
  end
62
+
63
+ # Return a first plugin to array in config gem
64
+ def plugin
65
+ Tools::Config.instance.options['janus']['plugins'][0]
66
+ end
59
67
  end
60
68
  end
61
69
  end
@@ -78,11 +78,16 @@ module RubyRabbitmqJanus
78
78
  def rewrite_key_to_string(node)
79
79
  Hash[
80
80
  node.map do |key, value|
81
- [key.to_s, value.is_a?(Hash) ? rewrite_key_to_string(value) : value]
81
+ [key.to_s, value?(value)]
82
82
  end
83
83
  ]
84
84
  end
85
85
 
86
+ # Test the value is an array
87
+ def value?(value)
88
+ value.is_a?(Hash) ? rewrite_key_to_string(value) : value
89
+ end
90
+
86
91
  # Replace value in request Hash
87
92
  def running_hash(hash, parent = 'body')
88
93
  hash.each do |key, value|
@@ -5,7 +5,8 @@ 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, level: :admin, name: :handle_info do
8
+ describe '#message_admin', type: :request,
9
+ level: :admin, name: :handle_info do
9
10
  include_examples 'message_handle_admin should match json schema'
10
11
  end
11
12
 
@@ -7,7 +7,9 @@ describe 'RubyRabbitmqJanus::RRJ -- message type trickle', broken: true do
7
7
  before(:example) { @type = 'peer::trickle' }
8
8
 
9
9
  describe '#message_handle', type: :request, level: :peer, name: :trickle do
10
- let(:cdd) { { 'sdpMid' => 'video', 'sdpMLineIndex' => 1, 'candidate' => '...' } }
10
+ let(:cdd) do
11
+ { 'sdpMid' => 'video', 'sdpMLineIndex' => 1, 'candidate' => '...' }
12
+ end
11
13
  let(:candidate) { { 'candidate' => cdd } }
12
14
  let(:candidates) { { 'candidates' => [cdd, cdd] } }
13
15
 
@@ -4,7 +4,8 @@ require 'spec_helper'
4
4
 
5
5
  describe 'RubyRabbitmqJanus::RabitMQ', type: :config, name: :rabbit do
6
6
  it 'Start connection with RabbitMQ server' do
7
- expect(RubyRabbitmqJanus::Rabbit::Connect.new.start.class).to eq Bunny::Session
7
+ expect(RubyRabbitmqJanus::Rabbit::Connect.new.start.class).to \
8
+ eq Bunny::Session
8
9
  end
9
10
 
10
11
  it 'Close connection with RabbitMQ Server' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_rabbitmq_janus
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.9
4
+ version: 1.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - VAILLANT Jeremy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-01 00:00:00.000000000 Z
11
+ date: 2016-12-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler