Merged
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
sgfn
reviewed
Feb 12, 2024
test/jellyfish_web/controllers/component/sip_component_test.exs
Outdated
Show resolved
Hide resolved
roznawsk
reviewed
Feb 14, 2024
| require OpenApiSpex | ||
|
|
||
| OpenApiSpex.schema(%{ | ||
| title: "Credentials", |
Member
There was a problem hiding this comment.
I suggest we rename it to SIPCredentials, to indicate that those are sip-specific credentials.
Karolk99
approved these changes
Feb 15, 2024
| 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) |
Contributor
There was a problem hiding this comment.
As far as I know, this is anti-pattern
lib/jellyfish/component/sip.ex
Outdated
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 |
Contributor
There was a problem hiding this comment.
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 |
c9094d8 to
0a4259a
Compare
6bd1842 to
d07c085
Compare
d07c085 to
bc3ff2b
Compare
sgfn
approved these changes
Feb 19, 2024
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 |
Comment on lines
+39
to
+40
| not_found: ApiSpec.error("Room doesn't exist") | ||
| ] |
Co-authored-by: Jakub Pisarek <99591440+sgfn@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Acknowledging the stipulations set forth:
Docs
Elixir SDK
Python SDK