janus_gateway 0.0.9 → 0.0.10

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: 908b95a165885d274c18d8ccbcab220393b96305
4
- data.tar.gz: 4eb82b5358b9c5002364f6ac18ba00cf313487d9
3
+ metadata.gz: 3efb7f20974406b25284ea454c139c0e06628fd7
4
+ data.tar.gz: aea8862680a1ca5480b40f1aeac051da14b4a9a2
5
5
  SHA512:
6
- metadata.gz: aea42c50429f18371bdf1ee186c8f11165d7815e5689fa8a8acbf805c8bc3ff0815285fe6eb0091627bd1c2907cfe0f937bc01e714a0eb53fc206862b7d21550
7
- data.tar.gz: ffac69f51a3f8f3a7571145330540c4460b2b994b508fff584ffe7acffd0fb64ada7b6748bcb73eb42032aceced8231e97922ca2235e7e050fc347b9110193ed
6
+ metadata.gz: 0b664bcedb7a01197fb759b2063d98a28ebe482b84b90f61acabf8509b28ba9336d890e4efec1117fb0632eb1210f9dce98711af7cb16ea9c6e2097b1ae158f6
7
+ data.tar.gz: fdce0287abdbcee990bd803de044823efb7e6ec7097b89e4ac0550775e4ef0363adc5a376e11d54bc1007ce71adb929c00e265ec9b240621b633acb94f017b8f
data/README.md CHANGED
@@ -100,8 +100,11 @@ Plugin must be installed and active in `Janus` server.
100
100
 
101
101
  Plugin resource supports `events` and `chaining` in the same way like `Janus` resource.
102
102
 
103
+ #### List
104
+ Endpoint allows to retrieve the list of current mountpoints.
105
+
103
106
  ##### Mountpoint create
104
- Plugins allows to create `RTP` mountpoint.
107
+ Endpoint allows to create `RTP` mountpoint.
105
108
 
106
109
  ```ruby
107
110
  ws = JanusGateway::Transport::WebSocket.new('ws://localhost:8188/janus')
@@ -119,3 +122,12 @@ end
119
122
 
120
123
  client.run
121
124
  ```
125
+
126
+ #### Audioroom plugin
127
+ This is custom plugin for `audio` bridging. Please find more details in official [repository](https://github.com/cargomedia/janus-gateway-audioroom).
128
+ Plugin must be installed and active in `Janus` server.
129
+
130
+ Plugin resource supports `events` and `chaining` in the same way like `Janus` resource.
131
+
132
+ ##### List
133
+ Endpoint allows to retrieve the list of current audio rooms.
data/lib/janus_gateway.rb CHANGED
@@ -11,10 +11,13 @@ module JanusGateway
11
11
  require 'janus_gateway/resource/session'
12
12
  require 'janus_gateway/resource/plugin'
13
13
 
14
+ require 'janus_gateway/transport/http'
14
15
  require 'janus_gateway/transport/websocket'
15
16
 
16
17
  require 'janus_gateway/plugin/rtpbroadcast'
17
18
  require 'janus_gateway/plugin/rtpbroadcast/mountpoint'
18
19
 
20
+ require 'janus_gateway/plugin/audioroom'
21
+
19
22
  require 'janus_gateway/version'
20
23
  end
@@ -0,0 +1,50 @@
1
+ module JanusGateway::Plugin
2
+ class Audioroom < JanusGateway::Resource::Plugin
3
+ # @param [JanusGateway::Client] client
4
+ # @param [JanusGateway::Resource::Session] session
5
+ def initialize(client, session)
6
+ super(client, session, 'janus.plugin.cm.audioroom')
7
+ end
8
+
9
+ # @return [Concurrent::Promise]
10
+ def list
11
+ promise = Concurrent::Promise.new
12
+
13
+ client.send_transaction(
14
+ janus: 'message',
15
+ session_id: session.id,
16
+ handle_id: id,
17
+ body: { request: 'list' }
18
+ ).then do |data|
19
+ plugindata = data['plugindata']['data']
20
+ if plugindata['error_code'].nil?
21
+ _on_success(data)
22
+
23
+ promise.set(data).execute
24
+ else
25
+ error = JanusGateway::Error.new(plugindata['error_code'], plugindata['error'])
26
+
27
+ _on_error(error)
28
+
29
+ promise.fail(error).execute
30
+ end
31
+ end.rescue do |error|
32
+ promise.fail(error).execute
33
+ end
34
+
35
+ promise
36
+ end
37
+
38
+ private
39
+
40
+ def _on_success(data)
41
+ @data = data['plugindata']
42
+
43
+ emit :success
44
+ end
45
+
46
+ def _on_error(error)
47
+ emit :error, error
48
+ end
49
+ end
50
+ end
@@ -5,5 +5,46 @@ module JanusGateway::Plugin
5
5
  def initialize(client, session)
6
6
  super(client, session, 'janus.plugin.cm.rtpbroadcast')
7
7
  end
8
+
9
+ # @return [Concurrent::Promise]
10
+ def list
11
+ promise = Concurrent::Promise.new
12
+
13
+ client.send_transaction(
14
+ janus: 'message',
15
+ session_id: session.id,
16
+ handle_id: id,
17
+ body: { request: 'list' }
18
+ ).then do |data|
19
+ plugindata = data['plugindata']['data']
20
+ if plugindata['error_code'].nil?
21
+ _on_success(data)
22
+
23
+ promise.set(data).execute
24
+ else
25
+ error = JanusGateway::Error.new(plugindata['error_code'], plugindata['error'])
26
+
27
+ _on_error(error)
28
+
29
+ promise.fail(error).execute
30
+ end
31
+ end.rescue do |error|
32
+ promise.fail(error).execute
33
+ end
34
+
35
+ promise
36
+ end
37
+
38
+ private
39
+
40
+ def _on_success(data)
41
+ @data = data['plugindata']
42
+
43
+ emit :success
44
+ end
45
+
46
+ def _on_error(error)
47
+ emit :error, error
48
+ end
8
49
  end
9
50
  end
@@ -0,0 +1,123 @@
1
+ require 'eventmachine'
2
+ require 'em-http-request'
3
+
4
+ module JanusGateway
5
+ class Transport::Http < Transport
6
+ attr_reader :transaction_queue
7
+
8
+ # @param [String] url
9
+ def initialize(url)
10
+ @url = url
11
+ @transaction_queue = {}
12
+ end
13
+
14
+ def run
15
+ EventMachine.run do
16
+ EM.error_handler { |e| fail(e) }
17
+ # will be used for long-pooling. currently does nothing
18
+ end
19
+ end
20
+
21
+ # @param [Hash] data
22
+ def send(data)
23
+ sender = _send(data)
24
+
25
+ sender.then do |response|
26
+ response_transaction_id = response['transaction']
27
+
28
+ transaction_list = @transaction_queue.clone
29
+ unless response_transaction_id.nil?
30
+ promise = transaction_list[response_transaction_id]
31
+ unless promise.nil?
32
+ if %w(success).include?(response['janus'])
33
+ promise.set(response).execute
34
+ elsif %w(ack event).include?(response['janus'])
35
+ # do nothing for now
36
+ else
37
+ error_data = response['error']
38
+ error = JanusGateway::Error.new(error_data['code'], error_data['reason'])
39
+ promise.fail(error).execute
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+ sender.rescue do |error|
46
+ request_transaction_id = data[:transaction]
47
+
48
+ transaction_list = @transaction_queue.clone
49
+ unless request_transaction_id.nil?
50
+ promise = transaction_list[request_transaction_id]
51
+ unless promise.nil?
52
+ error = JanusGateway::Error.new(0, "HTTP/Transport response: `#{error}`")
53
+ promise.fail(error).execute
54
+ end
55
+ end
56
+ end
57
+ end
58
+
59
+ # @param [Hash] data
60
+ # @return [Concurrent::Promise]
61
+ def send_transaction(data)
62
+ promise = Concurrent::Promise.new
63
+ transaction = transaction_id_new
64
+
65
+ data[:transaction] = transaction
66
+
67
+ @transaction_queue[transaction] = promise
68
+ send(data)
69
+
70
+ thread = Thread.new do
71
+ sleep(_transaction_timeout)
72
+ error = JanusGateway::Error.new(0, "Transaction id `#{transaction}` has failed due to timeout!")
73
+ promise.fail(error).execute
74
+ end
75
+
76
+ promise.then do
77
+ @transaction_queue.remove(transaction)
78
+ thread.exit
79
+ end
80
+ promise.rescue do
81
+ @transaction_queue.remove(transaction)
82
+ thread.exit
83
+ end
84
+
85
+ promise
86
+ end
87
+
88
+ private
89
+
90
+ # @param [Hash] data
91
+ # @return [EventMachine::HttpRequest]
92
+ def _send(data)
93
+ promise = Concurrent::Promise.new
94
+
95
+ http = EventMachine::HttpRequest.new(@url)
96
+ request = http.post(body: JSON.generate(data), head: { 'Content-Type' => 'application/json' })
97
+
98
+ request.callback do
99
+ status = request.response_header.status
100
+ if status == 200
101
+ begin
102
+ promise.set(JSON.parse(request.response)).execute
103
+ rescue StandardError => e
104
+ promise.fail(e).execute
105
+ end
106
+ else
107
+ promise.fail(Error.new(status, "Invalid response. Status: `#{status}`. Body: `#{request.response}`")).execute
108
+ end
109
+ end
110
+
111
+ request.errback do
112
+ promise.fail(request.error).execute
113
+ end
114
+
115
+ promise
116
+ end
117
+
118
+ # @return [Float, Integer]
119
+ def _transaction_timeout
120
+ 30
121
+ end
122
+ end
123
+ end
@@ -1,3 +1,3 @@
1
1
  module JanusGateway
2
- VERSION = '0.0.9'
2
+ VERSION = '0.0.10'.freeze
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.9
4
+ version: 0.0.10
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: 2016-01-11 00:00:00.000000000 Z
14
+ date: 2016-01-21 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: faye-websocket
@@ -69,6 +69,20 @@ dependencies:
69
69
  - - "~>"
70
70
  - !ruby/object:Gem::Version
71
71
  version: 1.0.0
72
+ - !ruby/object:Gem::Dependency
73
+ name: em-http-request
74
+ requirement: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - "~>"
77
+ - !ruby/object:Gem::Version
78
+ version: 1.1.3
79
+ type: :runtime
80
+ prerelease: false
81
+ version_requirements: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - "~>"
84
+ - !ruby/object:Gem::Version
85
+ version: 1.1.3
72
86
  - !ruby/object:Gem::Dependency
73
87
  name: rake
74
88
  requirement: !ruby/object:Gem::Requirement
@@ -111,6 +125,26 @@ dependencies:
111
125
  - - "~>"
112
126
  - !ruby/object:Gem::Version
113
127
  version: '0.35'
128
+ - !ruby/object:Gem::Dependency
129
+ name: webmock
130
+ requirement: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - "~>"
133
+ - !ruby/object:Gem::Version
134
+ version: '1.22'
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: 1.22.6
138
+ type: :development
139
+ prerelease: false
140
+ version_requirements: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - "~>"
143
+ - !ruby/object:Gem::Version
144
+ version: '1.22'
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ version: 1.22.6
114
148
  description: janus-gateway API client
115
149
  email: tech@cargomedia.ch
116
150
  executables: []
@@ -122,12 +156,14 @@ files:
122
156
  - lib/janus_gateway.rb
123
157
  - lib/janus_gateway/client.rb
124
158
  - lib/janus_gateway/error.rb
159
+ - lib/janus_gateway/plugin/audioroom.rb
125
160
  - lib/janus_gateway/plugin/rtpbroadcast.rb
126
161
  - lib/janus_gateway/plugin/rtpbroadcast/mountpoint.rb
127
162
  - lib/janus_gateway/resource.rb
128
163
  - lib/janus_gateway/resource/plugin.rb
129
164
  - lib/janus_gateway/resource/session.rb
130
165
  - lib/janus_gateway/transport.rb
166
+ - lib/janus_gateway/transport/http.rb
131
167
  - lib/janus_gateway/transport/websocket.rb
132
168
  - lib/janus_gateway/version.rb
133
169
  homepage: https://github.com/cargomedia/janus-gateway-ruby