ruby_rabbitmq_janus 1.1.8 → 1.1.9

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.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +14 -0
  3. data/config/default.yml +5 -3
  4. data/config/requests/channel/README.md +29 -0
  5. data/config/requests/channel/answer.json +13 -0
  6. data/config/requests/channel/create.json +9 -0
  7. data/config/requests/channel/describe.json +10 -0
  8. data/config/requests/channel/destroy.json +10 -0
  9. data/config/requests/channel/exists.json +10 -0
  10. data/config/requests/channel/join.json +11 -0
  11. data/config/requests/channel/leave.json +11 -0
  12. data/config/requests/channel/list.json +9 -0
  13. data/config/requests/channel/offer.json +14 -0
  14. data/config/requests/channel/select.json +11 -0
  15. data/config/requests/channel/trickle.json +10 -0
  16. data/config/requests/peer/trickle.json +7 -0
  17. data/config/requests/videocast/join.json +12 -0
  18. data/config/requests/videocast/leave.json +11 -0
  19. data/config/ruby-rabbitmq-janus.yml +27 -0
  20. data/lib/generators/ruby_rabbitmq_janus/initializer_generator.rb +15 -24
  21. data/lib/generators/ruby_rabbitmq_janus/install_generator.rb +49 -0
  22. data/lib/rrj/info.rb +1 -1
  23. data/lib/rrj/init.rb +0 -2
  24. data/lib/rrj/rabbit/publish/listener.rb +38 -12
  25. data/lib/rrj/tools/config.rb +10 -6
  26. data/lib/rrj/tools/log.rb +5 -5
  27. data/spec/request/admin/request_handle_info_spec.rb +13 -0
  28. data/spec/request/admin/request_sessions_spec.rb +12 -0
  29. data/spec/request/base/request_attach_spec.rb +25 -0
  30. data/spec/request/base/request_create_spec.rb +17 -0
  31. data/spec/request/base/request_destroy_spec.rb +17 -0
  32. data/spec/request/base/request_detach_spec.rb +23 -0
  33. data/spec/request/base/request_info_spec.rb +17 -0
  34. data/spec/request/base/request_keepalive_spec.rb +17 -0
  35. data/spec/request/peer/request_trickle_spec.rb +42 -0
  36. data/spec/rrj/rrj_config_spec.rb +10 -0
  37. data/spec/rrj/rrj_log_spec.rb +21 -0
  38. data/spec/rrj/rrj_rabbitmq_spec.rb +18 -0
  39. data/spec/rrj/rrj_spec.rb +25 -0
  40. data/spec/spec_helper.rb +53 -0
  41. data/spec/support/aruba.rb +3 -0
  42. data/spec/support/examples.rb +83 -0
  43. data/spec/support/examples_peer.rb +18 -0
  44. data/spec/support/schemas/config/config.json +101 -0
  45. data/spec/support/schemas/config/rabbit.json +13 -0
  46. data/spec/support/schemas/request/admin/handle_info.json +17 -0
  47. data/spec/support/schemas/request/admin/sessions.json +13 -0
  48. data/spec/support/schemas/request/base/attach.json +19 -0
  49. data/spec/support/schemas/request/base/create.json +17 -0
  50. data/spec/support/schemas/request/base/destroy.json +13 -0
  51. data/spec/support/schemas/request/base/detach.json +13 -0
  52. data/spec/support/schemas/request/base/info.json +25 -0
  53. data/spec/support/schemas/request/base/keepalive.json +13 -0
  54. data/spec/support/schemas/request/channel/create.json +39 -0
  55. data/spec/support/schemas/request/channel/destroy.json +39 -0
  56. data/spec/support/schemas/request/channel/exist.json +41 -0
  57. data/spec/support/schemas/request/channel/list.json +37 -0
  58. data/spec/support/schemas/request/peer/trickle.json +21 -0
  59. metadata +57 -32
  60. data/.gitignore +0 -77
  61. data/.overcommit.yml +0 -12
  62. data/.reek +0 -7
  63. data/.rspec +0 -2
  64. data/.rubocop.yml +0 -12
  65. data/.travis.yml +0 -5
  66. data/.yardopts +0 -5
  67. data/CHANGELOG.md +0 -27
  68. data/CODE_OF_CONDUCT.md +0 -49
  69. data/README.md +0 -177
  70. data/rrj.gemspec +0 -41
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ffd08f2f0ae315d6330ae87407c249c8de25bb55
4
- data.tar.gz: 12a22014d95a64e3231d1ac9de1c36b4eb4d263a
3
+ metadata.gz: e3153d60baafdf940b9b95b691e9a96db5ddbb14
4
+ data.tar.gz: d55879f82f8a52e4dd17834de27b70f19b6a371c
5
5
  SHA512:
6
- metadata.gz: 619529b2da03ed8582cb91b4009894dbfbf5cf4f4d45f8d91fda3b7e392326ac33285dbf4df3b2bb45988695875085945ce9322ddcd77760a6cd0536c93499ca
7
- data.tar.gz: 4e15f89cb74a0b0574ec06bc518fe5e8c6393d3c68b5aefaaeaee501369f2dc0c37ccbd9a0b6204d928aaa4aa24cfc21e10da5ff1498beb448a88a0b4ee56078
6
+ metadata.gz: cc3ff0b7f739fbc25f1a253940f67305ccb8faa8208f60456fb3643c4ab3fc0cb524c42adb81f6e7b4557c72f8e115edc750dea301b4fe76a8ec830765871397
7
+ data.tar.gz: 72925fdbfee645bd0666faf7ca86877afc9a5f8d7b7a0f280385cc43030672b7a7fa2f2a18fca4ed1eb71276dffdac932ce451d4d28ddfe2663da993931865c4
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec) do |t|
7
+ t.rspec_opts = '--tag ~level:admin'
8
+ end
9
+
10
+ RSpec::Core::RakeTask.new(:no_request_spec) do |t|
11
+ t.rspec_opts = '--tag ~type:request'
12
+ end
13
+
14
+ task default: :spec
data/config/default.yml CHANGED
@@ -1,7 +1,7 @@
1
1
  # Rabbit information connection
2
2
  rabbit:
3
3
  # Precise RabbitMQ host - Default 'localhost'
4
- host: localhost
4
+ host: rabbit
5
5
  # Precise RabbitMQ port - Default '5672'
6
6
  port: 5672
7
7
  # Precise RabbitMQ vhost - Default '/'
@@ -19,9 +19,11 @@ queues:
19
19
  queue_from: from-janus
20
20
  # Queue sending a message for janus server
21
21
  queue_to: to-janus
22
- # Queues for admin janus
22
+ # Queues for admin janus
23
23
  admin:
24
+ # Queue sending response to admin API janus
24
25
  queue_from: from-janus-admin
26
+ # Queue sending a message for admin API janus
25
27
  queue_to: to-janus-admin
26
28
 
27
29
  # Janus plugin used
@@ -36,7 +38,7 @@ gem:
36
38
  log:
37
39
  # Define level to log
38
40
  # UNKNOW, FATAL, ERROR, WARN, INFO, DEBUG
39
- level: INFO
41
+ level: info
40
42
  # Option for sessions
41
43
  session:
42
44
  # Define time to send a keepalive message in seconds
@@ -0,0 +1,29 @@
1
+ # Channel
2
+
3
+ How to use gem for channels
4
+
5
+ For each example initialize a gem with command : `t = RubyRabbitmqJanus::RRJ.new`
6
+
7
+ ## List channels
8
+
9
+ ```ruby
10
+ # Create a session
11
+ create = t.ask('create')
12
+ session = t.response(create)
13
+
14
+ # Attach a session to plugin
15
+ attach = t.ask('attach', session)
16
+ session = t.response(attach)
17
+
18
+ # List a channels
19
+ list = t.ask('channel::list', session)
20
+ session = t.response(list)
21
+
22
+ # Detach a session
23
+ detach = t.ask('detach', session)
24
+ session = t.response(detach)
25
+
26
+ # Destroy a session
27
+ destroy = t.ask('destroy', session)
28
+ session = t.response(destroy)
29
+ ```
@@ -0,0 +1,13 @@
1
+ {
2
+ "janus": "message",
3
+ "session_id": "<number>",
4
+ "handle_id": "<number>",
5
+ "transaction": "<string>",
6
+ "body": {
7
+ "request": "configure",
8
+ },
9
+ "jsep": {
10
+ "type": "answer",
11
+ "sdp": "<string>"
12
+ }
13
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "janus": "message",
3
+ "session_id": "<number>",
4
+ "handle_id": "<number>",
5
+ "transaction": "<string>",
6
+ "body": {
7
+ "request": "create"
8
+ }
9
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "janus": "message",
3
+ "session_id": "<number>",
4
+ "handle_id": "<number>",
5
+ "transaction": "<string>",
6
+ "body": {
7
+ "request": "describe",
8
+ "channel": "<number>"
9
+ }
10
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "janus": "message",
3
+ "session_id": "<number>",
4
+ "handle_id": "<number>",
5
+ "transaction": "<string>",
6
+ "body": {
7
+ "request": "destroy",
8
+ "channel": "<number>"
9
+ }
10
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "janus": "message",
3
+ "session_id": "<number>",
4
+ "handle_id": "<number>",
5
+ "transaction": "<string>",
6
+ "body": {
7
+ "request": "exists",
8
+ "channel": "<number>"
9
+ }
10
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "janus": "message",
3
+ "session_id": "<number>",
4
+ "handle_id": "<number>",
5
+ "transaction": "<string>",
6
+ "body": {
7
+ "request": "join",
8
+ "channel": "<number>",
9
+ "type": "<string>"
10
+ }
11
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "janus": "message",
3
+ "session_id": "<number>",
4
+ "handle_id": "<number>",
5
+ "transaction": "<string>",
6
+ "body": {
7
+ "request": "leave",
8
+ "videocast": "<number>",
9
+ "channel": "<number>"
10
+ }
11
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "janus": "message",
3
+ "session_id": "<number>",
4
+ "handle_id": "<number>",
5
+ "transaction": "<string>",
6
+ "body": {
7
+ "request": "list"
8
+ }
9
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "janus": "message",
3
+ "session_id": "<number>",
4
+ "handle_id": "<number>",
5
+ "transaction": "<string>",
6
+ "body": {
7
+ "audio": "true",
8
+ "video": "true"
9
+ },
10
+ "jsep": {
11
+ "type": "offer",
12
+ "sdp": "<string>"
13
+ }
14
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "janus": "message",
3
+ "session_id": "<number>",
4
+ "handle_id": "<number>",
5
+ "transaction": "<string>",
6
+ "body": {
7
+ "request": "select",
8
+ "channel": "<number>",
9
+ "videocast": "<number>"
10
+ }
11
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "janus": "message",
3
+ "session_id": "<number>",
4
+ "handle_id": "<number>",
5
+ "transaction": "<string>",
6
+ "body": {
7
+ "request": "trickle",
8
+ "candidate": "<array>"
9
+ }
10
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "janus": "trickle",
3
+ "session_id": "<number>",
4
+ "handle_id": "<number>",
5
+ "transaction": "<string>",
6
+ "candidate": "<array>"
7
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "janus": "message",
3
+ "session_id": "<number>",
4
+ "handle_id": "<number>",
5
+ "transaction": "<string>",
6
+ "body": {
7
+ "request": "join",
8
+ "channel": "<number>",
9
+ "videocast": "<number>",
10
+ "type": "<string>"
11
+ }
12
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "janus": "message",
3
+ "session_id": "<number>",
4
+ "handle_id": "<number>",
5
+ "transaction": "<string>",
6
+ "body": {
7
+ "request": "leave",
8
+ "videocast": "<number>",
9
+ "channel": "<number>"
10
+ }
11
+ }
@@ -0,0 +1,27 @@
1
+ rabbit:
2
+ host: localhost
3
+ port: 5672
4
+ vhost: /
5
+ user: dazzl_admin
6
+ pass: koMpmVU8
7
+ admin_pass: Guj9khoN
8
+
9
+ queues:
10
+ queue_from: from-janus
11
+ queue_to: to-janus
12
+ admin:
13
+ queue_from: from-janus-admin
14
+ queue_to: to-janus-admin
15
+
16
+ janus:
17
+ plugins:
18
+ - janus.plugin.dazzl.videocontrol
19
+
20
+ gem:
21
+ log:
22
+ level: DEBUG
23
+ session:
24
+ keepalive: 59
25
+ thread:
26
+ enable: false
27
+ number: 1
@@ -5,37 +5,28 @@ module RubyRabbitmqJanus
5
5
  # Create an class for generate a initializer
6
6
  class InitializerGenerator < Rails::Generators::Base
7
7
  desc 'Generate a initializer to this gem for rails application.'
8
-
9
- # Create an initializer
10
- def copy_initializer
11
- initializer 'ruby_rabbitmq_janus.rb' do
12
- <<-INIT
8
+ INITIALIZER = <<-INIT
13
9
  # frozen_string_literal: true
14
10
 
11
+ require 'actions'
12
+
13
+ # Initialize a gem and create an session with a keepalive
14
+ ::RRJ = RubyRabbitmqJanus::RRJ.new
15
+
15
16
  # This test disable this gems execution when you running an task with rake
16
17
  unless File.basename($PROGRAM_NAME) == 'rake'
17
- # Write your methods for listening standar queue here
18
- #
19
- # Example :
20
- # action_events = lambda do |reason, data|
21
- # logger.debug 'Execute block code with reason :'
22
- # logger.debug reason
23
- # logger.debug --
24
- # logger.debug data
25
- # end
26
-
27
18
  Rails.configuration.after_initialize do
28
- # Initialize a gem and create an session with a keepalive
29
- ::RRJ = RubyRabbitmqJanus::RRJ.new
30
-
31
- # If you want listen a standard queue and execute an block code uncomment
32
- # this line and craete an method sendind to run
33
- # ::JEvents = RubyRabbitmqJanus::Janus::Concurrencies::Event.instance
34
- # JEvents.run(&action_events)
19
+ # If you don't want listen a standard queue, comment this lines and
20
+ # "require 'actions'"
21
+ actions = RubyRabbitmqJanus::ActionEvents.new.actions
22
+ RubyRabbitmqJanus::Janus::Concurrencies::Event.instance.run(&actions)
35
23
  end
36
24
  end
37
- INIT
38
- end
25
+ INIT
26
+
27
+ # Create an initializer
28
+ def copy_initializer
29
+ initializer 'ruby_rabbitmq_janus.rb', INITIALIZER
39
30
  end
40
31
  end
41
32
  end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyRabbitmqJanus
4
+ module Generators
5
+ # Create an class for generate a installing
6
+ class InstallGenerator < Rails::Generators::Base
7
+ desc 'Install RubyRabbitmqJanus in your Rails application'
8
+ ACTION_CLASS = <<-BASE
9
+ module RubyRabbitmqJanus
10
+ # Execute this code when janus return an events in standard queue
11
+ class ActionsEvents
12
+ # Default method using for sending a block of code
13
+ def actions
14
+ lambda do |reason, data|
15
+ Rails.logger.debug "Execute block code with reason : \#{reason}"
16
+ case reason
17
+ when event this case_events(data.to_hash)
18
+ end
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ def case_events(data)
25
+ Rails.logger.debug "Event : \#{data}"
26
+ end
27
+ end
28
+ end
29
+ BASE
30
+ APPLICATION = <<-AUTOLOAD
31
+ # Load RubyRabbitmqJanus actions events code blocks
32
+ config.autoload_paths += Dir[Rails.root.join('app', 'ruby_rabbitmq_janus')]
33
+ AUTOLOAD
34
+
35
+ def add_actions
36
+ # Create an class
37
+ create_file 'app/ruby_rabbitmq_janus/actions.rb', ACTION_CLASS
38
+
39
+ # Add to application.rb
40
+ application do
41
+ APPLICATION
42
+ end
43
+
44
+ # Add initializer
45
+ generate 'ruby_rabbitmq_janus:initializer'
46
+ end
47
+ end
48
+ end
49
+ 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.1.8'
6
+ VERSION = '1.1.9'
7
7
 
8
8
  # Define a summary description to gem
9
9
  SUMMARY = 'Ruby RabbitMQ Janus'
data/lib/rrj/init.rb CHANGED
@@ -8,8 +8,6 @@ require 'bunny'
8
8
  require 'logger'
9
9
  require 'key_path'
10
10
  require 'active_support'
11
- require 'concurrent'
12
- require 'colorize'
13
11
 
14
12
  module RubyRabbitmqJanus
15
13
  # @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
@@ -4,20 +4,16 @@ module RubyRabbitmqJanus
4
4
  module Rabbit
5
5
  module Publisher
6
6
  # @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
7
- # This publisher don't post message. Is listen just an standard queue to Janus.
8
- # By default is "from-janus". It's a parameter in config to this gem.
7
+ # This publisher don't post message. Is listen just an standard queue to
8
+ # Janus. By default is "from-janus". It's a parameter in config to this
9
+ # gem.
9
10
  class Listener < BasePublisher
10
11
  # Define an publisher
11
12
  def initialize(rabbit)
12
13
  super()
13
- @response = nil
14
- @count = 1
15
14
  @rabbit = rabbit.channel
16
- @reply = @rabbit.queue(Tools::Config.instance.options['queues']['queue_from'])
17
- Tools::Log.instance.debug "Waiting message from queue : #{@reply.name}"
18
- @reply.subscribe do |_info_delivery, _propertie, payload|
19
- synchronize_response(payload)
20
- end
15
+ @response = nil
16
+ subscribe_queue
21
17
  end
22
18
 
23
19
  # Listen a queue and return a body response
@@ -31,11 +27,41 @@ module RubyRabbitmqJanus
31
27
 
32
28
  private
33
29
 
30
+ def queue_name
31
+ Tools::Config.instance.options['queues']['queue_from']
32
+ end
33
+
34
+ # Subscribe queue
35
+ def subscribe_queue
36
+ reply = @rabbit.queue(queue_name)
37
+ @rabbit.prefetch(1)
38
+ reply.bind(binding).subscribe(opts_subs) do |info, prop, payload|
39
+ log_message_id(prop)
40
+ synchronize_response(info, payload)
41
+ end
42
+ end
43
+
44
+ # Define type binding used for subscriber
45
+ def binding
46
+ @rabbit.direct('amq.direct')
47
+ end
48
+
49
+ # Options subscribe
50
+ def opts_subs
51
+ { block: false, manual_ack: true, arguments: { 'x-priority': 2 } }
52
+ end
53
+
54
+ # Counts transmitted messages
55
+ def log_message_id(propertie)
56
+ message_id = propertie.message_id
57
+ Tools::Log.instance.info "[X] Message reading with ID ##{message_id}"
58
+ end
59
+
34
60
  # Sending an signal when an response is reading in queue
35
- def synchronize_response(payload)
61
+ def synchronize_response(info, payload)
62
+ sleep 0.2
36
63
  @response = Janus::Responses::Event.new(JSON.parse(payload))
37
- Tools::Log.instance.info "[X] Message number reading ##{@count}"
38
- @count += 1
64
+ @rabbit.acknowledge(info.delivery_tag, false)
39
65
  lock.synchronize { condition.signal }
40
66
  end
41
67
  end