import {GameSceneInterface, GameScene} from "./GameScene";
import {ROOM} from "../../Enum/EnvironmentVariable"
import {Connexion, ConnexionInterface, ListMessageUserPositionInterface} from "../../Connexion";
-import {SimplePeer} from "../../WebRtc/SimplePeer";
+import {SimplePeerInterface, SimplePeer} from "../../WebRtc/SimplePeer";
export enum StatusGameManagerEnum {
IN_PROGRESS = 1,
export interface GameManagerInterface {
GameScenes: Array<GameSceneInterface>;
status : number;
+ SimplePeer: SimplePeerInterface;
createCurrentPlayer() : void;
+ startWebRtc() : void;
shareUserPosition(ListMessageUserPosition : ListMessageUserPositionInterface): void;
}
export class GameManager implements GameManagerInterface {
GameScenes: Array<GameSceneInterface> = [];
status: number;
+ SimplePeer : SimplePeerInterface;
constructor() {
this.status = StatusGameManagerEnum.IN_PROGRESS;
return ConnexionInstance.createConnexion().then(() => {
this.configureGame();
/** TODO add loader in the page **/
- //initialise cam
- new SimplePeer(ConnexionInstance);
+ //initialise Pear Connexion of game
+ this.SimplePeer = new SimplePeer(ConnexionInstance);
}).catch((err) => {
console.error(err);
throw err;
this.status = StatusGameManagerEnum.CURRENT_USER_CREATED;
}
+ startWebRtc() : void {
+ this.SimplePeer.startWebRtc();
+ }
+
/**
* Share position in game
* @param ListMessageUserPosition
//init colision
this.physics.add.collider(this.CurrentPlayer, player, (CurrentPlayer: CurrentGamerInterface, MapPlayer: GamerInterface) => {
CurrentPlayer.say("Hello, how are you ? ");
+ this.GameManager.startWebRtc();
});
}
}
//update tracking
});
- this.enabledMicrophone();
this.enabledCamera();
+ this.enabledMicrophone();
let webRtc = document.getElementById('webRtc');
webRtc.classList.add('active');
-
- //this.getCamera();
}
enabledCamera() {
this.constraintsMedia.video = true;
this.localStream = null;
this.myCamVideo.srcObject = null;
- //this.getCamera();
}
disabledCamera() {
}
this.localStream = null;
this.myCamVideo.srcObject = null;
- //this.getCamera();
}
enabledMicrophone() {
this.microphoneClose.style.display = "none";
this.microphone.style.display = "block";
this.constraintsMedia.audio = true;
- //this.getCamera();
}
disabledMicrophone() {
}
});
}
- //this.getCamera();
}
//get camera
.then((stream: MediaStream) => {
this.localStream = stream;
this.myCamVideo.srcObject = this.localStream;
- this.myCamVideo.play();
return stream;
}).catch((err) => {
console.error(err);
addActiveVideo(userId : string){
let elementRemoteVideo = document.getElementById("activeCam");
elementRemoteVideo.insertAdjacentHTML('beforeend', '<video id="'+userId+'" autoplay></video>');
-
this.remoteVideo[(userId as any)] = document.getElementById(userId);
}
import {MediaManager} from "./MediaManager";
let Peer = require('simple-peer');
+export interface SimplePeerInterface {
+ startWebRtc(): void;
+}
+
export class SimplePeer {
Connexion: ConnexionInterface;
MediaManager: MediaManager;
constructor(Connexion: ConnexionInterface, roomId: string = "test-webrtc") {
this.Connexion = Connexion;
- this.MediaManager = new MediaManager();
this.RoomId = roomId;
- this.initialise();
}
/**
* server has two person connected, start the meet
*/
- initialise() {
- return this.MediaManager.getCamera().then(() => {
+ startWebRtc() {
+ this.MediaManager = new MediaManager();
+ return this.MediaManager.getCamera().then((stream: MediaStream) => {
+ this.MediaManager.localStream = stream;
//send message to join a room
this.Connexion.sendWebrtcRomm(this.RoomId);