Update front mutli peer conncexion
This commit is contained in:
parent
575054fe4f
commit
e4a30712b5
@ -118,8 +118,8 @@ export class MediaManager {
|
|||||||
*/
|
*/
|
||||||
addActiveVideo(userId : any){
|
addActiveVideo(userId : any){
|
||||||
let elementRemoteVideo = document.getElementById("activeCam");
|
let elementRemoteVideo = document.getElementById("activeCam");
|
||||||
elementRemoteVideo.insertAdjacentHTML('beforeend', '<video id="myCamVideo'+userId+'" autoplay></video>');
|
elementRemoteVideo.insertAdjacentHTML('beforeend', '<video id="'+userId+'" autoplay></video>');
|
||||||
|
|
||||||
this.remoteVideo[userId] = document.getElementById('myCamVideo'+userId);
|
this.remoteVideo[userId] = document.getElementById(userId);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -41,47 +41,61 @@ export class SimplePeer {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
* @param message
|
||||||
*/
|
*/
|
||||||
receiveWebrtcStart(message: string) {
|
receiveWebrtcStart(message: string) {
|
||||||
let data = JSON.parse(message);
|
let data = JSON.parse(message);
|
||||||
|
|
||||||
//create pear connexion of user stared
|
//create pear connexion of user stared
|
||||||
this.createPeerConnexion(data.usersId, data.initiator);
|
this.createPeerConnexion(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param userId
|
* @param users
|
||||||
* @param initiator
|
|
||||||
*/
|
*/
|
||||||
createPeerConnexion(usersId : Array<string>, initiator : boolean = false) {
|
createPeerConnexion(users : Array<any>) {
|
||||||
usersId.forEach((userId: any) => {
|
console.log("createPeerConnexion", users);
|
||||||
if(this.PeerConnexionArray[userId]){
|
users.forEach((user: any) => {
|
||||||
|
if(this.PeerConnexionArray[user.userId]){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.MediaManager.addActiveVideo(userId);
|
this.MediaManager.addActiveVideo(user.userId);
|
||||||
|
|
||||||
this.PeerConnexion = new Peer({initiator: initiator});
|
this.PeerConnexion = new Peer({initiator: user.initiator});
|
||||||
|
|
||||||
this.PeerConnexion.on('signal', (data: any) => {
|
this.PeerConnexion.on('signal', (data: any) => {
|
||||||
this.sendWebrtcSignal(data);
|
this.sendWebrtcSignal(data);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.PeerConnexion.on('stream', (stream: MediaStream) => {
|
this.PeerConnexion.on('stream', (stream: MediaStream) => {
|
||||||
this.stream(userId, stream);
|
this.stream(user.userId, stream);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.PeerConnexionArray[userId] = this.PeerConnexion;
|
this.PeerConnexionArray[user.userId] = this.PeerConnexion;
|
||||||
this.addMedia(userId);
|
this.addMedia(user.userId);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/*let elements = document.getElementById("activeCam");
|
||||||
|
console.log("element.childNodes", elements.childNodes);
|
||||||
|
elements.childNodes.forEach((element : any) => {
|
||||||
|
if(!element.id){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(users.find((user) => user.userId === element.id)){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
elements.removeChild(element);
|
||||||
|
});*/
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* permit to send signal
|
*
|
||||||
|
* @param userId
|
||||||
* @param data
|
* @param data
|
||||||
*/
|
*/
|
||||||
sendWebrtcSignal(data: any) {
|
sendWebrtcSignal(data: any, userId : string) {
|
||||||
this.Connexion.sendWebrtcSignal(data, this.RoomId);
|
this.Connexion.sendWebrtcSignal(data, this.RoomId, userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user