Skip to content
This repository was archived by the owner on Jul 17, 2024. It is now read-only.

Commit b7f00cb

Browse files
authored
feat/add one url for fishjam (#82)
* feat: add one url for fishjam
1 parent f1d0eb9 commit b7f00cb

17 files changed

+56
-140
lines changed

.env.example

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ JF_SERVER_API_TOKEN="development"
66

77
# SSL
88
DOMAIN=localhost
9-
# BE_JF_ADDRESSES=<fishjam_domain_address1> <fishjam_domain_address2>
9+
# BE_JF_ADDRESS=<fishjam_domain_address>
1010
# BE_HOST=<backend_domain_address>
1111
# BE_JF_SECURE_CONNECTION=false
1212
# JF_CHECK_ORIGIN=false

.github/workflows/production_build_and_deploy.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
JF_SERVER_API_TOKEN=${{secrets.SERVER_API_TOKEN_CLOUD_PRODUCTION}}
3434
BE_HOST=${{env.BE_HOST}}
3535
BE_JF_SECURE_CONNECTION=true
36-
BE_JF_ADDRESSES=${{vars.JF1_HOST_CLOUD_PRODUCTION}}" > .env
36+
BE_JF_ADDRESS=${{vars.JF_HOST_CLOUD_PRODUCTION}}" > .env
3737
3838
- name: Remove old containers on first host
3939
uses: JimCronqvist/action-ssh@master

.github/workflows/sandbox_build_and_deploy.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
JF_SERVER_API_TOKEN=${{secrets.SERVER_API_TOKEN_CLOUD_SANDBOX}}
3636
BE_HOST=${{env.BE_HOST}}
3737
BE_JF_SECURE_CONNECTION=true
38-
BE_JF_ADDRESSES=${{vars.JF_HOST_CLOUD_SANDBOX}}" > .env
38+
BE_JF_ADDRESS=${{vars.JF_HOST_CLOUD_SANDBOX}}" > .env
3939
4040
- name: Remove old containers on first host
4141
uses: JimCronqvist/action-ssh@master

.github/workflows/staging_build_and_deploy.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,21 @@ jobs:
2727
- name: Prepare .env file for the deployment
2828
id: variables_population
2929
run: |
30-
echo "DOMAIN=${{env.DOMAIN}}
30+
echo "DOMAIN=${{env.DOMAIN}}
3131
FISHJAM_ROOM_VERSION=${{ steps.versions.outputs.fishjam_room }}
3232
FISHJAM_VERSION=${{ steps.versions.outputs.fishjam }}
3333
JF_SERVER_API_TOKEN=${{secrets.SERVER_API_TOKEN_CLOUD_STAGING}}
3434
BE_HOST=${{env.BE_HOST}}
3535
BE_JF_SECURE_CONNECTION=true
36-
BE_JF_ADDRESSES=${{vars.JF1_HOST_CLOUD_STAGING}}" > .env
36+
BE_JF_ADDRESS=${{vars.JF_HOST_CLOUD_STAGING}}" > .env
3737
3838
- name: Remove old containers on first host
3939
uses: JimCronqvist/action-ssh@master
4040
with:
4141
hosts: ${{ secrets.STAGING_HOST }}
4242
privateKey: ${{ secrets.SSH_PRIV_KEY }}
4343
command: |
44-
docker ps -aq | xargs -r docker stop | xargs -r docker rm
44+
docker ps -aq | xargs -r docker stop | xargs -r docker rm
4545
4646
- name: Deploy docker compose to a pre-configured server on first host
4747
uses: TapTap21/docker-remote-deployment-action@v1.1

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,5 @@ videoroom-*.tar
3535
.env
3636

3737
certbot/
38+
39+
.vscode

README.md

+6-10
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ When running the build version of the Phoenix app, you must specify the addresse
3131
As well as the authentication token via the environment variables:
3232

3333
```sh
34-
BE_JF_ADDRESSES=<IP_ADDRESS1>:<PORT1> OR <DOMAIN1> <IP_ADDRESS2>:<PORT2> OR <DOMAIN2> #Example of using two fishjams: `127.0.0.1:5002 room.fishjam.ovh`, if not provided in dev environment `localhost:5002 localhost:5003` is used.
34+
BE_JF_ADDRESS=<IP_ADDRESS>:<PORT1> OR <DOMAIN1> #Example `127.0.0.1:5002 OR room.fishjam.ovh`, if not provided in dev environment `localhost:5002` is used.
3535
BE_JF_SERVER_API_TOKEN=<TOKEN> #This must be the same token that was setup in fishjam. In `docker-compose-dev.yaml` we setup `development` and this variable is used by default in `dev` environment
3636
```
3737

38-
Optionally, in production, these variables can be set:
38+
Optionally, in production, these variables can be set:
3939
* `BE_PEER_JOIN_TIMEOUT` - can be used to limit the period in which a new peer must join the meeting,
4040
* `BE_JF_SECURE_CONNECTION` - enforces connecting the backend to fishjam through `wss` protocol,
4141
* `BE_HOST` - address of backend
@@ -57,21 +57,17 @@ You can copy the `.env.example` file to `.env` and adjust it to your needs.
5757
## Deployment with load-balancing
5858

5959
`docker-compose.yaml` allows to run a fishjam videoroom with multiple fishjams but all of that runs on the same machine.
60-
For properly using load-balancing two machines will be needed and `docker-compose-deploy.yaml` will be used.
60+
For properly using load-balancing two machines will be needed and `docker-compose-deploy.yaml` will be used.
6161
You can see our deployment workflow [here](.github/workflows/test_build_and_deploy.yml).
62-
This deployment is pretty simple.
62+
This deployment is pretty simple.
6363
All containers besides `fishjam2` are started on node1 and `fishjam2` is started on node2.
6464
All environment variables used in our deployment are presented below:
6565

6666
```sh
6767
DOMAIN=<FRONTEND_DOMAIN>
68-
JF1_IP=<NODE1_IP> # IP address of first node on which fishjam will be run
69-
JF2_IP=<NODE2_IP> # IP address of second node on which fishjam will be run
7068
JF_SERVER_API_TOKEN=<API_TOKEN> #The same API token is used for all fishjams
71-
JF1_HOST=<DOMAIN_FISHJAM1> OR <JF1_IP>:<FISHJAM1_PORT> # Value passed to fishjam and returns by it when creating a room on this speicific fishjam
72-
JF2_HOST=<DOMAIN_FISHJAM2> OR <JF2_IP>:<FISHJAM2_PORT>
73-
BE_JF_ADDRESSES=<JF1_HOST> <JF2_HOST> #Used by backend to create a notifier to one of fishjams
74-
PROMETHEUS_TARGETS=<JF1_IP>:9568,<JF2_IP>:9568 #Addresses on which prometheus will query for data
69+
BE_JF_ADDRESS=<DOMAIN_FISHJAM1> OR <FISHJAM_IP>:<FISHJAM_PORT> #Used by backend to create a notifier and to communicate with fishjam
70+
PROMETHEUS_TARGETS=<FISHJAM_IP>:9568 #Addresses on which prometheus will query for data
7571
BE_HOST=<BACKEND_DOMAIN>
7672
GF_SECURITY_ADMIN_PASSWORD=<GRAFANA_PASSWORD>
7773
GF_SECURITY_ADMIN_USER=<GRAFANA_LOGIN>

config/dev.exs

+1-5
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,12 @@ config :fishjam_server_sdk,
4343
# configured to run both http and https servers on
4444
# different ports.
4545

46-
fishjam_addresses = System.get_env("BE_JF_ADDRESSES", "localhost:5002 localhost:5003")
47-
48-
fishjam_addresses = String.split(fishjam_addresses, " ")
49-
5046
# Enable dev routes for dashboard and mailbox
5147
config :videoroom,
5248
dev_routes: true,
5349
peer_disconnected_timeout: 60,
5450
peerless_purge_timeout: 120,
55-
fishjam_addresses: fishjam_addresses
51+
fishjam_address: "localhost:5002"
5652

5753
# Do not include metadata nor timestamps in development logs
5854
config :logger, :console, format: "[$level] $message\n"

config/integration_test.exs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ config :fishjam_server_sdk,
55
server_api_token: "development"
66

77
config :videoroom,
8-
fishjam_addresses: ["fishjam:5002"],
8+
fishjam_address: "fishjam:5002",
99
peer_disconnected_timeout: 1,
1010
peerless_purge_timeout: 3

config/runtime.exs

+2-63
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,5 @@
11
import Config
22

3-
# config/runtime.exs is executed for all environments, including
4-
# during releases. It is executed after compilation and before the
5-
# system starts, so it is typically used to load production configuration
6-
# and secrets from environment variables or elsewhere. Do not define
7-
# any compile-time configuration in here, as it won't be applied.
8-
# The block below contains prod specific runtime configuration.
9-
10-
# ## Using releases
11-
#
12-
# If you use `mix release`, you need to explicitly enable the server
13-
# by passing the BE_PHX_SERVER=true when you start it:
14-
#
15-
# BE_PHX_SERVER=true bin/videoroom start
16-
#
17-
# Alternatively, you can use `mix phx.gen.release` to generate a `bin/server`
18-
# script that automatically sets the env var above.
193
if System.get_env("BE_PHX_SERVER") do
204
config :videoroom, VideoroomWeb.Endpoint, server: true
215
end
@@ -29,11 +13,6 @@ if config_env() == :test do
2913
end
3014

3115
if config_env() == :prod do
32-
# The secret key base is used to sign/encrypt cookies and other secrets.
33-
# A default value is used in config/dev.exs and config/test.exs but you
34-
# want to use a different value for prod and you most likely don't want
35-
# to check this value into version control, so we use an environment
36-
# variable instead.
3716
secret_key_base =
3817
System.get_env("BE_SECRET_KEY_BASE") || Base.encode64(:crypto.strong_rand_bytes(48))
3918

@@ -43,20 +22,11 @@ if config_env() == :prod do
4322
config :videoroom, VideoroomWeb.Endpoint,
4423
url: [host: host, port: 443, scheme: "https"],
4524
http: [
46-
# Enable IPv6 and bind on all interfaces.
47-
# Set it to {0, 0, 0, 0, 0, 0, 0, 1} for local network only access.
48-
# See the documentation on https://hexdocs.pm/plug_cowboy/Plug.Cowboy.html
49-
# for details about using IPv6 vs IPv4 and loopback vs public addresses.
5025
ip: {0, 0, 0, 0, 0, 0, 0, 0},
5126
port: port
5227
],
5328
secret_key_base: secret_key_base
5429

55-
fishjam_addresses =
56-
System.get_env("BE_JF_ADDRESSES") || raise "Environment variable BE_JF_ADDRESSES is missing."
57-
58-
fishjam_addresses = String.split(fishjam_addresses, " ")
59-
6030
secure_connection? = System.get_env("BE_JF_SECURE_CONNECTION", "false") == "true"
6131

6232
config :fishjam_server_sdk,
@@ -68,40 +38,9 @@ if config_env() == :prod do
6838
""")
6939

7040
config :videoroom,
71-
fishjam_addresses: fishjam_addresses,
41+
fishjam_address:
42+
System.get_env("BE_JF_ADDRESS") || raise("Environment variable BE_JF_ADDRESS is missing."),
7243
peer_disconnected_timeout:
7344
String.to_integer(System.get_env("PEER_DISCONNECTED_TIMEOUT") || "120"),
7445
peerless_purge_timeout: String.to_integer(System.get_env("PEERLESS_PURGE_TIMEOUT") || "60")
75-
76-
# ## SSL Support
77-
#
78-
# To get SSL working, you will need to add the `https` key
79-
# to your endpoint configuration:
80-
#
81-
# config :videoroom, VideoroomWeb.Endpoint,
82-
# https: [
83-
# ...,
84-
# port: 443,
85-
# cipher_suite: :strong,
86-
# keyfile: System.get_env("SOME_APP_SSL_KEY_PATH"),
87-
# certfile: System.get_env("SOME_APP_SSL_CERT_PATH")
88-
# ]
89-
#
90-
# The `cipher_suite` is set to `:strong` to support only the
91-
# latest and more secure SSL ciphers. This means old browsers
92-
# and clients may not be supported. You can set it to
93-
# `:compatible` for wider support.
94-
#
95-
# `:keyfile` and `:certfile` expect an absolute path to the key
96-
# and cert in disk or a relative path inside priv, for example
97-
# "priv/ssl/server.key". For all supported SSL configuration
98-
# options, see https://hexdocs.pm/plug/Plug.SSL.html#configure/1
99-
#
100-
# We also recommend setting `force_ssl` in your endpoint, ensuring
101-
# no data is ever sent via http, always redirecting to https:
102-
#
103-
# config :videoroom, VideoroomWeb.Endpoint,
104-
# force_ssl: [hsts: true]
105-
#
106-
# Check `Plug.SSL` for all available options in `force_ssl`.
10746
end

config/test.exs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ config :fishjam_server_sdk,
1414
config :videoroom,
1515
divo: "docker-compose-dev.yaml",
1616
divo_wait: [dwell: 1500, max_tries: 50],
17-
fishjam_addresses: ["localhost:5002"],
17+
fishjam_address: "localhost:5002",
1818
peer_disconnected_timeout: 1,
1919
peerless_purge_timeout: 3
2020

docker-compose-deploy.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ services:
2727
BE_PHX_SERVER: "true"
2828
BE_JF_SECURE_CONNECTION: ${BE_JF_SECURE_CONNECTION:-false}
2929
BE_JF_SERVER_API_TOKEN: ${JF_SERVER_API_TOKEN}
30-
BE_JF_ADDRESSES: ${BE_JF_ADDRESSES:-$JF1_IP:$JF_PORT $JF2_IP:$JF_PORT}
30+
BE_JF_ADDRESS: ${BE_JF_ADDRESS}
3131
restart: unless-stopped
3232
ports:
3333
- "5004:5004"

docker-compose-integration.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ services:
66
command: sh -c "cd app/ && apk add git && mix local.hex --force && mix local.rebar --force && mix deps.get && mix test --warnings-as-errors"
77
environment:
88
MIX_ENV: integration_test
9-
BE_JF_ADDRESSES: fishjam:5002
9+
BE_JF_ADDRESS: fishjam:5002
1010
BE_JF_SECURE_CONNECTION: false
1111

1212
volumes:

docker-compose.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ services:
1717
container_name: fishjam1
1818
environment:
1919
<<: *fishjam-environment
20-
JF_HOST: "${JF1_HOST:-${JF1_IP:-$EXTERNAL_IP}:5002}"
20+
JF_HOST: "localhost:5002}"
2121
JF_PORT: 5002
2222
JF_DIST_NODE_NAME: app@fishjam1
2323
JF_WEBRTC_TURN_PORT_RANGE: "50000-50100"
@@ -33,7 +33,7 @@ services:
3333
container_name: fishjam2
3434
environment:
3535
<<: *fishjam-environment
36-
JF_HOST: "${JF2_HOST:-${JF2_IP:-$EXTERNAL_IP}:5003}"
36+
JF_HOST: "localhost:5003}"
3737
JF_PORT: 5003
3838
JF_DIST_NODE_NAME: app@fishjam2
3939
JF_WEBRTC_TURN_PORT_RANGE: "50101-50200"
@@ -69,7 +69,7 @@ services:
6969
BE_PORT: 5004
7070
BE_HOST: ${BE_HOST:-$DOMAIN}
7171
BE_PHX_SERVER: "true"
72-
BE_JF_ADDRESSES: ${BE_JF_ADDRESSES:-fishjam1:5002 fishjam2:5003}
72+
BE_JF_ADDRESS: ${BE_JF_ADDRESS:-fishjam1:5002}
7373
BE_JF_SECURE_CONNECTION: ${BE_JF_SECURE_CONNECTION:-false}
7474
BE_JF_SERVER_API_TOKEN: ${JF_SERVER_API_TOKEN:-development}
7575
restart: unless-stopped

lib/videoroom/meeting.ex

+10-18
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ defmodule Videoroom.Meeting do
1818
@enforce_keys [
1919
:name,
2020
:client,
21-
:room_id,
22-
:fishjam_address
21+
:room_id
2322
]
2423

2524
defstruct @enforce_keys
@@ -98,30 +97,28 @@ defmodule Videoroom.Meeting do
9897
# Callbacks
9998

10099
@impl true
101-
def init(%{name: name, fishjam_address: fishjam_address}) do
100+
def init(%{name: name}) do
102101
Logger.metadata(room_name: name)
102+
fishjam_address = Application.fetch_env!(:videoroom, :fishjam_address)
103103

104104
client = Fishjam.Client.new(server_address: fishjam_address)
105105

106106
peer_disconnected_timeout = Application.fetch_env!(:videoroom, :peer_disconnected_timeout)
107107
peerless_purge_timeout = Application.fetch_env!(:videoroom, :peerless_purge_timeout)
108108

109-
with {:ok, room, fishjam_address} <-
109+
with {:ok, room} <-
110110
create_new_room(client, name,
111111
video_codec: :h264,
112112
peer_disconnected_timeout: peer_disconnected_timeout,
113113
peerless_purge_timeout: peerless_purge_timeout
114114
) do
115-
client = Fishjam.Client.update_address(client, fishjam_address)
116-
117115
Logger.info("Created meeting room id: #{room.id}")
118116

119117
{:ok,
120118
%State{
121119
client: client,
122120
name: name,
123-
room_id: room.id,
124-
fishjam_address: fishjam_address
121+
room_id: room.id
125122
}}
126123
else
127124
{:error, reason} ->
@@ -131,10 +128,9 @@ defmodule Videoroom.Meeting do
131128
end
132129

133130
defp create_new_room(client, name, opts) do
134-
with {:ok, room, fishjam_address} <- Room.create(client, opts),
135-
client <- Fishjam.Client.update_address(client, fishjam_address),
131+
with {:ok, room, _fishjam_address} <- Room.create(client, opts),
136132
:ok <- add_room_to_registry(client, name, room) do
137-
{:ok, room, fishjam_address}
133+
{:ok, room}
138134
end
139135
end
140136

@@ -156,19 +152,15 @@ defmodule Videoroom.Meeting do
156152
{:ok, %{peer: peer, token: token}} ->
157153
Logger.info("Added peer #{peer.id}")
158154

159-
{:reply, {:ok, token, state.fishjam_address}, state}
155+
{:reply, {:ok, token}, state}
160156

161157
{:error, ^text} ->
162-
Logger.error(
163-
"Failed to add peer, because of room #{state.room_id} does not exist on fishjam: #{state.fishjam_address}"
164-
)
158+
Logger.error("Failed to add peer, because of room #{state.room_id} does not exist")
165159

166160
{:stop, :room_not_exist, {:error, "Failed to add peer"}, state}
167161

168162
error ->
169-
Logger.error(
170-
"Failed to add peer, because of error: #{inspect(error)} on fishjam: #{state.fishjam_address}"
171-
)
163+
Logger.error("Failed to add peer, because of error: #{inspect(error)}")
172164

173165
{:reply, {:error, "Failed to add peer"}, state}
174166
end

0 commit comments

Comments
 (0)