Start visio with user colision
When user enter in colision with other colision, webrtc start visio
This commit is contained in:
parent
d7d7be9ed0
commit
707931724f
4 changed files with 20 additions and 16 deletions
|
@ -1,7 +1,7 @@
|
||||||
import {GameSceneInterface, GameScene} from "./GameScene";
|
import {GameSceneInterface, GameScene} from "./GameScene";
|
||||||
import {ROOM} from "../../Enum/EnvironmentVariable"
|
import {ROOM} from "../../Enum/EnvironmentVariable"
|
||||||
import {Connexion, ConnexionInterface, ListMessageUserPositionInterface} from "../../Connexion";
|
import {Connexion, ConnexionInterface, ListMessageUserPositionInterface} from "../../Connexion";
|
||||||
import {SimplePeer} from "../../WebRtc/SimplePeer";
|
import {SimplePeerInterface, SimplePeer} from "../../WebRtc/SimplePeer";
|
||||||
|
|
||||||
export enum StatusGameManagerEnum {
|
export enum StatusGameManagerEnum {
|
||||||
IN_PROGRESS = 1,
|
IN_PROGRESS = 1,
|
||||||
|
@ -13,12 +13,15 @@ export let ConnexionInstance : ConnexionInterface;
|
||||||
export interface GameManagerInterface {
|
export interface GameManagerInterface {
|
||||||
GameScenes: Array<GameSceneInterface>;
|
GameScenes: Array<GameSceneInterface>;
|
||||||
status : number;
|
status : number;
|
||||||
|
SimplePeer: SimplePeerInterface;
|
||||||
createCurrentPlayer() : void;
|
createCurrentPlayer() : void;
|
||||||
|
startWebRtc() : void;
|
||||||
shareUserPosition(ListMessageUserPosition : ListMessageUserPositionInterface): void;
|
shareUserPosition(ListMessageUserPosition : ListMessageUserPositionInterface): void;
|
||||||
}
|
}
|
||||||
export class GameManager implements GameManagerInterface {
|
export class GameManager implements GameManagerInterface {
|
||||||
GameScenes: Array<GameSceneInterface> = [];
|
GameScenes: Array<GameSceneInterface> = [];
|
||||||
status: number;
|
status: number;
|
||||||
|
SimplePeer : SimplePeerInterface;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.status = StatusGameManagerEnum.IN_PROGRESS;
|
this.status = StatusGameManagerEnum.IN_PROGRESS;
|
||||||
|
@ -29,8 +32,8 @@ export class GameManager implements GameManagerInterface {
|
||||||
return ConnexionInstance.createConnexion().then(() => {
|
return ConnexionInstance.createConnexion().then(() => {
|
||||||
this.configureGame();
|
this.configureGame();
|
||||||
/** TODO add loader in the page **/
|
/** TODO add loader in the page **/
|
||||||
//initialise cam
|
//initialise Pear Connexion of game
|
||||||
new SimplePeer(ConnexionInstance);
|
this.SimplePeer = new SimplePeer(ConnexionInstance);
|
||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
throw err;
|
throw err;
|
||||||
|
@ -59,6 +62,10 @@ export class GameManager implements GameManagerInterface {
|
||||||
this.status = StatusGameManagerEnum.CURRENT_USER_CREATED;
|
this.status = StatusGameManagerEnum.CURRENT_USER_CREATED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
startWebRtc() : void {
|
||||||
|
this.SimplePeer.startWebRtc();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Share position in game
|
* Share position in game
|
||||||
* @param ListMessageUserPosition
|
* @param ListMessageUserPosition
|
||||||
|
|
|
@ -253,6 +253,7 @@ export class GameScene extends Phaser.Scene implements GameSceneInterface{
|
||||||
//init colision
|
//init colision
|
||||||
this.physics.add.collider(this.CurrentPlayer, player, (CurrentPlayer: CurrentGamerInterface, MapPlayer: GamerInterface) => {
|
this.physics.add.collider(this.CurrentPlayer, player, (CurrentPlayer: CurrentGamerInterface, MapPlayer: GamerInterface) => {
|
||||||
CurrentPlayer.say("Hello, how are you ? ");
|
CurrentPlayer.say("Hello, how are you ? ");
|
||||||
|
this.GameManager.startWebRtc();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,13 +40,11 @@ export class MediaManager {
|
||||||
//update tracking
|
//update tracking
|
||||||
});
|
});
|
||||||
|
|
||||||
this.enabledMicrophone();
|
|
||||||
this.enabledCamera();
|
this.enabledCamera();
|
||||||
|
this.enabledMicrophone();
|
||||||
|
|
||||||
let webRtc = document.getElementById('webRtc');
|
let webRtc = document.getElementById('webRtc');
|
||||||
webRtc.classList.add('active');
|
webRtc.classList.add('active');
|
||||||
|
|
||||||
//this.getCamera();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
enabledCamera() {
|
enabledCamera() {
|
||||||
|
@ -55,7 +53,6 @@ export class MediaManager {
|
||||||
this.constraintsMedia.video = true;
|
this.constraintsMedia.video = true;
|
||||||
this.localStream = null;
|
this.localStream = null;
|
||||||
this.myCamVideo.srcObject = null;
|
this.myCamVideo.srcObject = null;
|
||||||
//this.getCamera();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
disabledCamera() {
|
disabledCamera() {
|
||||||
|
@ -73,14 +70,12 @@ export class MediaManager {
|
||||||
}
|
}
|
||||||
this.localStream = null;
|
this.localStream = null;
|
||||||
this.myCamVideo.srcObject = null;
|
this.myCamVideo.srcObject = null;
|
||||||
//this.getCamera();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
enabledMicrophone() {
|
enabledMicrophone() {
|
||||||
this.microphoneClose.style.display = "none";
|
this.microphoneClose.style.display = "none";
|
||||||
this.microphone.style.display = "block";
|
this.microphone.style.display = "block";
|
||||||
this.constraintsMedia.audio = true;
|
this.constraintsMedia.audio = true;
|
||||||
//this.getCamera();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
disabledMicrophone() {
|
disabledMicrophone() {
|
||||||
|
@ -94,7 +89,6 @@ export class MediaManager {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
//this.getCamera();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//get camera
|
//get camera
|
||||||
|
@ -103,7 +97,6 @@ export class MediaManager {
|
||||||
.then((stream: MediaStream) => {
|
.then((stream: MediaStream) => {
|
||||||
this.localStream = stream;
|
this.localStream = stream;
|
||||||
this.myCamVideo.srcObject = this.localStream;
|
this.myCamVideo.srcObject = this.localStream;
|
||||||
this.myCamVideo.play();
|
|
||||||
return stream;
|
return stream;
|
||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
|
@ -119,7 +112,6 @@ export class MediaManager {
|
||||||
addActiveVideo(userId : string){
|
addActiveVideo(userId : string){
|
||||||
let elementRemoteVideo = document.getElementById("activeCam");
|
let elementRemoteVideo = document.getElementById("activeCam");
|
||||||
elementRemoteVideo.insertAdjacentHTML('beforeend', '<video id="'+userId+'" autoplay></video>');
|
elementRemoteVideo.insertAdjacentHTML('beforeend', '<video id="'+userId+'" autoplay></video>');
|
||||||
|
|
||||||
this.remoteVideo[(userId as any)] = document.getElementById(userId);
|
this.remoteVideo[(userId as any)] = document.getElementById(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,10 @@ import {ConnexionInterface} from "../Connexion";
|
||||||
import {MediaManager} from "./MediaManager";
|
import {MediaManager} from "./MediaManager";
|
||||||
let Peer = require('simple-peer');
|
let Peer = require('simple-peer');
|
||||||
|
|
||||||
|
export interface SimplePeerInterface {
|
||||||
|
startWebRtc(): void;
|
||||||
|
}
|
||||||
|
|
||||||
export class SimplePeer {
|
export class SimplePeer {
|
||||||
Connexion: ConnexionInterface;
|
Connexion: ConnexionInterface;
|
||||||
MediaManager: MediaManager;
|
MediaManager: MediaManager;
|
||||||
|
@ -11,16 +15,16 @@ export class SimplePeer {
|
||||||
|
|
||||||
constructor(Connexion: ConnexionInterface, roomId: string = "test-webrtc") {
|
constructor(Connexion: ConnexionInterface, roomId: string = "test-webrtc") {
|
||||||
this.Connexion = Connexion;
|
this.Connexion = Connexion;
|
||||||
this.MediaManager = new MediaManager();
|
|
||||||
this.RoomId = roomId;
|
this.RoomId = roomId;
|
||||||
this.initialise();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* server has two person connected, start the meet
|
* server has two person connected, start the meet
|
||||||
*/
|
*/
|
||||||
initialise() {
|
startWebRtc() {
|
||||||
return this.MediaManager.getCamera().then(() => {
|
this.MediaManager = new MediaManager();
|
||||||
|
return this.MediaManager.getCamera().then((stream: MediaStream) => {
|
||||||
|
this.MediaManager.localStream = stream;
|
||||||
//send message to join a room
|
//send message to join a room
|
||||||
this.Connexion.sendWebrtcRomm(this.RoomId);
|
this.Connexion.sendWebrtcRomm(this.RoomId);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue