Add feature to mute or switch off cam

This commit is contained in:
gparant 2020-05-03 17:19:42 +02:00
parent c48073b908
commit fb255140e5
5 changed files with 41 additions and 71 deletions

View file

@ -16,11 +16,15 @@ export class MediaManager {
video: videoConstraint
};
getCameraPromise : Promise<any> = null;
updatedLocalStreamCallBack : Function;
constructor(updatedLocalStreamCallBack : Function) {
this.updatedLocalStreamCallBack = updatedLocalStreamCallBack;
constructor() {
this.myCamVideo = document.getElementById('myCamVideo');
this.microphoneClose = document.getElementById('microphone-close');
this.microphoneClose = document.getElementById('microphone-close');
this.microphoneClose.style.display = "none";
this.microphoneClose.addEventListener('click', (e: any) => {
e.preventDefault();
this.enabledMicrophone();
@ -34,6 +38,7 @@ export class MediaManager {
});
this.cinemaClose = document.getElementById('cinema-close');
this.cinemaClose.style.display = "none";
this.cinemaClose.addEventListener('click', (e: any) => {
e.preventDefault();
this.enabledCamera();
@ -58,6 +63,9 @@ export class MediaManager {
this.constraintsMedia.video = videoConstraint;
this.localStream = null;
this.myCamVideo.srcObject = null;
this.getCamera().then((stream) => {
this.updatedLocalStreamCallBack(stream);
});
}
disabledCamera() {
@ -75,12 +83,18 @@ export class MediaManager {
}
this.localStream = null;
this.myCamVideo.srcObject = null;
this.getCamera().then((stream) => {
this.updatedLocalStreamCallBack(stream);
});
}
enabledMicrophone() {
this.microphoneClose.style.display = "none";
this.microphone.style.display = "block";
this.constraintsMedia.audio = true;
this.getCamera().then((stream) => {
this.updatedLocalStreamCallBack(stream);
});
}
disabledMicrophone() {
@ -94,18 +108,9 @@ export class MediaManager {
}
});
}
}
getElementActivePhone(){
return document.getElementById('phone-open');
}
activePhoneOpen(){
return this.getElementActivePhone().classList.add("active");
}
disablePhoneOpen(){
return this.getElementActivePhone().classList.remove("active");
this.getCamera().then((stream) => {
this.updatedLocalStreamCallBack(stream);
});
}
//get camera

View file

@ -17,7 +17,9 @@ export class SimplePeer {
constructor(Connexion: ConnexionInterface, WebRtcRoomId: string = "test-webrtc") {
this.Connexion = Connexion;
this.WebRtcRoomId = WebRtcRoomId;
this.MediaManager = new MediaManager();
this.MediaManager = new MediaManager((stream : MediaStream) => {
this.updatedLocalStream();
});
this.PeerConnexionArray = new Array<any>();
this.initialise();
@ -100,7 +102,7 @@ export class SimplePeer {
{
urls: 'turn:numb.viagenie.ca',
username: 'g.parant@thecodingmachine.com',
credential: 'Muzuvo$6'
credential: 'itcugcOHxle9Acqi$'
},
]
},
@ -202,4 +204,10 @@ export class SimplePeer {
console.error(`addMedia => addMedia => ${userId}`, e);
}
}
updatedLocalStream(){
this.Users.forEach((user) => {
this.addMedia(user.userId);
})
}
}