Authentication
The Authentication mechanism is based on a bearer token. How does it work? Both Jellyfish and Business Logic are configured with the same secret. This secret is used for authorizing HTTP requests between them (via HTTP authorization request header). When a new client wants to join a room, Business Logic (assuming the client is authorized to join) requests adding a new peer and receives a token generated by Jellyfish. The token must then be passed to the client, that will use it to connect to the room as a new peer. The token encodes both peer and room IDs. The token exchange is handled by our Client SDKs when connecting. Under the hood, Jellyfish expects the token in the first message after opening the Web Socket connection.
Token encodes peer id and room id.
- Run Jellyfish
JF_SERVER_API_TOKEN=JF_SERVER_API_TOKEN mix phx.server
- Create a room and add one peer
client = Jellyfish.Client.new("http://address-of-your-server.com", "JF_SERVER_API_TOKEN")
{:ok, room, _jellyfish_address} = Jellyfish.Room.create(client, max_peers: 10)
{:ok, peer, peer_token} = Jellyfish.Room.add_peer(client, room.id, "BobId")
- Connect as a peer to Jellyfish
client.connect({
token: peerToken,
peerMetadata: { name: "Bob" },
isSimulcastOn: false
})