Skip to content

Commit

Permalink
Add support for Fly.io deployments
Browse files Browse the repository at this point in the history
  • Loading branch information
mickel8 committed Sep 20, 2024
1 parent ef5b5d2 commit 13ef499
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 12 deletions.
2 changes: 1 addition & 1 deletion broadcaster/lib/broadcaster/peer_supervisor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ defmodule Broadcaster.PeerSupervisor do
{:ok, pc} = spawn_peer_connection(pc_id)

Logger.info("Received offer for #{inspect(pc)}")
Logger.debug("Offer SDP for #{inspect(pc)}:\n#{offer.sdp}")
Logger.info("Offer SDP for #{inspect(pc)}:\n#{offer.sdp}")

with :ok <- PeerConnection.set_remote_description(pc, offer),
:ok <- setup_transceivers(pc, direction),
Expand Down
10 changes: 5 additions & 5 deletions nexus/assets/js/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ async function createPeerConnection() {

pc.onconnectionstatechange = () => {
console.log('Connection state change: ' + pc.connectionState);
if (pc.connectionState == 'failed') {
pc.restartIce();
}
// if (pc.connectionState == 'failed') {
// pc.restartIce();
// }
};
pc.onicecandidate = (event) => {
if (event.candidate == null) {
Expand Down Expand Up @@ -81,11 +81,11 @@ async function joinChannel() {

channel.onError(() => {
socket.disconnect();
window.location.reload();
// window.location.reload();
});
channel.onClose(() => {
socket.disconnect();
window.location.reload();
// window.location.reload();
});

channel.on('sdp_offer', async (payload) => {
Expand Down
2 changes: 1 addition & 1 deletion nexus/config/prod.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Config
config :nexus, NexusWeb.Endpoint, cache_static_manifest: "priv/static/cache_manifest.json"

# Do not print debug messages in production
config :logger, level: :info
config :logger, level: :debug

# Runtime production configuration, including reading
# of environment variables, is done on config/runtime.exs.
4 changes: 4 additions & 0 deletions nexus/config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ if System.get_env("PHX_SERVER") do
config :nexus, NexusWeb.Endpoint, server: true
end

if System.get_env("FLY_IO") do
config :nexus, ice_ip_filter: &ExWebRTC.ICE.FlyIpFilter.ip_filter/1
end

config :nexus, ice_port_range: read_ice_port_range!.()

if config_env() == :prod do
Expand Down
33 changes: 33 additions & 0 deletions nexus/fly.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# fly.toml app configuration file generated for nexus-crimson-sea-2293 on 2024-09-17T19:35:04+02:00
#
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#

app = 'nexus-crimson-sea-2293'
primary_region = 'waw'
kill_signal = 'SIGTERM'

[build]

[env]
PHX_HOST = 'nexus-crimson-sea-2293.fly.dev'
PORT = '8080'
FLY_IO = 'true'

[http_service]
internal_port = 8080
force_https = true
auto_stop_machines = 'stop'
auto_start_machines = true
min_machines_running = 0
processes = ['app']

[http_service.concurrency]
type = 'connections'
hard_limit = 1000
soft_limit = 1000

[[vm]]
memory = '1gb'
cpu_kind = 'shared'
cpus = 2
5 changes: 4 additions & 1 deletion nexus/lib/nexus/peer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@ defmodule Nexus.Peer do
def init([id, channel, peer_ids]) do
Logger.debug("Starting new peer #{id}")
ice_port_range = Application.fetch_env!(:nexus, :ice_port_range)
pc_opts = @opts ++ [ice_port_range: ice_port_range]

ip_filter = Application.get_env(:nexus, :ice_ip_filter)
pc_opts = @opts ++ [ice_ip_filter: ip_filter, ice_port_range: ice_port_range]

{:ok, pc} = PeerConnection.start_link(pc_opts)
Process.monitor(pc)
Logger.debug("Starting peer connection #{inspect(pc)}")
Expand Down
4 changes: 3 additions & 1 deletion nexus/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ defmodule Nexus.MixProject do
{:jason, "~> 1.2"},
{:dns_cluster, "~> 0.1.1"},
{:bandit, "~> 1.2"},
{:ex_webrtc, "~> 0.5.0"},
# {:ex_webrtc, "~> 0.5.0"},
{:ex_webrtc, github: "elixir-webrtc/ex_webrtc", branch: "fly", override: true},
{:ex_webrtc_dashboard, "~> 0.5.0"},
{:ex_ice, github: "elixir-webrtc/ex_ice", branch: "keepalive", override: true},

# Dialyzer and credo
{:dialyxir, ">= 0.0.0", only: :dev, runtime: false},
Expand Down
6 changes: 3 additions & 3 deletions nexus/mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
"erlex": {:hex, :erlex, "0.2.7", "810e8725f96ab74d17aac676e748627a07bc87eb950d2b83acd29dc047a30595", [:mix], [], "hexpm", "3ed95f79d1a844c3f6bf0cea61e0d5612a42ce56da9c03f01df538685365efb0"},
"esbuild": {:hex, :esbuild, "0.8.1", "0cbf919f0eccb136d2eeef0df49c4acf55336de864e63594adcea3814f3edf41", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}, {:jason, "~> 1.4", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "25fc876a67c13cb0a776e7b5d7974851556baeda2085296c14ab48555ea7560f"},
"ex_dtls": {:hex, :ex_dtls, "0.16.0", "3ae38025ccc77f6db573e2e391602fa9bbc02253c137d8d2d59469a66cbe806b", [:mix], [{:bundlex, "~> 1.5.3", [hex: :bundlex, repo: "hexpm", optional: false]}, {:unifex, "~> 1.0", [hex: :unifex, repo: "hexpm", optional: false]}], "hexpm", "2a4e30d74c6ddf95cc5b796423293c06a0da295454c3823819808ff031b4b361"},
"ex_ice": {:hex, :ex_ice, "0.8.1", "4d5c911766ce92e13323b632a55d9ab821092f13fc2ebf236dc233c8c1f9a64c", [:mix], [{:elixir_uuid, "~> 1.0", [hex: :elixir_uuid, repo: "hexpm", optional: false]}, {:ex_stun, "~> 0.2.0", [hex: :ex_stun, repo: "hexpm", optional: false]}, {:ex_turn, "~> 0.1.0", [hex: :ex_turn, repo: "hexpm", optional: false]}], "hexpm", "8f10134e2eb7e6aebbf8fba0d5fcec56d8f8db3e94c3dde045feb463979c2dda"},
"ex_ice": {:git, "https://github.com/elixir-webrtc/ex_ice.git", "bddcb3b647a4dd6baf7dc785ac96bcf25f8caa11", [branch: "keepalive"]},
"ex_libsrtp": {:hex, :ex_libsrtp, "0.7.2", "211bd89c08026943ce71f3e2c0231795b99cee748808ed3ae7b97cd8d2450b6b", [:mix], [{:bunch, "~> 1.6", [hex: :bunch, repo: "hexpm", optional: false]}, {:bundlex, "~> 1.3", [hex: :bundlex, repo: "hexpm", optional: false]}, {:membrane_precompiled_dependency_provider, "~> 0.1.0", [hex: :membrane_precompiled_dependency_provider, repo: "hexpm", optional: false]}, {:unifex, "~> 1.1", [hex: :unifex, repo: "hexpm", optional: false]}], "hexpm", "2e20645d0d739a4ecdcf8d4810a0c198120c8a2f617f2b75b2e2e704d59f492a"},
"ex_rtcp": {:hex, :ex_rtcp, "0.4.0", "f9e515462a9581798ff6413583a25174cfd2101c94a2ebee871cca7639886f0a", [:mix], [], "hexpm", "28956602cf210d692fcdaf3f60ca49681634e1deb28ace41246aee61ee22dc3b"},
"ex_rtp": {:hex, :ex_rtp, "0.4.0", "1f1b5c1440a904706011e3afbb41741f5da309ce251cb986690ce9fd82636658", [:mix], [], "hexpm", "0f72d80d5953a62057270040f0f1ee6f955c08eeae82ac659c038001d7d5a790"},
"ex_sdp": {:hex, :ex_sdp, "1.0.0", "c66cd66d60ad03ff1eecdc6db6a1b8a7b89fec260fcc22e8d6703fc5bbf430a3", [:mix], [{:bunch, "~> 1.3", [hex: :bunch, repo: "hexpm", optional: false]}, {:elixir_uuid, "~> 1.2", [hex: :elixir_uuid, repo: "hexpm", optional: false]}], "hexpm", "e165dff988b8ab9d93588636aa5f3f683e1f848fc63b78b12382c8fa3dd39216"},
"ex_sdp": {:hex, :ex_sdp, "1.0.1", "1608551d740a1882fe89d2b1df807167de62c44ab5409a795f257069e348ac05", [:mix], [{:bunch, "~> 1.3", [hex: :bunch, repo: "hexpm", optional: false]}, {:elixir_uuid, "~> 1.2", [hex: :elixir_uuid, repo: "hexpm", optional: false]}], "hexpm", "0b8c53b15f18122feed9b65c1318603bebbe33cbad36efb3995b6e03b1bf27ee"},
"ex_stun": {:hex, :ex_stun, "0.2.0", "feb1fc7db0356406655b2a617805e6c712b93308c8ea2bf0ba1197b1f0866deb", [:mix], [], "hexpm", "1e01ba8290082ccbf37acaa5190d1f69b51edd6de2026a8d6d51368b29d115d0"},
"ex_turn": {:hex, :ex_turn, "0.1.0", "177405aadf3d754567d0d37cf881a83f9cacf8f45314d188633b04c4a9e7c1ec", [:mix], [{:ex_stun, "~> 0.2.0", [hex: :ex_stun, repo: "hexpm", optional: false]}], "hexpm", "d677737fb7d45274d5dac19fe3c26b9038b6effbc0a6b3e7417bccc76b6d1cd3"},
"ex_webrtc": {:hex, :ex_webrtc, "0.5.0", "18bb3f5de329edd4410979c2882c971b3c310e33769405a6d160c8b5210ac371", [:mix], [{:crc, "~> 0.10", [hex: :crc, repo: "hexpm", optional: false]}, {:ex_dtls, "~> 0.16.0", [hex: :ex_dtls, repo: "hexpm", optional: false]}, {:ex_ice, "~> 0.8.0", [hex: :ex_ice, repo: "hexpm", optional: false]}, {:ex_libsrtp, "~> 0.7.1", [hex: :ex_libsrtp, repo: "hexpm", optional: false]}, {:ex_rtcp, "~> 0.4.0", [hex: :ex_rtcp, repo: "hexpm", optional: false]}, {:ex_rtp, "~> 0.4.0", [hex: :ex_rtp, repo: "hexpm", optional: false]}, {:ex_sctp, "0.1.0", [hex: :ex_sctp, repo: "hexpm", optional: true]}, {:ex_sdp, "~> 1.0", [hex: :ex_sdp, repo: "hexpm", optional: false]}], "hexpm", "6a701e7925cc627c24faee3fbd362a5b9c5d86262ec72980e2af847e1ad8ec98"},
"ex_webrtc": {:git, "https://github.com/elixir-webrtc/ex_webrtc.git", "173ab82aa370196029a4215039e673d90fcb3f13", [branch: "fly"]},
"ex_webrtc_dashboard": {:hex, :ex_webrtc_dashboard, "0.5.0", "05840125fcac9f708318115a5101fa58bd936735dc6f5900fb230af293305df8", [:mix], [{:ex_webrtc, "~> 0.5.0", [hex: :ex_webrtc, repo: "hexpm", optional: false]}, {:phoenix_live_dashboard, "~> 0.8.3", [hex: :phoenix_live_dashboard, repo: "hexpm", optional: false]}], "hexpm", "b0fcef6c23df888f0f094e7f63541e980db175e27b551f2f314e277ac3eb2f29"},
"file_system": {:hex, :file_system, "1.0.1", "79e8ceaddb0416f8b8cd02a0127bdbababe7bf4a23d2a395b983c1f8b3f73edd", [:mix], [], "hexpm", "4414d1f38863ddf9120720cd976fce5bdde8e91d8283353f0e31850fa89feb9e"},
"finch": {:hex, :finch, "0.19.0", "c644641491ea854fc5c1bbaef36bfc764e3f08e7185e1f084e35e0672241b76d", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:mint, "~> 1.6.2 or ~> 1.7", [hex: :mint, repo: "hexpm", optional: false]}, {:nimble_options, "~> 0.4 or ~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:nimble_pool, "~> 1.1", [hex: :nimble_pool, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "fc5324ce209125d1e2fa0fcd2634601c52a787aff1cd33ee833664a5af4ea2b6"},
Expand Down
13 changes: 13 additions & 0 deletions nexus/rel/env.sh.eex
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh

# configure node for distributed erlang with IPV6 support
export ERL_AFLAGS="-proto_dist inet6_tcp"
export ECTO_IPV6="true"
export DNS_CLUSTER_QUERY="${FLY_APP_NAME}.internal"
export RELEASE_DISTRIBUTION="name"
export RELEASE_NODE="${FLY_APP_NAME}-${FLY_IMAGE_REF##*-}@${FLY_PRIVATE_IP}"

# Uncomment to send crash dumps to stderr
# This can be useful for debugging, but may log sensitive information
# export ERL_CRASH_DUMP=/dev/stderr
# export ERL_CRASH_DUMP_BYTES=4096

0 comments on commit 13ef499

Please sign in to comment.