1. Install Livekit Server SDK
Add this line to your application's Gemfile:
gem 'livekit-server-sdk'
Then run bundle install
.
2. Keys and Configuration
Create a new file at development.env
and with your API Key and Secret:
export LIVEKIT_API_KEY=<API Key>export LIVEKIT_API_SECRET=<API Secret hidden>
3. Make an endpoint that returns a token
Create a server that returns a token for a participant to join a room:
require 'livekit'require 'sinatra'def createTokentoken = LiveKit::AccessToken.new(api_key: 'yourkey', api_secret: 'yoursecret')token.identity = 'quickstart-identity'token.name = 'quickstart-name'token.add_grant(roomJoin: true, room: 'room-name')token.to_jwtendget '/getToken' docreateTokenend
Run the server:
$ source development.env$ ruby server.rb
4. Create a client app to connect
Create a client app that fetches a token from the server you just made, then uses it to connect to a LiveKit room: