ruby_rabbitmq_janus 1.0.3 → 1.0.4

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: bb6b179f8eb2d1d0f17269da3861f0d128100a3e
4
- data.tar.gz: e4dae7a3f07f17a4d92cf10b537830bc7e74b9a7
3
+ metadata.gz: 140c1b43d9ba2409e0b80b35e19d48f6a04fd56e
4
+ data.tar.gz: 808fbef0a6edb0cd92f5ed0b9f4abb134e8b899d
5
5
  SHA512:
6
- metadata.gz: 95f5ed36b90f240b1c42b36785826795a501a4d7f4c7b57a342dcb55007d1a795d5102efdcd35c49df5571d1188ae12d3c0b7409fa8ee51a7e73dc79b0131e20
7
- data.tar.gz: 7e352cabebf3d24213768e49466588205c7557d95c6be73e9e31089aa8c73a8331dda52cc2682f2502a7e18bdd01e9be97dff60399e6121e6f3b13f8f2dcabb8
6
+ metadata.gz: 4ac7f253fd46569ddc326b40e5e2e47b6aef05986be23a6b0016d2016f3d49e317d40507ffcadaaa11bd4a690d57c3cf457374fec7f9287766cb5e0e036cd76b
7
+ data.tar.gz: b312ac04662450523558cf049e9bb8dec3ce659422824ac4b1b3cac164f2ae5fe08da472721d04df0b9451e9b09ad8ec9f4c1ab8c393665e0942b19eb619760d
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.0.3'
6
+ VERSION = '1.0.4'
7
7
 
8
8
  # Define a summary description to gem
9
9
  SUMMARY = 'Ruby RabbitMQ Janus'
data/lib/rrj/init.rb CHANGED
@@ -25,19 +25,9 @@ module RubyRabbitmqJanus
25
25
  start_instances_tools
26
26
 
27
27
  # Create an session while time opening
28
- @session = Janus::Keepalive.instance.session
28
+ @session = Janus::Concurrencies::Keepalive.instance.session
29
29
 
30
30
  @transaction = nil
31
- rescue => error
32
- raise Errors::RRJErrorInit, error
33
- end
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
31
  end
42
32
 
43
33
  # Send an simple message to janus. No options in request with this method.
@@ -142,7 +132,6 @@ module RubyRabbitmqJanus
142
132
  Tools::Log.instance
143
133
  Tools::Config.instance
144
134
  Tools::Requests.instance
145
- Janus::Event.instance
146
135
  end
147
136
 
148
137
  # Return a current session if not specified
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rrj/janus/threads/thread'
3
+ require 'rrj/janus/processus/concurrency'
4
4
  require 'rrj/janus/message'
5
5
  require 'rrj/janus/admin'
6
6
  require 'rrj/janus/response'
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyRabbitmqJanus
4
+ module Janus
5
+ # Modules for create autonomous processus
6
+ module Concurrencies
7
+ # @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
8
+ # Abstract class for janus Event and Keepalive
9
+ class Concurrency
10
+ # Initialize class with elements for thread communication
11
+ def initialize
12
+ Tools::Log.instance.info "Create an thread -- #{self.class.name}"
13
+ @rabbit = Rabbit::Connect.new
14
+ @lock = Mutex.new
15
+ @condition = ConditionVariable.new
16
+ @thread = Thread.new { initialize_thread }
17
+ @thread.abort_on_exception = true
18
+ end
19
+
20
+ private
21
+
22
+ # Initialize a thread
23
+ def initialize_thread
24
+ rabbit.transaction_long { transaction_running }
25
+ rescue Interrupt
26
+ Tools::Log.instance.info "Stop transaction #{self.class.name}"
27
+ rabbit.close
28
+ end
29
+
30
+ # Wait an signal
31
+ def wait
32
+ @lock.synchronize do
33
+ @condition.wait(@lock)
34
+ Tools::Log.instance.info 'Waitting signal'
35
+ yield
36
+ end
37
+ end
38
+
39
+ # Send and signal
40
+ def signal
41
+ @lock.synchronize do
42
+ Tools::Log.instance.info 'Sending signal'
43
+ @condition.signal
44
+ end
45
+ end
46
+
47
+ attr_accessor :rabbit, :publish
48
+ end
49
+ end
50
+ end
51
+ end
52
+
53
+ require 'rrj/janus/processus/keepalive'
54
+ require 'rrj/janus/processus/event'
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyRabbitmqJanus
4
+ # @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
5
+ module Janus
6
+ module Concurrencies
7
+ # For listen standard queue ("from-janus" by default)
8
+ class Event < Concurrency
9
+ include Singleton
10
+
11
+ # Initialize Event object. Is used for listen an standard out queue to Janus
12
+ def initialize
13
+ @publish = @response = nil
14
+ super
15
+ end
16
+
17
+ # Start listen queue and work with each message reading
18
+ def listen(&block)
19
+ wait do
20
+ Tools::Log.instance.info 'Action !!!'.red
21
+ @publish.event_received(&block)
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ # Start a transaction with Rabbit an Janus
28
+ def transaction_running
29
+ @publish = Rabbit::Publisher::Listener.new(rabbit)
30
+ @response = @publish.listen_events
31
+ signal
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyRabbitmqJanus
4
+ module Janus
5
+ module Concurrencies
6
+ # @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
7
+ # Manage sending keepalive message
8
+ class Keepalive < Concurrency
9
+ include Singleton
10
+
11
+ # Initalize a keepalive message
12
+ def initialize
13
+ @publish = @response = nil
14
+ super
15
+ end
16
+
17
+ # Return an number session created
18
+ def session
19
+ wait { @response.session }
20
+ end
21
+
22
+ private
23
+
24
+ # Star an session with janus and waiting an signal for saving session_id
25
+ def transaction_running
26
+ @response = Janus::Response.new(create_session)
27
+ signal
28
+ session_keepalive(ttl)
29
+ end
30
+
31
+ # Create an loop for sending a keepalive message
32
+ def session_keepalive(time_to_live)
33
+ loop do
34
+ sleep time_to_live
35
+ @publish.send_a_message(Janus::Message.new('base::keepalive',
36
+ 'session_id' => running_session))
37
+ end
38
+ rescue => message
39
+ Tools::Log.instance.debug "Error keepalive : #{message}"
40
+ end
41
+
42
+ # Define a Time To Live between each request sending to janus
43
+ def ttl
44
+ Tools::Config.instance.options['gem']['session']['keepalive'].to_i
45
+ rescue => error
46
+ Tools::Log.instance.debug "TTL Not loading - #{error}"
47
+ end
48
+
49
+ # Create an message and publish for create session in Janus
50
+ def create_session
51
+ @publish = Rabbit::Publisher::PublishExclusive.new(rabbit.channel, '')
52
+ @publish.send_a_message(Janus::Message.new('base::create'))
53
+ end
54
+
55
+ # Return session_id
56
+ def running_session
57
+ @response.session
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -26,9 +26,8 @@ module RubyRabbitmqJanus
26
26
 
27
27
  # Execute an action for each response received in queue
28
28
  def event_received
29
- Tools::Log.instance.debug 'Response received'
30
- lock.synchronize do
31
- condition.wait(lock)
29
+ loop do
30
+ return_response
32
31
  yield @response.event, @response.data, @response.jsep
33
32
  end
34
33
  end
@@ -40,7 +39,7 @@ module RubyRabbitmqJanus
40
39
  @response = Janus::Response.new(JSON.parse(payload))
41
40
  Tools::Log.instance.info \
42
41
  "[X] Message number reading : #{@count} --\n\r" \
43
- "type : #{@response}"
42
+ "#{@response.to_hash}"
44
43
  @count += 1
45
44
  lock.synchronize { condition.signal }
46
45
  end
data/listen.rb ADDED
@@ -0,0 +1,55 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # :reek:NilCheck and :reek:TooManyStatements
4
+
5
+ require 'ruby_rabbitmq_janus'
6
+
7
+ @t = RubyRabbitmqJanus::RRJ.new
8
+
9
+ def case_event(data, jsep)
10
+ puts "Event : #{data.class} -- #{data}"
11
+ case data['videocontrol']
12
+ when 'joined'
13
+ puts 'Joined request ...'
14
+ @t.handle_message_simple('channel::offer', jsep)
15
+ when 'selected' then puts 'Selected request ...'
16
+ when 'unselected' then puts 'Unselected request ...'
17
+ when 'left' then puts 'Left request ...'
18
+ end
19
+ update_jsep(jsep) unless jsep.nil?
20
+ end
21
+
22
+ def update_jsep(jsep)
23
+ puts "JSEP : #{jsep}"
24
+ end
25
+
26
+ def case_hangup
27
+ puts 'Hangup'
28
+ Thread.stop
29
+ end
30
+
31
+ def case_stop
32
+ puts 'Stop'
33
+ Thread.stop
34
+ end
35
+
36
+ def case_error
37
+ puts 'Error ...'
38
+ end
39
+
40
+ puts "## Start listen Block"
41
+ RubyRabbitmqJanus::Janus::Concurrencies::Event.instance.listen do |reason, data, jsep|
42
+ case reason
43
+ when 'event' then case_event(data, jsep)
44
+ when 'hangup' then case_hangup
45
+ when 'stop' then case_stop
46
+ when 'error' then case_error
47
+ else
48
+ puts "REASON default : #{reason}"
49
+ end
50
+ end
51
+ puts "## End listen block"
52
+
53
+ #puts "apps running"
54
+ #loop do
55
+ #end
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.3
4
+ version: 1.0.4
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-10 00:00:00.000000000 Z
11
+ date: 2016-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -343,10 +343,10 @@ files:
343
343
  - lib/rrj/janus/admin.rb
344
344
  - lib/rrj/janus/janus.rb
345
345
  - lib/rrj/janus/message.rb
346
+ - lib/rrj/janus/processus/concurrency.rb
347
+ - lib/rrj/janus/processus/event.rb
348
+ - lib/rrj/janus/processus/keepalive.rb
346
349
  - lib/rrj/janus/response.rb
347
- - lib/rrj/janus/threads/event.rb
348
- - lib/rrj/janus/threads/keepalive.rb
349
- - lib/rrj/janus/threads/thread.rb
350
350
  - lib/rrj/janus/transactions/admin.rb
351
351
  - lib/rrj/janus/transactions/handle.rb
352
352
  - lib/rrj/janus/transactions/session.rb
@@ -368,6 +368,7 @@ files:
368
368
  - lib/rrj/tools/requests.rb
369
369
  - lib/rrj/tools/tools.rb
370
370
  - lib/ruby_rabbitmq_janus.rb
371
+ - listen.rb
371
372
  - rrj.gemspec
372
373
  homepage: https://github.com/dazzl-tv/ruby-rabbitmq-janus
373
374
  licenses:
@@ -1,42 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RubyRabbitmqJanus
4
- # @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
5
- module Janus
6
- # For listen standard queue ("from-janus" by default)
7
- class Event < Concurrency
8
- include Singleton
9
-
10
- # Initialize Event object. Is used for listen an standard out queue to Janus
11
- def initialize
12
- Tools::Log.instance.debug 'Start listen events in from-janus queue'
13
- @publish = @response = nil
14
- super
15
- start_thread
16
- end
17
-
18
- # Start listen queue and work with each message reading
19
- def listen(&block)
20
- loop { @publish.event_received(&block) }
21
- end
22
-
23
- private
24
-
25
- # Intialize an listen to queue
26
- def initialize_thread
27
- start_transaction
28
- rescue Interrupt
29
- Tools::Log.instance.info 'Stop to listen standard queue'
30
- rabbit.close
31
- end
32
-
33
- # Start a transaction with Rabbit an Janus
34
- def start_transaction
35
- rabbit.transaction_long do
36
- @publish = Rabbit::Publisher::Listener.new(rabbit)
37
- @publish.listen_events
38
- end
39
- end
40
- end
41
- end
42
- end
@@ -1,70 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RubyRabbitmqJanus
4
- module Janus
5
- # @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
6
- # Manage sending keepalive message
7
- class Keepalive < Concurrency
8
- include Singleton
9
-
10
- # Initalize a keepalive message
11
- def initialize
12
- Tools::Log.instance.debug 'Create an session for keepalive'
13
- @publish = @response = nil
14
- super
15
- start_thread
16
- end
17
-
18
- # Return an number session created
19
- def session
20
- wait { @response.session }
21
- end
22
-
23
- private
24
-
25
- # Initialize an session with janus and start a keepalive transaction
26
- def initialize_thread
27
- rabbit.transaction_long { transaction_keepalive }
28
- rescue Interrupt
29
- Tools::Log.instance.info 'Stop to sending keepalive'
30
- rabbit.close
31
- end
32
-
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)
38
- end
39
-
40
- # Create an loop for sending a keepalive message
41
- def session_keepalive(time_to_live)
42
- loop do
43
- sleep time_to_live
44
- @publish.send_a_message(Janus::Message.new('base::keepalive',
45
- 'session_id' => running_session))
46
- end
47
- rescue => message
48
- Tools::Log.instance.debug "Error keepalive : #{message}"
49
- end
50
-
51
- # Define a Time To Live between each request sending to janus
52
- def ttl
53
- Tools::Config.instance.options['gem']['session']['keepalive'].to_i
54
- rescue => error
55
- Tools::Log.instance.debug "TTL Not loading - #{error}"
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
68
- end
69
- end
70
- end
@@ -1,45 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RubyRabbitmqJanus
4
- module Janus
5
- # @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
6
- # Abstract class for janus Event and Keepalive
7
- class Concurrency
8
- # Initialize class with elements for thread communication
9
- def initialize
10
- Tools::Log.instance.info 'Create an subprocess'
11
- @rabbit = Rabbit::Connect.new
12
- @lock = Mutex.new
13
- @condition = ConditionVariable.new
14
- end
15
-
16
- private
17
-
18
- # Start a new thread
19
- def start_thread
20
- Thread.new { initialize_thread }
21
- # pid = fork { initialize_thread }
22
- # Tools::Log.instance.info "Process IDentifier : #{pid}"
23
- # initialize_thread
24
- end
25
-
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
40
- end
41
- end
42
- end
43
-
44
- require 'rrj/janus/threads/keepalive'
45
- require 'rrj/janus/threads/event'