-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for Fly.io deployments (#167)
- Loading branch information
Showing
7 changed files
with
89 additions
and
19 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Deploying on Fly.io | ||
|
||
Elixir WebRTC-based apps can be easily deployed on [Fly.io](https://fly.io)! | ||
|
||
There are just two things you need to do: | ||
|
||
* configure a STUN server both on the client and server side | ||
* use a custom Fly.io IP filter on the server side | ||
|
||
In theory, configuring a STUN server just on one side should be enough but we recommend doing it on both sides. | ||
|
||
In JavaScript code: | ||
|
||
```js | ||
pc = new RTCPeerConnection({ | ||
iceServers: [{ urls: "stun:stun.l.google.com:19302" }], | ||
}); | ||
``` | ||
|
||
In Elixir code: | ||
|
||
```elixir | ||
ip_filter = Application.get_env(:your_app, :ice_ip_filter) | ||
|
||
{:ok, pc} = | ||
PeerConnection.start_link( | ||
ice_ip_filter: ip_filter, | ||
ice_servers: [%{urls: "stun:stun.l.google.com:19302"}] | ||
) | ||
``` | ||
|
||
In `runtime.exs`: | ||
|
||
```elixir | ||
if System.get_env("FLY_IO") do | ||
config :your_app, ice_ip_filter: &ExWebRTC.ICE.FlyIpFilter.ip_filter/1 | ||
end | ||
``` | ||
|
||
In fly.toml: | ||
|
||
```toml | ||
[env] | ||
# add one additional env | ||
FLY_IO = 'true' | ||
``` | ||
|
||
That's it! | ||
No special UDP port exports or dedicated IP address are needed. | ||
Just run `fly launch` and enjoy your deployment :) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
defmodule ExWebRTC.ICE.FlyIpFilter do | ||
@moduledoc """ | ||
ICE IP filter for Fly.io deployments. | ||
This module defines a single function, which filters IP addresses, | ||
which ICE Agent will use as its host candidates. | ||
It accepts only the IPv4 address that `fly-global-services` resolves to. | ||
""" | ||
|
||
@spec ip_filter(:inet.ip_address()) :: boolean() | ||
def ip_filter(ip_address) do | ||
case :inet.gethostbyname(~c"fly-global-services") do | ||
# Assume that fly-global-services has to resolve | ||
# to a single ipv4 address. | ||
# In other case, don't even try to connect. | ||
{:ok, {:hostent, _, _, :inet, 4, [addr]}} -> | ||
addr == ip_address | ||
|
||
_ -> | ||
false | ||
end | ||
end | ||
end |
This file contains 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
This file contains 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
This file contains 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