From 0d257ee3d0789316b43a718b44192dc853a406bb Mon Sep 17 00:00:00 2001 From: "feliks.pobiedzinski@swmansion.com" Date: Mon, 3 Mar 2025 17:07:02 +0100 Subject: [PATCH] Send Objects via websocket instead of strings --- assets/capture.js | 4 ++-- assets/player.js | 4 ++-- lib/membrane_webrtc_live/capture.ex | 9 --------- lib/membrane_webrtc_live/player.ex | 9 --------- 4 files changed, 4 insertions(+), 22 deletions(-) diff --git a/assets/capture.js b/assets/capture.js index 46f7950..664bde2 100644 --- a/assets/capture.js +++ b/assets/capture.js @@ -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); }; @@ -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); }); }, diff --git a/assets/player.js b/assets/player.js index 54ca7a0..7a9e769 100644 --- a/assets/player.js +++ b/assets/player.js @@ -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); }; @@ -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); diff --git a/lib/membrane_webrtc_live/capture.ex b/lib/membrane_webrtc_live/capture.ex index ba01430..5d8b7bd 100644 --- a/lib/membrane_webrtc_live/capture.ex +++ b/lib/membrane_webrtc_live/capture.ex @@ -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)} """) @@ -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 diff --git a/lib/membrane_webrtc_live/player.ex b/lib/membrane_webrtc_live/player.ex index 7ca9026..b1a48e3 100644 --- a/lib/membrane_webrtc_live/player.ex +++ b/lib/membrane_webrtc_live/player.ex @@ -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)} """) @@ -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