ruby_rabbitmq_janus 1.2.3 → 1.2.4

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 (50) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +31 -28
  3. data/config/requests/peer/offer.json +2 -2
  4. data/lib/generators/ruby_rabbitmq_janus/create_request_generator.rb +2 -0
  5. data/lib/rrj/errors/init.rb +1 -1
  6. data/lib/rrj/errors/rabbit/rabbit.rb +14 -0
  7. data/lib/rrj/info.rb +15 -1
  8. data/lib/rrj/janus/processus/event.rb +4 -1
  9. data/lib/rrj/janus/processus/keepalive.rb +19 -13
  10. data/lib/rrj/janus/responses/response.rb +4 -0
  11. data/lib/rrj/janus/transactions/admin.rb +10 -4
  12. data/lib/rrj/janus/transactions/handle.rb +8 -3
  13. data/lib/rrj/janus/transactions/transaction.rb +14 -13
  14. data/lib/rrj/rabbit/publish/admin.rb +8 -1
  15. data/lib/rrj/rabbit/publish/exclusive.rb +13 -1
  16. data/lib/rrj/rabbit/publish/listener.rb +2 -0
  17. data/lib/rrj/rabbit/publish/non_exclusive.rb +3 -1
  18. data/lib/rrj/rabbit/publish/publisher.rb +10 -2
  19. data/lib/rrj/tools/config.rb +2 -0
  20. data/lib/rrj/tools/log.rb +2 -0
  21. data/lib/rrj/tools/replaces/replace.rb +3 -0
  22. data/lib/rrj/tools/replaces/standard.rb +1 -1
  23. data/lib/rrj/tools/replaces/type.rb +17 -0
  24. data/spec/fixtures/config/requests/admin/handle_info.json +3 -0
  25. data/spec/fixtures/config/requests/admin/handles.json +3 -0
  26. data/spec/fixtures/config/requests/admin/log_level.json +3 -0
  27. data/spec/fixtures/config/requests/admin/sessions.json +3 -0
  28. data/spec/fixtures/config/requests/base/attach.json +3 -0
  29. data/spec/fixtures/config/requests/base/create.json +4 -0
  30. data/spec/fixtures/config/requests/base/destroy.json +3 -0
  31. data/spec/fixtures/config/requests/base/detach.json +3 -0
  32. data/spec/fixtures/config/requests/base/info.json +3 -0
  33. data/spec/fixtures/config/requests/base/keepalive.json +3 -0
  34. data/spec/fixtures/config/requests/peer/answer.json +3 -0
  35. data/spec/fixtures/config/requests/peer/offer.json +3 -0
  36. data/spec/fixtures/config/requests/peer/trickle.json +3 -0
  37. data/spec/request/peer/request_offer_spec.rb +3 -5
  38. data/spec/rrj/rrj_config_spec.rb +1 -1
  39. data/spec/rrj/rrj_spec.rb +36 -10
  40. data/spec/support/examples_config.rb +6 -0
  41. data/spec/support/{examples.rb → examples_request.rb} +17 -0
  42. data/spec/support/schemas/request/peer/answer.json +2 -4
  43. data/spec/support/schemas/request/peer/offer.json +2 -4
  44. metadata +20 -12
  45. data/spec/request/peer/request_answer_spec.rb +0 -66
  46. data/spec/support/examples_peer.rb +0 -18
  47. data/spec/support/schemas/request/channel/create.json +0 -39
  48. data/spec/support/schemas/request/channel/destroy.json +0 -39
  49. data/spec/support/schemas/request/channel/exist.json +0 -41
  50. data/spec/support/schemas/request/channel/list.json +0 -37
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3d1ffd3bf9b6fe114af2808fa4bff38fcb9793d7
4
- data.tar.gz: c8b7e0025337cb7458ceaf785116abc3db07df5a
3
+ metadata.gz: 47210929d2091a11e4fe5430763ba83bee5d5306
4
+ data.tar.gz: 95733e7ac3ceac85f893f761440ba68447a1f51c
5
5
  SHA512:
6
- metadata.gz: 436f8a3cd02de4b1905898ee4bf744a86ca5c3ae2dab7964d35038a5923a919042ffae5b8e623ce1406cbc037198cb5d804822f65388f24f815e8dbbcd860bea
7
- data.tar.gz: cad78ce33154b8c3fe54dc6883e8fffe6bf9c3ad16bd9970a3880b13782ca37b42803af97096e31d408cdeaf68ed0f4708038c5b85fc0c63d56df4a15ed72951
6
+ metadata.gz: efc53b14b7d13c1ce73c0f3da5e8c666a47c7e1f7065d529776c2c30e5d2680343311c1185826fe1372e8c0854c22d1c6e53301460aff704349dbabc3bd989c1
7
+ data.tar.gz: c146be172fc950ae710b5e78725e11c8770ec58155856352c7b35355362a8ee8e4763802d92d06719260ab77340f965a0cc615bbbb7225a7c44f0cd9ff3cf458
data/README.md CHANGED
@@ -6,11 +6,11 @@
6
6
 
7
7
  Ruby Gem for Janus WebRTC Gateway integration using RabbitMQ message queue
8
8
 
9
- This gem is used to communicate to a server Janus through RabbitMQ software (
10
- Message-oriented middleware). It waiting a messages to Rails API who send to RabbitMQ
11
- server in a queue for janus server. janus processes a message and send to RabbitMQ server
12
- in a queue for gem. Once the received message is decoded and returned through the Rails API.
13
-
9
+ This gem is used to communicate to a server Janus through RabbitMQ software
10
+ (Message-oriented middleware). It waiting a messages to Rails API who send to
11
+ RabbitMQ server in a queue for janus server. janus processes a message and send
12
+ to RabbitMQ server in a queue for gem. Once the received message is decoded
13
+ and returned through the Rails API.
14
14
 
15
15
  This gem is product by [Dazzl.tv](http://dazzl.tv)
16
16
 
@@ -48,17 +48,11 @@ Use generator for complete installation :
48
48
  ```ruby
49
49
  rails g -h
50
50
  RubyRabbitmqJanus:
51
- ruby_rabbitmq_janus:configuration
52
- # Generate a custom configuration file.
53
-
54
- ruby_rabbitmq_janus:default_request
55
- # Copy base request file sending to janus in application. It's necessary if you want add your request.
56
-
57
- ruby_rabbitmq_janus:initializer
58
- # Generate a initializer to this gem for rails application.
59
-
60
- ruby_rabbitmq_janus:create_request
61
- # Create an request to json format for RubyRabbitmqJanus transaction.
51
+ ruby_rabbitmq_janus:configuration # Generate a custom configuration file.
52
+ ruby_rabbitmq_janus:create_request # Create an request to json format for RubyRabbitmqJanus transaction.
53
+ ruby_rabbitmq_janus:default_request # Copy base request file sending to janus in application.
54
+ ruby_rabbitmq_janus:initializer # Generate a initializer to this gem for rails application.
55
+ ruby_rabbitmq_janus:install # Install RubyRabbitmqJanus in your Rails application
62
56
  ```
63
57
 
64
58
  #### Requests
@@ -90,18 +84,27 @@ rabbitmq and use plugin echotest for janus server.
90
84
 
91
85
  Use tags for rspec :
92
86
 
93
- | type | name |
94
- | --------------- | --------------- |
95
- | request | attach |
96
- | | create |
97
- | | detach |
98
- | | info |
99
- | | test |
100
- | level | base |
101
- | | admin |
102
- | config | rabbit |
103
- | | log |
104
- | | config |
87
+ | Describe | Type | Name |
88
+ | ------------------------------------------------------------- | --------------- | --------------- |
89
+ | **Internaly function** | config | |
90
+ | Use bunny gem | | rabbit |
91
+ | Test log functions | | log |
92
+ | Test configuration function | | config |
93
+ | Test Gem contains CONSTANTS | | describe |
94
+ | **Level request sending to janus (admin monitor API or classic)** | level | |
95
+ | Request with no admin right. | | base |
96
+ | Request with admin right in Janus application. | | admin |
97
+ | **Request JSON sending to Rabbitmq -> Janus** | request | |
98
+ | Test request attach type | | attach |
99
+ | Test request type create | | create |
100
+ | Test request type detach | | detach |
101
+ | Test request type info | | info |
102
+ | Test request type test | | test |
103
+
104
+ Example usage rspec with tags :
105
+ ```ruby
106
+ rspec --tag --name:config --tag level:base
107
+ ```
105
108
 
106
109
  ## Upgrade
107
110
 
@@ -4,8 +4,8 @@
4
4
  "handle_id": "<number>",
5
5
  "transaction": "<string>",
6
6
  "body": {
7
- "audio": "true",
8
- "video": "true"
7
+ "audio": true,
8
+ "video": true
9
9
  },
10
10
  "jsep": {
11
11
  "type": "offer",
@@ -21,6 +21,8 @@ end
21
21
  # Create an hash with an array
22
22
  class HashString
23
23
  # Initialize an array
24
+ #
25
+ # @param [Array] string_array It's a string who converted to array
24
26
  def initialize(string_array)
25
27
  @array = string_array
26
28
  @hash = {}
@@ -15,7 +15,7 @@ module RubyRabbitmqJanus
15
15
  end
16
16
 
17
17
  # Define an exception if gem dont initialize correctly
18
- class InstaciateGemFailed < RRJ
18
+ class InstanciateGemFailed < RRJ
19
19
  # Initialize a error for instanciate class. It's a fatal error
20
20
  # @param [String] message Text returning in raise
21
21
  def initialize(message)
@@ -11,5 +11,19 @@ module RubyRabbitmqJanus
11
11
  super message, :fatal
12
12
  end
13
13
  end
14
+
15
+ # Execpetion primary for Rabbit class
16
+ class Rabbit < RRJError
17
+ def initialize(message)
18
+ super "[Rabbit]#{message}", :fatal
19
+ end
20
+ end
21
+
22
+ # Send exception when publish a message to rabbitmq failed
23
+ class RabbitPublishMessage < Rabbit
24
+ def initialize(message, request)
25
+ super "[Publish] #{message} -- #{request}"
26
+ end
27
+ end
14
28
  end
15
29
  end
data/lib/rrj/info.rb CHANGED
@@ -1,9 +1,23 @@
1
1
  # frozen_string_literal: true
2
+ # :reek:TooManyConstants
3
+
2
4
  # @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
3
5
  # Define constant to gem.
4
6
  module RubyRabbitmqJanus
5
7
  # Define version to gem
6
- VERSION = '1.2.3'
8
+ VERSION = '1.2.4'
9
+
10
+ # Name to gem
11
+ GEM_NAME = 'ruby_rabbitmq_janus'
12
+
13
+ # Authors
14
+ AUTHORS = ['VAILLANT Jeremy'].freeze
15
+
16
+ # Emails
17
+ EMAILS = ['jeremy@dazzl.tv'].freeze
18
+
19
+ # Licence
20
+ LICENSE = 'MIT'
7
21
 
8
22
  # Define a summary description to gem
9
23
  SUMMARY = 'Ruby RabbitMQ Janus'
@@ -16,7 +16,10 @@ module RubyRabbitmqJanus
16
16
 
17
17
  # Create a thred for execute a block code in a thread
18
18
  #
19
- # @yield Send to publisher the actions when a Janus event is received
19
+ # @param [Proc] block Block code for execute action when queue
20
+ # standard 'from-janus' receive a message.
21
+ #
22
+ # @return [Thread] It's a thread who listen queue and execute action
20
23
  def run(&block)
21
24
  thread.join
22
25
  Thread.new do
@@ -14,7 +14,7 @@ module RubyRabbitmqJanus
14
14
 
15
15
  # Create a thread
16
16
  def initialize
17
- @response = @publish = nil
17
+ @response = @publisher = nil
18
18
  super
19
19
  end
20
20
 
@@ -30,24 +30,30 @@ module RubyRabbitmqJanus
30
30
 
31
31
  def transaction_running
32
32
  @response = Janus::Responses::Standard.new(create_session)
33
- lock.synchronize do
34
- condition.signal
35
- end
36
- loop_session(Tools::Config.instance.ttl)
33
+ synchronize
34
+ create_loop_session
35
+ rescue => error
36
+ raise Errors::KeepaliveLoopSession, error
37
+ end
38
+
39
+ def synchronize
40
+ lock.synchronize { condition.signal }
41
+ end
42
+
43
+ def create_loop_session
44
+ loop { loop_session(Tools::Config.instance.ttl) }
37
45
  end
38
46
 
39
47
  def loop_session(time_to_live)
40
- loop do
41
- sleep time_to_live
42
- @publish.send_a_message(message_keepalive)
43
- end
44
- rescue => error
45
- raise Errors::KeepaliveLoopSession, error
48
+ sleep time_to_live
49
+ @publisher.publish(message_keepalive)
50
+ Tools::Log.instance.info "Keepalive for #{running_session}"
46
51
  end
47
52
 
48
53
  def create_session
49
- @publish = Rabbit::Publisher::PublishExclusive.new(rabbit.channel, '')
50
- @publish.send_a_message(Janus::Messages::Standard.new('base::create'))
54
+ @publisher = Rabbit::Publisher::PublishExclusive.new(rabbit.channel,
55
+ '')
56
+ @publisher.publish(Janus::Messages::Standard.new('base::create'))
51
57
  rescue => error
52
58
  raise Errors::KeepaliveCreateSession, error
53
59
  end
@@ -8,6 +8,10 @@ module RubyRabbitmqJanus
8
8
  # Read and decryt a response to janus
9
9
  class Response
10
10
  # Instanciate a response
11
+ #
12
+ # @param [Hash] response_janus
13
+ # Request parsing after Janus/RabbitMQ receive a response to request
14
+ # sending by user
11
15
  def initialize(response_janus)
12
16
  @request = response_janus
13
17
  rescue => error
@@ -8,6 +8,13 @@ module RubyRabbitmqJanus
8
8
  # This class work with janus and send a series of message
9
9
  class Admin < Handle
10
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
11
18
  def publish_message_handle(type, options)
12
19
  opts = {
13
20
  'session_id' => session,
@@ -15,8 +22,7 @@ module RubyRabbitmqJanus
15
22
  'admin_secret' => admin_secret
16
23
  }
17
24
  msg = Janus::Messages::Admin.new(type, opts.merge!(options))
18
- publisher = publish.send_a_message(msg)
19
- Janus::Responses::Standard.new(read_response(publisher))
25
+ Janus::Responses::Standard.new(read_response(publisher.publish(msg)))
20
26
  end
21
27
 
22
28
  private
@@ -24,13 +30,13 @@ module RubyRabbitmqJanus
24
30
  # Define queue used for admin message
25
31
  def choose_queue
26
32
  chan = rabbit.channel
27
- @publish = Rabbit::Publisher::PublisherAdmin.new(chan)
33
+ @publisher = Rabbit::Publisher::PublisherAdmin.new(chan)
28
34
  end
29
35
 
30
36
  # Override method for publishing an message and reading a response
31
37
  def send_a_message
32
38
  Tools::Log.instance.info 'Publish a message ...'
33
- Janus::Responses::Standard.new(publish.send_a_message(yield))
39
+ Janus::Responses::Standard.new(publisher.publish(yield))
34
40
  end
35
41
 
36
42
  # Read a admin pass in configuration file to this gem
@@ -33,11 +33,16 @@ module RubyRabbitmqJanus
33
33
  end
34
34
 
35
35
  # Publish an message in handle
36
+ #
37
+ # @param [String] type Request file used
38
+ # @param [Hash] options Replace/add element in request
39
+ #
40
+ # @return [Janus::Responses::Standard] Response to message sending
36
41
  def publish_message_handle(type, options)
37
42
  opts = { 'session_id' => session, 'handle_id' => handle }
38
43
  msg = Janus::Messages::Standard.new(type, opts.merge!(options))
39
- publisher = publish.send_a_message(msg)
40
- Janus::Responses::Standard.new(read_response(publisher))
44
+ response = read_response(publisher.publish(msg))
45
+ Janus::Responses::Standard.new(response)
41
46
  end
42
47
 
43
48
  private
@@ -61,7 +66,7 @@ module RubyRabbitmqJanus
61
66
  def read_response_exclusive
62
67
  chan = rabbit.channel
63
68
  tmp_publish = Rabbit::Publisher::PublishExclusive.new(chan, '')
64
- tmp_publish.send_a_message(yield)
69
+ tmp_publish.publish(yield)
65
70
  end
66
71
  end
67
72
  end
@@ -16,32 +16,33 @@ module RubyRabbitmqJanus
16
16
  def initialize(session)
17
17
  @rabbit = Rabbit::Connect.new
18
18
  @session = session
19
- @publish = @exclusive = nil
19
+ @publisher = @exclusive = nil
20
20
  rescue => error
21
21
  raise Errors::JanusTransaction, error
22
22
  end
23
23
 
24
24
  private
25
25
 
26
- attr_reader :rabbit, :session, :response, :handle, :publish, :exclusive
26
+ attr_reader :rabbit, :session, :response, :handle, :publisher,
27
+ :exclusive
27
28
 
28
29
  def choose_queue
29
30
  chan = @rabbit.channel
30
- @publish = if @exclusive
31
- Tools::Log.instance.debug \
32
- 'Choose an queue Exclusive : ampq.gen-xxx'
33
- Rabbit::Publisher::PublishExclusive.new(chan, '')
34
- else
35
- Tools::Log.instance.debug \
36
- 'Choose an queue non Exclusive : to-janus'
37
- Rabbit::Publisher::PublishNonExclusive.new(chan)
38
- end
31
+ @publisher = if @exclusive
32
+ Tools::Log.instance.debug \
33
+ 'Choose an queue Exclusive : ampq.gen-xxx'
34
+ Rabbit::Publisher::PublishExclusive.new(chan, '')
35
+ else
36
+ Tools::Log.instance.debug \
37
+ 'Choose an queue non Exclusive : to-janus'
38
+ Rabbit::Publisher::PublishNonExclusive.new(chan)
39
+ end
39
40
  end
40
41
 
41
42
  def send_a_message
42
43
  Tools::Log.instance.info 'Publish a message ...'
43
- publish = @publish.send_a_message(yield)
44
- Janus::Responses::Standard.new(read_response(publish))
44
+ response = read_response(@publisher.publish(yield))
45
+ Janus::Responses::Standard.new(response)
45
46
  end
46
47
 
47
48
  def read_response(publish)
@@ -7,6 +7,8 @@ module RubyRabbitmqJanus
7
7
  # This publisher send and read an message in admin queues
8
8
  class PublisherAdmin < Publisher
9
9
  # Intialize an queue non eclusive for admin/monitor API with Janus
10
+ #
11
+ # @param [String] exchange Exchange used for the transaction
10
12
  def initialize(exchange)
11
13
  @reply = exchange.queue(queue_from)
12
14
  super(exchange)
@@ -14,7 +16,12 @@ module RubyRabbitmqJanus
14
16
  end
15
17
 
16
18
  # Send an message to queue and waiting a response
17
- def send_a_message(request)
19
+ #
20
+ # @param [String] request JSON request sending to rabbitmq queue
21
+ #
22
+ # @return [Janus::Response::Standard] response for an request reading
23
+ # by janus instance
24
+ def publish(request)
18
25
  super(request)
19
26
  return_response
20
27
  end
@@ -4,8 +4,15 @@ module RubyRabbitmqJanus
4
4
  module Rabbit
5
5
  module Publisher
6
6
  # @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
7
+ # # Publish message
8
+ #
9
+ # Publish message in queue exclusive. Bunny create automaticaly a name for
10
+ # this queue. The queue name like to 'amq.gen-1A456DGVHDVUS'.
7
11
  class PublishExclusive < Publisher
8
12
  # Initialize an queue exclusive and generated automaticaly by bunny
13
+ #
14
+ # @param [String] exchange Exchange used for the transaction
15
+ # @param [String] name_queue Name to queue exclusive
9
16
  def initialize(exchange, name_queue)
10
17
  @reply = exchange.queue(name_queue, exclusive: true)
11
18
  super(exchange)
@@ -13,7 +20,12 @@ module RubyRabbitmqJanus
13
20
  end
14
21
 
15
22
  # Send an message to queue and waiting a response
16
- def send_a_message(request)
23
+ #
24
+ # @param [String] request JSON request sending to rabbitmq queue
25
+ #
26
+ # @return [Janus::Response::Standard] response for an request reading
27
+ # by janus instance
28
+ def publish(request)
17
29
  super(request)
18
30
  return_response
19
31
  end
@@ -9,6 +9,8 @@ module RubyRabbitmqJanus
9
9
  # gem.
10
10
  class Listener < BasePublisher
11
11
  # Define an publisher
12
+ #
13
+ # @param [String] rabbit Information connection to rabbitmq server
12
14
  def initialize(rabbit)
13
15
  super()
14
16
  @rabbit = rabbit.channel
@@ -14,7 +14,9 @@ module RubyRabbitmqJanus
14
14
  end
15
15
 
16
16
  # Send an message to queue
17
- def send_a_message(request)
17
+ #
18
+ # @param [String] request JSON request sending to rabbitmq queue
19
+ def publish(request)
18
20
  super(request)
19
21
  end
20
22
 
@@ -8,8 +8,9 @@ module RubyRabbitmqJanus
8
8
  # This publisher send and read an message in queues
9
9
  class Publisher < BasePublisher
10
10
  # Intialize a publisher for sending and reading a message
11
- # @param [String] rabbit object
12
11
  #
12
+ # @param [String] exchange Determine type exchange used for all
13
+ # transaction between gem and rabbitmq
13
14
  def initialize(exchange)
14
15
  super()
15
16
  @exchange = exchange.default_exchange
@@ -18,11 +19,18 @@ module RubyRabbitmqJanus
18
19
  end
19
20
 
20
21
  # Publish an message in queue
21
- def send_a_message(request)
22
+ #
23
+ # @param [String] request JSON request sending to rabbitmq queue
24
+ #
25
+ # @raise [Errors::RabbitPublishMessage] If request is false the
26
+ # execption is calling
27
+ def publish(request)
22
28
  Tools::Log.instance.info "Send request type : #{request.type}"
23
29
  @message = request
24
30
  @exchange.publish(@message.to_json,
25
31
  request.options.merge!(reply_to: queue_name))
32
+ rescue => error
33
+ raise Errors::RabbitPublishMessage, error, request
26
34
  end
27
35
 
28
36
  private
@@ -9,6 +9,8 @@ module RubyRabbitmqJanus
9
9
  #
10
10
  # @!attribute [r] options
11
11
  # @return [Hash] Return all options to configured in config file.
12
+ # @!attribute [r] configuration
13
+ # @return [String] Path to configuration file used
12
14
  class Config
13
15
  include Singleton
14
16
 
data/lib/rrj/tools/log.rb CHANGED
@@ -91,6 +91,8 @@ module RubyRabbitmqJanus
91
91
  end
92
92
 
93
93
  # Save log level used in this gem
94
+ #
95
+ # @param [Symbol] gem_level Level used for log in this gem
94
96
  def save_level(gem_level)
95
97
  @level = LEVELS[gem_level]
96
98
  end
@@ -8,6 +8,9 @@ module RubyRabbitmqJanus
8
8
  # @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
9
9
  class Replace
10
10
  # Initialize tool replace
11
+ #
12
+ # @param [Hash] request Request parsing before sending to RabbitMQ/Janus
13
+ # @param [Hash] options Replace/Add element in request
11
14
  def initialize(request, options = {})
12
15
  @request = request
13
16
  @opts = options
@@ -32,7 +32,7 @@ module RubyRabbitmqJanus
32
32
 
33
33
  # Replace sdp in request
34
34
  def replace_sdp
35
- request['jsep']['sdp'] = opts['replace']['sdp']
35
+ request['jsep']['sdp'] = opts['replace']['sdp'].gsub("\n", "\r\n")
36
36
  rescue => message
37
37
  Tools::Log.instance.warn "Error sdp replace : #{message}"
38
38
  end
@@ -6,17 +6,25 @@ module RubyRabbitmqJanus
6
6
  # to request sending
7
7
  class Type
8
8
  # Initalize an object for cast a type to data given by app
9
+ #
10
+ # @param [Hash] request Request parsing before sending to RabbitMQ/Janus
9
11
  def initialize(request)
10
12
  @request = request
11
13
  @data = nil
12
14
  end
13
15
 
14
16
  # Return an data with a type corresponding to string in request
17
+ #
18
+ # @param [String] key Key testing
19
+ # @param [Hash] option Datas sending by user and adding/replace in request
20
+ #
21
+ # @return data with good type for JSON format
15
22
  def convert(key, option)
16
23
  @data = option[key]
17
24
  case @request[key]
18
25
  when '<string>' then convert_to_type_string
19
26
  when '<number>' then convert_to_type_number
27
+ when '<boolean>' then convert_to_type_boolean
20
28
  end
21
29
  end
22
30
 
@@ -31,6 +39,15 @@ module RubyRabbitmqJanus
31
39
  def convert_to_type_number
32
40
  @data.to_i
33
41
  end
42
+
43
+ # Convert a data to Boolean type
44
+ def convert_to_type_boolean
45
+ if @data.casecmp('TRUE')
46
+ true
47
+ elsif @data.casecmp('FALSE')
48
+ false
49
+ end
50
+ end
34
51
  end
35
52
  end
36
53
  end
@@ -0,0 +1,3 @@
1
+ {
2
+ "error": "Request is False !!"
3
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "error": "Request is False !!"
3
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "error": "Request is False !!"
3
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "error": "Request is False !!"
3
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "error": "Request is False !!"
3
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "janus": "create",
3
+ "transaction": "<string>"
4
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "error": "Request is False !!"
3
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "error": "Request is False !!"
3
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "error": "Request is False !!"
3
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "error": "Request is False !!"
3
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "error": "Request is False !!"
3
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "error": "Request is False !!"
3
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "error": "Request is False !!"
3
+ }
@@ -2,13 +2,13 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- describe 'RubyRabbitmqJanus::RRJ -- message type offer', broken: true do
5
+ describe 'RubyRabbitmqJanus::RRJ -- message type offer' do
6
6
  before(:example) do
7
7
  sdp = <<END
8
8
  v=0
9
9
  o=- 7041456084360858977 2 IN IP4 127.0.0.1
10
10
  s=-
11
- t=0 0
11
+ t=0 0
12
12
  a=group:BUNDLE audio video
13
13
  a=msid-semantic: WMS 2jKToeOlpzKTn7anwnHOJmzFyhvEYt1kpcMY
14
14
  m=audio 9 UDP/TLS/RTP/SAVPF 111 103 104 9 0 8 106 105 13 126
@@ -94,12 +94,10 @@ a=ssrc:258141567 mslabel:2jKToeOlpzKTn7anwnHOJmzFyhvEYt1kpcMY
94
94
  a=ssrc:258141567 label:25d58816-114a-41d2-aa08-1039e09f942f
95
95
  END
96
96
  @type = 'peer::offer'
97
- @options = { 'replace' => { 'sdp' => sdp }, 'add' => {} }
97
+ @options = { 'replace' => { 'sdp' => sdp.to_s }, 'add' => {} }
98
98
  end
99
99
 
100
100
  describe '#message_handle', type: :request, level: :peer, name: :offer do
101
- let(:sdp) { 'v=0\r\no=[..more sdp stuff..]' }
102
-
103
101
  context 'when queue is exclusive' do
104
102
  it_behaves_like 'message_handle should match json schema'
105
103
  end
@@ -21,7 +21,7 @@ describe RubyRabbitmqJanus::Tools::Config, type: :config, name: :config do
21
21
  expect(@cfg.plugin_at).to be_a(String)
22
22
  end
23
23
 
24
- it 'When janus/plugins/0 defualt value is lading' do
24
+ it 'When janus/plugins/0 default value is loading' do
25
25
  expect(@cfg.plugin_at).to eq 'janus.plugin.echotest'
26
26
  end
27
27
 
data/spec/rrj/rrj_spec.rb CHANGED
@@ -3,23 +3,49 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe 'RubyRabbitmqJanus::RRJ', type: :config, name: :describe do
6
- it 'Has a version number' do
7
- expect(RubyRabbitmqJanus::VERSION).not_to be nil
6
+ context 'Has a version number' do
7
+ let(:data) { RubyRabbitmqJanus::VERSION }
8
+ it_behaves_like 'constant is', String
8
9
  end
9
10
 
10
- it 'Has a description' do
11
- expect(RubyRabbitmqJanus::DESCRIPTION).not_to be nil
11
+ context 'Has a name' do
12
+ let(:data) { RubyRabbitmqJanus::GEM_NAME }
13
+ it_behaves_like 'constant is', String
12
14
  end
13
15
 
14
- it 'Has a summary description' do
15
- expect(RubyRabbitmqJanus::SUMMARY).not_to be nil
16
+ context 'Has a author' do
17
+ let(:data) { RubyRabbitmqJanus::AUTHORS }
18
+ it_behaves_like 'constant is', Array
16
19
  end
17
20
 
18
- it 'Has a homepage' do
19
- expect(RubyRabbitmqJanus::HOMEPAGE).not_to be nil
21
+ context 'Has a email' do
22
+ let(:data) { RubyRabbitmqJanus::EMAILS }
23
+ it_behaves_like 'constant is', Array
20
24
  end
21
25
 
22
- it 'Has a post install message' do
23
- expect(RubyRabbitmqJanus::POST_INSTALL).not_to be nil
26
+ context 'Has a license' do
27
+ let(:data) { RubyRabbitmqJanus::LICENSE }
28
+ it_behaves_like 'constant is', String
29
+ it { expect('../../LICENSE').to be_an_existing_file }
30
+ end
31
+
32
+ context 'Has a description' do
33
+ let(:data) { RubyRabbitmqJanus::DESCRIPTION }
34
+ it_behaves_like 'constant is', String
35
+ end
36
+
37
+ context 'Has a summary description' do
38
+ let(:data) { RubyRabbitmqJanus::SUMMARY }
39
+ it_behaves_like 'constant is', String
40
+ end
41
+
42
+ context 'Has a homepage' do
43
+ let(:data) { RubyRabbitmqJanus::HOMEPAGE }
44
+ it_behaves_like 'constant is', String
45
+ end
46
+
47
+ context 'Has a post install message' do
48
+ let(:data) { RubyRabbitmqJanus::POST_INSTALL }
49
+ it_behaves_like 'constant is', String
24
50
  end
25
51
  end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ shared_examples 'constant is' do |type|
4
+ it { expect(data).not_to be nil }
5
+ it { expect(data).to be_kind_of(type) }
6
+ end
@@ -78,3 +78,20 @@ shared_examples 'message_admin should match json schema' do
78
78
  expect(message.to_json).to match_json_schema(@type)
79
79
  end
80
80
  end
81
+
82
+ # Simple request
83
+ shared_examples 'peer message_simple should match json empty' do
84
+ let(:message) { @gateway.message_simple(@type) }
85
+
86
+ it 'should match JSON empty' do
87
+ expect(message.to_json).to eq('{}')
88
+ end
89
+ end
90
+
91
+ shared_examples 'peer message_simple should match json schema' do
92
+ let(:message) { @gateway.message_simple(@type, true) }
93
+
94
+ it do
95
+ expect(message.to_json).to match_json_schema(@type)
96
+ end
97
+ end
@@ -3,13 +3,11 @@
3
3
  "properties": {
4
4
  "janus": { "type": "string", "pattern": "ack" },
5
5
  "transaction": { "type": "string" },
6
- "session_id": { "type": "integer" },
7
- "handle_id": { "type": "integer" }
6
+ "session_id": { "type": "integer" }
8
7
  },
9
8
  "required": [
10
9
  "janus",
11
10
  "transaction",
12
- "session_id",
13
- "handle_id"
11
+ "session_id"
14
12
  ]
15
13
  }
@@ -3,13 +3,11 @@
3
3
  "properties": {
4
4
  "janus": { "type": "string", "pattern": "ack" },
5
5
  "transaction": { "type": "string" },
6
- "session_id": { "type": "integer" },
7
- "handle_id": { "type": "integer" }
6
+ "session_id": { "type": "integer" }
8
7
  },
9
8
  "required": [
10
9
  "janus",
11
10
  "transaction",
12
- "session_id",
13
- "handle_id"
11
+ "session_id"
14
12
  ]
15
13
  }
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.2.3
4
+ version: 1.2.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-12-20 00:00:00.000000000 Z
11
+ date: 2017-01-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '12.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '12.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -285,7 +285,7 @@ description: |
285
285
  to RabbitMQ server in a queue for gem. Once the received message is decoded and
286
286
  returned through the Rails API.
287
287
  email:
288
- - jeremy.vaillant@dazzl.tv
288
+ - jeremy@dazzl.tv
289
289
  executables: []
290
290
  extensions: []
291
291
  extra_rdoc_files: []
@@ -359,6 +359,19 @@ files:
359
359
  - lib/rrj/tools/requests.rb
360
360
  - lib/rrj/tools/tools.rb
361
361
  - lib/ruby_rabbitmq_janus.rb
362
+ - spec/fixtures/config/requests/admin/handle_info.json
363
+ - spec/fixtures/config/requests/admin/handles.json
364
+ - spec/fixtures/config/requests/admin/log_level.json
365
+ - spec/fixtures/config/requests/admin/sessions.json
366
+ - spec/fixtures/config/requests/base/attach.json
367
+ - spec/fixtures/config/requests/base/create.json
368
+ - spec/fixtures/config/requests/base/destroy.json
369
+ - spec/fixtures/config/requests/base/detach.json
370
+ - spec/fixtures/config/requests/base/info.json
371
+ - spec/fixtures/config/requests/base/keepalive.json
372
+ - spec/fixtures/config/requests/peer/answer.json
373
+ - spec/fixtures/config/requests/peer/offer.json
374
+ - spec/fixtures/config/requests/peer/trickle.json
362
375
  - spec/request/admin/request_handle_info_spec.rb
363
376
  - spec/request/admin/request_sessions_spec.rb
364
377
  - spec/request/base/request_attach_spec.rb
@@ -367,7 +380,6 @@ files:
367
380
  - spec/request/base/request_detach_spec.rb
368
381
  - spec/request/base/request_info_spec.rb
369
382
  - spec/request/base/request_keepalive_spec.rb
370
- - spec/request/peer/request_answer_spec.rb
371
383
  - spec/request/peer/request_offer_spec.rb
372
384
  - spec/request/peer/request_trickle_spec.rb
373
385
  - spec/rrj/rrj_config_spec.rb
@@ -376,8 +388,8 @@ files:
376
388
  - spec/rrj/rrj_spec.rb
377
389
  - spec/spec_helper.rb
378
390
  - spec/support/aruba.rb
379
- - spec/support/examples.rb
380
- - spec/support/examples_peer.rb
391
+ - spec/support/examples_config.rb
392
+ - spec/support/examples_request.rb
381
393
  - spec/support/schemas/config/config.json
382
394
  - spec/support/schemas/config/rabbit.json
383
395
  - spec/support/schemas/request/admin/handle_info.json
@@ -388,10 +400,6 @@ files:
388
400
  - spec/support/schemas/request/base/detach.json
389
401
  - spec/support/schemas/request/base/info.json
390
402
  - spec/support/schemas/request/base/keepalive.json
391
- - spec/support/schemas/request/channel/create.json
392
- - spec/support/schemas/request/channel/destroy.json
393
- - spec/support/schemas/request/channel/exist.json
394
- - spec/support/schemas/request/channel/list.json
395
403
  - spec/support/schemas/request/peer/answer.json
396
404
  - spec/support/schemas/request/peer/offer.json
397
405
  - spec/support/schemas/request/peer/trickle.json
@@ -1,66 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe 'RubyRabbitmqJanus::RRJ -- message type answer', broken: true do
6
- before(:example) do
7
- sdp = <<END
8
- v=0
9
- o=- 7041456084360858977 2 IN IP4 127.0.0.1
10
- s=-
11
- t=0 0
12
- a=group:BUNDLE audio video
13
- a=msid-semantic: WMS 2jKToeOlpzKTn7anwnHOJmzFyhvEYt1kpcMY
14
- m=audio 9 UDP/TLS/RTP/SAVPF 111
15
- c=IN IP4 0.0.0.0
16
- a=rtcp:9 IN IP4 0.0.0.0
17
- a=ice-ufrag:T9QI
18
- a=ice-pwd:s9YvfGuavTZN0Lqc53JNInEP
19
- a=fingerprint:sha-256 6D:ED:BC:93:AC:EC:C2:29:03:7D:6A:60:9F:D3:F5:A1:6D:1A:38:CE:F0:C0:EC:C8:5D:87:19:19:BE:0F:89:BB
20
- a=setup:actpass
21
- a=mid:audio
22
- a=extmap:1 urn:ietf:params:rtp-hdrext:ssrc-audio-level
23
- a=extmap:3 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time
24
- a=sendonly
25
- a=rtcp-mux
26
- a=rtpmap:111 opus/48000/2
27
- a=rtcp-fb:111 transport-cc
28
- a=fmtp:111 minptime=10;useinbandfec=1
29
- m=video 9 UDP/TLS/RTP/SAVPF 100
30
- c=IN IP4 0.0.0.0
31
- a=rtcp:9 IN IP4 0.0.0.0
32
- a=ice-ufrag:T9QI
33
- a=ice-pwd:s9YvfGuavTZN0Lqc53JNInEP
34
- a=fingerprint:sha-256 6D:ED:BC:93:AC:EC:C2:29:03:7D:6A:60:9F:D3:F5:A1:6D:1A:38:CE:F0:C0:EC:C8:5D:87:19:19:BE:0F:89:BB
35
- a=setup:actpass
36
- a=mid:video
37
- a=extmap:2 urn:ietf:params:rtp-hdrext:toffset
38
- a=extmap:3 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time
39
- a=extmap:4 urn:3gpp:video-orientation
40
- a=extmap:6 http://www.webrtc.org/experiments/rtp-hdrext/playout-delay
41
- a=sendonly
42
- a=rtcp-mux
43
- a=rtcp-rsize
44
- a=rtpmap:100 VP8/90000
45
- a=rtcp-fb:100 ccm fir
46
- a=rtcp-fb:100 nack
47
- a=rtcp-fb:100 nack pli
48
- a=rtcp-fb:100 goog-remb
49
- a=rtcp-fb:100 transport-cc
50
- END
51
- @type = 'peer::answer'
52
- @options = { 'replace' => { 'sdp' => sdp }, 'add' => {} }
53
- end
54
-
55
- describe '#message_handle', type: :request, level: :peer, name: :answer do
56
- context 'when queue is exclusive' do
57
- it_behaves_like 'message_handle should match json schema'
58
- end
59
-
60
- context 'when queue is not exclusive' do
61
- it_behaves_like 'message_handle should match json empty'
62
- end
63
- end
64
-
65
- after(:example) { @gateway.handle_message_simple('base::detach') }
66
- end
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Simple request
4
- shared_examples 'peer message_simple should match json empty' do
5
- let(:message) { @gateway.message_simple(@type) }
6
-
7
- it 'should match JSON empty' do
8
- expect(message.to_json).to eq('{}')
9
- end
10
- end
11
-
12
- shared_examples 'peer message_simple should match json schema' do
13
- let(:message) { @gateway.message_simple(@type, true) }
14
-
15
- it do
16
- expect(message.to_json).to match_json_schema(@type)
17
- end
18
- end
@@ -1,39 +0,0 @@
1
- {
2
- "type": "object",
3
- "properties": {
4
- "janus": { "type": "string", "pattern": "success" },
5
- "session_id": { "type": "integer" },
6
- "transaction": { "type": "string" },
7
- "sender": { "type": "integer" },
8
- "plugindata": {
9
- "type": "hash",
10
- "properties": {
11
- "data": {
12
- "type": "hash",
13
- "properties": {
14
- "videocontrol": { "type": "string", "pattern": "created" },
15
- "channel": { "type": "integer"}
16
- },
17
- "required": [
18
- "videocontrol",
19
- "channel"
20
- ]
21
- },
22
- "plugin": {
23
- "type": "string"
24
- }
25
- },
26
- "required": [
27
- "plugin",
28
- "data"
29
- ]
30
- }
31
- },
32
- "required": [
33
- "janus",
34
- "session_id",
35
- "sender",
36
- "transaction",
37
- "plugindata"
38
- ]
39
- }
@@ -1,39 +0,0 @@
1
- {
2
- "type": "object",
3
- "properties": {
4
- "janus": { "type": "string", "pattern": "success" },
5
- "session_id": { "type": "integer" },
6
- "transaction": { "type": "string" },
7
- "sender": { "type": "integer" },
8
- "plugindata": {
9
- "type": "hash",
10
- "properties": {
11
- "data": {
12
- "type": "hash",
13
- "properties": {
14
- "videocontrol": { "type": "string", "pattern": "destroyed" },
15
- "channel": { "type": "integer"}
16
- },
17
- "required": [
18
- "videocontrol",
19
- "channel"
20
- ]
21
- },
22
- "plugin": {
23
- "type": "string"
24
- }
25
- },
26
- "required": [
27
- "data",
28
- "plugin"
29
- ]
30
- }
31
- },
32
- "required": [
33
- "janus",
34
- "session_id",
35
- "sender",
36
- "transaction",
37
- "plugindata"
38
- ]
39
- }
@@ -1,41 +0,0 @@
1
- {
2
- "type": "object",
3
- "properties": {
4
- "janus": { "type": "string", "pattern": "success" },
5
- "session_id": { "type": "integer" },
6
- "transaction": { "type": "string" },
7
- "sender": { "type": "integer" },
8
- "plugindata": {
9
- "type": "hash",
10
- "properties": {
11
- "data": {
12
- "type": "hash",
13
- "properties": {
14
- "videocontrol": { "type": "string", "pattern": "success" },
15
- "channel": { "type": "integer"},
16
- "exists": { "type": "boolean" }
17
- },
18
- "required": [
19
- "videocontrol",
20
- "channel",
21
- "exists"
22
- ]
23
- },
24
- "plugin": {
25
- "type": "string"
26
- }
27
- },
28
- "required": [
29
- "plugin",
30
- "data"
31
- ]
32
- }
33
- },
34
- "required": [
35
- "janus",
36
- "session_id",
37
- "sender",
38
- "transaction",
39
- "plugindata"
40
- ]
41
- }
@@ -1,37 +0,0 @@
1
- {
2
- "type": "object",
3
- "properties": {
4
- "janus": { "type": "string", "pattern": "success" },
5
- "session_id": { "type": "integer" },
6
- "transaction": { "type": "string" },
7
- "sender": { "type": "integer" },
8
- "plugindata": {
9
- "type": "hash",
10
- "properties": {
11
- "data": {
12
- "type": "hash",
13
- "properties": {
14
- "videocontrol": { "type": "string" },
15
- "list": { "type": "array" }
16
- },
17
- "required": [
18
- "videocontrol",
19
- "list"
20
- ]
21
- },
22
- "plugin": { "type": "string" }
23
- },
24
- "required": [
25
- "data",
26
- "plugin"
27
- ]
28
- }
29
- },
30
- "required": [
31
- "janus",
32
- "session_id",
33
- "sender",
34
- "transaction",
35
- "plugindata"
36
- ]
37
- }