-
Notifications
You must be signed in to change notification settings - Fork 20
RTC-377 SIP Component #147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
3671be2 to
66b6e8b
Compare
Codecov Report
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
Continue to review full report in Codecov by Sentry.
|
5927cd8 to
adcb972
Compare
test/jellyfish_web/controllers/component/sip_component_test.exs
Outdated
Show resolved
Hide resolved
| require OpenApiSpex | ||
|
|
||
| OpenApiSpex.schema(%{ | ||
| title: "Credentials", |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
lib/jellyfish/component/sip.ex
Outdated
| 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 |
There was a problem hiding this comment.
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
| 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 |
c9094d8 to
0a4259a
Compare
6bd1842 to
d07c085
Compare
d07c085 to
bc3ff2b
Compare
| 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💪 💪 💪
| not_found: ApiSpec.error("Room doesn't exist") | ||
| ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+unauthorized
Co-authored-by: Jakub Pisarek <99591440+sgfn@users.noreply.github.com>
Acknowledging the stipulations set forth:
Docs
Elixir SDK
Python SDK