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
18 changes: 9 additions & 9 deletions lib/jellyfish/client.ex
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,24 @@ defmodule Jellyfish.Client do
}

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

## Parameters

* `address` - url or IP address of the Jellyfish server instance
* `token` - token used for authorizing HTTP requests. It's the same
* `server_api_token` - token used for authorizing HTTP requests. It's the same
token as the one configured in Jellyfish.
"""
@spec new(String.t(), String.t()) :: t()
def new(address, token), do: build_client(address, token)
def new(address, server_api_token), do: build_client(address, server_api_token)

@doc """
Creates new instance of `t:Jellyfish.Client.t/0`.
Creates a 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"
config :jellyfish_server_sdk, server_api_token: "your-jellyfish-token"

client = Jellyfish.Client.new("http://address-of-your-server.com")
```
Expand All @@ -53,14 +53,14 @@ defmodule Jellyfish.Client do
"""
@spec new(String.t()) :: t()
def new(address) do
token = Application.fetch_env!(:jellyfish_server_sdk, :token)
build_client(address, token)
server_api_token = Application.fetch_env!(:jellyfish_server_sdk, :server_api_token)
build_client(address, server_api_token)
end

defp build_client(address, token) do
defp build_client(address, server_api_token) do
middleware = [
{Tesla.Middleware.BaseUrl, address},
{Tesla.Middleware.BearerAuth, token: token},
{Tesla.Middleware.BearerAuth, token: server_api_token},
Tesla.Middleware.JSON
]

Expand Down
4 changes: 2 additions & 2 deletions lib/jellyfish/room.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ defmodule Jellyfish.Room do
peers: []
}}

iex> {:ok, peer, token} = Jellyfish.Room.add_peer(client, room.id, "webrtc")
iex> {:ok, peer, peer_token} = Jellyfish.Room.add_peer(client, room.id, "webrtc")
{:ok,
%Jellyfish.Peer{id: "5a731f2e-f49f-4d58-8f64-16a5c09b520e", type: "webrtc"},
"3LTQ3ZDEtYTRjNy0yZDQyZjU1MDAxY2FkAAdyb29tX2lkbQAAACQ0M"}
Expand Down Expand Up @@ -41,7 +41,7 @@ defmodule Jellyfish.Room do
@type id :: String.t()

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

Expand Down
6 changes: 3 additions & 3 deletions test/jellyfish/client_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ defmodule Jellyfish.ClientTest do

describe "sdk" do
test "creates client struct" do
token = "mock_token"
client = Client.new(@url, token)
server_api_token = "mock_token"
client = Client.new(@url, server_api_token)

assert %Client{
http_client: %Tesla.Client{
adapter: {Tesla.Adapter.Mint, :call, [[]]},
pre: [
{Tesla.Middleware.BaseUrl, :call, [@url]},
{Tesla.Middleware.BearerAuth, :call, [[token: ^token]]},
{Tesla.Middleware.BearerAuth, :call, [[token: ^server_api_token]]},
{Tesla.Middleware.JSON, :call, [[]]}
]
}
Expand Down
10 changes: 5 additions & 5 deletions test/jellyfish/room_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ defmodule Jellyfish.RoomTest do

alias Jellyfish.{Client, Component, Peer, Room}

@token "testtoken"
@server_api_token "testtoken"

@url "http://mockurl.com"
@invalid_url "http://invalid-url.com"
Expand Down Expand Up @@ -43,7 +43,7 @@ defmodule Jellyfish.RoomTest do
end
end)

%{client: Client.new(@url, @token)}
%{client: Client.new(@url, @server_api_token)}
end

describe "auth" do
Expand All @@ -56,7 +56,7 @@ defmodule Jellyfish.RoomTest do
body: ^valid_body
} = env ->
case Tesla.get_header(env, "authorization") do
"Bearer " <> @token ->
"Bearer " <> @server_api_token ->
json(%{"data" => build_room_json(true)}, status: 201)

"Bearer " <> _other ->
Expand All @@ -71,7 +71,7 @@ defmodule Jellyfish.RoomTest do
end

test "invalid token" do
client = Client.new(@url, "invalid" <> @token)
client = Client.new(@url, "invalid" <> @server_api_token)
assert {:error, _reason} = Room.create(client, max_peers: @max_peers)
end
end
Expand Down Expand Up @@ -283,7 +283,7 @@ defmodule Jellyfish.RoomTest do
end

test "when request is valid", %{client: client} do
assert {:ok, peer, _token} = Room.add_peer(client, @room_id, @peer_type)
assert {:ok, peer, _peer_token} = Room.add_peer(client, @room_id, @peer_type)
assert peer == build_peer()
end

Expand Down