openvidu-basic-ruby
This commit is contained in:
parent
7e05804a80
commit
ccb1838bb3
56
openvidu-basic-ruby/.gitignore
vendored
Normal file
56
openvidu-basic-ruby/.gitignore
vendored
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
*.gem
|
||||||
|
*.rbc
|
||||||
|
/.config
|
||||||
|
/coverage/
|
||||||
|
/InstalledFiles
|
||||||
|
/pkg/
|
||||||
|
/spec/reports/
|
||||||
|
/spec/examples.txt
|
||||||
|
/test/tmp/
|
||||||
|
/test/version_tmp/
|
||||||
|
/tmp/
|
||||||
|
|
||||||
|
# Used by dotenv library to load environment variables.
|
||||||
|
# .env
|
||||||
|
|
||||||
|
# Ignore Byebug command history file.
|
||||||
|
.byebug_history
|
||||||
|
|
||||||
|
## Specific to RubyMotion:
|
||||||
|
.dat*
|
||||||
|
.repl_history
|
||||||
|
build/
|
||||||
|
*.bridgesupport
|
||||||
|
build-iPhoneOS/
|
||||||
|
build-iPhoneSimulator/
|
||||||
|
|
||||||
|
## Specific to RubyMotion (use of CocoaPods):
|
||||||
|
#
|
||||||
|
# We recommend against adding the Pods directory to your .gitignore. However
|
||||||
|
# you should judge for yourself, the pros and cons are mentioned at:
|
||||||
|
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
||||||
|
#
|
||||||
|
# vendor/Pods/
|
||||||
|
|
||||||
|
## Documentation cache and generated files:
|
||||||
|
/.yardoc/
|
||||||
|
/_yardoc/
|
||||||
|
/doc/
|
||||||
|
/rdoc/
|
||||||
|
|
||||||
|
## Environment normalization:
|
||||||
|
/.bundle/
|
||||||
|
/vendor/bundle
|
||||||
|
/lib/bundler/man/
|
||||||
|
|
||||||
|
# for a library or gem, you might want to ignore these files since the code is
|
||||||
|
# intended to run in multiple environments; otherwise, check them in:
|
||||||
|
# Gemfile.lock
|
||||||
|
# .ruby-version
|
||||||
|
# .ruby-gemset
|
||||||
|
|
||||||
|
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
||||||
|
.rvmrc
|
||||||
|
|
||||||
|
# Used by RuboCop. Remote config files pulled in from inherit_from directive.
|
||||||
|
# .rubocop-https?--*
|
||||||
6
openvidu-basic-ruby/Gemfile
Normal file
6
openvidu-basic-ruby/Gemfile
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
source 'https://rubygems.org'
|
||||||
|
|
||||||
|
gem 'sinatra'
|
||||||
|
gem 'sinatra-cors'
|
||||||
|
gem 'faraday'
|
||||||
|
gem 'json'
|
||||||
33
openvidu-basic-ruby/Gemfile.lock
Normal file
33
openvidu-basic-ruby/Gemfile.lock
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
GEM
|
||||||
|
remote: https://rubygems.org/
|
||||||
|
specs:
|
||||||
|
faraday (2.7.4)
|
||||||
|
faraday-net_http (>= 2.0, < 3.1)
|
||||||
|
ruby2_keywords (>= 0.0.4)
|
||||||
|
faraday-net_http (3.0.2)
|
||||||
|
json (2.6.3)
|
||||||
|
mustermann (3.0.0)
|
||||||
|
ruby2_keywords (~> 0.0.1)
|
||||||
|
rack (2.2.6.4)
|
||||||
|
rack-protection (3.0.5)
|
||||||
|
rack
|
||||||
|
ruby2_keywords (0.0.5)
|
||||||
|
sinatra (3.0.5)
|
||||||
|
mustermann (~> 3.0)
|
||||||
|
rack (~> 2.2, >= 2.2.4)
|
||||||
|
rack-protection (= 3.0.5)
|
||||||
|
tilt (~> 2.0)
|
||||||
|
sinatra-cors (1.2.0)
|
||||||
|
tilt (2.1.0)
|
||||||
|
|
||||||
|
PLATFORMS
|
||||||
|
x86_64-linux
|
||||||
|
|
||||||
|
DEPENDENCIES
|
||||||
|
faraday
|
||||||
|
json
|
||||||
|
sinatra
|
||||||
|
sinatra-cors
|
||||||
|
|
||||||
|
BUNDLED WITH
|
||||||
|
2.4.10
|
||||||
@ -1,3 +1,28 @@
|
|||||||
# openvidu-basic-ruby
|
# openvidu-basic-ruby
|
||||||
|
|
||||||
Coming soon...
|
This is a minimal OpenVidu server application sample built for Ruby with [Sinatra](https://sinatrarb.com/) and [Faraday](https://lostisland.github.io/faraday/). Visit [Application server](https://docs.openvidu.io/en/stable/application-server/) documentation for further context.
|
||||||
|
|
||||||
|
## Prerequisites
|
||||||
|
|
||||||
|
- [Ruby](https://www.ruby-lang.org/en/downloads/)
|
||||||
|
|
||||||
|
## Run
|
||||||
|
|
||||||
|
Download repository
|
||||||
|
|
||||||
|
```
|
||||||
|
git clone git@github.com:OpenVidu/openvidu-tutorials.git
|
||||||
|
cd openvidu-tutorials/openvidu-basic-ruby
|
||||||
|
```
|
||||||
|
|
||||||
|
Install gems
|
||||||
|
|
||||||
|
```
|
||||||
|
bundle install
|
||||||
|
```
|
||||||
|
|
||||||
|
Run the application
|
||||||
|
|
||||||
|
```
|
||||||
|
ruby app.rb
|
||||||
|
```
|
||||||
64
openvidu-basic-ruby/app.rb
Normal file
64
openvidu-basic-ruby/app.rb
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
#!/usr/bin/ruby
|
||||||
|
|
||||||
|
require 'sinatra'
|
||||||
|
require 'sinatra/cors'
|
||||||
|
require 'faraday'
|
||||||
|
require 'json'
|
||||||
|
require './env.rb'
|
||||||
|
|
||||||
|
# Load env variables
|
||||||
|
SERVER_PORT = ENV['SERVER_PORT']
|
||||||
|
OPENVIDU_URL = ENV['OPENVIDU_URL']
|
||||||
|
OPENVIDU_SECRET = ENV['OPENVIDU_SECRET']
|
||||||
|
|
||||||
|
set :port, SERVER_PORT
|
||||||
|
|
||||||
|
register Sinatra::Cors
|
||||||
|
set :allow_origin, "*"
|
||||||
|
set :allow_methods, "POST,OPTIONS"
|
||||||
|
set :allow_headers, "content-type"
|
||||||
|
|
||||||
|
post '/api/sessions' do
|
||||||
|
begin
|
||||||
|
body = request.body.read
|
||||||
|
response = Faraday.post do |req|
|
||||||
|
req.url "#{OPENVIDU_URL}openvidu/api/sessions"
|
||||||
|
req.headers['Content-Type'] = 'application/json'
|
||||||
|
req.headers['Authorization'] = "Basic #{Base64.encode64("OPENVIDUAPP:#{OPENVIDU_SECRET}").strip}"
|
||||||
|
req.body = body
|
||||||
|
end
|
||||||
|
if response.success?
|
||||||
|
(JSON.parse response.body)['sessionId']
|
||||||
|
else
|
||||||
|
if response.status == 409
|
||||||
|
# Session already exists in OpenVidu
|
||||||
|
(JSON.parse body)['customSessionId']
|
||||||
|
else
|
||||||
|
status response.status
|
||||||
|
body response.body
|
||||||
|
end
|
||||||
|
end
|
||||||
|
rescue Faraday::Error => err
|
||||||
|
err.response
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
post '/api/sessions/:sessionId/connections' do
|
||||||
|
begin
|
||||||
|
body = request.body.read
|
||||||
|
response = Faraday.post do |req|
|
||||||
|
req.url "#{OPENVIDU_URL}openvidu/api/sessions/#{params['sessionId']}/connection"
|
||||||
|
req.headers['Content-Type'] = 'application/json'
|
||||||
|
req.headers['Authorization'] = "Basic #{Base64.encode64("OPENVIDUAPP:#{OPENVIDU_SECRET}").strip}"
|
||||||
|
req.body = body
|
||||||
|
end
|
||||||
|
if response.success?
|
||||||
|
(JSON.parse response.body)['token']
|
||||||
|
else
|
||||||
|
status response.status
|
||||||
|
body response.body
|
||||||
|
end
|
||||||
|
rescue Faraday::Error => err
|
||||||
|
err.response
|
||||||
|
end
|
||||||
|
end
|
||||||
3
openvidu-basic-ruby/env.rb
Normal file
3
openvidu-basic-ruby/env.rb
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
ENV['SERVER_PORT'] = '5000'
|
||||||
|
ENV['OPENVIDU_URL'] = 'http://localhost:4443/'
|
||||||
|
ENV['OPENVIDU_SECRET'] = 'MY_SECRET'
|
||||||
Loading…
x
Reference in New Issue
Block a user