Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ end

## Usage

Make API calls to Jellyfish:
Make API calls to Jellyfish (authentication required, for more information see [Jellyfish docs](https://jellyfish-dev.github.io/jellyfish-docs/getting_started/authentication)):

```elixir
client = Jellyfish.Client.new("http://address-of-your-server.com")
client = Jellyfish.Client.new("http://address-of-your-server.com", "your-jellyfish-token")

# Create room
{:ok, %Jellyfish.Room{id: room_id}} = Jellyfish.Room.create(client, max_peers: 10)
Expand All @@ -36,7 +36,7 @@ room_id
# => "8878cd13-99a6-40d6-8d7e-8da23d803dab"

# Add peer
{:ok, %Jellyfish.Peer{id: peer_id}, token} = Jellyfish.Room.add_peer(client, room_id, "webrtc")
{:ok, %Jellyfish.Peer{id: peer_id}, peer_token} = Jellyfish.Room.add_peer(client, room_id, "webrtc")

# Delete peer
:ok = Jellyfish.Room.delete_peer(client, room_id, peer_id)
Expand Down
25 changes: 23 additions & 2 deletions lib/jellyfish/client.ex
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ defmodule Jellyfish.Client do
}

@doc """
Creates new instance of `t:Jellyfish.SDK.Client.t/0`.
Creates new instance of `t:Jellyfish.Client.t/0`.

## Parameters

Expand All @@ -36,7 +36,28 @@ defmodule Jellyfish.Client do
token as the one configured in Jellyfish.
"""
@spec new(String.t(), String.t()) :: t()
def new(address, token) do
def new(address, token), do: build_client(address, token)

@doc """
Creates new instance of `t:Jellyfish.Client.t/0`.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JFYI, you can also write t:t/0 but the result will be slighlity different


Uses token set in `config.exs`. To explicitly pass the token, see `new/2`.
```
# in config.exs
config :jellyfish_server_sdk, token: "your-jellyfish-token"

client = Jellyfish.Client.new("http://address-of-your-server.com")
```

See `new/2` for description of parameters.
"""
@spec new(String.t()) :: t()
def new(address) do
token = Application.fetch_env!(:jellyfish_server_sdk, :token)
build_client(address, token)
end

defp build_client(address, token) do
middleware = [
{Tesla.Middleware.BaseUrl, address},
{Tesla.Middleware.BearerAuth, token: token},
Expand Down
3 changes: 1 addition & 2 deletions lib/jellyfish/component.ex
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@ defmodule Jellyfish.Component do
"""
@type type :: String.t()

# TODO update to proper link when it's done
@typedoc """
Type describing component options.
For the list of available options, please refer to the [component's documentation](https://jellyfish-dev.github.io/jellyfish-docs/).
For the list of available options, please refer to the [documentation](https://jellyfish-dev.github.io/jellyfish-docs/).
"""
@type options :: Keyword.t()

Expand Down
8 changes: 7 additions & 1 deletion lib/jellyfish/room.ex
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ defmodule Jellyfish.Room do
"""
@type id :: String.t()

@typedoc """
Client token, created by Jellyfish. Required by client application to open connection to Jellyfish.
"""
@type peer_token :: String.t()

@typedoc """
Type describing room options.

Expand Down Expand Up @@ -122,7 +127,8 @@ defmodule Jellyfish.Room do
@doc """
Add a peer to the room with `room_id`.
"""
@spec add_peer(Client.t(), id(), Peer.type()) :: {:ok, Peer.t()} | {:error, atom() | String.t()}
@spec add_peer(Client.t(), id(), Peer.type()) ::
{:ok, Peer.t(), peer_token()} | {:error, atom() | String.t()}
def add_peer(client, room_id, type) do
with {:ok, %Env{status: 201, body: body}} <-
Tesla.post(
Expand Down