janus_gateway 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c10a9ee81c818aee4fe4073e737cf3eda8191e04
4
- data.tar.gz: 9340bc834c427717721675b34b7960e1d3caf302
3
+ metadata.gz: bc4b9beb3a1785cdd57969399012134c3d9cf1f6
4
+ data.tar.gz: 6f0f36f3d20e628ce3e71a9bba8048e29c7e0fcf
5
5
  SHA512:
6
- metadata.gz: 9889e2845a169b208ccb1e8d45d0f2e0102e1d2bf3a3fd996905475e1957ebe5e1536dbbe017bbb4914f983baa3805213cf72bf43f3d088f4976556fd0f889e2
7
- data.tar.gz: f0934ba4c35e31de9b7e75f13277a779fd3c9ff8d47d7074cb37f828729fb92236321fca3821bd7242ad7c30d4c3bf4cdbf357aab5240c704ce320d20c3642e7
6
+ metadata.gz: 61469d3bf261e225d482a2a1a5ad7fe06c6e475125ad7bf106d1106361617e4a0aa8a23f9432bcd23669ba15203e405cfd80ebda369fe4b1899eaefe007b3962
7
+ data.tar.gz: b8105fbd4c6e7a56939d4667c031d8356e245d531b311747a3df0bb59702c1febffcf5c786081ee8eacd5deedf6ec90dfc8a389bfe29884b41b32a48f7658f27
data/README.md CHANGED
@@ -1,6 +1,9 @@
1
- janus-gateway-ruby [![Build Status](https://travis-ci.org/cargomedia/janus-gateway-ruby.svg)](https://travis-ci.org/cargomedia/janus-gateway-ruby)
1
+ janus-gateway-ruby
2
2
  ==================
3
- Minimalistic [janus-gateway](https://github.com/meetecho/janus-gateway) client for ruby
3
+ Minimalistic client for the [Janus](https://github.com/meetecho/janus-gateway) WebRTC gateway.
4
+
5
+ [![Build Status](https://img.shields.io/travis/cargomedia/janus-gateway-ruby/master.svg)](https://travis-ci.org/cargomedia/janus-gateway-ruby)
6
+ [![Gem Version](https://img.shields.io/gem/v/janus_gateway.svg)](https://rubygems.org/gems/janus_gateway)
4
7
 
5
8
  Installation
6
9
  ------------
data/lib/janus_gateway.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  module JanusGateway
2
-
3
2
  require 'json'
4
3
  require 'events'
5
4
  require 'concurrent'
@@ -1,7 +1,5 @@
1
1
  module JanusGateway
2
-
3
2
  class Client
4
-
5
3
  attr_accessor :transport
6
4
 
7
5
  # @param [JanusGateway::Transport]
@@ -9,8 +7,8 @@ module JanusGateway
9
7
  def initialize(transport, options = {})
10
8
  @transport = transport
11
9
  @options = {
12
- :token => nil,
13
- :admin_secret => nil
10
+ token: nil,
11
+ admin_secret: nil
14
12
  }.merge(options)
15
13
  end
16
14
 
@@ -29,13 +27,13 @@ module JanusGateway
29
27
  # @param [Hash] data
30
28
  # @return [Concurrent::Promise]
31
29
  def send_transaction(data)
32
- extra_fields = @options.delete_if { |k, v| v.nil? }
30
+ extra_fields = @options.delete_if { |_, v| v.nil? }
33
31
  @transport.send_transaction(data.merge(extra_fields))
34
32
  end
35
33
 
36
34
  # @return [TrueClass, FalseClass]
37
- def is_connected?
38
- @transport.is_connected?
35
+ def connected?
36
+ @transport.connected?
39
37
  end
40
38
 
41
39
  # @param [Symbol, String] event
@@ -43,6 +41,5 @@ module JanusGateway
43
41
  def on(event, &block)
44
42
  @transport.on(event, &block)
45
43
  end
46
-
47
44
  end
48
45
  end
@@ -1,24 +1,18 @@
1
1
  module JanusGateway
2
-
3
2
  class Error < StandardError
3
+ # @return [Integer]
4
+ attr_reader :code
5
+
6
+ # @return [String]
7
+ attr_reader :info
4
8
 
5
9
  # @param [Integer] error_code
6
10
  # @param [String] error_info
7
11
  def initialize(error_code, error_info)
8
- @code, @info = error_code, error_info
12
+ @code = error_code
13
+ @info = error_info
9
14
 
10
15
  super("<Code: #{code}> <Info: #{info}>")
11
16
  end
12
-
13
- # @return [Integer]
14
- def code
15
- @code
16
- end
17
-
18
- # @return [String]
19
- def info
20
- @info
21
- end
22
-
23
17
  end
24
18
  end
@@ -1,12 +1,9 @@
1
1
  module JanusGateway::Plugin
2
-
3
2
  class Rtpbroadcast < JanusGateway::Resource::Plugin
4
-
5
3
  # @param [JanusGateway::Client] client
6
4
  # @param [JanusGateway::Resource::Session] session
7
5
  def initialize(client, session)
8
6
  super(client, session, 'janus.plugin.cm.rtpbroadcast')
9
7
  end
10
-
11
8
  end
12
9
  end
@@ -1,6 +1,10 @@
1
1
  module JanusGateway::Plugin
2
-
3
2
  class Rtpbroadcast::Mountpoint < JanusGateway::Resource
3
+ # @return [JanusGateway::Resource::Plugin]
4
+ attr_reader :plugin
5
+
6
+ # @return [Hash, NilClass]
7
+ attr_reader :data
4
8
 
5
9
  # @param [JanusGateway::Client] client
6
10
  # @param [JanusGateway::Plugin::Rtpbroadcast] plugin
@@ -14,12 +18,12 @@ module JanusGateway::Plugin
14
18
 
15
19
  @streams = streams || [
16
20
  {
17
- :audio => 'yes',
18
- :video => 'yes',
19
- :audiopt => 111,
20
- :audiortpmap => 'opus/48000/2',
21
- :videopt => 100,
22
- :videortpmap => 'VP8/90000'
21
+ audio: 'yes',
22
+ video: 'yes',
23
+ audiopt: 111,
24
+ audiortpmap: 'opus/48000/2',
25
+ videopt: 100,
26
+ videortpmap: 'VP8/90000'
23
27
  }
24
28
  ]
25
29
 
@@ -31,19 +35,17 @@ module JanusGateway::Plugin
31
35
  promise = Concurrent::Promise.new
32
36
 
33
37
  client.send_transaction(
34
- {
35
- :janus => 'message',
36
- :session_id => plugin.session.id,
37
- :handle_id => plugin.id,
38
- :body => {
39
- :request => 'create',
40
- :id => id,
41
- :name => id,
42
- :description => id,
43
- :recorded => true,
44
- :streams => @streams,
45
- :channel_data => @channel_data
46
- }
38
+ janus: 'message',
39
+ session_id: plugin.session.id,
40
+ handle_id: plugin.id,
41
+ body: {
42
+ request: 'create',
43
+ id: id,
44
+ name: id,
45
+ description: id,
46
+ recorded: true,
47
+ streams: @streams,
48
+ channel_data: @channel_data
47
49
  }
48
50
  ).then do |data|
49
51
  plugindata = data['plugindata']['data']
@@ -85,20 +87,10 @@ module JanusGateway::Plugin
85
87
  plugin.session
86
88
  end
87
89
 
88
- # @return [JanusGateway::Resource::Plugin]
89
- def plugin
90
- @plugin
91
- end
92
-
93
- # @return [Hash, NilClass]
94
- def data
95
- @data
96
- end
97
-
98
90
  private
99
91
 
100
92
  def _on_error(error)
101
- self.emit :error, error
93
+ emit :error, error
102
94
  end
103
95
 
104
96
  def _on_created(data)
@@ -108,11 +100,11 @@ module JanusGateway::Plugin
108
100
  destroy
109
101
  end
110
102
 
111
- self.emit :create
103
+ emit :create
112
104
  end
113
105
 
114
106
  def _on_destroyed
115
- self.emit :destroy
107
+ emit :destroy
116
108
  end
117
109
  end
118
110
  end
@@ -1,9 +1,14 @@
1
1
  module JanusGateway
2
-
3
2
  class Resource
4
-
5
3
  include Events::Emitter
6
4
 
5
+ # @return [String, NilClass]
6
+ attr_reader :id
7
+
8
+ # @return [JanusGateway::Client]
9
+ attr_reader :client
10
+
11
+ # @return [String]
7
12
  attr_accessor :id
8
13
 
9
14
  # @param [JanusGateway::Client] client
@@ -13,25 +18,14 @@ module JanusGateway
13
18
  @id = id
14
19
  end
15
20
 
16
- # @return [String, NilClass]
17
- def id
18
- @id
19
- end
20
-
21
- # @return [JanusGateway::Client]
22
- def client
23
- @client
24
- end
25
-
26
21
  # @return [Concurrent::Promise]
27
22
  def create
28
- raise("`#{__method__}` is not implemented for `#{self.class.name}`")
23
+ fail("`#{__method__}` is not implemented for `#{self.class.name}`")
29
24
  end
30
25
 
31
26
  # @return [Concurrent::Promise]
32
27
  def destroy
33
- raise("`#{__method__}` is not implemented for `#{self.class.name}`")
28
+ fail("`#{__method__}` is not implemented for `#{self.class.name}`")
34
29
  end
35
-
36
30
  end
37
31
  end
@@ -1,6 +1,10 @@
1
1
  module JanusGateway
2
-
3
2
  class Resource::Plugin < Resource
3
+ # @return [JanusGateway::Resource::Session]
4
+ attr_reader :session
5
+
6
+ # @return [String]
7
+ attr_reader :name
4
8
 
5
9
  # @param [JanusGateway::Client] client
6
10
  # @param [JanusGateway::Resource::Session] session
@@ -12,21 +16,14 @@ module JanusGateway
12
16
  super(client)
13
17
  end
14
18
 
15
- # @return [String]
16
- def name
17
- @name
18
- end
19
-
20
19
  # @return [Concurrent::Promise]
21
20
  def create
22
21
  promise = Concurrent::Promise.new
23
22
 
24
23
  client.send_transaction(
25
- {
26
- :janus => 'attach',
27
- :plugin => name,
28
- :session_id => @session.id
29
- }
24
+ janus: 'attach',
25
+ plugin: name,
26
+ session_id: @session.id
30
27
  ).then do |*args|
31
28
  _on_created(*args)
32
29
 
@@ -47,26 +44,20 @@ module JanusGateway
47
44
  promise
48
45
  end
49
46
 
50
- # @return [JanusGateway::Resource::Session]
51
- def session
52
- @session
53
- end
54
-
55
47
  private
56
48
 
57
49
  def _on_created(data)
58
50
  @id = data['data']['id']
59
51
 
60
- session.on :destroy do |data|
52
+ session.on :destroy do |_data|
61
53
  destroy
62
54
  end
63
55
 
64
- self.emit :create
56
+ emit :create
65
57
  end
66
58
 
67
59
  def _on_destroyed
68
- self.emit :destroy
60
+ emit :destroy
69
61
  end
70
-
71
62
  end
72
63
  end
@@ -1,7 +1,5 @@
1
1
  module JanusGateway
2
-
3
2
  class Resource::Session < Resource
4
-
5
3
  # @param [JanusGateway::Client] client
6
4
  def initialize(client)
7
5
  @heartbeat_thread = nil
@@ -14,9 +12,7 @@ module JanusGateway
14
12
  promise = Concurrent::Promise.new
15
13
 
16
14
  client.send_transaction(
17
- {
18
- :janus => 'create'
19
- }
15
+ janus: 'create'
20
16
  ).then do |*args|
21
17
  _on_created(*args)
22
18
  heartbeat
@@ -34,11 +30,9 @@ module JanusGateway
34
30
  promise = Concurrent::Promise.new
35
31
 
36
32
  client.send_transaction(
37
- {
38
- :janus => 'destroy',
39
- :session_id => id
40
- }
41
- ).then do |*args|
33
+ janus: 'destroy',
34
+ session_id: id
35
+ ).then do |*_args|
42
36
  _on_destroyed
43
37
 
44
38
  promise.set(self).execute
@@ -55,16 +49,14 @@ module JanusGateway
55
49
 
56
50
  @heartbeat_thread = Thread.new do
57
51
  sleep_time = 5
58
- while true do
52
+ loop do
59
53
  sleep(sleep_time)
60
54
  client.send_transaction(
61
- {
62
- :janus => 'keepalive',
63
- :session_id => id
64
- }
65
- ).then do |*args|
55
+ janus: 'keepalive',
56
+ session_id: id
57
+ ).then do |*_args|
66
58
  sleep_time = 30
67
- end.rescue do |error|
59
+ end.rescue do |_error|
68
60
  sleep_time = 1
69
61
  end
70
62
  end
@@ -77,27 +69,26 @@ module JanusGateway
77
69
  def _on_created(data)
78
70
  @id = data['data']['id']
79
71
 
80
- client.on :message do |data|
81
- if data['janus'] == 'timeout' and data['session_id'] == id
72
+ client.on :message do |message|
73
+ if message['janus'] == 'timeout' && message['session_id'] == id
82
74
  send(:_on_destroyed)
83
75
  end
84
76
  end
85
77
 
86
78
  client.on :close do
87
- self.emit :destroy
79
+ emit :destroy
88
80
  end
89
81
 
90
82
  client.on :error do
91
- self.emit :destroy
83
+ emit :destroy
92
84
  end
93
85
 
94
- self.emit :create
86
+ emit :create
95
87
  end
96
88
 
97
89
  def _on_destroyed
98
90
  @heartbeat_thread.exit unless @heartbeat_thread.nil?
99
- self.emit :destroy
91
+ emit :destroy
100
92
  end
101
-
102
93
  end
103
94
  end
@@ -1,35 +1,33 @@
1
1
  module JanusGateway
2
-
3
2
  class Transport
4
-
5
3
  include Events::Emitter
6
4
 
7
5
  def run
8
- raise("`#{__method__}` is not implemented for `#{self.class.name}`")
6
+ fail("`#{__method__}` is not implemented for `#{self.class.name}`")
9
7
  end
10
8
 
11
9
  def connect
12
- raise("`#{__method__}` is not implemented for `#{self.class.name}`")
10
+ fail("`#{__method__}` is not implemented for `#{self.class.name}`")
13
11
  end
14
12
 
15
13
  def disconnect
16
- raise("`#{__method__}` is not implemented for `#{self.class.name}`")
14
+ fail("`#{__method__}` is not implemented for `#{self.class.name}`")
17
15
  end
18
16
 
19
17
  # @param [Hash] data
20
- def send(data)
21
- raise("`#{__method__}` is not implemented for `#{self.class.name}`")
18
+ def send(_data)
19
+ fail("`#{__method__}` is not implemented for `#{self.class.name}`")
22
20
  end
23
21
 
24
22
  # @param [Hash] data
25
23
  # @return [Concurrent::Promise]
26
- def send_transaction(data)
27
- raise("`#{__method__}` is not implemented for `#{self.class.name}`")
24
+ def send_transaction(_data)
25
+ fail("`#{__method__}` is not implemented for `#{self.class.name}`")
28
26
  end
29
27
 
30
28
  # @return [TrueClass, FalseClass]
31
- def is_connected?
32
- raise("`#{__method__}` is not implemented for `#{self.class.name}`")
29
+ def connected?
30
+ fail("`#{__method__}` is not implemented for `#{self.class.name}`")
33
31
  end
34
32
 
35
33
  # @return [String]
@@ -40,6 +38,5 @@ module JanusGateway
40
38
  end
41
39
  transaction_id
42
40
  end
43
-
44
41
  end
45
42
  end
@@ -2,9 +2,7 @@ require 'eventmachine'
2
2
  require 'faye/websocket'
3
3
 
4
4
  module JanusGateway
5
-
6
5
  class Transport::WebSocket < Transport
7
-
8
6
  attr_reader :transaction_queue
9
7
 
10
8
  # @param [String] url
@@ -13,23 +11,23 @@ module JanusGateway
13
11
  @url = url
14
12
  @protocol = protocol
15
13
  @client = nil
16
- @transaction_queue = Hash.new
14
+ @transaction_queue = {}
17
15
  end
18
16
 
19
17
  def run
20
18
  EventMachine.run do
21
- EM.error_handler { |e| raise(e) }
19
+ EM.error_handler { |e| fail(e) }
22
20
  connect
23
21
  end
24
22
  end
25
23
 
26
24
  def connect
27
- raise('WebSocket client already exists!') unless @client.nil?
25
+ fail('WebSocket client already exists!') unless @client.nil?
28
26
 
29
27
  @client = _create_client(@url, @protocol)
30
28
 
31
29
  client.on :open do
32
- self.emit :open
30
+ emit :open
33
31
  end
34
32
 
35
33
  client.on :message do |event|
@@ -41,7 +39,7 @@ module JanusGateway
41
39
  unless transaction_id.nil?
42
40
  promise = transaction_list[transaction_id]
43
41
  unless promise.nil?
44
- if ['success', 'ack'].include?(data['janus'])
42
+ if %w(success ack).include?(data['janus'])
45
43
  promise.set(data).execute
46
44
  else
47
45
  error_data = data['error']
@@ -51,11 +49,11 @@ module JanusGateway
51
49
  end
52
50
  end
53
51
 
54
- self.emit :message, data
52
+ emit :message, data
55
53
  end
56
54
 
57
55
  client.on :close do
58
- self.emit :close
56
+ emit :close
59
57
  end
60
58
  end
61
59
 
@@ -81,8 +79,14 @@ module JanusGateway
81
79
  promise.fail(error).execute
82
80
  end
83
81
 
84
- promise.then { @transaction_queue.remove(transaction); thread.exit }
85
- promise.rescue { @transaction_queue.remove(transaction); thread.exit }
82
+ promise.then do
83
+ @transaction_queue.remove(transaction)
84
+ thread.exit
85
+ end
86
+ promise.rescue do
87
+ @transaction_queue.remove(transaction)
88
+ thread.exit
89
+ end
86
90
 
87
91
  promise
88
92
  end
@@ -92,14 +96,12 @@ module JanusGateway
92
96
  end
93
97
 
94
98
  # @return [TrueClass, FalseClass]
95
- def is_connected?
96
- !client.nil? and (client.ready_state == Faye::WebSocket::API::OPEN)
99
+ def connected?
100
+ !client.nil? && (client.ready_state == Faye::WebSocket::API::OPEN)
97
101
  end
98
102
 
99
103
  # @return [Faye::WebSocket::Client, NilClass]
100
- def client
101
- @client
102
- end
104
+ attr_reader :client
103
105
 
104
106
  private
105
107
 
@@ -114,7 +116,5 @@ module JanusGateway
114
116
  def _transaction_timeout
115
117
  30
116
118
  end
117
-
118
119
  end
119
-
120
120
  end
@@ -1,3 +1,3 @@
1
1
  module JanusGateway
2
- VERSION = '0.0.6'
2
+ VERSION = '0.0.7'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: janus_gateway
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cargo Media
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2015-11-29 00:00:00.000000000 Z
14
+ date: 2015-12-06 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: faye-websocket
@@ -97,6 +97,20 @@ dependencies:
97
97
  - - "~>"
98
98
  - !ruby/object:Gem::Version
99
99
  version: '2.0'
100
+ - !ruby/object:Gem::Dependency
101
+ name: rubocop
102
+ requirement: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - "~>"
105
+ - !ruby/object:Gem::Version
106
+ version: '0.35'
107
+ type: :development
108
+ prerelease: false
109
+ version_requirements: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - "~>"
112
+ - !ruby/object:Gem::Version
113
+ version: '0.35'
100
114
  description: janus-gateway API client
101
115
  email: tech@cargomedia.ch
102
116
  executables: []
@@ -136,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
150
  version: '0'
137
151
  requirements: []
138
152
  rubyforge_project:
139
- rubygems_version: 2.5.0
153
+ rubygems_version: 2.4.8
140
154
  signing_key:
141
155
  specification_version: 4
142
156
  summary: janus-gateway client