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;
});
}
}
+
export interface ConnexionInterface {
- socket : any;
- token : string;
- email : string;
+ socket: any;
+ token: string;
+ email: string;
userId: string;
- startedRoom : string;
- createConnexion() : Promise<any>;
- joinARoom(roomId : string) : void;
- sharePosition(x : number, y : number, direction : string) : void;
- positionOfAllUser() : void;
+ startedRoom: string;
+
+ createConnexion(): Promise<any>;
+
+ 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;
}
* @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());
}
/**
- 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,
export let ConnexionInstance : ConnexionInterface;
- export interface GameManagerInterface {
- GameScenes: Array<GameSceneInterface>;
- status : number;
- SimplePeer: SimplePeerInterface;
- createCurrentPlayer() : void;
- shareUserPosition(ListMessageUserPosition : ListMessageUserPositionInterface): void;
- connect(email : string) : Promise<any>;
- }
- export class GameManager implements GameManagerInterface {
- GameScenes: Array<GameSceneInterface> = [];
+ 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<any> {
- 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