ruby_rabbitmq_janus 1.0.4 → 1.0.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 140c1b43d9ba2409e0b80b35e19d48f6a04fd56e
4
- data.tar.gz: 808fbef0a6edb0cd92f5ed0b9f4abb134e8b899d
3
+ metadata.gz: 315daf05da37138a7cbd49ee535669ade8fba813
4
+ data.tar.gz: 00bf29601cb4f70693875466db4a52f5aa488188
5
5
  SHA512:
6
- metadata.gz: 4ac7f253fd46569ddc326b40e5e2e47b6aef05986be23a6b0016d2016f3d49e317d40507ffcadaaa11bd4a690d57c3cf457374fec7f9287766cb5e0e036cd76b
7
- data.tar.gz: b312ac04662450523558cf049e9bb8dec3ce659422824ac4b1b3cac164f2ae5fe08da472721d04df0b9451e9b09ad8ec9f4c1ab8c393665e0942b19eb619760d
6
+ metadata.gz: 3d931cd33d7c2a7ceac9fb2ed395f188fc9fb7d41637462f02c3e5afffa2493e3cb431701c5036f26f25ac61b7beb1a83eedf47a561604be8b7c6e725a07af4f
7
+ data.tar.gz: 256f28e5db381ad148dc8c2ab7c8a8a558e97e6a60666b2775b0d865bc73e261caf66bc0d2776310dc3d8d4f3f5206fd30b4c4f57d08c2871b80e4e8d17aa70c
@@ -9,7 +9,9 @@ module RubyRabbitmqJanus
9
9
  # Create an initializer
10
10
  def copy_initializer
11
11
  initializer 'ruby_rabbitmq_janus.rb' do
12
- "# frozen_string_literal: true\n\n::RRJ = RubyRabbitmqJanus::RRJ.new"
12
+ "# frozen_string_literal: true\n\n" \
13
+ "::RRJ = RubyRabbitmqJanus::RRJ.new\n"\
14
+ '::Events = RubyRabbitmqJanus::Janus::Concurrencies::Event.instance'
13
15
  end
14
16
  end
15
17
  end
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.4'
6
+ VERSION = '1.0.5'
7
7
 
8
8
  # Define a summary description to gem
9
9
  SUMMARY = 'Ruby RabbitMQ Janus'
data/lib/rrj/init.rb CHANGED
@@ -93,7 +93,7 @@ module RubyRabbitmqJanus
93
93
 
94
94
  # Define an handle transaction and establish connection with janus
95
95
  def start_handle(exclusive = false)
96
- @transaction ||= Janus::Transactions::Handle.new(@session)
96
+ @transaction = Janus::Transactions::Handle.new(@session)
97
97
  @transaction.handle_connect(exclusive) { yield }
98
98
  rescue => error
99
99
  raise Errors::RRJErrorHandle, error
@@ -101,7 +101,7 @@ module RubyRabbitmqJanus
101
101
 
102
102
  # Define an handle admin transaction and establish connection with janus
103
103
  def start_handle_admin
104
- @transaction ||= Janus::Transactions::Admin.new(@session)
104
+ @transaction = Janus::Transactions::Admin.new(@session)
105
105
  @transaction.handle_connect { yield }
106
106
  rescue => error
107
107
  raise Errors::RRJErrorHandle, error
@@ -114,7 +114,7 @@ module RubyRabbitmqJanus
114
114
 
115
115
  # Start an short transaction, this queue is not exclusive
116
116
  def handle_message_simple(type, replace = {}, add = {})
117
- @transaction ||= Janus::Transactions::Handle.new(@session)
117
+ @transaction = Janus::Transactions::Handle.new(@session)
118
118
  @transaction.handle_connect_and_stop(false) do
119
119
  message_handle(type, replace, add).for_plugin
120
120
  end
@@ -5,30 +5,45 @@ module RubyRabbitmqJanus
5
5
  module Janus
6
6
  module Concurrencies
7
7
  # For listen standard queue ("from-janus" by default)
8
- class Event < Concurrency
8
+ # :reek:InstanceVariableAssumption and :reek:NilCheck
9
+ # :reek:TooManyInstanceVariables and :reek:TooManyStatements
10
+ class Event
9
11
  include Singleton
10
12
 
11
13
  # Initialize Event object. Is used for listen an standard out queue to Janus
12
14
  def initialize
13
15
  @publish = @response = nil
14
- super
16
+ Tools::Log.instance.info "Create an thread -- #{self.class.name}"
17
+ @rabbit = Rabbit::Connect.new
18
+ @lock = Mutex.new
19
+ @condition = ConditionVariable.new
20
+ @thread_subscribe = Thread.new { initialize_thread }
15
21
  end
16
22
 
17
23
  # Start listen queue and work with each message reading
18
24
  def listen(&block)
19
- wait do
20
- Tools::Log.instance.info 'Action !!!'.red
25
+ @thread_subscribe.join
26
+ puts 'LISTEN !!'
27
+ @thread_listen = Thread.new do
28
+ puts 'LISTEN in thread !!'
29
+ Thread.pass
21
30
  @publish.event_received(&block)
22
31
  end
23
32
  end
24
33
 
25
34
  private
26
35
 
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
36
+ # Initialize a thread
37
+ def initialize_thread
38
+ Thread.pass
39
+ @rabbit.transaction_long do
40
+ @publish = Rabbit::Publisher::Listener.new(@rabbit)
41
+ @response = @publish.listen_events
42
+ @thread_listen&.join # Call if not nil
43
+ end
44
+ rescue Interrupt
45
+ Tools::Log.instance.info "Stop transaction #{self.class.name}"
46
+ @rabbit.close
32
47
  end
33
48
  end
34
49
  end
@@ -38,7 +38,7 @@ module RubyRabbitmqJanus
38
38
 
39
39
  # Define queue used for admin message
40
40
  def choose_queue
41
- @publish = Rabbit::PublisherPublishAdmin.new(rabbit.channel)
41
+ @publish = Rabbit::Publisher::PublisherAdmin.new(rabbit.channel)
42
42
  end
43
43
  end
44
44
  end
@@ -8,8 +8,8 @@ module RubyRabbitmqJanus
8
8
  class PublisherAdmin < Publisher
9
9
  # Intialize an queue non eclusive for admin/monitor API with Janus
10
10
  def initialize(exchange)
11
- super(exchange)
12
11
  @reply = exchange.queue(queue_from)
12
+ super(exchange)
13
13
  end
14
14
 
15
15
  private
data/listen.rb CHANGED
@@ -1,13 +1,14 @@
1
1
  #!/usr/bin/env ruby
2
-
3
- # :reek:NilCheck and :reek:TooManyStatements
2
+ # frozen_string_literal: true
4
3
 
5
4
  require 'ruby_rabbitmq_janus'
6
5
 
7
6
  @t = RubyRabbitmqJanus::RRJ.new
7
+ @events = RubyRabbitmqJanus::Janus::Concurrencies::Event.instance
8
8
 
9
+ # :reek:NilCheck and :reek:TooManyStatements
9
10
  def case_event(data, jsep)
10
- puts "Event : #{data.class} -- #{data}"
11
+ puts "REASON : Event : #{data.class} -- #{data}"
11
12
  case data['videocontrol']
12
13
  when 'joined'
13
14
  puts 'Joined request ...'
@@ -24,32 +25,32 @@ def update_jsep(jsep)
24
25
  end
25
26
 
26
27
  def case_hangup
27
- puts 'Hangup'
28
- Thread.stop
28
+ puts 'REASON : Hangup'
29
+ Thread.current.stop
29
30
  end
30
31
 
31
32
  def case_stop
32
- puts 'Stop'
33
- Thread.stop
33
+ puts 'REASON : Stop'
34
+ Thread.current.stop
34
35
  end
35
36
 
36
37
  def case_error
37
- puts 'Error ...'
38
+ puts 'REASON : Error ...'
38
39
  end
39
40
 
40
- puts "## Start listen Block"
41
- RubyRabbitmqJanus::Janus::Concurrencies::Event.instance.listen do |reason, data, jsep|
41
+ puts '## Start listen Block'
42
+ @events.listen do |reason, data, jsep|
42
43
  case reason
43
44
  when 'event' then case_event(data, jsep)
44
45
  when 'hangup' then case_hangup
45
46
  when 'stop' then case_stop
46
47
  when 'error' then case_error
47
48
  else
48
- puts "REASON default : #{reason}"
49
+ puts 'REASON default'
49
50
  end
50
51
  end
51
- puts "## End listen block"
52
+ puts '## End listen block'
52
53
 
53
- #puts "apps running"
54
- #loop do
55
- #end
54
+ puts 'apps running'
55
+ loop do
56
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_rabbitmq_janus
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - VAILLANT Jeremy