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 +4 -4
- data/lib/generators/ruby_rabbitmq_janus/configuration_generator.rb +8 -2
- data/lib/generators/ruby_rabbitmq_janus/create_request_generator.rb +18 -8
- data/lib/generators/ruby_rabbitmq_janus/default_request_generator.rb +8 -1
- data/lib/rrj/errors/config.rb +4 -2
- data/lib/rrj/errors/error.rb +2 -0
- data/lib/rrj/errors/janus_response.rb +4 -2
- data/lib/rrj/info.rb +1 -1
- data/lib/rrj/janus/messages/admin.rb +4 -3
- data/lib/rrj/janus/messages/message.rb +8 -3
- data/lib/rrj/janus/messages/standard.rb +4 -2
- data/lib/rrj/janus/processus/event.rb +4 -3
- data/lib/rrj/janus/responses/response.rb +2 -1
- data/lib/rrj/janus/transactions/admin.rb +8 -2
- data/lib/rrj/janus/transactions/session.rb +2 -1
- data/lib/rrj/rabbit/propertie.rb +8 -1
- data/lib/rrj/tools/env.rb +2 -2
- data/lib/rrj/tools/replaces/admin.rb +8 -2
- data/lib/rrj/tools/replaces/replace.rb +12 -4
- data/lib/rrj/tools/replaces/standard.rb +6 -1
- data/spec/request/admin/request_handle_info_spec.rb +2 -1
- data/spec/request/peer/request_trickle_spec.rb +3 -1
- data/spec/rrj/rrj_rabbitmq_spec.rb +2 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e43decf663e6b315b6bfa75620e9bc85023a0812
|
4
|
+
data.tar.gz: 67843fec8156528f645869d2628661fc419cf8f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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(
|
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
|
-
|
6
|
+
SEP_LINE = ','
|
7
7
|
# Character used for delimited an key and this value
|
8
|
-
|
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(
|
14
|
-
hash.merge!
|
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?('{')
|
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::
|
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
|
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?
|
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(
|
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
|
data/lib/rrj/errors/config.rb
CHANGED
@@ -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
|
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
|
18
|
+
super \
|
19
|
+
'Error in configuration file : option level is not present.', :warn
|
18
20
|
end
|
19
21
|
end
|
20
22
|
end
|
data/lib/rrj/errors/error.rb
CHANGED
@@ -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
|
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
|
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
@@ -16,10 +16,11 @@ module RubyRabbitmqJanus
|
|
16
16
|
|
17
17
|
private
|
18
18
|
|
19
|
-
# Transform raw request in request to janus, so replace element
|
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,
|
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
|
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
|
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 =
|
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
|
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,
|
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
|
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
|
-
|
32
|
-
|
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') &&
|
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
|
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' =>
|
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
|
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)
|
data/lib/rrj/rabbit/propertie.rb
CHANGED
@@ -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:
|
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
|
-
|
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
|
-
|
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
|
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
|
40
|
+
# Create an transaction string and replace in request field with an
|
41
|
+
# String format
|
40
42
|
def replace_transaction
|
41
|
-
@request['transaction'].replace
|
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'] =
|
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
|
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,
|
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)
|
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
|
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.
|
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-
|
11
|
+
date: 2016-12-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|