Skip to content

Commit 5c25ed5

Browse files
authored
[Broadcaster] Fix Docker image not working with bridge network (#64)
1 parent 35a2fde commit 5c25ed5

File tree

7 files changed

+65
-18
lines changed

7 files changed

+65
-18
lines changed

broadcaster/Dockerfile

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ ARG DEBIAN_VERSION=bookworm-20240701-slim
1818
ARG BUILDER_IMAGE="hexpm/elixir:${ELIXIR_VERSION}-erlang-${OTP_VERSION}-debian-${DEBIAN_VERSION}"
1919
ARG RUNNER_IMAGE="debian:${DEBIAN_VERSION}"
2020

21-
FROM ${BUILDER_IMAGE} as builder
21+
FROM ${BUILDER_IMAGE} AS builder
2222

2323
# install build dependencies
2424
RUN apt-get update -y && apt-get install -y build-essential git pkg-config libssl-dev \
@@ -74,9 +74,9 @@ RUN apt-get update -y && \
7474
# Set the locale
7575
RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen
7676

77-
ENV LANG en_US.UTF-8
78-
ENV LANGUAGE en_US:en
79-
ENV LC_ALL en_US.UTF-8
77+
ENV LANG=en_US.UTF-8
78+
ENV LANGUAGE=en_US:en
79+
ENV LC_ALL=en_US.UTF-8
8080

8181
WORKDIR "/app"
8282
RUN chown nobody /app

broadcaster/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ docker run \
4747
```
4848

4949
Note that secret has to be at least 64 bytes long.
50-
You can generate one with `mix phx.gen.secret`.
50+
You can generate one with `mix phx.gen.secret` or `head -c64 /dev/urandom | base64`.
5151

5252
If you are running on MacOS, instead of using `--network host` option, you have to explicitly publish ports:
5353

5454
```
5555
docker run \
56-
-e SECRET_KEY_BASE="secert" \
56+
-e SECRET_KEY_BASE="secret" \
5757
-e PHX_HOST=localhost \
5858
-e ADMIN_USERNAME=admin \
5959
-e ADMIN_PASSWORD=admin \

broadcaster/assets/js/panel.js

+47
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,27 @@ function enableControls() {
105105
async function startStreaming() {
106106
disableControls();
107107

108+
const candidates = [];
109+
let patchEndpoint = undefined;
108110
pc = new RTCPeerConnection();
111+
112+
pc.onicegatheringstatechange = () =>
113+
console.log('Gathering state change:', pc.iceGatheringState);
114+
pc.onconnectionstatechange = () =>
115+
console.log('Connection state change:', pc.connectionState);
116+
pc.onicecandidate = (event) => {
117+
if (event.candidate == null) {
118+
return;
119+
}
120+
121+
const candidate = JSON.stringify(event.candidate);
122+
if (patchEndpoint === undefined) {
123+
candidates.push(candidate);
124+
} else {
125+
sendCandidate(patchEndpoint, candidate);
126+
}
127+
};
128+
109129
pc.addTrack(localStream.getAudioTracks()[0], localStream);
110130
const { sender: videoSender } = pc.addTransceiver(
111131
localStream.getVideoTracks()[0],
@@ -145,6 +165,13 @@ async function startStreaming() {
145165
});
146166

147167
if (response.status == 201) {
168+
patchEndpoint = response.headers.get('location');
169+
console.log('Successfully initialized WHIP connection');
170+
171+
for (const candidate of candidates) {
172+
sendCandidate(patchEndpoint, candidate);
173+
}
174+
148175
const sdp = await response.text();
149176
await pc.setRemoteDescription({ type: 'answer', sdp: sdp });
150177
button.innerText = 'Stop Streaming';
@@ -163,6 +190,26 @@ async function startStreaming() {
163190
}
164191
}
165192

193+
async function sendCandidate(patchEndpoint, candidate) {
194+
const response = await fetch(patchEndpoint, {
195+
method: 'PATCH',
196+
cache: 'no-cache',
197+
headers: {
198+
'Content-Type': 'application/trickle-ice-sdpfrag',
199+
},
200+
body: candidate,
201+
});
202+
203+
if (response.status === 204) {
204+
console.log(`Successfully sent ICE candidate:`, candidate);
205+
} else {
206+
console.error(
207+
`Failed to send ICE, status: ${response.status}, candidate:`,
208+
candidate
209+
);
210+
}
211+
}
212+
166213
function stopStreaming() {
167214
pc.close();
168215
pc = undefined;

nexus/Dockerfile

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ ARG DEBIAN_VERSION=bookworm-20240701-slim
1818
ARG BUILDER_IMAGE="hexpm/elixir:${ELIXIR_VERSION}-erlang-${OTP_VERSION}-debian-${DEBIAN_VERSION}"
1919
ARG RUNNER_IMAGE="debian:${DEBIAN_VERSION}"
2020

21-
FROM ${BUILDER_IMAGE} as builder
21+
FROM ${BUILDER_IMAGE} AS builder
2222

2323
# install build dependencies
2424
RUN apt-get update -y && apt-get install -y build-essential git pkg-config libssl-dev \
@@ -74,9 +74,9 @@ RUN apt-get update -y && \
7474
# Set the locale
7575
RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen
7676

77-
ENV LANG en_US.UTF-8
78-
ENV LANGUAGE en_US:en
79-
ENV LC_ALL en_US.UTF-8
77+
ENV LANG=en_US.UTF-8
78+
ENV LANGUAGE=en_US:en
79+
ENV LC_ALL=en_US.UTF-8
8080

8181
WORKDIR "/app"
8282
RUN chown nobody /app

nexus/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ and run:
3030

3131
```
3232
docker run \
33-
-e SECRET_KEY_BASE="secert" \
33+
-e SECRET_KEY_BASE="secret" \
3434
-e PHX_HOST=localhost \
3535
-e ADMIN_USERNAME=admin \
3636
-e ADMIN_PASSWORD=admin \
@@ -39,13 +39,13 @@ docker run \
3939
```
4040

4141
Note that secret has to be at least 64 bytes long.
42-
You can generate one with `mix phx.gen.secret`.
42+
You can generate one with `mix phx.gen.secret` or `head -c64 /dev/urandom | base64`.
4343

4444
If you are running on MacOS, instead of using `--network host` option, you have to explicitly publish ports:
4545

4646
```
4747
docker run \
48-
-e SECRET_KEY_BASE="secert" \
48+
-e SECRET_KEY_BASE="secret" \
4949
-e PHX_HOST=localhost \
5050
-e ADMIN_USERNAME=admin \
5151
-e ADMIN_PASSWORD=admin \

recognizer/Dockerfile

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ ARG DEBIAN_VERSION=bookworm-20240701-slim
1717
ARG BUILDER_IMAGE="hexpm/elixir:${ELIXIR_VERSION}-erlang-${OTP_VERSION}-debian-${DEBIAN_VERSION}"
1818
ARG RUNNER_IMAGE="debian:${DEBIAN_VERSION}"
1919

20-
FROM ${BUILDER_IMAGE} as builder
20+
FROM ${BUILDER_IMAGE} AS builder
2121

2222
# install build dependencies
2323
RUN apt-get update -y && apt-get install -y \
@@ -96,9 +96,9 @@ RUN apt-get update -y && \
9696
# Set the locale
9797
RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen
9898

99-
ENV LANG en_US.UTF-8
100-
ENV LANGUAGE en_US:en
101-
ENV LC_ALL en_US.UTF-8
99+
ENV LANG=en_US.UTF-8
100+
ENV LANGUAGE=en_US:en
101+
ENV LC_ALL=en_US.UTF-8
102102

103103
WORKDIR "/app"
104104
RUN chown nobody /app

recognizer/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ docker run -e SECRET_KEY_BASE="secret" -e PHX_HOST=localhost --network host reco
2626
```
2727

2828
Note that secret has to be at least 64 bytes long.
29-
You can generate one with `mix phx.gen.secret`.
29+
You can generate one with `mix phx.gen.secret` or `head -c64 /dev/urandom | base64`.
3030

3131
If you are running on MacOS, instead of using `--network host` option, you have to explicitly publish ports:
3232

0 commit comments

Comments
 (0)