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.
- checksums.yaml +4 -4
- data/Rakefile +14 -0
- data/config/default.yml +5 -3
- data/config/requests/channel/README.md +29 -0
- data/config/requests/channel/answer.json +13 -0
- data/config/requests/channel/create.json +9 -0
- data/config/requests/channel/describe.json +10 -0
- data/config/requests/channel/destroy.json +10 -0
- data/config/requests/channel/exists.json +10 -0
- data/config/requests/channel/join.json +11 -0
- data/config/requests/channel/leave.json +11 -0
- data/config/requests/channel/list.json +9 -0
- data/config/requests/channel/offer.json +14 -0
- data/config/requests/channel/select.json +11 -0
- data/config/requests/channel/trickle.json +10 -0
- data/config/requests/peer/trickle.json +7 -0
- data/config/requests/videocast/join.json +12 -0
- data/config/requests/videocast/leave.json +11 -0
- data/config/ruby-rabbitmq-janus.yml +27 -0
- data/lib/generators/ruby_rabbitmq_janus/initializer_generator.rb +15 -24
- data/lib/generators/ruby_rabbitmq_janus/install_generator.rb +49 -0
- data/lib/rrj/info.rb +1 -1
- data/lib/rrj/init.rb +0 -2
- data/lib/rrj/rabbit/publish/listener.rb +38 -12
- data/lib/rrj/tools/config.rb +10 -6
- data/lib/rrj/tools/log.rb +5 -5
- data/spec/request/admin/request_handle_info_spec.rb +13 -0
- data/spec/request/admin/request_sessions_spec.rb +12 -0
- data/spec/request/base/request_attach_spec.rb +25 -0
- data/spec/request/base/request_create_spec.rb +17 -0
- data/spec/request/base/request_destroy_spec.rb +17 -0
- data/spec/request/base/request_detach_spec.rb +23 -0
- data/spec/request/base/request_info_spec.rb +17 -0
- data/spec/request/base/request_keepalive_spec.rb +17 -0
- data/spec/request/peer/request_trickle_spec.rb +42 -0
- data/spec/rrj/rrj_config_spec.rb +10 -0
- data/spec/rrj/rrj_log_spec.rb +21 -0
- data/spec/rrj/rrj_rabbitmq_spec.rb +18 -0
- data/spec/rrj/rrj_spec.rb +25 -0
- data/spec/spec_helper.rb +53 -0
- data/spec/support/aruba.rb +3 -0
- data/spec/support/examples.rb +83 -0
- data/spec/support/examples_peer.rb +18 -0
- data/spec/support/schemas/config/config.json +101 -0
- data/spec/support/schemas/config/rabbit.json +13 -0
- data/spec/support/schemas/request/admin/handle_info.json +17 -0
- data/spec/support/schemas/request/admin/sessions.json +13 -0
- data/spec/support/schemas/request/base/attach.json +19 -0
- data/spec/support/schemas/request/base/create.json +17 -0
- data/spec/support/schemas/request/base/destroy.json +13 -0
- data/spec/support/schemas/request/base/detach.json +13 -0
- data/spec/support/schemas/request/base/info.json +25 -0
- data/spec/support/schemas/request/base/keepalive.json +13 -0
- data/spec/support/schemas/request/channel/create.json +39 -0
- data/spec/support/schemas/request/channel/destroy.json +39 -0
- data/spec/support/schemas/request/channel/exist.json +41 -0
- data/spec/support/schemas/request/channel/list.json +37 -0
- data/spec/support/schemas/request/peer/trickle.json +21 -0
- metadata +57 -32
- data/.gitignore +0 -77
- data/.overcommit.yml +0 -12
- data/.reek +0 -7
- data/.rspec +0 -2
- data/.rubocop.yml +0 -12
- data/.travis.yml +0 -5
- data/.yardopts +0 -5
- data/CHANGELOG.md +0 -27
- data/CODE_OF_CONDUCT.md +0 -49
- data/README.md +0 -177
- data/rrj.gemspec +0 -41
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e3153d60baafdf940b9b95b691e9a96db5ddbb14
|
4
|
+
data.tar.gz: d55879f82f8a52e4dd17834de27b70f19b6a371c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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:
|
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
|
-
|
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:
|
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,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
|
-
#
|
29
|
-
|
30
|
-
|
31
|
-
|
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
|
-
|
38
|
-
|
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
data/lib/rrj/init.rb
CHANGED
@@ -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
|
8
|
-
# By default is "from-janus". It's a parameter in config to this
|
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
|
-
@
|
17
|
-
|
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
|
-
|
38
|
-
@count += 1
|
64
|
+
@rabbit.acknowledge(info.delivery_tag, false)
|
39
65
|
lock.synchronize { condition.signal }
|
40
66
|
end
|
41
67
|
end
|