ruby_rabbitmq_janus 1.0.2 → 1.0.3
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/lib/rrj/errors/janus_response.rb +4 -3
- data/lib/rrj/info.rb +1 -1
- data/lib/rrj/init.rb +21 -9
- data/lib/rrj/janus/response.rb +29 -3
- data/lib/rrj/janus/threads/event.rb +8 -15
- data/lib/rrj/janus/threads/keepalive.rb +24 -20
- data/lib/rrj/janus/threads/thread.rb +20 -2
- data/lib/rrj/janus/transactions/admin.rb +32 -30
- data/lib/rrj/janus/transactions/handle.rb +29 -27
- data/lib/rrj/janus/transactions/session.rb +10 -8
- data/lib/rrj/janus/transactions/transaction.rb +47 -42
- data/lib/rrj/rabbit/publish/base_publisher.rb +3 -2
- data/lib/rrj/rabbit/publish/listener.rb +14 -4
- data/lib/rrj/rabbit/publish/non_exclusive.rb +1 -0
- 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: bb6b179f8eb2d1d0f17269da3861f0d128100a3e
|
4
|
+
data.tar.gz: e4dae7a3f07f17a4d92cf10b537830bc7e74b9a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95f5ed36b90f240b1c42b36785826795a501a4d7f4c7b57a342dcb55007d1a795d5102efdcd35c49df5571d1188ae12d3c0b7409fa8ee51a7e73dc79b0131e20
|
7
|
+
data.tar.gz: 7e352cabebf3d24213768e49466588205c7557d95c6be73e9e31089aa8c73a8331dda52cc2682f2502a7e18bdd01e9be97dff60399e6121e6f3b13f8f2dcabb8
|
@@ -23,7 +23,8 @@ module RubyRabbitmqJanus
|
|
23
23
|
# Define an error for simple message
|
24
24
|
class JanusResponseSimple < JanusResponse
|
25
25
|
def initialize(message)
|
26
|
-
|
26
|
+
error = message['error']
|
27
|
+
super "[#{error['code']}] #{error['reason']} -- #{message}"
|
27
28
|
end
|
28
29
|
end
|
29
30
|
|
@@ -39,7 +40,7 @@ module RubyRabbitmqJanus
|
|
39
40
|
# Define an exception for json
|
40
41
|
class JanusResponseJson < JanusResponse
|
41
42
|
def initialize(message)
|
42
|
-
super "Error transform to JSON : #{message}"
|
43
|
+
super "Error transform to JSON : #{message[0]} -- message : #{message[1]}"
|
43
44
|
end
|
44
45
|
end
|
45
46
|
|
@@ -55,7 +56,7 @@ module RubyRabbitmqJanus
|
|
55
56
|
# Define an exception for hash
|
56
57
|
class JanusResponseHash < JanusResponse
|
57
58
|
def initialize(message)
|
58
|
-
super "Error transform to Hash : #{message}"
|
59
|
+
super "Error transform to Hash : #{message[0]} -- message : #{message[1]}"
|
59
60
|
end
|
60
61
|
end
|
61
62
|
|
data/lib/rrj/info.rb
CHANGED
data/lib/rrj/init.rb
CHANGED
@@ -15,20 +15,31 @@ module RubyRabbitmqJanus
|
|
15
15
|
# @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
|
16
16
|
# Initialize gem and create automatically an session with Janus
|
17
17
|
# @!attribute [r] session
|
18
|
-
# :reek:BooleanParameter
|
18
|
+
# :reek:BooleanParameter and :reek:ControlParameter
|
19
19
|
class RRJ
|
20
20
|
attr_reader :session, :event
|
21
21
|
|
22
22
|
# Returns a new instance of RubyRabbitmqJanus
|
23
|
-
def initialize
|
23
|
+
def initialize
|
24
|
+
# Instanciate singleton tools
|
24
25
|
start_instances_tools
|
26
|
+
|
27
|
+
# Create an session while time opening
|
25
28
|
@session = Janus::Keepalive.instance.session
|
26
|
-
|
29
|
+
|
27
30
|
@transaction = nil
|
28
31
|
rescue => error
|
29
32
|
raise Errors::RRJErrorInit, error
|
30
33
|
end
|
31
34
|
|
35
|
+
# Listen a standar queue and working if necesary
|
36
|
+
def listen(&block)
|
37
|
+
# Send a processus to background
|
38
|
+
# fork do
|
39
|
+
Janus::Event.instance.listen(&block)
|
40
|
+
# end
|
41
|
+
end
|
42
|
+
|
32
43
|
# Send an simple message to janus. No options in request with this method.
|
33
44
|
# @param [String] type
|
34
45
|
# Given a type to request. JSON request writing in 'config/requests/'
|
@@ -39,7 +50,7 @@ module RubyRabbitmqJanus
|
|
39
50
|
# #=> {"janus":"server_info","name":"Janus WebRTC Gateway" ... }
|
40
51
|
# @return [RubyRabbitmqJanus::Janus::Response] Give an object response to janus server
|
41
52
|
def message_simple(type = 'base::info', exclusive = false)
|
42
|
-
Janus::Transaction.new(@session).connect(exclusive) do
|
53
|
+
Janus::Transactions::Transaction.new(@session).connect(exclusive) do
|
43
54
|
Janus::Message.new(type)
|
44
55
|
end
|
45
56
|
end
|
@@ -55,7 +66,7 @@ module RubyRabbitmqJanus
|
|
55
66
|
# #=> {"janus":"server_info","name":"Janus WebRTC Gateway" ... }
|
56
67
|
# @return [RubyRabbitmqJanus::Janus::Response] Give an object response to janus server
|
57
68
|
def message_session(type, options = {}, exclusive = false)
|
58
|
-
Janus::
|
69
|
+
Janus::Transactions::Session.new(@session).session_connect(exclusive) do
|
59
70
|
Janus::Message.new(type, use_current_session?(options))
|
60
71
|
end
|
61
72
|
rescue => error
|
@@ -71,7 +82,7 @@ module RubyRabbitmqJanus
|
|
71
82
|
# #=> {"janus":"success","sessions": [12345, 8786567465465, ...] }
|
72
83
|
# @return [RubyRabbitmqJanus::Janus::Response] Give an object response to janus server
|
73
84
|
def message_admin(type, options = {})
|
74
|
-
Janus::
|
85
|
+
Janus::Transactions::Admin.new(@session).connect do
|
75
86
|
Janus::MessageAdmin.new(type, options.merge!('session_id' => @session))
|
76
87
|
end
|
77
88
|
end
|
@@ -92,7 +103,7 @@ module RubyRabbitmqJanus
|
|
92
103
|
|
93
104
|
# Define an handle transaction and establish connection with janus
|
94
105
|
def start_handle(exclusive = false)
|
95
|
-
@transaction ||= Janus::
|
106
|
+
@transaction ||= Janus::Transactions::Handle.new(@session)
|
96
107
|
@transaction.handle_connect(exclusive) { yield }
|
97
108
|
rescue => error
|
98
109
|
raise Errors::RRJErrorHandle, error
|
@@ -100,7 +111,7 @@ module RubyRabbitmqJanus
|
|
100
111
|
|
101
112
|
# Define an handle admin transaction and establish connection with janus
|
102
113
|
def start_handle_admin
|
103
|
-
@transaction ||= Janus::
|
114
|
+
@transaction ||= Janus::Transactions::Admin.new(@session)
|
104
115
|
@transaction.handle_connect { yield }
|
105
116
|
rescue => error
|
106
117
|
raise Errors::RRJErrorHandle, error
|
@@ -113,7 +124,7 @@ module RubyRabbitmqJanus
|
|
113
124
|
|
114
125
|
# Start an short transaction, this queue is not exclusive
|
115
126
|
def handle_message_simple(type, replace = {}, add = {})
|
116
|
-
@transaction ||= Janus::
|
127
|
+
@transaction ||= Janus::Transactions::Handle.new(@session)
|
117
128
|
@transaction.handle_connect_and_stop(false) do
|
118
129
|
message_handle(type, replace, add).for_plugin
|
119
130
|
end
|
@@ -131,6 +142,7 @@ module RubyRabbitmqJanus
|
|
131
142
|
Tools::Log.instance
|
132
143
|
Tools::Config.instance
|
133
144
|
Tools::Requests.instance
|
145
|
+
Janus::Event.instance
|
134
146
|
end
|
135
147
|
|
136
148
|
# Return a current session if not specified
|
data/lib/rrj/janus/response.rb
CHANGED
@@ -4,6 +4,7 @@ module RubyRabbitmqJanus
|
|
4
4
|
module Janus
|
5
5
|
# @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
|
6
6
|
# Read and decryt a response to janus
|
7
|
+
# :reek:TooManyMethods
|
7
8
|
class Response
|
8
9
|
# Instanciate a response
|
9
10
|
def initialize(response_janus)
|
@@ -21,7 +22,7 @@ module RubyRabbitmqJanus
|
|
21
22
|
@request.to_json
|
22
23
|
rescue => error
|
23
24
|
Tools::Log.instance.debug "Request error : #{@request}"
|
24
|
-
raise Errors::JanusResponseJson, error
|
25
|
+
raise Errors::JanusResponseJson, [error, @request]
|
25
26
|
end
|
26
27
|
|
27
28
|
# Return request to json format with nice format
|
@@ -38,7 +39,7 @@ module RubyRabbitmqJanus
|
|
38
39
|
@request
|
39
40
|
rescue => error
|
40
41
|
Tools::Log.instance.debug "Request error : #{@request}"
|
41
|
-
raise Errors::JanusResponseHash, error
|
42
|
+
raise Errors::JanusResponseHash, [error, @request]
|
42
43
|
end
|
43
44
|
|
44
45
|
# Return a response simple for client
|
@@ -62,8 +63,33 @@ module RubyRabbitmqJanus
|
|
62
63
|
data_id
|
63
64
|
end
|
64
65
|
|
66
|
+
# Return event to message
|
67
|
+
def event
|
68
|
+
@request['janus']
|
69
|
+
end
|
70
|
+
|
71
|
+
# Return body data
|
72
|
+
def data
|
73
|
+
@request['plugindata']['data'] if plugin_response?
|
74
|
+
end
|
75
|
+
|
76
|
+
# Return jsep data
|
77
|
+
def jsep
|
78
|
+
@request['jsep'] if contains_jsep?
|
79
|
+
end
|
80
|
+
|
65
81
|
private
|
66
82
|
|
83
|
+
# Test if response is returning by plugin
|
84
|
+
def plugin_response?
|
85
|
+
@request.key?('plugindata') && @request['plugindata'].key?('data')
|
86
|
+
end
|
87
|
+
|
88
|
+
# Test if response contains jsep data
|
89
|
+
def contains_jsep?
|
90
|
+
@request.key?('jsep')
|
91
|
+
end
|
92
|
+
|
67
93
|
# Read a hash and return an identifier
|
68
94
|
def data_id
|
69
95
|
analysis
|
@@ -75,7 +101,7 @@ module RubyRabbitmqJanus
|
|
75
101
|
# Analysis response and send exception if janus return an error
|
76
102
|
# :reek:DuplicateMethodCall
|
77
103
|
def analysis
|
78
|
-
raise Errors::JanusResponseSimple, @request
|
104
|
+
raise Errors::JanusResponseSimple, @request if error_simple?
|
79
105
|
raise Errors::JanusResponsePlugin, @request['plugindata']['data'] if error_plugin?
|
80
106
|
end
|
81
107
|
|
@@ -4,30 +4,24 @@ module RubyRabbitmqJanus
|
|
4
4
|
# @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
|
5
5
|
module Janus
|
6
6
|
# For listen standard queue ("from-janus" by default)
|
7
|
-
class Event <
|
7
|
+
class Event < Concurrency
|
8
8
|
include Singleton
|
9
9
|
|
10
10
|
# Initialize Event object. Is used for listen an standard out queue to Janus
|
11
11
|
def initialize
|
12
12
|
Tools::Log.instance.debug 'Start listen events in from-janus queue'
|
13
|
-
@response = nil
|
13
|
+
@publish = @response = nil
|
14
14
|
super
|
15
|
-
|
15
|
+
start_thread
|
16
16
|
end
|
17
17
|
|
18
|
-
# Start listen queue and
|
19
|
-
def listen
|
20
|
-
|
21
|
-
@response
|
18
|
+
# Start listen queue and work with each message reading
|
19
|
+
def listen(&block)
|
20
|
+
loop { @publish.event_received(&block) }
|
22
21
|
end
|
23
22
|
|
24
23
|
private
|
25
24
|
|
26
|
-
# Listen q queue "from-janus"
|
27
|
-
def listen_live
|
28
|
-
start_thread
|
29
|
-
end
|
30
|
-
|
31
25
|
# Intialize an listen to queue
|
32
26
|
def initialize_thread
|
33
27
|
start_transaction
|
@@ -39,9 +33,8 @@ module RubyRabbitmqJanus
|
|
39
33
|
# Start a transaction with Rabbit an Janus
|
40
34
|
def start_transaction
|
41
35
|
rabbit.transaction_long do
|
42
|
-
|
43
|
-
@
|
44
|
-
lock.synchronize { condition.signal }
|
36
|
+
@publish = Rabbit::Publisher::Listener.new(rabbit)
|
37
|
+
@publish.listen_events
|
45
38
|
end
|
46
39
|
end
|
47
40
|
end
|
@@ -4,44 +4,37 @@ module RubyRabbitmqJanus
|
|
4
4
|
module Janus
|
5
5
|
# @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
|
6
6
|
# Manage sending keepalive message
|
7
|
-
class Keepalive <
|
7
|
+
class Keepalive < Concurrency
|
8
8
|
include Singleton
|
9
9
|
|
10
10
|
# Initalize a keepalive message
|
11
11
|
def initialize
|
12
12
|
Tools::Log.instance.debug 'Create an session for keepalive'
|
13
|
-
super
|
14
13
|
@publish = @response = nil
|
15
|
-
|
14
|
+
super
|
15
|
+
start_thread
|
16
16
|
end
|
17
17
|
|
18
18
|
# Return an number session created
|
19
19
|
def session
|
20
|
-
|
21
|
-
@response.session
|
20
|
+
wait { @response.session }
|
22
21
|
end
|
23
22
|
|
24
23
|
private
|
25
24
|
|
26
|
-
# Send to regular interval a message keepalive
|
27
|
-
def session_live
|
28
|
-
start_thread
|
29
|
-
end
|
30
|
-
|
31
25
|
# Initialize an session with janus and start a keepalive transaction
|
32
26
|
def initialize_thread
|
33
|
-
rabbit.
|
34
|
-
|
35
|
-
|
36
|
-
session_keepalive(ttl)
|
27
|
+
rabbit.transaction_long { transaction_keepalive }
|
28
|
+
rescue Interrupt
|
29
|
+
Tools::Log.instance.info 'Stop to sending keepalive'
|
37
30
|
rabbit.close
|
38
31
|
end
|
39
32
|
|
40
|
-
# Star an session janus
|
41
|
-
def
|
42
|
-
|
43
|
-
|
44
|
-
|
33
|
+
# Star an session with janus and waiting an signal for saving session_id
|
34
|
+
def transaction_keepalive
|
35
|
+
@response = Janus::Response.new(create_session)
|
36
|
+
signal
|
37
|
+
session_keepalive(ttl)
|
45
38
|
end
|
46
39
|
|
47
40
|
# Create an loop for sending a keepalive message
|
@@ -49,7 +42,7 @@ module RubyRabbitmqJanus
|
|
49
42
|
loop do
|
50
43
|
sleep time_to_live
|
51
44
|
@publish.send_a_message(Janus::Message.new('base::keepalive',
|
52
|
-
'session_id' =>
|
45
|
+
'session_id' => running_session))
|
53
46
|
end
|
54
47
|
rescue => message
|
55
48
|
Tools::Log.instance.debug "Error keepalive : #{message}"
|
@@ -61,6 +54,17 @@ module RubyRabbitmqJanus
|
|
61
54
|
rescue => error
|
62
55
|
Tools::Log.instance.debug "TTL Not loading - #{error}"
|
63
56
|
end
|
57
|
+
|
58
|
+
# Create an message and publish for create session in Janus
|
59
|
+
def create_session
|
60
|
+
@publish = Rabbit::Publisher::PublishExclusive.new(rabbit.channel, '')
|
61
|
+
@publish.send_a_message(Janus::Message.new('base::create'))
|
62
|
+
end
|
63
|
+
|
64
|
+
# Return session_id
|
65
|
+
def running_session
|
66
|
+
@response.session
|
67
|
+
end
|
64
68
|
end
|
65
69
|
end
|
66
70
|
end
|
@@ -4,9 +4,10 @@ module RubyRabbitmqJanus
|
|
4
4
|
module Janus
|
5
5
|
# @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
|
6
6
|
# Abstract class for janus Event and Keepalive
|
7
|
-
class
|
7
|
+
class Concurrency
|
8
8
|
# Initialize class with elements for thread communication
|
9
9
|
def initialize
|
10
|
+
Tools::Log.instance.info 'Create an subprocess'
|
10
11
|
@rabbit = Rabbit::Connect.new
|
11
12
|
@lock = Mutex.new
|
12
13
|
@condition = ConditionVariable.new
|
@@ -14,11 +15,28 @@ module RubyRabbitmqJanus
|
|
14
15
|
|
15
16
|
private
|
16
17
|
|
18
|
+
# Start a new thread
|
17
19
|
def start_thread
|
18
20
|
Thread.new { initialize_thread }
|
21
|
+
# pid = fork { initialize_thread }
|
22
|
+
# Tools::Log.instance.info "Process IDentifier : #{pid}"
|
23
|
+
# initialize_thread
|
19
24
|
end
|
20
25
|
|
21
|
-
|
26
|
+
# Wait an signal
|
27
|
+
def wait
|
28
|
+
@lock.synchronize do
|
29
|
+
@condition.wait(@lock)
|
30
|
+
yield
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# Send and signal
|
35
|
+
def signal
|
36
|
+
@lock.synchronize { @condition.signal }
|
37
|
+
end
|
38
|
+
|
39
|
+
attr_accessor :rabbit, :publish
|
22
40
|
end
|
23
41
|
end
|
24
42
|
end
|
@@ -2,42 +2,44 @@
|
|
2
2
|
|
3
3
|
module RubyRabbitmqJanus
|
4
4
|
module Janus
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
5
|
+
module Transactions
|
6
|
+
# @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
|
7
|
+
# This class work with janus and send a series of message
|
8
|
+
class Admin < Handle
|
9
|
+
# Initialize conncetion to Rabbit and Janus
|
10
|
+
def connect
|
11
|
+
rabbit.transaction_short do
|
12
|
+
choose_queue
|
13
|
+
send_a_message { yield }
|
14
|
+
end
|
13
15
|
end
|
14
|
-
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
17
|
+
# Choose queue, create an handle, connect to rabbitmq server and send messages
|
18
|
+
def handle_connect
|
19
|
+
rabbit.transaction_long do
|
20
|
+
choose_queue
|
21
|
+
create_handle
|
22
|
+
yield
|
23
|
+
end
|
22
24
|
end
|
23
|
-
end
|
24
25
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
26
|
+
# Publish an message in handle
|
27
|
+
def publish_message_handle(type, options = {})
|
28
|
+
opts = { 'session_id' => session, 'handle_id' => handle }
|
29
|
+
msg = Janus::MessageAdmin.new(type, opts.merge!(options))
|
30
|
+
Janus::Response.new(publish.send_a_message(msg))
|
31
|
+
end
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
33
|
+
# Stop an handle running
|
34
|
+
def handle_running_stop
|
35
|
+
secret = Tools::Config.instance.options['rabbit']['admin_pass']
|
36
|
+
publish_message_handle('base::detach', admin_secret: secret)
|
37
|
+
end
|
37
38
|
|
38
|
-
|
39
|
-
|
40
|
-
|
39
|
+
# Define queue used for admin message
|
40
|
+
def choose_queue
|
41
|
+
@publish = Rabbit::PublisherPublishAdmin.new(rabbit.channel)
|
42
|
+
end
|
41
43
|
end
|
42
44
|
end
|
43
45
|
end
|
@@ -2,38 +2,40 @@
|
|
2
2
|
|
3
3
|
module RubyRabbitmqJanus
|
4
4
|
module Janus
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
5
|
+
module Transactions
|
6
|
+
# @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
|
7
|
+
# This class work with janus and send a series of message
|
8
|
+
class Handle < Session
|
9
|
+
# Initialize connection to Rabbit and Janus
|
10
|
+
def handle_connect(exclusive)
|
11
|
+
rabbit.transaction_long do
|
12
|
+
choose_queue(exclusive)
|
13
|
+
create_handle
|
14
|
+
yield
|
15
|
+
end
|
14
16
|
end
|
15
|
-
end
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
18
|
+
# Initialize connection to Rabbit and Janus and close after sending an received
|
19
|
+
# a response
|
20
|
+
def handle_connect_and_stop(exclusive)
|
21
|
+
rabbit.transaction_short do
|
22
|
+
choose_queue(exclusive)
|
23
|
+
create_handle
|
24
|
+
yield
|
25
|
+
end
|
24
26
|
end
|
25
|
-
end
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
28
|
+
# Stop an handle running
|
29
|
+
def handle_running_stop
|
30
|
+
publish_message_handle('base::detach')
|
31
|
+
end
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
33
|
+
# Publish an message in handle
|
34
|
+
def publish_message_handle(type, options = {})
|
35
|
+
opts = { 'session_id' => session, 'handle_id' => handle }
|
36
|
+
msg = Janus::Message.new(type, opts.merge!(options))
|
37
|
+
Janus::Response.new(publish.send_a_message(msg))
|
38
|
+
end
|
37
39
|
end
|
38
40
|
end
|
39
41
|
end
|
@@ -2,14 +2,16 @@
|
|
2
2
|
|
3
3
|
module RubyRabbitmqJanus
|
4
4
|
module Janus
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
5
|
+
module Transactions
|
6
|
+
# @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
|
7
|
+
# This class work with janus and send a series of message for session level
|
8
|
+
class Session < Transaction
|
9
|
+
# Connect to session and post an message
|
10
|
+
def session_connect(exclusive)
|
11
|
+
rabbit.transaction_short do
|
12
|
+
choose_queue(exclusive)
|
13
|
+
send_a_message { yield }
|
14
|
+
end
|
13
15
|
end
|
14
16
|
end
|
15
17
|
end
|
@@ -2,53 +2,58 @@
|
|
2
2
|
|
3
3
|
module RubyRabbitmqJanus
|
4
4
|
module Janus
|
5
|
-
#
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
#
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
5
|
+
# Define an module for manipulate a message between apps and janus
|
6
|
+
module Transactions
|
7
|
+
# @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
|
8
|
+
# This class work with janus and send a series of message
|
9
|
+
# :reek:TooManyInstanceVariables
|
10
|
+
class Transaction
|
11
|
+
# Initialize an transaction
|
12
|
+
def initialize(session)
|
13
|
+
@rabbit = Rabbit::Connect.new
|
14
|
+
@session = session
|
15
|
+
@response = @handle = @publish = nil
|
16
|
+
rescue => error
|
17
|
+
raise Errors::JanusTransaction, error
|
18
|
+
end
|
17
19
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
# Opening a short transaction with rabbitmq and close when is ending
|
21
|
+
def connect(exclusive)
|
22
|
+
@rabbit.transaction_short do
|
23
|
+
choose_queue(exclusive)
|
24
|
+
send_a_message { yield }
|
25
|
+
end
|
23
26
|
end
|
24
|
-
end
|
25
27
|
|
26
|
-
|
27
|
-
|
28
|
-
attr_reader :rabbit, :session, :response, :handle, :publish
|
29
|
-
|
30
|
-
# determine queue used
|
31
|
-
# :reek:ControlParameter and :reek:BooleanParameter
|
32
|
-
def choose_queue(exclusive = false)
|
33
|
-
chan = @rabbit.channel
|
34
|
-
@publish = if exclusive
|
35
|
-
Tools::Log.instance.debug 'Choose an queue non Exclusive : to-janus'
|
36
|
-
Rabbit::Publisher::PublishNonExclusive.new(chan)
|
37
|
-
else
|
38
|
-
Tools::Log.instance.debug 'Choose an queue Exclusive : ampq.gen-xxx'
|
39
|
-
Rabbit::Publisher::PublishExclusive.new(chan, '')
|
40
|
-
end
|
41
|
-
end
|
28
|
+
private
|
42
29
|
|
43
|
-
|
44
|
-
def send_a_message
|
45
|
-
Janus::Response.new(@publish.send_a_message(yield))
|
46
|
-
end
|
30
|
+
attr_reader :rabbit, :session, :response, :handle, :publish
|
47
31
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
32
|
+
# determine queue used
|
33
|
+
# :reek:ControlParameter and :reek:BooleanParameter
|
34
|
+
def choose_queue(exclusive = false)
|
35
|
+
chan = @rabbit.channel
|
36
|
+
@publish = if exclusive
|
37
|
+
Tools::Log.instance.debug \
|
38
|
+
'Choose an queue non Exclusive : to-janus'
|
39
|
+
Rabbit::Publisher::PublishNonExclusive.new(chan)
|
40
|
+
else
|
41
|
+
Tools::Log.instance.debug \
|
42
|
+
'Choose an queue Exclusive : ampq.gen-xxx'
|
43
|
+
Rabbit::Publisher::PublishExclusive.new(chan, '')
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# Send a message to queue
|
48
|
+
def send_a_message
|
49
|
+
Janus::Response.new(@publish.send_a_message(yield))
|
50
|
+
end
|
51
|
+
|
52
|
+
# Associate handle to transaction
|
53
|
+
def create_handle
|
54
|
+
msg = Janus::Message.new('base::attach', 'session_id' => @session)
|
55
|
+
@handle = send_a_message { msg }.sender
|
56
|
+
end
|
52
57
|
end
|
53
58
|
end
|
54
59
|
end
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
module RubyRabbitmqJanus
|
4
4
|
module Rabbit
|
5
|
+
# Define an module for create an publisher
|
5
6
|
module Publisher
|
6
7
|
# @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
|
7
8
|
# @abstract Publish message in RabbitMQ
|
@@ -22,10 +23,10 @@ module RubyRabbitmqJanus
|
|
22
23
|
|
23
24
|
# return an response when signal is trigger
|
24
25
|
def return_response
|
25
|
-
Tools::Log.instance.debug '
|
26
|
+
Tools::Log.instance.debug 'Response received'
|
26
27
|
@lock.synchronize do
|
27
28
|
@condition.wait(@lock)
|
28
|
-
response
|
29
|
+
@response
|
29
30
|
end
|
30
31
|
end
|
31
32
|
end
|
@@ -10,6 +10,7 @@ module RubyRabbitmqJanus
|
|
10
10
|
# Define an publisher
|
11
11
|
def initialize(rabbit)
|
12
12
|
super()
|
13
|
+
@response = nil
|
13
14
|
@count = 1
|
14
15
|
@rabbit = rabbit.channel
|
15
16
|
@reply = @rabbit.queue(Tools::Config.instance.options['queues']['queue_from'])
|
@@ -21,16 +22,25 @@ module RubyRabbitmqJanus
|
|
21
22
|
@reply.subscribe do |_info_delivery, _propertie, payload|
|
22
23
|
synchronize_response(payload)
|
23
24
|
end
|
24
|
-
|
25
|
+
end
|
26
|
+
|
27
|
+
# Execute an action for each response received in queue
|
28
|
+
def event_received
|
29
|
+
Tools::Log.instance.debug 'Response received'
|
30
|
+
lock.synchronize do
|
31
|
+
condition.wait(lock)
|
32
|
+
yield @response.event, @response.data, @response.jsep
|
33
|
+
end
|
25
34
|
end
|
26
35
|
|
27
36
|
private
|
28
37
|
|
29
38
|
# Sending an signal when an response is reading in queue
|
30
39
|
def synchronize_response(payload)
|
31
|
-
@response = JSON.parse
|
32
|
-
Tools::Log.instance.
|
33
|
-
"[X] Message number reading : #{@count}
|
40
|
+
@response = Janus::Response.new(JSON.parse(payload))
|
41
|
+
Tools::Log.instance.info \
|
42
|
+
"[X] Message number reading : #{@count} --\n\r" \
|
43
|
+
"type : #{@response}"
|
34
44
|
@count += 1
|
35
45
|
lock.synchronize { condition.signal }
|
36
46
|
end
|
@@ -7,6 +7,7 @@ module RubyRabbitmqJanus
|
|
7
7
|
# Publish message in queue non exclusive. By default "to-janus".
|
8
8
|
# This an option in config to this gem.
|
9
9
|
class PublishNonExclusive < Publisher
|
10
|
+
# Define an publisher for create non exclusive queue
|
10
11
|
def initialize(exchange)
|
11
12
|
@reply = exchange.queue(queue_from)
|
12
13
|
super(exchange)
|
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.0.
|
4
|
+
version: 1.0.3
|
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-11-
|
11
|
+
date: 2016-11-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|