From: gparant Date: Wed, 29 Apr 2020 15:37:17 +0000 (+0200) Subject: Merge remote-tracking branch 'github.com/master' into webrtc X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=91851c95f3135dd84de56132997a277ae8dff153;p=libreadventure.git Merge remote-tracking branch 'github.com/master' into webrtc # Conflicts: # front/src/Connexion.ts # front/src/Phaser/Game/GameManager.ts # front/src/Phaser/Game/GameScene.ts # front/src/index.ts --- 91851c95f3135dd84de56132997a277ae8dff153 diff --cc front/src/Connexion.ts index 77c9619,d3c4b87..dc48833 --- a/front/src/Connexion.ts +++ b/front/src/Connexion.ts @@@ -2,16 -2,8 +2,16 @@@ import {GameManager} from "./Phaser/Gam const SocketIo = require('socket.io-client'); import Axios from "axios"; - import {API_URL} from "./Enum/EnvironmentVariable"; + import {API_URL, ROOM} from "./Enum/EnvironmentVariable"; +enum EventMessage{ + WEBRTC_SIGNAL = "webrtc-signal", + WEBRTC_START = "webrtc-start", + JOIN_ROOM = "join-room", + USER_POSITION = "user-position", + MESSAGE_ERROR = "message-error" +} + class Message { userId: string; roomId: string; @@@ -109,40 -99,27 +109,40 @@@ class ListMessageUserPosition }); } } + export interface ConnexionInterface { - socket : any; - token : string; - email : string; + socket: any; + token: string; + email: string; userId: string; - startedRoom : string; - createConnexion() : Promise; - joinARoom(roomId : string) : void; - sharePosition(x : number, y : number, direction : string) : void; - positionOfAllUser() : void; + startedRoom: string; + + createConnexion(): Promise; + + joinARoom(roomId: string): void; + - sharePosition(roomId: string, x: number, y: number, direction: string): void; ++ sharePosition(x: number, y: number, direction: string): void; + + positionOfAllUser(): void; + + /*webrtc*/ + sendWebrtcSignal(signal: any, roomId: string, userId?: string, receiverId?: string): void; + + receiveWebrtcSignal(callBack: Function): void; + + receiveWebrtcStart(callBack: Function): void; } -export class Connexion implements ConnexionInterface{ - socket : any; - token : string; - email : string; + +export class Connexion implements ConnexionInterface { + socket: any; + token: string; + email: string; userId: string; - startedRoom : string; + startedRoom: string; - GameManager: GameManagerInterface; + GameManager: GameManager; - constructor(email: string, GameManager: GameManagerInterface) { + constructor(email : string, GameManager: GameManager) { this.email = email; this.GameManager = GameManager; } @@@ -194,12 -170,12 +193,12 @@@ * @param y * @param direction */ - sharePosition(roomId: string, x: number, y: number, direction: string = "none"): void { - if (!this.socket) { + sharePosition(x : number, y : number, direction : string = "none") : void{ + if(!this.socket){ return; } - let messageUserPosition = new MessageUserPosition(this.userId, roomId, new Point(x, y, direction)); + let messageUserPosition = new MessageUserPosition(this.userId, ROOM[0], new Point(x, y, direction)); - this.socket.emit('user-position', messageUserPosition.toString()); + this.socket.emit(EventMessage.USER_POSITION, messageUserPosition.toString()); } /** diff --cc front/src/Phaser/Game/GameManager.ts index 52f0805,916840f..1877b29 --- a/front/src/Phaser/Game/GameManager.ts +++ b/front/src/Phaser/Game/GameManager.ts @@@ -1,8 -1,6 +1,8 @@@ - import {GameSceneInterface, GameScene} from "./GameScene"; + import {GameScene} from "./GameScene"; import {ROOM} from "../../Enum/EnvironmentVariable" import {Connexion, ConnexionInterface, ListMessageUserPositionInterface} from "../../Connexion"; +import {SimplePeerInterface, SimplePeer} from "../../WebRtc/SimplePeer"; +import {LogincScene} from "../Login/LogincScene"; export enum StatusGameManagerEnum { IN_PROGRESS = 1, @@@ -11,52 -9,28 +11,31 @@@ export let ConnexionInstance : ConnexionInterface; - export interface GameManagerInterface { - GameScenes: Array; - status : number; - SimplePeer: SimplePeerInterface; - createCurrentPlayer() : void; - shareUserPosition(ListMessageUserPosition : ListMessageUserPositionInterface): void; - connect(email : string) : Promise; - } - export class GameManager implements GameManagerInterface { - GameScenes: Array = []; + export class GameManager { status: number; + private ConnexionInstance: Connexion; + private currentGameScene: GameScene; + SimplePeer : SimplePeerInterface; constructor() { this.status = StatusGameManagerEnum.IN_PROGRESS; - this.configureGame(); } - - /** - * - * @param email - */ - connect(email : string) : Promise { - ConnexionInstance = new Connexion(email, this); - return ConnexionInstance.createConnexion().then(() => { + + connect(email:string) { + this.ConnexionInstance = new Connexion(email, this); + ConnexionInstance = this.ConnexionInstance; - return this.ConnexionInstance.createConnexion() ++ return this.ConnexionInstance.createConnexion().then(() => { + this.SimplePeer = new SimplePeer(ConnexionInstance); + }); } - + - /** - * permit to config rooms - */ - configureGame() { - //create login scene - let LoginScene = new LogincScene(); - this.GameScenes.push(LoginScene) - - //create scene - ROOM.forEach((roomId) => { - let newGame = new GameScene(roomId, this); - this.GameScenes.push((newGame as GameSceneInterface)); - }); + setCurrentGameScene(gameScene: GameScene) { + this.currentGameScene = gameScene; } + /** - * + * Permit to create player in started room */ createCurrentPlayer(): void { //Get started room send by the backend