Skip to content

Commit

Permalink
add ability to disable audio/video from output
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Pokotilo committed Jun 22, 2022
1 parent a51c1fe commit c943908
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
7 changes: 7 additions & 0 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ <h3> Video Resolution</h3>
</select>
<input type="checkbox" id="natural" checked onclick="onSwapRotation()">
<label for="natural">Natural Video</label>
<input type="checkbox" id="videoRequired" checked>
<label for="videoRequired">Stream Video</label>
<input type="checkbox" id="audioRequired" checked>
<label for="audioRequired">Stream Audio</label>
</div>
<h3> Local Video </h3>
<div id="localVideoWrp">
Expand Down Expand Up @@ -84,6 +88,9 @@ <h3> Logs </h3>
videoBandwidth: document.getElementById("bandwidth").value,
width: document.getElementById("resolution").value.split('x')[0],
height: document.getElementById("resolution").value.split('x')[1],
videoRequired: document.getElementById("videoRequired").checked,
audioRequired: document.getElementById("audioRequired").checked,

onPublisherCreated: function(settings){ logItem('Ready to WebRTC publishing'); },
onConnectionStateChange: function(connectionState){ logItem('Connection state change', connectionState); },
onIceconnectionStateChange: function(connectionIceState){ logItem('Connection ice state change', connectionIceState); },
Expand Down
18 changes: 12 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export default class WebRTCjs {
videoBandwidth: 0,
width: 640,
height: 480,

videoRequired: true,
audioRequired: true,
onConnectionStateChange: null,
onPublisherCreated: null,
onOffer: null,
Expand Down Expand Up @@ -42,13 +43,18 @@ export default class WebRTCjs {

async publish() {

let constraints = {
audio: true,
video: {
let constraints = {};


constraints.audio = this.settings.audioRequired;
if(this.settings.videoRequired) {
constraints.video = {
width: this.settings.width,
height: this.settings.height
}
};
};
} else {
constraints.video = false;
}

this.stream = await navigator.mediaDevices.getUserMedia(constraints);

Expand Down

0 comments on commit c943908

Please sign in to comment.