This project is not maintained anymore. If you want to take over contact us at tech@cargomedia.ch.
Minimalistic client for the Janus WebRTC gateway.
gem install janus_gateway
Current implementation support only a few of API features. For more details please follow official documentation of REST API
Source code itself is well-documented so when writing code it should auto-complete and hint in all supported usages.
In order to make any request you need to instantiate client with correct transport layer (see transport section).
ws = JanusGateway::Transport::WebSocket.new('ws://localhost:8188/janus')
client = JanusGateway::Client.new(ws)
The client's connect
method should be called in an EventMachine context, for events to be emitted etc.
You can call the run
method to start an EventMachine (which will block the execution of the program):
ws = JanusGateway::Transport::WebSocket.new('ws://localhost:8188/janus')
client = JanusGateway::Client.new(ws)
client.on(:open) do
# We can start sending commands to the server now
end
client.run
Refer to the Examples section for a complete example of connecting to a server.
Client allows to use multiple, supported by Janus transportation layers. Currently the WebSocket
transport is implemented and is the default.
ws = JanusGateway::Transport::WebSocket.new('ws://localhost:8188/janus')
Each resource has built-in event emitter to handle basic behaviours like create
and destroy
. Additionally the creation of resources can be chained.
There are two types of resources: Janus-API resource and Plugin-API (please see Plugin section).
You can bind on events:
session = JanusGateway::Resource::Session.new(client)
session.on :create do
# do something
end
session.on :destroy do
# do something
end
session.create
Resource creation and destroying are asynchronous operations which return a Concurrent::Promise
:
session = JanusGateway::Resource::Session.new(client)
session.create.then do |session|
# do something with success
end.rescue do |error|
# do something with error
end
Create new session:
session = JanusGateway::Resource::Session.new(client)
session.create
Destroy a session:
session.destroy
Create new plugin:
plugin = JanusGateway::Resource::Plugin.new(client, session, 'plugin-name')
plugin.create
Destroy a plugin:
plugin.destroy
Janus support for native and custom plugins.
This is custom plugin for RTP
streaming. Please find more details in official repository.
Plugin must be installed and active in Janus
server.
Plugin resource supports events
and chaining
in the same way like Janus
resource.
Endpoint allows to retrieve the list of current mountpoints.
Endpoint allows to create RTP
mountpoint.
ws = JanusGateway::Transport::WebSocket.new('ws://localhost:8188/janus')
client = JanusGateway::Client.new(ws)
client.on :open do
JanusGateway::Resource::Session.new(client).create.then do |session|
JanusGateway::Plugin::Rtpbroadcast.new(client, session).create.then do |plugin|
JanusGateway::Plugin::Rtpbroadcast::Mountpoint.new(client, plugin, 'test-mountpoint').create.then do |mountpoint|
# do something with mountpoint
end
end
end
end
client.run
This is custom plugin for audio
bridging. Please find more details in official repository.
Plugin must be installed and active in Janus
server.
Plugin resource supports events
and chaining
in the same way like Janus
resource.
Endpoint allows to retrieve the list of current audio rooms.
Connect to the server using the WebSocket transport and create a session:
ws = JanusGateway::Transport::WebSocket.new('ws://localhost:8188/janus')
client = JanusGateway::Client.new(ws)
client.on(:open) { puts 'client connected' }
client.on(:close) { puts 'client disconnected' }
client.on(:open) do
session = JanusGateway::Resource::Session.new(client)
session.on(:create) { puts 'session created' }
session.on(:destroy) { puts 'session destroyed' }
session.create
end
client.run
Install dependencies:
bundle install
Run tests:
bundle exec rspec
Release a new version:
- Bump the version in
lib/janus_gateway/version.rb
, merge to master. - Push a new tag to master.
- Release to RubyGems with
bundle exec rake release
.