Skip to content

Commit

Permalink
Suffix event names with player id
Browse files Browse the repository at this point in the history
  • Loading branch information
FelonEkonom committed Feb 12, 2025
1 parent 8922025 commit ee595c4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/webrtc/player.ex
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ defmodule Boombox.Live.Player do

{:noreply,
socket
|> push_event("webrtc_signaling", message)}
|> push_event("webrtc_signaling-#{socket.assigns.player.id}", message)}
end

@impl true
Expand Down
6 changes: 2 additions & 4 deletions player_demo.exs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ defmodule Example.HomeLive do
this.pc = new RTCPeerConnection({ iceServers: iceServers });
this.el.srcObject = new MediaStream()
// todo: get element by player id, different for every player
this.pc.ontrack = (event) => {
console.log("NEW TRACK", this.el)
this.el.srcObject.addTrack(event.track);
Expand All @@ -115,14 +114,13 @@ defmodule Example.HomeLive do
this.pushEventTo(this.el, "webrtc_signaling", message);
};
// todo: event name ("webrtc_signaling") should be suffixed with the component id
this.handleEvent("webrtc_signaling", async (event) => {
const eventName = "webrtc_signaling-" + this.el.id
this.handleEvent(eventName, async (event) => {
console.log("NEW SIGNALING MESSAGE", event)
const { type, data } = event;
switch (type) {
case "sdp_offer":
console.log("Received SDP offer:", data);
Expand Down

0 comments on commit ee595c4

Please sign in to comment.