Skip to content

Commit

Permalink
Send Objects via websocket instead of strings
Browse files Browse the repository at this point in the history
  • Loading branch information
FelonEkonom committed Mar 3, 2025
1 parent e6ce995 commit 0d257ee
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 22 deletions.
4 changes: 2 additions & 2 deletions assets/capture.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function createCaptureHook(iceServers = [{ urls: "stun:stun.l.google.com:
this.pc.onicecandidate = (event) => {
if (event.candidate === null) return;
console.log("[" + this.el.id + "] Sent ICE candidate:", event.candidate);
message = JSON.stringify({ type: "ice_candidate", data: event.candidate });
message = { type: "ice_candidate", data: event.candidate };
this.pushEventTo(this.el, "webrtc_signaling", message);
};

Expand Down Expand Up @@ -49,7 +49,7 @@ export function createCaptureHook(iceServers = [{ urls: "stun:stun.l.google.com:
const offer = await this.pc.createOffer();
await this.pc.setLocalDescription(offer);
console.log("[" + this.el.id + "] Sent SDP offer:", offer);
message = JSON.stringify({ type: "sdp_offer", data: offer });
message = { type: "sdp_offer", data: offer };
this.pushEventTo(this.el, "webrtc_signaling", message);
});
},
Expand Down
4 changes: 2 additions & 2 deletions assets/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export function createPlayerHook(iceServers = [{ urls: "stun:stun.l.google.com:1

this.pc.onicecandidate = (ev) => {
console.log("[" + this.el.id + "] Sent ICE candidate:", ev.candidate);
message = JSON.stringify({ type: "ice_candidate", data: ev.candidate });
message = { type: "ice_candidate", data: ev.candidate };
this.pushEventTo(this.el, "webrtc_signaling", message);
};

Expand All @@ -26,7 +26,7 @@ export function createPlayerHook(iceServers = [{ urls: "stun:stun.l.google.com:1
const answer = await this.pc.createAnswer();
await this.pc.setLocalDescription(answer);

message = JSON.stringify({ type: "sdp_answer", data: answer });
message = { type: "sdp_answer", data: answer };
this.pushEventTo(this.el, "webrtc_signaling", message);
console.log("[" + this.el.id + "] Sent SDP answer:", answer);

Expand Down
9 changes: 0 additions & 9 deletions lib/membrane_webrtc_live/capture.ex
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,6 @@ defmodule Membrane.WebRTC.Live.Capture do

@impl true
def handle_event("webrtc_signaling", message, socket) do
# this is a hack to supress dialyzer, that for some reason thinks that `message`
# is a map, while it is a binary
message =
apply(__MODULE__, :identity, [message])
|> Jason.decode!()

Logger.debug("""
#{log_prefix(socket.assigns.capture.id)} Received WebRTC signaling message: #{inspect(message, pretty: true)}
""")
Expand All @@ -233,7 +227,4 @@ defmodule Membrane.WebRTC.Live.Capture do
end

defp log_prefix(id), do: [module: __MODULE__, id: id] |> inspect()

@spec identity(term()) :: term()
def identity(sth), do: sth
end
9 changes: 0 additions & 9 deletions lib/membrane_webrtc_live/player.ex
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,6 @@ defmodule Membrane.WebRTC.Live.Player do

@impl true
def handle_event("webrtc_signaling", message, socket) do
# this is a hack to supress dialyzer, that for some reason thinks that `message`
# is a map, while it is a binary
message =
apply(__MODULE__, :identity, [message])
|> Jason.decode!()

Logger.debug("""
#{log_prefix(socket.assigns.player.id)} Received WebRTC signaling message: #{inspect(message, pretty: true)}
""")
Expand All @@ -201,7 +195,4 @@ defmodule Membrane.WebRTC.Live.Player do
end

defp log_prefix(id), do: [module: __MODULE__, id: id] |> inspect()

@spec identity(term()) :: term()
def identity(sth), do: sth
end

0 comments on commit 0d257ee

Please sign in to comment.