Skip to content

Commit 2bdf80e

Browse files
authored
Merge pull request #29 from membraneframework/fix-media-constraints
Fix media constraints
2 parents db28d4d + 85ce5a9 commit 2bdf80e

File tree

7 files changed

+58
-50
lines changed

7 files changed

+58
-50
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ The package can be installed by adding `membrane_webrtc_plugin` to your list of
1515
```elixir
1616
def deps do
1717
[
18-
{:membrane_webrtc_plugin, "~> 0.25.2"}
18+
{:membrane_webrtc_plugin, "~> 0.25.3"}
1919
]
2020
end
2121
```

assets/capture.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export function createCaptureHook(iceServers = [{ urls: `stun:stun.l.google.com:
4040
await this.pc.setRemoteDescription(data);
4141
break;
4242
case `ice_candidate`:
43-
console.log(`[${this.el.id}] Recieved ICE candidate:`, data);
43+
console.log(`[${this.el.id}] Received ICE candidate:`, data);
4444
await this.pc.addIceCandidate(data);
4545
break;
4646
}

assets/player.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export function createPlayerHook(iceServers = [{ urls: `stun:stun.l.google.com:1
3232

3333
break;
3434
case `ice_candidate`:
35-
console.log(`[${this.el.id}] Recieved ICE candidate:`, data);
35+
console.log(`[${this.el.id}] Received ICE candidate:`, data);
3636
await this.pc.addIceCandidate(data);
3737
}
3838
});
Lines changed: 43 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
1-
import {Socket} from "phoenix"
1+
import { Socket } from "phoenix";
22

33
async function startEgressConnection(channel, topic) {
4-
const pcConfig = { 'iceServers': [{ 'urls': 'stun:stun.l.google.com:19302' },] };
5-
const mediaConstraints = { video: true, audio: true }
4+
const pcConfig = { iceServers: [{ urls: "stun:stun.l.google.com:19302" }] };
5+
const mediaConstraints = { video: true, audio: true };
66

7-
const connStatus = document.getElementById("status");
7+
const connStatus = document.getElementById("status");
88
const localStream = await navigator.mediaDevices.getUserMedia(mediaConstraints);
99
const pc = new RTCPeerConnection(pcConfig);
1010

11-
pc.onicecandidate = event => {
11+
pc.onicecandidate = (event) => {
1212
if (event.candidate === null) return;
1313
console.log("Sent ICE candidate:", event.candidate);
1414
channel.push(topic, JSON.stringify({ type: "ice_candidate", data: event.candidate }));
1515
};
1616

1717
pc.onconnectionstatechange = () => {
1818
if (pc.connectionState == "connected") {
19-
const button = document.createElement('button');
19+
const button = document.createElement("button");
2020
button.innerHTML = "Disconnect";
2121
button.onclick = () => {
22-
localStream.getTracks().forEach(track => track.stop())
23-
}
22+
localStream.getTracks().forEach((track) => track.stop());
23+
};
2424
connStatus.innerHTML = "Connected ";
2525
connStatus.appendChild(button);
2626
}
27-
}
27+
};
2828

2929
for (const track of localStream.getTracks()) {
3030
pc.addTrack(track, localStream);
3131
}
3232

33-
channel.on(topic, async payload=> {
34-
type = payload.type
35-
data = payload.data
33+
channel.on(topic, async (payload) => {
34+
type = payload.type;
35+
data = payload.data;
3636

3737
switch (type) {
3838
case "sdp_answer":
@@ -44,29 +44,29 @@ const connStatus = document.getElementById("status");
4444
await pc.addIceCandidate(data);
4545
break;
4646
}
47-
})
47+
});
4848

4949
const offer = await pc.createOffer();
5050
await pc.setLocalDescription(offer);
51-
console.log("Sent SDP offer:", offer)
51+
console.log("Sent SDP offer:", offer);
5252
channel.push(topic, JSON.stringify({ type: "sdp_offer", data: offer }));
5353
}
5454

5555
async function startIngressConnection(channel, topic) {
5656
videoPlayer.srcObject = new MediaStream();
5757

5858
const pc = new RTCPeerConnection(pcConfig);
59-
pc.ontrack = event => videoPlayer.srcObject.addTrack(event.track);
60-
pc.onicecandidate = event => {
59+
pc.ontrack = (event) => videoPlayer.srcObject.addTrack(event.track);
60+
pc.onicecandidate = (event) => {
6161
if (event.candidate === null) return;
6262

6363
console.log("Sent ICE candidate:", event.candidate);
6464
channel.push(topic, JSON.stringify({ type: "ice_candidate", data: event.candidate }));
6565
};
6666

67-
channel.on(topic, async payload => {
68-
type = payload.type
69-
data = payload.data
67+
channel.on(topic, async (payload) => {
68+
type = payload.type;
69+
data = payload.data;
7070

7171
switch (type) {
7272
case "sdp_offer":
@@ -75,31 +75,39 @@ async function startIngressConnection(channel, topic) {
7575
const answer = await pc.createAnswer();
7676
await pc.setLocalDescription(answer);
7777
channel.push(topic, JSON.stringify({ type: "sdp_answer", data: answer }));
78-
console.log("Sent SDP answer:", answer)
78+
console.log("Sent SDP answer:", answer);
7979
break;
8080
case "ice_candidate":
81-
console.log("Recieved ICE candidate:", data);
81+
console.log("Received ICE candidate:", data);
8282
await pc.addIceCandidate(data);
8383
}
8484
});
8585
}
86-
const videoPlayer = document.getElementById('videoPlayer');
87-
const signalingId = videoPlayer.getAttribute('signaling_id');
88-
89-
let socket = new Socket("/signaling", {params: {token: window.userToken}})
90-
socket.connect()
91-
let egressChannel = socket.channel(`${signalingId}_egress`)
92-
egressChannel.join()
93-
.receive("ok", resp => { console.log("Joined successfully to egress signaling socket", resp)
86+
const videoPlayer = document.getElementById("videoPlayer");
87+
const signalingId = videoPlayer.getAttribute("signaling_id");
88+
89+
let socket = new Socket("/signaling", { params: { token: window.userToken } });
90+
socket.connect();
91+
let egressChannel = socket.channel(`${signalingId}_egress`);
92+
egressChannel
93+
.join()
94+
.receive("ok", (resp) => {
95+
console.log("Joined successfully to egress signaling socket", resp);
9496
startEgressConnection(egressChannel, `${signalingId}_egress`);
9597
})
96-
.receive("error", resp => { console.log("Unable to join egress signaling socket", resp) })
98+
.receive("error", (resp) => {
99+
console.log("Unable to join egress signaling socket", resp);
100+
});
97101

98-
const pcConfig = { 'iceServers': [{ 'urls': 'stun:stun.l.google.com:19302' },] };
102+
const pcConfig = { iceServers: [{ urls: "stun:stun.l.google.com:19302" }] };
99103

100-
let ingressChannel = socket.channel(`${signalingId}_ingress`)
101-
ingressChannel.join()
102-
.receive("ok", resp => { console.log("Joined successfully to ingress signaling socket", resp)
104+
let ingressChannel = socket.channel(`${signalingId}_ingress`);
105+
ingressChannel
106+
.join()
107+
.receive("ok", (resp) => {
108+
console.log("Joined successfully to ingress signaling socket", resp);
103109
startIngressConnection(ingressChannel, `${signalingId}_ingress`);
104110
})
105-
.receive("error", resp => { console.log("Unable to join ingress signaling socket", resp) })
111+
.receive("error", (resp) => {
112+
console.log("Unable to join ingress signaling socket", resp);
113+
});
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
const videoPlayer = document.getElementById("videoPlayer");
2-
const pcConfig = { 'iceServers': [{ 'urls': 'stun:stun.l.google.com:19302' },] };
3-
const proto = window.location.protocol === "https:" ? "wss:" : "ws:"
2+
const pcConfig = { iceServers: [{ urls: "stun:stun.l.google.com:19302" }] };
3+
const proto = window.location.protocol === "https:" ? "wss:" : "ws:";
44
const ws = new WebSocket(`${proto}//${window.location.hostname}:8829`);
55
ws.onopen = () => start_connection(ws);
6-
ws.onclose = event => console.log("WebSocket connection was terminated:", event);
6+
ws.onclose = (event) => console.log("WebSocket connection was terminated:", event);
77

88
const start_connection = async (ws) => {
99
videoPlayer.srcObject = new MediaStream();
1010

1111
const pc = new RTCPeerConnection(pcConfig);
12-
pc.ontrack = event => videoPlayer.srcObject.addTrack(event.track);
13-
pc.onicecandidate = event => {
12+
pc.ontrack = (event) => videoPlayer.srcObject.addTrack(event.track);
13+
pc.onicecandidate = (event) => {
1414
if (event.candidate === null) return;
1515

1616
console.log("Sent ICE candidate:", event.candidate);
1717
ws.send(JSON.stringify({ type: "ice_candidate", data: event.candidate }));
1818
};
1919

20-
ws.onmessage = async event => {
20+
ws.onmessage = async (event) => {
2121
const { type, data } = JSON.parse(event.data);
2222

2323
switch (type) {
@@ -27,11 +27,11 @@ const start_connection = async (ws) => {
2727
const answer = await pc.createAnswer();
2828
await pc.setLocalDescription(answer);
2929
ws.send(JSON.stringify({ type: "sdp_answer", data: answer }));
30-
console.log("Sent SDP answer:", answer)
30+
console.log("Sent SDP answer:", answer);
3131
break;
3232
case "ice_candidate":
33-
console.log("Recieved ICE candidate:", data);
33+
console.log("Received ICE candidate:", data);
3434
await pc.addIceCandidate(data);
3535
}
3636
};
37-
};
37+
};

lib/membrane_webrtc/live/capture.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,8 @@ if Code.ensure_loaded?(Phoenix) and Code.ensure_loaded?(Phoenix.LiveView) do
197197
|> Signaling.register_peer(message_format: :json_data)
198198

199199
media_constraints = %{
200-
"audio" => inspect(capture.audio?),
201-
"video" => inspect(capture.video?)
200+
"audio" => capture.audio?,
201+
"video" => capture.video?
202202
}
203203

204204
socket

mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
defmodule Membrane.WebRTC.Plugin.Mixfile do
22
use Mix.Project
33

4-
@version "0.25.2"
4+
@version "0.25.3"
55
@github_url "https://github.com/membraneframework/membrane_webrtc_plugin"
66

77
def project do

0 commit comments

Comments
 (0)