From 1fa39b07819eda40dc345c107d7add54df1eb38a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Sun, 24 May 2020 23:14:12 +0200 Subject: [PATCH] Fixing typos. Replaced connexion with connection and LogincScene with LoginScene --- front/src/{Connexion.ts => Connection.ts} | 12 +-- front/src/Phaser/Game/AddPlayerInterface.ts | 2 +- front/src/Phaser/Game/GameManager.ts | 20 ++--- front/src/Phaser/Game/GameScene.ts | 4 +- .../Login/{LogincScene.ts => LoginScene.ts} | 4 +- front/src/Phaser/Player/Player.ts | 2 +- front/src/WebRtc/SimplePeer.ts | 74 +++++++++---------- front/src/index.ts | 4 +- 8 files changed, 61 insertions(+), 61 deletions(-) rename front/src/{Connexion.ts => Connection.ts} (96%) rename front/src/Phaser/Login/{LogincScene.ts => LoginScene.ts} (98%) diff --git a/front/src/Connexion.ts b/front/src/Connection.ts similarity index 96% rename from front/src/Connexion.ts rename to front/src/Connection.ts index 9aa5135e..52d88da0 100644 --- a/front/src/Connexion.ts +++ b/front/src/Connection.ts @@ -120,13 +120,13 @@ export interface GroupCreatedUpdatedMessageInterface { groupId: string } -export interface ConnexionInterface { +export interface ConnectionInterface { socket: any; token: string; name: string; userId: string; - createConnexion(name: string, characterSelected: string): Promise; + createConnection(name: string, characterSelected: string): Promise; loadStartMap(): Promise; @@ -146,7 +146,7 @@ export interface ConnexionInterface { disconnectMessage(callBack: Function): void; } -export class Connexion implements ConnexionInterface { +export class Connection implements ConnectionInterface { socket: Socket; token: string; name: string; // TODO: drop "name" storage here @@ -162,7 +162,7 @@ export class Connexion implements ConnexionInterface { this.GameManager = GameManager; } - createConnexion(name: string, characterSelected: string): Promise { + createConnection(name: string, characterSelected: string): Promise { this.name = name; this.character = characterSelected; return Axios.post(`${API_URL}/login`, {name: name}) @@ -185,7 +185,7 @@ export class Connexion implements ConnexionInterface { * * @param character */ - connectSocketServer(): Promise{ + connectSocketServer(): Promise{ //listen event this.positionOfAllUser(); this.disconnectServer(); @@ -196,7 +196,7 @@ export class Connexion implements ConnexionInterface { this.onUserMoved(); this.onUserLeft(); - return new Promise((resolve, reject) => { + return new Promise((resolve, reject) => { this.socket.emit(EventMessage.SET_PLAYER_DETAILS, { name: this.name, character: this.character diff --git a/front/src/Phaser/Game/AddPlayerInterface.ts b/front/src/Phaser/Game/AddPlayerInterface.ts index 473fea29..9570c765 100644 --- a/front/src/Phaser/Game/AddPlayerInterface.ts +++ b/front/src/Phaser/Game/AddPlayerInterface.ts @@ -1,4 +1,4 @@ -import {PointInterface} from "../../Connexion"; +import {PointInterface} from "../../Connection"; export interface AddPlayerInterface { userId: string; diff --git a/front/src/Phaser/Game/GameManager.ts b/front/src/Phaser/Game/GameManager.ts index 797688b5..1b1bd337 100644 --- a/front/src/Phaser/Game/GameManager.ts +++ b/front/src/Phaser/Game/GameManager.ts @@ -1,6 +1,6 @@ import {GameScene} from "./GameScene"; import { - Connexion, + Connection, GroupCreatedUpdatedMessageInterface, ListMessageUserPositionInterface, MessageUserJoined, @@ -8,7 +8,7 @@ import { MessageUserPositionInterface, Point, PointInterface -} from "../../Connexion"; +} from "../../Connection"; import {SimplePeerInterface, SimplePeer} from "../../WebRtc/SimplePeer"; import {AddPlayerInterface} from "./AddPlayerInterface"; import {ReconnectingSceneName} from "../Reconnecting/ReconnectingScene"; @@ -32,7 +32,7 @@ export interface MapObject { export class GameManager { status: number; - private ConnexionInstance: Connexion; + private ConnectionInstance: Connection; private currentGameScene: GameScene; private playerName: string; SimplePeer : SimplePeerInterface; @@ -45,9 +45,9 @@ export class GameManager { connect(name: string, characterUserSelected : string) { this.playerName = name; this.characterUserSelected = characterUserSelected; - this.ConnexionInstance = new Connexion(this); - return this.ConnexionInstance.createConnexion(name, characterUserSelected).then((data : any) => { - this.SimplePeer = new SimplePeer(this.ConnexionInstance); + this.ConnectionInstance = new Connection(this); + return this.ConnectionInstance.createConnection(name, characterUserSelected).then((data : any) => { + this.SimplePeer = new SimplePeer(this.ConnectionInstance); return data; }).catch((err) => { throw err; @@ -55,7 +55,7 @@ export class GameManager { } loadStartMap(){ - return this.ConnexionInstance.loadStartMap().then((data) => { + return this.ConnectionInstance.loadStartMap().then((data) => { return data; }).catch((err) => { throw err; @@ -77,7 +77,7 @@ export class GameManager { } joinRoom(sceneKey: string, startX: number, startY: number, direction: string, moving: boolean){ - this.ConnexionInstance.joinARoom(sceneKey, startX, startY, direction, moving); + this.ConnectionInstance.joinARoom(sceneKey, startX, startY, direction, moving); } onUserJoins(message: MessageUserJoined): void { @@ -156,7 +156,7 @@ export class GameManager { } getPlayerId(): string { - return this.ConnexionInstance.userId; + return this.ConnectionInstance.userId; } getCharacterSelected(): string { @@ -164,7 +164,7 @@ export class GameManager { } pushPlayerPosition(event: HasMovedEvent) { - this.ConnexionInstance.sharePosition(event.x, event.y, event.direction, event.moving); + this.ConnectionInstance.sharePosition(event.x, event.y, event.direction, event.moving); } loadMap(mapUrl: string, scene: Phaser.Scenes.ScenePlugin, instance: string): string { diff --git a/front/src/Phaser/Game/GameScene.ts b/front/src/Phaser/Game/GameScene.ts index 4558bc7f..dfaf376a 100644 --- a/front/src/Phaser/Game/GameScene.ts +++ b/front/src/Phaser/Game/GameScene.ts @@ -3,7 +3,7 @@ import { GroupCreatedUpdatedMessageInterface, MessageUserMovedInterface, MessageUserPositionInterface, PointInterface, PositionInterface -} from "../../Connexion"; +} from "../../Connection"; import {CurrentGamerInterface, GamerInterface, hasMovedEventName, Player} from "../Player/Player"; import { DEBUG_MODE, ZOOM_LEVEL} from "../../Enum/EnvironmentVariable"; import {ITiledMap, ITiledMapLayer, ITiledTileSet} from "../Map/ITiledMap"; @@ -301,7 +301,7 @@ export class GameScene extends Phaser.Scene { //initialise player //TODO create animation moving between exit and start this.CurrentPlayer = new Player( - null, // The current player is not has no id (because the id can change if connexion is lost and we should check that id using the GameManager. + null, // The current player is not has no id (because the id can change if connection is lost and we should check that id using the GameManager. this, this.startX, this.startY, diff --git a/front/src/Phaser/Login/LogincScene.ts b/front/src/Phaser/Login/LoginScene.ts similarity index 98% rename from front/src/Phaser/Login/LogincScene.ts rename to front/src/Phaser/Login/LoginScene.ts index 9886f42b..4b42c6a9 100644 --- a/front/src/Phaser/Login/LogincScene.ts +++ b/front/src/Phaser/Login/LoginScene.ts @@ -6,7 +6,7 @@ import Image = Phaser.GameObjects.Image; import Rectangle = Phaser.GameObjects.Rectangle; import {PLAYER_RESOURCES} from "../Entity/PlayableCaracter"; import {cypressAsserter} from "../../Cypress/CypressAsserter"; -import {GroupCreatedUpdatedMessageInterface, MessageUserJoined, MessageUserPositionInterface} from "../../Connexion"; +import {GroupCreatedUpdatedMessageInterface, MessageUserJoined, MessageUserPositionInterface} from "../../Connection"; //todo: put this constants in a dedicated file export const LoginSceneName = "LoginScene"; @@ -16,7 +16,7 @@ enum LoginTextures { mainFont = "main_font" } -export class LogincScene extends Phaser.Scene { +export class LoginScene extends Phaser.Scene { private nameInput: TextInput; private textField: TextField; private playButton: ClickButton; diff --git a/front/src/Phaser/Player/Player.ts b/front/src/Phaser/Player/Player.ts index fe8e5b7f..2b5f8fea 100644 --- a/front/src/Phaser/Player/Player.ts +++ b/front/src/Phaser/Player/Player.ts @@ -1,6 +1,6 @@ import {getPlayerAnimations, PlayerAnimationNames} from "./Animation"; import {GameScene, Textures} from "../Game/GameScene"; -import {MessageUserPositionInterface, PointInterface} from "../../Connexion"; +import {MessageUserPositionInterface, PointInterface} from "../../Connection"; import {ActiveEventList, UserInputEvent, UserInputManager} from "../UserInput/UserInputManager"; import {PlayableCaracter} from "../Entity/PlayableCaracter"; diff --git a/front/src/WebRtc/SimplePeer.ts b/front/src/WebRtc/SimplePeer.ts index b301876e..3693924d 100644 --- a/front/src/WebRtc/SimplePeer.ts +++ b/front/src/WebRtc/SimplePeer.ts @@ -1,4 +1,4 @@ -import {ConnexionInterface} from "../Connexion"; +import {ConnectionInterface} from "../Connection"; import {MediaManager} from "./MediaManager"; let Peer = require('simple-peer'); @@ -9,16 +9,16 @@ class UserSimplePear{ } export class SimplePeerInterface {} export class SimplePeer implements SimplePeerInterface{ - private Connexion: ConnexionInterface; + private Connection: ConnectionInterface; private WebRtcRoomId: string; private Users: Array = new Array(); private MediaManager: MediaManager; - private PeerConnexionArray: Map = new Map(); + private PeerConnectionArray: Map = new Map(); - constructor(Connexion: ConnexionInterface, WebRtcRoomId: string = "test-webrtc") { - this.Connexion = Connexion; + constructor(Connection: ConnectionInterface, WebRtcRoomId: string = "test-webrtc") { + this.Connection = Connection; this.WebRtcRoomId = WebRtcRoomId; this.MediaManager = new MediaManager((stream : MediaStream) => { this.updatedLocalStream(); @@ -32,7 +32,7 @@ export class SimplePeer implements SimplePeerInterface{ private initialise() { //receive signal by gemer - this.Connexion.receiveWebrtcSignal((message: any) => { + this.Connection.receiveWebrtcSignal((message: any) => { this.receiveWebrtcSignal(message); }); @@ -40,7 +40,7 @@ export class SimplePeer implements SimplePeerInterface{ this.MediaManager.getCamera().then(() => { //receive message start - this.Connexion.receiveWebrtcStart((message: any) => { + this.Connection.receiveWebrtcStart((message: any) => { this.receiveWebrtcStart(message); }); @@ -49,8 +49,8 @@ export class SimplePeer implements SimplePeerInterface{ }); //receive signal by gemer - this.Connexion.disconnectMessage((data: any) => { - this.closeConnexion(data.userId); + this.Connection.disconnectMessage((data: any) => { + this.closeConnection(data.userId); }); } @@ -58,7 +58,7 @@ export class SimplePeer implements SimplePeerInterface{ this.WebRtcRoomId = data.roomId; this.Users = data.clients; - //start connexion + //start connection this.startWebRtc(); } @@ -67,19 +67,19 @@ export class SimplePeer implements SimplePeerInterface{ */ private startWebRtc() { this.Users.forEach((user: UserSimplePear) => { - //if it's not an initiator, peer connexion will be created when gamer will receive offer signal + //if it's not an initiator, peer connection will be created when gamer will receive offer signal if(!user.initiator){ return; } - this.createPeerConnexion(user); + this.createPeerConnection(user); }); } /** - * create peer connexion to bind users + * create peer connection to bind users */ - private createPeerConnexion(user : UserSimplePear) { - if(this.PeerConnexionArray.has(user.userId)) { + private createPeerConnection(user : UserSimplePear) { + if(this.PeerConnectionArray.has(user.userId)) { return; } @@ -109,14 +109,14 @@ export class SimplePeer implements SimplePeerInterface{ ] }, }); - this.PeerConnexionArray.set(user.userId, peer); + this.PeerConnectionArray.set(user.userId, peer); - //start listen signal for the peer connexion - this.PeerConnexionArray.get(user.userId).on('signal', (data: any) => { + //start listen signal for the peer connection + this.PeerConnectionArray.get(user.userId).on('signal', (data: any) => { this.sendWebrtcSignal(data, user.userId); }); - this.PeerConnexionArray.get(user.userId).on('stream', (stream: MediaStream) => { + this.PeerConnectionArray.get(user.userId).on('stream', (stream: MediaStream) => { let videoActive = false; let microphoneActive = false; stream.getTracks().forEach((track : MediaStreamTrack) => { @@ -141,23 +141,23 @@ export class SimplePeer implements SimplePeerInterface{ this.stream(user.userId, stream); }); - /*this.PeerConnexionArray.get(user.userId).on('track', (track: MediaStreamTrack, stream: MediaStream) => { + /*this.PeerConnectionArray.get(user.userId).on('track', (track: MediaStreamTrack, stream: MediaStream) => { this.stream(user.userId, stream); });*/ - this.PeerConnexionArray.get(user.userId).on('close', () => { - this.closeConnexion(user.userId); + this.PeerConnectionArray.get(user.userId).on('close', () => { + this.closeConnection(user.userId); }); - this.PeerConnexionArray.get(user.userId).on('error', (err: any) => { + this.PeerConnectionArray.get(user.userId).on('error', (err: any) => { console.error(`error => ${user.userId} => ${err.code}`, err); }); - this.PeerConnexionArray.get(user.userId).on('connect', () => { + this.PeerConnectionArray.get(user.userId).on('connect', () => { console.info(`connect => ${user.userId}`); }); - this.PeerConnexionArray.get(user.userId).on('data', (chunk: Buffer) => { + this.PeerConnectionArray.get(user.userId).on('data', (chunk: Buffer) => { let data = JSON.parse(chunk.toString('utf8')); if(data.type === "stream"){ this.stream(user.userId, data.stream); @@ -167,17 +167,17 @@ export class SimplePeer implements SimplePeerInterface{ this.addMedia(user.userId); } - private closeConnexion(userId : string) { + private closeConnection(userId : string) { try { this.MediaManager.removeActiveVideo(userId); - if (!this.PeerConnexionArray.get(userId)) { + if (!this.PeerConnectionArray.get(userId)) { return; } // @ts-ignore - this.PeerConnexionArray.get(userId).destroy(); - this.PeerConnexionArray.delete(userId) + this.PeerConnectionArray.get(userId).destroy(); + this.PeerConnectionArray.delete(userId) } catch (err) { - console.error("closeConnexion", err) + console.error("closeConnection", err) } } @@ -188,7 +188,7 @@ export class SimplePeer implements SimplePeerInterface{ */ private sendWebrtcSignal(data: any, userId : string) { try { - this.Connexion.sendWebrtcSignal(data, this.WebRtcRoomId, null, userId); + this.Connection.sendWebrtcSignal(data, this.WebRtcRoomId, null, userId); }catch (e) { console.error(`sendWebrtcSignal => ${userId}`, e); } @@ -196,11 +196,11 @@ export class SimplePeer implements SimplePeerInterface{ private receiveWebrtcSignal(data: any) { try { - //if offer type, create peer connexion + //if offer type, create peer connection if(data.signal.type === "offer"){ - this.createPeerConnexion(data); + this.createPeerConnection(data); } - this.PeerConnexionArray.get(data.userId).signal(data.signal); + this.PeerConnectionArray.get(data.userId).signal(data.signal); } catch (e) { console.error(`receiveWebrtcSignal => ${data.userId}`, e); } @@ -229,17 +229,17 @@ export class SimplePeer implements SimplePeerInterface{ let transceiver : any = null; if(!this.MediaManager.localStream){ //send fake signal - if(!this.PeerConnexionArray.has(userId)){ + if(!this.PeerConnectionArray.has(userId)){ return; } - this.PeerConnexionArray.get(userId).write(new Buffer(JSON.stringify({ + this.PeerConnectionArray.get(userId).write(new Buffer(JSON.stringify({ type: "stream", stream: null }))); return; } this.MediaManager.localStream.getTracks().forEach( - transceiver = (track: MediaStreamTrack) => this.PeerConnexionArray.get(userId).addTrack(track, this.MediaManager.localStream) + transceiver = (track: MediaStreamTrack) => this.PeerConnectionArray.get(userId).addTrack(track, this.MediaManager.localStream) ) }catch (e) { console.error(`addMedia => addMedia => ${userId}`, e); diff --git a/front/src/index.ts b/front/src/index.ts index 2ab8d91a..5ece7d56 100644 --- a/front/src/index.ts +++ b/front/src/index.ts @@ -2,7 +2,7 @@ import 'phaser'; import GameConfig = Phaser.Types.Core.GameConfig; import {DEBUG_MODE, RESOLUTION} from "./Enum/EnvironmentVariable"; import {cypressAsserter} from "./Cypress/CypressAsserter"; -import {LogincScene} from "./Phaser/Login/LogincScene"; +import {LoginScene} from "./Phaser/Login/LoginScene"; import {ReconnectingScene} from "./Phaser/Reconnecting/ReconnectingScene"; import {gameManager} from "./Phaser/Game/GameManager"; @@ -11,7 +11,7 @@ const config: GameConfig = { width: window.innerWidth / RESOLUTION, height: window.innerHeight / RESOLUTION, parent: "game", - scene: [LogincScene, ReconnectingScene], + scene: [LoginScene, ReconnectingScene], zoom: RESOLUTION, physics: { default: "arcade",