Skip to content

Commit

Permalink
[K8sBroadcaster] Add some debug logs
Browse files Browse the repository at this point in the history
  • Loading branch information
mickel8 committed Jan 8, 2025
1 parent 5dfe5e2 commit 8f0a315
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,13 @@ defmodule K8sBroadcasterWeb.PageController do
args: [Path.join(:code.priv_dir(:k8s_broadcaster), "headless_client.js")],
env: [
{~c"TOKEN", String.to_charlist(whip_token)},
{~c"URL", String.to_charlist("#{conn.scheme}://#{conn.host}:#{conn.port}")}
{~c"URL", String.to_charlist("#{conn.scheme}://#{conn.host}:#{conn.port}") |> dbg()}
]
)

Port.monitor(port)

receive do
:exit ->
{:os_pid, os_pid} = Port.info(port, :os_pid)
Logger.info("Closing headless client")
# For some reason, doing Port.close does not work
System.shell("kill #{os_pid}")

{:DOWN, _ref, :port, _, reason} ->
Logger.info("Headless client exited with reason: #{inspect(reason)}")
end
stream_receive(port)
end)

conn
Expand All @@ -56,4 +47,21 @@ defmodule K8sBroadcasterWeb.PageController do
|> resp(201, "")
|> send_resp()
end

defp stream_receive(port) do
receive do
:exit ->
{:os_pid, os_pid} = Port.info(port, :os_pid)
Logger.info("Closing headless client")
# For some reason, doing Port.close does not work
System.shell("kill #{os_pid}")

{:DOWN, _ref, :port, _, reason} ->
Logger.info("Headless client exited with reason: #{inspect(reason)}")

other ->
dbg(other)
stream_receive(port)
end
end
end
5 changes: 5 additions & 0 deletions k8s_broadcaster/priv/headless_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const url =
process.env.URL === undefined ? "http://localhost:4000" : process.env.URL;
const token = process.env.TOKEN === undefined ? "example" : process.env.TOKEN;

console.log(url);

async function stream(url, token) {
console.log("Starting new stream...");
let response;
Expand Down Expand Up @@ -48,6 +50,9 @@ async function stream(url, token) {
const offer = await pc.createOffer();
await pc.setLocalDescription(offer);

console.log(url);
console.log(window.location.origin);

response = await fetch(`${url}/api/whip`, {
method: "POST",
cache: "no-cache",
Expand Down

0 comments on commit 8f0a315

Please sign in to comment.