Fixing typos.

Replaced connexion with connection and LogincScene with LoginScene
This commit is contained in:
David Négrier 2020-05-24 23:14:12 +02:00
parent b58eef6e7f
commit 1fa39b0781
8 changed files with 61 additions and 61 deletions

View File

@ -120,13 +120,13 @@ export interface GroupCreatedUpdatedMessageInterface {
groupId: string groupId: string
} }
export interface ConnexionInterface { export interface ConnectionInterface {
socket: any; socket: any;
token: string; token: string;
name: string; name: string;
userId: string; userId: string;
createConnexion(name: string, characterSelected: string): Promise<any>; createConnection(name: string, characterSelected: string): Promise<any>;
loadStartMap(): Promise<any>; loadStartMap(): Promise<any>;
@ -146,7 +146,7 @@ export interface ConnexionInterface {
disconnectMessage(callBack: Function): void; disconnectMessage(callBack: Function): void;
} }
export class Connexion implements ConnexionInterface { export class Connection implements ConnectionInterface {
socket: Socket; socket: Socket;
token: string; token: string;
name: string; // TODO: drop "name" storage here name: string; // TODO: drop "name" storage here
@ -162,7 +162,7 @@ export class Connexion implements ConnexionInterface {
this.GameManager = GameManager; this.GameManager = GameManager;
} }
createConnexion(name: string, characterSelected: string): Promise<ConnexionInterface> { createConnection(name: string, characterSelected: string): Promise<ConnectionInterface> {
this.name = name; this.name = name;
this.character = characterSelected; this.character = characterSelected;
return Axios.post(`${API_URL}/login`, {name: name}) return Axios.post(`${API_URL}/login`, {name: name})
@ -185,7 +185,7 @@ export class Connexion implements ConnexionInterface {
* *
* @param character * @param character
*/ */
connectSocketServer(): Promise<ConnexionInterface>{ connectSocketServer(): Promise<ConnectionInterface>{
//listen event //listen event
this.positionOfAllUser(); this.positionOfAllUser();
this.disconnectServer(); this.disconnectServer();
@ -196,7 +196,7 @@ export class Connexion implements ConnexionInterface {
this.onUserMoved(); this.onUserMoved();
this.onUserLeft(); this.onUserLeft();
return new Promise<ConnexionInterface>((resolve, reject) => { return new Promise<ConnectionInterface>((resolve, reject) => {
this.socket.emit(EventMessage.SET_PLAYER_DETAILS, { this.socket.emit(EventMessage.SET_PLAYER_DETAILS, {
name: this.name, name: this.name,
character: this.character character: this.character

View File

@ -1,4 +1,4 @@
import {PointInterface} from "../../Connexion"; import {PointInterface} from "../../Connection";
export interface AddPlayerInterface { export interface AddPlayerInterface {
userId: string; userId: string;

View File

@ -1,6 +1,6 @@
import {GameScene} from "./GameScene"; import {GameScene} from "./GameScene";
import { import {
Connexion, Connection,
GroupCreatedUpdatedMessageInterface, GroupCreatedUpdatedMessageInterface,
ListMessageUserPositionInterface, ListMessageUserPositionInterface,
MessageUserJoined, MessageUserJoined,
@ -8,7 +8,7 @@ import {
MessageUserPositionInterface, MessageUserPositionInterface,
Point, Point,
PointInterface PointInterface
} from "../../Connexion"; } from "../../Connection";
import {SimplePeerInterface, SimplePeer} from "../../WebRtc/SimplePeer"; import {SimplePeerInterface, SimplePeer} from "../../WebRtc/SimplePeer";
import {AddPlayerInterface} from "./AddPlayerInterface"; import {AddPlayerInterface} from "./AddPlayerInterface";
import {ReconnectingSceneName} from "../Reconnecting/ReconnectingScene"; import {ReconnectingSceneName} from "../Reconnecting/ReconnectingScene";
@ -32,7 +32,7 @@ export interface MapObject {
export class GameManager { export class GameManager {
status: number; status: number;
private ConnexionInstance: Connexion; private ConnectionInstance: Connection;
private currentGameScene: GameScene; private currentGameScene: GameScene;
private playerName: string; private playerName: string;
SimplePeer : SimplePeerInterface; SimplePeer : SimplePeerInterface;
@ -45,9 +45,9 @@ export class GameManager {
connect(name: string, characterUserSelected : string) { connect(name: string, characterUserSelected : string) {
this.playerName = name; this.playerName = name;
this.characterUserSelected = characterUserSelected; this.characterUserSelected = characterUserSelected;
this.ConnexionInstance = new Connexion(this); this.ConnectionInstance = new Connection(this);
return this.ConnexionInstance.createConnexion(name, characterUserSelected).then((data : any) => { return this.ConnectionInstance.createConnection(name, characterUserSelected).then((data : any) => {
this.SimplePeer = new SimplePeer(this.ConnexionInstance); this.SimplePeer = new SimplePeer(this.ConnectionInstance);
return data; return data;
}).catch((err) => { }).catch((err) => {
throw err; throw err;
@ -55,7 +55,7 @@ export class GameManager {
} }
loadStartMap(){ loadStartMap(){
return this.ConnexionInstance.loadStartMap().then((data) => { return this.ConnectionInstance.loadStartMap().then((data) => {
return data; return data;
}).catch((err) => { }).catch((err) => {
throw err; throw err;
@ -77,7 +77,7 @@ export class GameManager {
} }
joinRoom(sceneKey: string, startX: number, startY: number, direction: string, moving: boolean){ 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 { onUserJoins(message: MessageUserJoined): void {
@ -156,7 +156,7 @@ export class GameManager {
} }
getPlayerId(): string { getPlayerId(): string {
return this.ConnexionInstance.userId; return this.ConnectionInstance.userId;
} }
getCharacterSelected(): string { getCharacterSelected(): string {
@ -164,7 +164,7 @@ export class GameManager {
} }
pushPlayerPosition(event: HasMovedEvent) { 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 { loadMap(mapUrl: string, scene: Phaser.Scenes.ScenePlugin, instance: string): string {

View File

@ -3,7 +3,7 @@ import {
GroupCreatedUpdatedMessageInterface, GroupCreatedUpdatedMessageInterface,
MessageUserMovedInterface, MessageUserMovedInterface,
MessageUserPositionInterface, PointInterface, PositionInterface MessageUserPositionInterface, PointInterface, PositionInterface
} from "../../Connexion"; } from "../../Connection";
import {CurrentGamerInterface, GamerInterface, hasMovedEventName, Player} from "../Player/Player"; import {CurrentGamerInterface, GamerInterface, hasMovedEventName, Player} from "../Player/Player";
import { DEBUG_MODE, ZOOM_LEVEL} from "../../Enum/EnvironmentVariable"; import { DEBUG_MODE, ZOOM_LEVEL} from "../../Enum/EnvironmentVariable";
import {ITiledMap, ITiledMapLayer, ITiledTileSet} from "../Map/ITiledMap"; import {ITiledMap, ITiledMapLayer, ITiledTileSet} from "../Map/ITiledMap";
@ -301,7 +301,7 @@ export class GameScene extends Phaser.Scene {
//initialise player //initialise player
//TODO create animation moving between exit and start //TODO create animation moving between exit and start
this.CurrentPlayer = new Player( 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,
this.startX, this.startX,
this.startY, this.startY,

View File

@ -6,7 +6,7 @@ import Image = Phaser.GameObjects.Image;
import Rectangle = Phaser.GameObjects.Rectangle; import Rectangle = Phaser.GameObjects.Rectangle;
import {PLAYER_RESOURCES} from "../Entity/PlayableCaracter"; import {PLAYER_RESOURCES} from "../Entity/PlayableCaracter";
import {cypressAsserter} from "../../Cypress/CypressAsserter"; 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 //todo: put this constants in a dedicated file
export const LoginSceneName = "LoginScene"; export const LoginSceneName = "LoginScene";
@ -16,7 +16,7 @@ enum LoginTextures {
mainFont = "main_font" mainFont = "main_font"
} }
export class LogincScene extends Phaser.Scene { export class LoginScene extends Phaser.Scene {
private nameInput: TextInput; private nameInput: TextInput;
private textField: TextField; private textField: TextField;
private playButton: ClickButton; private playButton: ClickButton;

View File

@ -1,6 +1,6 @@
import {getPlayerAnimations, PlayerAnimationNames} from "./Animation"; import {getPlayerAnimations, PlayerAnimationNames} from "./Animation";
import {GameScene, Textures} from "../Game/GameScene"; import {GameScene, Textures} from "../Game/GameScene";
import {MessageUserPositionInterface, PointInterface} from "../../Connexion"; import {MessageUserPositionInterface, PointInterface} from "../../Connection";
import {ActiveEventList, UserInputEvent, UserInputManager} from "../UserInput/UserInputManager"; import {ActiveEventList, UserInputEvent, UserInputManager} from "../UserInput/UserInputManager";
import {PlayableCaracter} from "../Entity/PlayableCaracter"; import {PlayableCaracter} from "../Entity/PlayableCaracter";

View File

@ -1,4 +1,4 @@
import {ConnexionInterface} from "../Connexion"; import {ConnectionInterface} from "../Connection";
import {MediaManager} from "./MediaManager"; import {MediaManager} from "./MediaManager";
let Peer = require('simple-peer'); let Peer = require('simple-peer');
@ -9,16 +9,16 @@ class UserSimplePear{
} }
export class SimplePeerInterface {} export class SimplePeerInterface {}
export class SimplePeer implements SimplePeerInterface{ export class SimplePeer implements SimplePeerInterface{
private Connexion: ConnexionInterface; private Connection: ConnectionInterface;
private WebRtcRoomId: string; private WebRtcRoomId: string;
private Users: Array<UserSimplePear> = new Array<UserSimplePear>(); private Users: Array<UserSimplePear> = new Array<UserSimplePear>();
private MediaManager: MediaManager; private MediaManager: MediaManager;
private PeerConnexionArray: Map<string, any> = new Map<string, any>(); private PeerConnectionArray: Map<string, any> = new Map<string, any>();
constructor(Connexion: ConnexionInterface, WebRtcRoomId: string = "test-webrtc") { constructor(Connection: ConnectionInterface, WebRtcRoomId: string = "test-webrtc") {
this.Connexion = Connexion; this.Connection = Connection;
this.WebRtcRoomId = WebRtcRoomId; this.WebRtcRoomId = WebRtcRoomId;
this.MediaManager = new MediaManager((stream : MediaStream) => { this.MediaManager = new MediaManager((stream : MediaStream) => {
this.updatedLocalStream(); this.updatedLocalStream();
@ -32,7 +32,7 @@ export class SimplePeer implements SimplePeerInterface{
private initialise() { private initialise() {
//receive signal by gemer //receive signal by gemer
this.Connexion.receiveWebrtcSignal((message: any) => { this.Connection.receiveWebrtcSignal((message: any) => {
this.receiveWebrtcSignal(message); this.receiveWebrtcSignal(message);
}); });
@ -40,7 +40,7 @@ export class SimplePeer implements SimplePeerInterface{
this.MediaManager.getCamera().then(() => { this.MediaManager.getCamera().then(() => {
//receive message start //receive message start
this.Connexion.receiveWebrtcStart((message: any) => { this.Connection.receiveWebrtcStart((message: any) => {
this.receiveWebrtcStart(message); this.receiveWebrtcStart(message);
}); });
@ -49,8 +49,8 @@ export class SimplePeer implements SimplePeerInterface{
}); });
//receive signal by gemer //receive signal by gemer
this.Connexion.disconnectMessage((data: any) => { this.Connection.disconnectMessage((data: any) => {
this.closeConnexion(data.userId); this.closeConnection(data.userId);
}); });
} }
@ -58,7 +58,7 @@ export class SimplePeer implements SimplePeerInterface{
this.WebRtcRoomId = data.roomId; this.WebRtcRoomId = data.roomId;
this.Users = data.clients; this.Users = data.clients;
//start connexion //start connection
this.startWebRtc(); this.startWebRtc();
} }
@ -67,19 +67,19 @@ export class SimplePeer implements SimplePeerInterface{
*/ */
private startWebRtc() { private startWebRtc() {
this.Users.forEach((user: UserSimplePear) => { 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){ if(!user.initiator){
return; return;
} }
this.createPeerConnexion(user); this.createPeerConnection(user);
}); });
} }
/** /**
* create peer connexion to bind users * create peer connection to bind users
*/ */
private createPeerConnexion(user : UserSimplePear) { private createPeerConnection(user : UserSimplePear) {
if(this.PeerConnexionArray.has(user.userId)) { if(this.PeerConnectionArray.has(user.userId)) {
return; 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 //start listen signal for the peer connection
this.PeerConnexionArray.get(user.userId).on('signal', (data: any) => { this.PeerConnectionArray.get(user.userId).on('signal', (data: any) => {
this.sendWebrtcSignal(data, user.userId); 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 videoActive = false;
let microphoneActive = false; let microphoneActive = false;
stream.getTracks().forEach((track : MediaStreamTrack) => { stream.getTracks().forEach((track : MediaStreamTrack) => {
@ -141,23 +141,23 @@ export class SimplePeer implements SimplePeerInterface{
this.stream(user.userId, stream); 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.stream(user.userId, stream);
});*/ });*/
this.PeerConnexionArray.get(user.userId).on('close', () => { this.PeerConnectionArray.get(user.userId).on('close', () => {
this.closeConnexion(user.userId); 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); 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}`); 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')); let data = JSON.parse(chunk.toString('utf8'));
if(data.type === "stream"){ if(data.type === "stream"){
this.stream(user.userId, data.stream); this.stream(user.userId, data.stream);
@ -167,17 +167,17 @@ export class SimplePeer implements SimplePeerInterface{
this.addMedia(user.userId); this.addMedia(user.userId);
} }
private closeConnexion(userId : string) { private closeConnection(userId : string) {
try { try {
this.MediaManager.removeActiveVideo(userId); this.MediaManager.removeActiveVideo(userId);
if (!this.PeerConnexionArray.get(userId)) { if (!this.PeerConnectionArray.get(userId)) {
return; return;
} }
// @ts-ignore // @ts-ignore
this.PeerConnexionArray.get(userId).destroy(); this.PeerConnectionArray.get(userId).destroy();
this.PeerConnexionArray.delete(userId) this.PeerConnectionArray.delete(userId)
} catch (err) { } 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) { private sendWebrtcSignal(data: any, userId : string) {
try { try {
this.Connexion.sendWebrtcSignal(data, this.WebRtcRoomId, null, userId); this.Connection.sendWebrtcSignal(data, this.WebRtcRoomId, null, userId);
}catch (e) { }catch (e) {
console.error(`sendWebrtcSignal => ${userId}`, e); console.error(`sendWebrtcSignal => ${userId}`, e);
} }
@ -196,11 +196,11 @@ export class SimplePeer implements SimplePeerInterface{
private receiveWebrtcSignal(data: any) { private receiveWebrtcSignal(data: any) {
try { try {
//if offer type, create peer connexion //if offer type, create peer connection
if(data.signal.type === "offer"){ 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) { } catch (e) {
console.error(`receiveWebrtcSignal => ${data.userId}`, e); console.error(`receiveWebrtcSignal => ${data.userId}`, e);
} }
@ -229,17 +229,17 @@ export class SimplePeer implements SimplePeerInterface{
let transceiver : any = null; let transceiver : any = null;
if(!this.MediaManager.localStream){ if(!this.MediaManager.localStream){
//send fake signal //send fake signal
if(!this.PeerConnexionArray.has(userId)){ if(!this.PeerConnectionArray.has(userId)){
return; return;
} }
this.PeerConnexionArray.get(userId).write(new Buffer(JSON.stringify({ this.PeerConnectionArray.get(userId).write(new Buffer(JSON.stringify({
type: "stream", type: "stream",
stream: null stream: null
}))); })));
return; return;
} }
this.MediaManager.localStream.getTracks().forEach( 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) { }catch (e) {
console.error(`addMedia => addMedia => ${userId}`, e); console.error(`addMedia => addMedia => ${userId}`, e);

View File

@ -2,7 +2,7 @@ import 'phaser';
import GameConfig = Phaser.Types.Core.GameConfig; import GameConfig = Phaser.Types.Core.GameConfig;
import {DEBUG_MODE, RESOLUTION} from "./Enum/EnvironmentVariable"; import {DEBUG_MODE, RESOLUTION} from "./Enum/EnvironmentVariable";
import {cypressAsserter} from "./Cypress/CypressAsserter"; import {cypressAsserter} from "./Cypress/CypressAsserter";
import {LogincScene} from "./Phaser/Login/LogincScene"; import {LoginScene} from "./Phaser/Login/LoginScene";
import {ReconnectingScene} from "./Phaser/Reconnecting/ReconnectingScene"; import {ReconnectingScene} from "./Phaser/Reconnecting/ReconnectingScene";
import {gameManager} from "./Phaser/Game/GameManager"; import {gameManager} from "./Phaser/Game/GameManager";
@ -11,7 +11,7 @@ const config: GameConfig = {
width: window.innerWidth / RESOLUTION, width: window.innerWidth / RESOLUTION,
height: window.innerHeight / RESOLUTION, height: window.innerHeight / RESOLUTION,
parent: "game", parent: "game",
scene: [LogincScene, ReconnectingScene], scene: [LoginScene, ReconnectingScene],
zoom: RESOLUTION, zoom: RESOLUTION,
physics: { physics: {
default: "arcade", default: "arcade",