Skip to content

Conversation

@Rados13
Copy link
Contributor

@Rados13 Rados13 commented Feb 2, 2024

Acknowledging the stipulations set forth:

  • I hereby confirm that a Pull Request involving updates to the Software Development Kit (SDK) has been smoothly merged, currently awaits processing, or is otherwise deemed unnecessary in this context.
  • I also affirm that another Pull Request, specifically addressing updates to the documentation body (commonly referred to as 'docs'), has either been successfully incorporated, is in the process of review, or is considered superfluous under the prevailing circumstances.

Docs
Elixir SDK
Python SDK

@Rados13 Rados13 self-assigned this Feb 2, 2024
@codecov
Copy link

codecov bot commented Feb 9, 2024

Codecov Report

Merging #147 (ccfd64a) into main (090a338) will decrease coverage by 0.16%.
The diff coverage is 89.02%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #147      +/-   ##
==========================================
- Coverage   86.84%   86.69%   -0.16%     
==========================================
  Files          64       68       +4     
  Lines        1247     1293      +46     
==========================================
+ Hits         1083     1121      +38     
- Misses        164      172       +8     
Files Coverage Δ
lib/jellyfish/component.ex 100.00% <100.00%> (ø)
lib/jellyfish/component/file.ex 100.00% <ø> (ø)
lib/jellyfish/component/hls.ex 96.77% <100.00%> (+5.46%) ⬆️
lib/jellyfish/component/hls/manager.ex 97.05% <ø> (ø)
lib/jellyfish/component/rtsp.ex 83.33% <100.00%> (-2.39%) ⬇️
lib/jellyfish/config_reader.ex 94.05% <100.00%> (+0.44%) ⬆️
lib/jellyfish/peer/webrtc.ex 48.27% <100.00%> (ø)
lib/jellyfish_web/api_spec/component.ex 100.00% <ø> (ø)
lib/jellyfish_web/api_spec/component/sip.ex 100.00% <100.00%> (ø)
lib/jellyfish_web/api_spec/dial.ex 100.00% <100.00%> (ø)
... and 5 more

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 090a338...ccfd64a. Read the comment docs.

@Rados13 Rados13 changed the title SIP Component RTC-377 SIP Component Feb 13, 2024
require OpenApiSpex

OpenApiSpex.schema(%{
title: "Credentials",
Copy link
Member

Choose a reason for hiding this comment

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

I suggest we rename it to SIPCredentials, to indicate that those are sip-specific credentials.

for filename <- @files, do: :ok = hls_dir |> Path.join(filename) |> File.touch!()

on_exit(fn -> File.rm_rf!(hls_dir) end)
on_exit(fn -> hls_dir |> File.rm_rf!() end)
Copy link
Contributor

Choose a reason for hiding this comment

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

As far as I know, this is anti-pattern

Comment on lines 35 to 60
with {:ok, valid_opts} <- OpenApiSpex.cast_value(options, Options.schema()) do
endpoint_spec =
Map.from_struct(valid_opts)
# OpenApiSpex will remove invalid options, so the following conversion, while ugly, is memory-safe
|> Map.new(fn {k, v} ->
{Atom.to_string(k) |> Macro.underscore() |> String.to_atom(), v}
end)
|> Map.put(:rtc_engine, engine)
|> Map.put(:external_ip, external_ip)
|> Map.update!(:registrar_credentials, fn credentials ->
credentials
|> Map.to_list()
|> Keyword.new()
|> RegistrarCredentials.new()
end)
|> then(&struct(SIP, &1))

properties = valid_opts |> Map.from_struct()

{:ok, %{endpoint: endpoint_spec, properties: properties}}
else
{:error, [%OpenApiSpex.Cast.Error{reason: :missing_field, name: name} | _rest]} ->
{:error, {:missing_parameter, name}}

{:error, _reason} = error ->
error
Copy link
Contributor

Choose a reason for hiding this comment

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

I would use function from HLS component

Suggested change
with {:ok, valid_opts} <- OpenApiSpex.cast_value(options, Options.schema()) do
endpoint_spec =
Map.from_struct(valid_opts)
# OpenApiSpex will remove invalid options, so the following conversion, while ugly, is memory-safe
|> Map.new(fn {k, v} ->
{Atom.to_string(k) |> Macro.underscore() |> String.to_atom(), v}
end)
|> Map.put(:rtc_engine, engine)
|> Map.put(:external_ip, external_ip)
|> Map.update!(:registrar_credentials, fn credentials ->
credentials
|> Map.to_list()
|> Keyword.new()
|> RegistrarCredentials.new()
end)
|> then(&struct(SIP, &1))
properties = valid_opts |> Map.from_struct()
{:ok, %{endpoint: endpoint_spec, properties: properties}}
else
{:error, [%OpenApiSpex.Cast.Error{reason: :missing_field, name: name} | _rest]} ->
{:error, {:missing_parameter, name}}
{:error, _reason} = error ->
error
with {:ok, valid_opts} <- OpenApiSpex.cast_value(options, Options.schema()),
{:ok, serialized_opts} <- serialize_options(options) do
# endpoint_spec =
# serialized_opts
# |> Map.put(:rtc_engine, engine)
# |> Map.put(:external_ip, external_ip)
# |> Map.update!(:registrar_credentials, fn credentials ->
# credentials
# |> Map.to_list()
# |> Keyword.new()
# |> RegistrarCredentials.new()
# end)
# |> then(&struct(SIP, &1))
endpoint_spec = %SIP{...}
{:ok, %{endpoint: endpoint_spec, properties: serialized_opts}}
else
{:error, [%OpenApiSpex.Cast.Error{reason: :missing_field, name: name} | _rest]} ->
{:error, {:missing_parameter, name}}
{:error, _reason} = error ->
error

@Rados13 Rados13 requested review from roznawsk and sgfn February 16, 2024 09:04
@Rados13 Rados13 force-pushed the SIP-component branch 3 times, most recently from 6bd1842 to d07c085 Compare February 16, 2024 10:33
Comment on lines +63 to +93
defmacro __using__(_opts) do
quote location: :keep do
@behaviour Jellyfish.Component

@impl true
def after_init(_room_state, _component, _component_options), do: :ok

@impl true
def on_remove(_room_state, _component), do: :ok

defoverridable after_init: 3, on_remove: 2

def serialize_options(opts, opts_schema) do
with {:ok, valid_opts} <- OpenApiSpex.Cast.cast(opts_schema, opts) do
valid_opts =
valid_opts
|> Map.from_struct()
|> Map.new(fn {k, v} -> {underscore(k), serialize(v)} end)

{:ok, valid_opts}
end
end

defp serialize(v) when is_struct(v),
do: v |> Map.from_struct() |> Map.new(fn {k, v} -> {underscore(k), v} end)

defp serialize(v), do: v

defp underscore(k), do: k |> Atom.to_string() |> Macro.underscore() |> String.to_atom()
end
end
Copy link
Member

Choose a reason for hiding this comment

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

💪 💪 💪

Comment on lines 39 to 40
not_found: ApiSpec.error("Room doesn't exist")
]
Copy link
Member

Choose a reason for hiding this comment

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

+unauthorized

Rados13 and others added 3 commits February 19, 2024 12:44
Co-authored-by: Jakub Pisarek <99591440+sgfn@users.noreply.github.com>
@Rados13 Rados13 merged commit 9dff586 into main Feb 19, 2024
@Rados13 Rados13 deleted the SIP-component branch February 19, 2024 12:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants