commit
0ade4daa99
@ -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<any>;
|
||||
createConnection(name: string, characterSelected: string): Promise<any>;
|
||||
|
||||
loadStartMap(): Promise<any>;
|
||||
|
||||
@ -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<ConnexionInterface> {
|
||||
createConnection(name: string, characterSelected: string): Promise<ConnectionInterface> {
|
||||
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<ConnexionInterface>{
|
||||
connectSocketServer(): Promise<ConnectionInterface>{
|
||||
//listen event
|
||||
this.positionOfAllUser();
|
||||
this.disconnectServer();
|
||||
@ -196,7 +196,7 @@ export class Connexion implements ConnexionInterface {
|
||||
this.onUserMoved();
|
||||
this.onUserLeft();
|
||||
|
||||
return new Promise<ConnexionInterface>((resolve, reject) => {
|
||||
return new Promise<ConnectionInterface>((resolve, reject) => {
|
||||
this.socket.emit(EventMessage.SET_PLAYER_DETAILS, {
|
||||
name: this.name,
|
||||
character: this.character
|
@ -1,4 +1,4 @@
|
||||
import {PointInterface} from "../../Connexion";
|
||||
import {PointInterface} from "../../Connection";
|
||||
|
||||
export interface AddPlayerInterface {
|
||||
userId: string;
|
||||
|
@ -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 {
|
||||
|
@ -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,
|
||||
|
@ -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;
|
@ -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";
|
||||
|
||||
|
@ -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<UserSimplePear> = new Array<UserSimplePear>();
|
||||
|
||||
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") {
|
||||
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);
|
||||
|
@ -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",
|
||||
|
Loading…
Reference in New Issue
Block a user