Start visio with user colision
authorgparant <g.parant@thecodingmachine.com>
Sun, 26 Apr 2020 17:59:51 +0000 (19:59 +0200)
committergparant <g.parant@thecodingmachine.com>
Sun, 26 Apr 2020 17:59:51 +0000 (19:59 +0200)
When user enter in colision with other colision, webrtc start visio

front/src/Phaser/Game/GameManager.ts
front/src/Phaser/Game/GameScene.ts
front/src/WebRtc/MediaManager.ts
front/src/WebRtc/SimplePeer.ts

index fbc1d5bde18eb6e42d8eeb272e38a57c4b8583a0..6121d262daa68d7be1672acf29edb8c836caed88 100644 (file)
@@ -1,7 +1,7 @@
 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,
@@ -13,12 +13,15 @@ export let ConnexionInstance : ConnexionInterface;
 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;
@@ -29,8 +32,8 @@ export class GameManager implements GameManagerInterface {
         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;
@@ -59,6 +62,10 @@ export class GameManager implements GameManagerInterface {
         this.status = StatusGameManagerEnum.CURRENT_USER_CREATED;
     }
 
+    startWebRtc() : void {
+        this.SimplePeer.startWebRtc();
+    }
+
     /**
      * Share position in game
      * @param ListMessageUserPosition
index a08c8fd2f34f33e86c97dbcb67f2a10cf47980f4..0fac397e35b691d3f3e84bbed99e991aaa9e594d 100644 (file)
@@ -253,6 +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();
         });
     }
 }
index 7363f1559a37b3b19f088e1607b18b1269a6fdcd..0d1a3a99ef5b9fb78fa2efe5c3a6632513fd88a0 100644 (file)
@@ -40,13 +40,11 @@ export class MediaManager {
             //update tracking
         });
 
-        this.enabledMicrophone();
         this.enabledCamera();
+        this.enabledMicrophone();
 
         let webRtc = document.getElementById('webRtc');
         webRtc.classList.add('active');
-
-        //this.getCamera();
     }
 
     enabledCamera() {
@@ -55,7 +53,6 @@ export class MediaManager {
         this.constraintsMedia.video = true;
         this.localStream = null;
         this.myCamVideo.srcObject = null;
-        //this.getCamera();
     }
 
     disabledCamera() {
@@ -73,14 +70,12 @@ export class MediaManager {
         }
         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() {
@@ -94,7 +89,6 @@ export class MediaManager {
                 }
             });
         }
-        //this.getCamera();
     }
 
     //get camera
@@ -103,7 +97,6 @@ export class MediaManager {
             .then((stream: MediaStream) => {
                 this.localStream = stream;
                 this.myCamVideo.srcObject = this.localStream;
-                this.myCamVideo.play();
                 return stream;
             }).catch((err) => {
                 console.error(err);
@@ -119,7 +112,6 @@ export class MediaManager {
     addActiveVideo(userId : string){
         let elementRemoteVideo = document.getElementById("activeCam");
         elementRemoteVideo.insertAdjacentHTML('beforeend', '<video id="'+userId+'" autoplay></video>');
-
         this.remoteVideo[(userId as any)] = document.getElementById(userId);
     }
 
index a410906b9b7c8bd60f368a9ec6d774780adf794d..86b33850560d57d1a2a083ce26221accddb42459 100644 (file)
@@ -2,6 +2,10 @@ import {ConnexionInterface} from "../Connexion";
 import {MediaManager} from "./MediaManager";
 let Peer = require('simple-peer');
 
+export interface SimplePeerInterface {
+    startWebRtc(): void;
+}
+
 export class SimplePeer {
     Connexion: ConnexionInterface;
     MediaManager: MediaManager;
@@ -11,16 +15,16 @@ export class SimplePeer {
 
     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);