diff --git a/README.md b/README.md index 8daa959..e4bd1cf 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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) diff --git a/lib/jellyfish/client.ex b/lib/jellyfish/client.ex index b3f4182..71ea351 100644 --- a/lib/jellyfish/client.ex +++ b/lib/jellyfish/client.ex @@ -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 @@ -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`. + + 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}, diff --git a/lib/jellyfish/component.ex b/lib/jellyfish/component.ex index 21ca3ce..ed1d1bf 100644 --- a/lib/jellyfish/component.ex +++ b/lib/jellyfish/component.ex @@ -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() diff --git a/lib/jellyfish/room.ex b/lib/jellyfish/room.ex index 25263f8..f44137e 100644 --- a/lib/jellyfish/room.ex +++ b/lib/jellyfish/room.ex @@ -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. @@ -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(