-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
97 additions
and
21 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 custom Fly.io IP filter on the server side | ||
|
||
In theory, configuring a STUN server just on a one side should be enough but we recommend to do 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 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,22 @@ | ||
defmodule ExWebRTC.ICE.FlyIpFilter do | ||
@moduledoc """ | ||
ICE IP filter for Fly.io deployments. | ||
This module defines a single function, which filters out IP addresses, | ||
which ICE Agent will use as its host candidates. | ||
""" | ||
|
||
@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