Add button to enter un visio

This commit is contained in:
gparant 2020-04-26 20:55:20 +02:00
parent 707931724f
commit b49c012319
7 changed files with 91 additions and 12 deletions

View file

@ -15,7 +15,6 @@ export interface GameManagerInterface {
status : number;
SimplePeer: SimplePeerInterface;
createCurrentPlayer() : void;
startWebRtc() : void;
shareUserPosition(ListMessageUserPosition : ListMessageUserPositionInterface): void;
}
export class GameManager implements GameManagerInterface {
@ -62,10 +61,6 @@ export class GameManager implements GameManagerInterface {
this.status = StatusGameManagerEnum.CURRENT_USER_CREATED;
}
startWebRtc() : void {
this.SimplePeer.startWebRtc();
}
/**
* Share position in game
* @param ListMessageUserPosition

View file

@ -253,7 +253,7 @@ export class GameScene extends Phaser.Scene implements GameSceneInterface{
//init colision
this.physics.add.collider(this.CurrentPlayer, player, (CurrentPlayer: CurrentGamerInterface, MapPlayer: GamerInterface) => {
CurrentPlayer.say("Hello, how are you ? ");
this.GameManager.startWebRtc();
this.GameManager.SimplePeer.activePhone();
});
}
}

View file

@ -1,25 +1,23 @@
export class MediaManager {
localStream: MediaStream;
remoteStream: MediaStream;
remoteVideo: Array<any> = new Array<any>();
myCamVideo: any;
cinemaClose: any = null;
cinema: any = null;
microphoneClose: any = null;
microphone: any = null;
constraintsMedia = {audio: true, video: true};
constraintsMedia = {audio: false, video: true};
getCameraPromise : Promise<any> = null;
constructor() {
this.myCamVideo = document.getElementById('myCamVideo');
this.microphoneClose = document.getElementById('microphone-close');
this.microphoneClose.addEventListener('click', (e: any) => {
e.preventDefault();
this.enabledMicrophone();
//update tracking
});
this.microphone = document.getElementById('microphone');
this.microphone.addEventListener('click', (e: any) => {
e.preventDefault();
@ -42,7 +40,9 @@ export class MediaManager {
this.enabledCamera();
this.enabledMicrophone();
}
activeVisio(){
let webRtc = document.getElementById('webRtc');
webRtc.classList.add('active');
}
@ -91,6 +91,18 @@ export class MediaManager {
}
}
getElementActivePhone(){
return document.getElementById('phone-open');
}
activePhoneOpen(){
return this.getElementActivePhone().classList.add("active");
}
disablePhoneOpen(){
return this.getElementActivePhone().classList.remove("active");
}
//get camera
getCamera() {
return this.getCameraPromise = navigator.mediaDevices.getUserMedia(this.constraintsMedia)

View file

@ -3,7 +3,8 @@ import {MediaManager} from "./MediaManager";
let Peer = require('simple-peer');
export interface SimplePeerInterface {
startWebRtc(): void;
activePhone(): void;
disablePhone(): void;
}
export class SimplePeer {
@ -16,13 +17,18 @@ export class SimplePeer {
constructor(Connexion: ConnexionInterface, roomId: string = "test-webrtc") {
this.Connexion = Connexion;
this.RoomId = roomId;
this.MediaManager = new MediaManager();
this.MediaManager.getElementActivePhone().addEventListener("click", () => {
this.startWebRtc();
this.disablePhone();
});
}
/**
* server has two person connected, start the meet
*/
startWebRtc() {
this.MediaManager = new MediaManager();
this.MediaManager.activeVisio();
return this.MediaManager.getCamera().then((stream: MediaStream) => {
this.MediaManager.localStream = stream;
//send message to join a room
@ -126,4 +132,12 @@ export class SimplePeer {
addMedia (userId : any) {
this.PeerConnexionArray[userId].addStream(this.MediaManager.localStream) // <- add streams to peer dynamically
}
activePhone(){
this.MediaManager.activePhoneOpen();
}
disablePhone(){
this.MediaManager.disablePhoneOpen();
}
}