ruby_rabbitmq_janus 1.2.9 → 2.0.0.pre.42

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 (118) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -0
  3. data/README.md +145 -32
  4. data/config/default.yml +2 -0
  5. data/config/requests.md +2 -1
  6. data/config/requests/admin/add_token.json +6 -0
  7. data/config/requests/admin/allow_token.json +6 -0
  8. data/config/requests/admin/disallow_token.json +6 -0
  9. data/config/requests/admin/handle_info.json +1 -1
  10. data/config/requests/admin/handles.json +1 -1
  11. data/config/requests/admin/remove_token.json +6 -0
  12. data/config/requests/admin/sessions.json +1 -1
  13. data/config/requests/admin/set_locking_debug.json +6 -0
  14. data/config/requests/admin/{log_level.json → set_log_level.json} +1 -1
  15. data/config/requests/admin/tokens.json +5 -0
  16. data/config/requests/base/attach.json +1 -1
  17. data/config/requests/base/create.json +1 -1
  18. data/config/requests/base/destroy.json +1 -1
  19. data/config/requests/base/detach.json +1 -1
  20. data/config/requests/base/info.json +1 -1
  21. data/config/requests/base/keepalive.json +1 -1
  22. data/config/requests/peer/answer.json +1 -1
  23. data/config/requests/peer/offer.json +1 -1
  24. data/config/requests/peer/trickle.json +1 -1
  25. data/lib/generators/ruby_rabbitmq_janus/initializer_generator.rb +3 -0
  26. data/lib/rrj/admin.rb +34 -0
  27. data/lib/rrj/errors/error.rb +2 -1
  28. data/lib/rrj/errors/init.rb +6 -0
  29. data/lib/rrj/errors/janus/janus.rb +1 -0
  30. data/lib/rrj/errors/janus/janus_message.rb +8 -4
  31. data/lib/rrj/errors/janus/janus_processus_keepalive.rb +1 -0
  32. data/lib/rrj/errors/janus/janus_response.rb +27 -6
  33. data/lib/rrj/errors/janus/janus_transaction.rb +4 -0
  34. data/lib/rrj/errors/rabbit/rabbit.rb +3 -1
  35. data/lib/rrj/errors/tools/config.rb +1 -0
  36. data/lib/rrj/info.rb +1 -1
  37. data/lib/rrj/init.rb +37 -169
  38. data/lib/rrj/janus/messages/admin.rb +1 -2
  39. data/lib/rrj/janus/messages/message.rb +4 -4
  40. data/lib/rrj/janus/messages/standard.rb +3 -5
  41. data/lib/rrj/janus/processus/concurrency.rb +1 -1
  42. data/lib/rrj/janus/processus/keepalive.rb +10 -4
  43. data/lib/rrj/janus/responses/admin.rb +31 -0
  44. data/lib/rrj/janus/responses/event.rb +23 -5
  45. data/lib/rrj/janus/responses/response.rb +2 -0
  46. data/lib/rrj/janus/responses/standard.rb +26 -5
  47. data/lib/rrj/janus/transactions/admin.rb +22 -26
  48. data/lib/rrj/janus/transactions/handle.rb +13 -8
  49. data/lib/rrj/janus/transactions/session.rb +25 -7
  50. data/lib/rrj/janus/transactions/transaction.rb +2 -1
  51. data/lib/rrj/rabbit/connect.rb +2 -3
  52. data/lib/rrj/rabbit/publish/admin.rb +1 -6
  53. data/lib/rrj/rabbit/publish/base_publisher.rb +6 -11
  54. data/lib/rrj/rabbit/publish/exclusive.rb +1 -0
  55. data/lib/rrj/rabbit/publish/listener.rb +10 -27
  56. data/lib/rrj/rabbit/publish/non_exclusive.rb +2 -6
  57. data/lib/rrj/rabbit/publish/publisher.rb +4 -17
  58. data/lib/rrj/tools/{config.rb → gem/config.rb} +5 -5
  59. data/lib/rrj/tools/{log.rb → gem/log.rb} +21 -6
  60. data/lib/rrj/tools/gem/option.rb +57 -0
  61. data/lib/rrj/tools/{requests.rb → gem/requests.rb} +0 -0
  62. data/lib/rrj/tools/replaces/admin.rb +7 -13
  63. data/lib/rrj/tools/replaces/handle.rb +61 -0
  64. data/lib/rrj/tools/replaces/replace.rb +57 -27
  65. data/lib/rrj/tools/replaces/session.rb +34 -0
  66. data/lib/rrj/tools/replaces/type.rb +63 -11
  67. data/lib/rrj/tools/tools.rb +4 -3
  68. data/lib/ruby_rabbitmq_janus.rb +1 -0
  69. data/spec/request/admin/request_handle_info_spec.rb +13 -7
  70. data/spec/request/admin/request_handles_spec.rb +20 -0
  71. data/spec/request/admin/request_sessions_spec.rb +5 -4
  72. data/spec/request/admin/request_set_locking_debug_spec.rb +16 -0
  73. data/spec/request/admin/request_set_log_level_spec.rb +16 -0
  74. data/spec/request/admin/request_tokens_spec.rb +13 -0
  75. data/spec/request/base/request_attach_spec.rb +6 -9
  76. data/spec/request/base/request_create_spec.rb +5 -3
  77. data/spec/request/base/request_destroy_spec.rb +5 -3
  78. data/spec/request/base/request_detach_spec.rb +6 -7
  79. data/spec/request/base/request_info_spec.rb +5 -3
  80. data/spec/request/base/request_keepalive_spec.rb +5 -3
  81. data/spec/request/peer/request_offer_spec.rb +18 -92
  82. data/spec/request/peer/request_trickle_spec.rb +9 -28
  83. data/spec/request/peer/request_trickles_spec.rb +23 -0
  84. data/spec/rrj/responses/responses_admin_spec.rb +39 -0
  85. data/spec/rrj/responses/responses_event_spec.rb +25 -0
  86. data/spec/rrj/responses/responses_response_spec.rb +31 -0
  87. data/spec/rrj/responses/responses_standard_spec.rb +43 -0
  88. data/spec/rrj/rrj_config_spec.rb +7 -7
  89. data/spec/rrj/rrj_rabbitmq_spec.rb +1 -1
  90. data/spec/rrj/tools/replace_admin_spec.rb +86 -0
  91. data/spec/rrj/tools/replace_handle_spec.rb +78 -0
  92. data/spec/rrj/tools/replace_session_spec.rb +66 -0
  93. data/spec/rrj/tools/replace_spec.rb +69 -0
  94. data/spec/rrj/tools/type_spec.rb +150 -0
  95. data/spec/spec_helper.rb +46 -7
  96. data/spec/support/examples_request.rb +33 -61
  97. data/spec/support/examples_response.rb +30 -0
  98. data/spec/support/schemas/request/admin/handles.json +15 -0
  99. data/spec/support/schemas/request/admin/set_locking_debug.json +13 -0
  100. data/spec/support/schemas/request/admin/set_log_level.json +11 -0
  101. data/spec/support/schemas/request/admin/tokens.json +13 -0
  102. data/spec/support/type.rb +66 -0
  103. metadata +41 -69
  104. data/config/requests/peer/trickles.json +0 -7
  105. data/lib/rrj/tools/replaces/standard.rb +0 -101
  106. data/spec/fixtures/config/requests/admin/handle_info.json +0 -3
  107. data/spec/fixtures/config/requests/admin/handles.json +0 -3
  108. data/spec/fixtures/config/requests/admin/log_level.json +0 -3
  109. data/spec/fixtures/config/requests/admin/sessions.json +0 -3
  110. data/spec/fixtures/config/requests/base/attach.json +0 -3
  111. data/spec/fixtures/config/requests/base/create.json +0 -4
  112. data/spec/fixtures/config/requests/base/destroy.json +0 -3
  113. data/spec/fixtures/config/requests/base/detach.json +0 -3
  114. data/spec/fixtures/config/requests/base/info.json +0 -3
  115. data/spec/fixtures/config/requests/base/keepalive.json +0 -3
  116. data/spec/fixtures/config/requests/peer/answer.json +0 -3
  117. data/spec/fixtures/config/requests/peer/offer.json +0 -3
  118. data/spec/fixtures/config/requests/peer/trickle.json +0 -3
@@ -4,6 +4,7 @@ module RubyRabbitmqJanus
4
4
  module Janus
5
5
  module Messages
6
6
  # @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
7
+ #
7
8
  # Create an message for janus
8
9
  class Admin < Message
9
10
  # Return options to message for rabbitmq
@@ -16,8 +17,6 @@ module RubyRabbitmqJanus
16
17
 
17
18
  private
18
19
 
19
- # Transform raw request in request to janus, so replace element
20
- # <string>, <number> and other with real value
21
20
  def prepare_request(options)
22
21
  @request = Tools::Replaces::Admin.new(request,
23
22
  options).transform_request
@@ -5,8 +5,9 @@ module RubyRabbitmqJanus
5
5
  # Modules for create message for Janus
6
6
  module Messages
7
7
  # @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
8
-
8
+ #
9
9
  # # Create a message for janus.
10
+ #
10
11
  # Create a message, in hash format, and sending to json format.
11
12
  # It's loading file base and change elements and configure message for
12
13
  # used in rabbitmq.
@@ -21,11 +22,13 @@ module RubyRabbitmqJanus
21
22
  attr_reader :type
22
23
 
23
24
  # Instanciate an message
25
+ #
24
26
  # @param template_request [String] Name of request prepare
25
27
  # @param [Hash] options Options to request
26
28
  # @option options [String] :session_id Identifier to session
27
29
  # @option options [String] :handle_id Identifier to session manipulate
28
30
  # @option options [Hash] :other Element contains in request sending
31
+ #
29
32
  # @example Initialize a message
30
33
  # Message.new('test', {
31
34
  # "session_id": 42,
@@ -77,18 +80,15 @@ module RubyRabbitmqJanus
77
80
 
78
81
  attr_accessor :properties, :request
79
82
 
80
- # Load raw request
81
83
  def load_request_file
82
84
  @request = request_instance
83
85
  Tools::Log.instance.debug "Opening request : #{to_json}"
84
86
  end
85
87
 
86
- # Transform JSON request with elements necessary
87
88
  def prepare_request(_options)
88
89
  Tools::Log.instance.debug "Prepare request for janus : #{to_json}"
89
90
  end
90
91
 
91
- # Return request to json format
92
92
  def request_instance
93
93
  JSON.parse File.read Tools::Requests.instance.requests[@type]
94
94
  end
@@ -4,6 +4,7 @@ module RubyRabbitmqJanus
4
4
  module Janus
5
5
  module Messages
6
6
  # @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
7
+ #
7
8
  # # Create an standard message
8
9
  class Standard < Message
9
10
  # Return options to message for rabbitmq
@@ -15,12 +16,9 @@ module RubyRabbitmqJanus
15
16
 
16
17
  private
17
18
 
18
- # Transform raw request in request to janus, so replace element
19
- # <string>, <number>
20
- # and other with real value
21
19
  def prepare_request(options)
22
- @request = Tools::Replaces::Standard.new(request,
23
- options).transform_request
20
+ @request = Tools::Replaces::Handle.new(request,
21
+ options).transform_request
24
22
  super
25
23
  end
26
24
  end
@@ -5,7 +5,7 @@ module RubyRabbitmqJanus
5
5
  # Modules for create autonomous processus
6
6
  module Concurrencies
7
7
  # @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
8
-
8
+ #
9
9
  # # Class for manage threads
10
10
  #
11
11
  # @abstract Manage thread in this gem for keepalive message and listen
@@ -4,7 +4,7 @@ module RubyRabbitmqJanus
4
4
  module Janus
5
5
  module Concurrencies
6
6
  # @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
7
-
7
+ #
8
8
  # # Manage keepalive message
9
9
  #
10
10
  # Create a thread for sending a message with type keepalive to session
@@ -26,6 +26,7 @@ module RubyRabbitmqJanus
26
26
  # @example Ask session
27
27
  # Keepalive.instance.session
28
28
  # => 852803383803249
29
+ #
29
30
  # @return [Fixnum] Identifier to session created by Janus
30
31
  def session
31
32
  lock.synchronize do
@@ -56,6 +57,8 @@ module RubyRabbitmqJanus
56
57
  sleep time_to_live
57
58
  @pub.publish(message_keepalive)
58
59
  Tools::Log.instance.info "Keepalive for #{@session}"
60
+ rescue => error
61
+ raise Errors::KeepaliveMessage, error
59
62
  end
60
63
 
61
64
  def create_session
@@ -66,14 +69,17 @@ module RubyRabbitmqJanus
66
69
  end
67
70
 
68
71
  def message_keepalive
69
- opt = { 'session_id' => @session }
70
- Janus::Messages::Standard.new('base::keepalive', opt)
72
+ Janus::Messages::Standard.new('base::keepalive', param_session)
71
73
  rescue => error
72
74
  raise Errors::KeepaliveMessage, error
73
75
  end
74
76
 
75
77
  def find_session
76
- Janus::Responses::Standard.new(create_session).to_hash['data']['id']
78
+ Janus::Responses::Standard.new(create_session).session
79
+ end
80
+
81
+ def param_session
82
+ { 'session_id' => @session }
77
83
  end
78
84
  end
79
85
  end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyRabbitmqJanus
4
+ module Janus
5
+ module Responses
6
+ # Response for admin request
7
+ class Admin < Standard
8
+ # List of sessions running in Janus Instance.
9
+ #
10
+ # @return [Array] List of sessions
11
+ def sessions
12
+ request['sessions']
13
+ end
14
+
15
+ # List of handles running in one session in Janus Instance.
16
+ #
17
+ # @return [Array] List of handles
18
+ def handles
19
+ request['handles']
20
+ end
21
+
22
+ # Info to session or handle in Janus Instance
23
+ #
24
+ # @return [Hash] Information to session/handle
25
+ def info
26
+ request['info']
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -7,33 +7,51 @@ module RubyRabbitmqJanus
7
7
  # Response for events message
8
8
  class Event < Standard
9
9
  # Return event to message
10
+ #
11
+ # @example Januse response
12
+ # request.event #=> 'success'
13
+ #
14
+ # @return [String] result to request
10
15
  def event
11
16
  request['janus']
12
17
  end
13
18
 
14
- # Return body data
19
+ # Read plugindata data
20
+ #
21
+ # @example Plugindata data
22
+ # request.data #=> { 'data': { 'audio': false } }
23
+ #
24
+ # @return [Hash] body data
15
25
  def data
16
26
  request['plugindata']['data'] if plugin_response?
17
27
  end
18
28
 
19
- # Return jsep data
29
+ # Read jsep data
30
+ #
31
+ # @example Data to jsep
32
+ # request.jsep #=> { 'jsep': { 'type': '...', 'sdp': '...' } }
33
+ #
34
+ # @return [Hash] jsep data
20
35
  def jsep
21
36
  request['jsep'] if contains_jsep?
22
37
  end
23
38
 
24
- # Return a couple session_id and handle_id
39
+ # session_id and handle_id
40
+ #
41
+ # @example Data to any request
42
+ # request.keys #=> [123456789, 987654321]
43
+ #
44
+ # @return [Array] Contains session_id and handle_id
25
45
  def keys
26
46
  [request['session_id'], request['sender']]
27
47
  end
28
48
 
29
49
  private
30
50
 
31
- # Test if response contains jsep data
32
51
  def contains_jsep?
33
52
  request.key?('jsep')
34
53
  end
35
54
 
36
- # Test if response is returning by plugin
37
55
  def plugin_response?
38
56
  request.key?('plugindata') && request['plugindata'].key?('data')
39
57
  end
@@ -5,6 +5,7 @@ module RubyRabbitmqJanus
5
5
  # Modules for manipulate responses sending by Janus
6
6
  module Responses
7
7
  # @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
8
+ #
8
9
  # Read and decryt a response to janus
9
10
  class Response
10
11
  # Instanciate a response
@@ -54,4 +55,5 @@ module RubyRabbitmqJanus
54
55
  end
55
56
 
56
57
  require 'rrj/janus/responses/standard'
58
+ require 'rrj/janus/responses/admin'
57
59
  require 'rrj/janus/responses/event'
@@ -11,16 +11,37 @@ module RubyRabbitmqJanus
11
11
  data_id
12
12
  end
13
13
 
14
- # Return a integer to handle
15
- def sender
16
- data_id
14
+ alias sender session
15
+
16
+ # Return session used in request
17
+ def session_id
18
+ request['session_id']
19
+ end
20
+
21
+ # Read response for plugin request
22
+ def plugin
23
+ request['plugindata']
24
+ end
25
+
26
+ # Read data response for plugin request
27
+ def plugin_data
28
+ plugin['data']
29
+ end
30
+
31
+ # Read data response for normal request
32
+ def data
33
+ request['data']
34
+ end
35
+
36
+ # Read SDP response
37
+ def sdp
38
+ request['jsep']['sdp']
17
39
  end
18
40
 
19
41
  private
20
42
 
21
- # Read a hash and return an identifier
22
43
  def data_id
23
- request['data']['id'].to_i
44
+ data['id'].to_i
24
45
  rescue => error
25
46
  raise Errors::JanusResponseDataId, error
26
47
  end
@@ -6,43 +6,39 @@ module RubyRabbitmqJanus
6
6
  # @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
7
7
 
8
8
  # This class work with janus and send a series of message
9
- class Admin < Handle
10
- # Publish an message in handle
11
- #
12
- # @param [String] type
13
- # Given a type to request. JSON request writing in 'config/requests/'
14
- # @param [Hash] options Replace/add element to request
15
- #
16
- # @return [Janus::Response::Standard] a response to message pusblishing
17
- # in queue Admin API
18
- def publish_message_handle(type, options)
19
- opts = {
20
- 'session_id' => session,
21
- 'handle_id' => handle,
22
- 'admin_secret' => admin_secret
23
- }
24
- msg = Janus::Messages::Admin.new(type, opts.merge!(options))
25
- Janus::Responses::Standard.new(read_response(publisher.publish(msg)))
9
+ class Admin < Session
10
+ def initialize(session)
11
+ super(true, session)
26
12
  end
27
13
 
28
- private
14
+ # Begin connection with RabbitMQ
15
+ def connect
16
+ rabbit.transaction_short do
17
+ @publisher = Rabbit::Publisher::PublisherAdmin.new(rabbit.channel)
18
+ yield
19
+ end
20
+ end
29
21
 
30
- # Define queue used for admin message
31
- def choose_queue
32
- chan = rabbit.channel
33
- @publisher = Rabbit::Publisher::PublisherAdmin.new(chan)
22
+ # Write a message in queue in RabbitMQ
23
+ def publish_message(type, options = {})
24
+ msg = Janus::Messages::Admin.new(type, opts.merge(options))
25
+ response = read_response(publisher.publish(msg))
26
+ Janus::Responses::Admin.new(response)
34
27
  end
35
28
 
36
- # Override method for publishing an message and reading a response
29
+ private
30
+
37
31
  def send_a_message
38
- Tools::Log.instance.info 'Publish a message ...'
39
- Janus::Responses::Standard.new(publisher.publish(yield))
32
+ Janus::Responses::Admin.new(publisher.publish(yield))
40
33
  end
41
34
 
42
- # Read a admin pass in configuration file to this gem
43
35
  def admin_secret
44
36
  Tools::Config.instance.options['rabbit']['admin_pass']
45
37
  end
38
+
39
+ def opts
40
+ { 'session_id' => session, 'admin_secret' => admin_secret }
41
+ end
46
42
  end
47
43
  end
48
44
  end
@@ -4,14 +4,14 @@ module RubyRabbitmqJanus
4
4
  module Janus
5
5
  module Transactions
6
6
  # @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
7
-
7
+ #
8
8
  # This class work with janus and send a series of message
9
- class Handle < Session
9
+ class Handle < Transaction
10
10
  # Initialize a transaction with handle
11
11
  #
12
12
  # @param [Fixnum] session
13
13
  # Use a session identifier for created message
14
- def initialize(session, exclusive, handle = 0)
14
+ def initialize(exclusive, session, handle = 0)
15
15
  super(session)
16
16
  @exclusive = exclusive
17
17
  @handle = handle
@@ -38,16 +38,19 @@ module RubyRabbitmqJanus
38
38
  # @param [Hash] options Replace/add element in request
39
39
  #
40
40
  # @return [Janus::Responses::Standard] Response to message sending
41
- def publish_message_handle(type, options)
42
- opts = { 'session_id' => session, 'handle_id' => handle }
41
+ def publish_message(type, options = {})
43
42
  msg = Janus::Messages::Standard.new(type, opts.merge!(options))
44
43
  response = read_response(publisher.publish(msg))
45
44
  Janus::Responses::Standard.new(response)
46
45
  end
47
46
 
47
+ # Send a message detach
48
+ def detach
49
+ publisher.publish(Janus::Messages::Standard.new('base::detach', opts))
50
+ end
51
+
48
52
  private
49
53
 
50
- # Create an handle for transaction
51
54
  def create_handle
52
55
  Tools::Log.instance.info 'Create an handle'
53
56
  opt = { 'session_id' => session }
@@ -55,19 +58,21 @@ module RubyRabbitmqJanus
55
58
  @handle = send_a_message_exclusive { msg }
56
59
  end
57
60
 
58
- # Send a messaeg in exclusive queue
59
61
  def send_a_message_exclusive
60
62
  Janus::Responses::Standard.new(read_response_exclusive do
61
63
  yield
62
64
  end).sender
63
65
  end
64
66
 
65
- # Read an response in queue exclusive
66
67
  def read_response_exclusive
67
68
  chan = rabbit.channel
68
69
  tmp_publish = Rabbit::Publisher::PublishExclusive.new(chan, '')
69
70
  tmp_publish.publish(yield)
70
71
  end
72
+
73
+ def opts
74
+ { 'session_id' => session, 'handle_id' => @handle }
75
+ end
71
76
  end
72
77
  end
73
78
  end
@@ -4,23 +4,41 @@ module RubyRabbitmqJanus
4
4
  module Janus
5
5
  module Transactions
6
6
  # @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
7
-
7
+ #
8
8
  # # Manage a transaction
9
+ #
9
10
  # Manage a transaction with message if contains a session identifier
10
11
  class Session < Transaction
11
- # Opening a short transaction with rabbitmq and close when is ending
12
+ # Initialize a transaction with handle
12
13
  #
13
- # @param [Boolean] exclusive
14
- # Determine if the message is sending to a exclusive queue or not
14
+ # @param [Fixnum] session
15
+ # Use a session identifier for created message
16
+ def initialize(exclusive, session)
17
+ super(session)
18
+ @exclusive = exclusive
19
+ end
20
+
21
+ # Opening a short transaction with rabbitmq and close when is ending
15
22
  #
16
23
  # @yield Send a message to Janus
17
- def connect(exclusive)
18
- @exclusive = exclusive
24
+ def connect
19
25
  rabbit.transaction_short do
20
26
  choose_queue
21
- send_a_message { yield }
27
+ yield
22
28
  end
23
29
  end
30
+
31
+ def publish_message(type, options = {})
32
+ msg = Janus::Messages::Standard.new(type, opts.merge!(options))
33
+ response = read_response(publisher.publish(msg))
34
+ Janus::Responses::Standard.new(response)
35
+ end
36
+
37
+ private
38
+
39
+ def opts
40
+ { 'session_id' => session }
41
+ end
24
42
  end
25
43
  end
26
44
  end