Fix mediam stream manage and server back down
This commit is contained in:
parent
ab798b1c09
commit
ab32021fc0
5 changed files with 61 additions and 20 deletions
|
@ -165,25 +165,20 @@ export class Connexion implements ConnexionInterface {
|
|||
createConnexion(name: string, characterSelected: string): Promise<ConnexionInterface> {
|
||||
this.name = name;
|
||||
this.character = characterSelected;
|
||||
/*return Axios.post(`${API_URL}/login`, {email: this.email})
|
||||
return Axios.post(`${API_URL}/login`, {name: name})
|
||||
.then((res) => {
|
||||
this.token = res.data.token;
|
||||
this.userId = res.data.userId;*/
|
||||
|
||||
this.socket = SocketIo(`${API_URL}`, {
|
||||
/*query: {
|
||||
query: {
|
||||
token: this.token
|
||||
}*/
|
||||
}
|
||||
});
|
||||
|
||||
return this.connectSocketServer();
|
||||
|
||||
/* return res.data;
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(err);
|
||||
throw err;
|
||||
});*/
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -3,7 +3,7 @@ import {
|
|||
GroupCreatedUpdatedMessageInterface,
|
||||
MessageUserJoined,
|
||||
MessageUserMovedInterface,
|
||||
MessageUserPositionInterface
|
||||
MessageUserPositionInterface, PointInterface
|
||||
} from "../../Connexion";
|
||||
import {CurrentGamerInterface, GamerInterface, hasMovedEventName, Player} from "../Player/Player";
|
||||
import { DEBUG_MODE, RESOLUTION, ROOM, ZOOM_LEVEL} from "../../Enum/EnvironmentVariable";
|
||||
|
@ -14,6 +14,7 @@ import Sprite = Phaser.GameObjects.Sprite;
|
|||
import CanvasTexture = Phaser.Textures.CanvasTexture;
|
||||
import {AddPlayerInterface} from "./AddPlayerInterface";
|
||||
import {PlayerAnimationNames} from "../Player/Animation";
|
||||
import {MessageUserMoved} from "../../../../back/src/Model/Websocket/MessageUserMoved";
|
||||
|
||||
export enum Textures {
|
||||
Player = "male1"
|
||||
|
@ -410,6 +411,14 @@ export class GameScene extends Phaser.Scene {
|
|||
* Create new player
|
||||
*/
|
||||
public addPlayer(addPlayerData : AddPlayerInterface) : void{
|
||||
//check if exist player, if exist, move position
|
||||
if(this.MapPlayersByKey.has(addPlayerData.userId)){
|
||||
this.updatePlayerPosition({
|
||||
userId: addPlayerData.userId,
|
||||
position: addPlayerData.position
|
||||
});
|
||||
return;
|
||||
}
|
||||
//initialise player
|
||||
let player = new Player(
|
||||
addPlayerData.userId,
|
||||
|
|
|
@ -141,9 +141,9 @@ export class SimplePeer implements SimplePeerInterface{
|
|||
this.stream(user.userId, stream);
|
||||
});
|
||||
|
||||
this.PeerConnexionArray.get(user.userId).on('track', (track: MediaStreamTrack, stream: MediaStream) => {
|
||||
/*this.PeerConnexionArray.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);
|
||||
|
@ -157,6 +157,13 @@ export class SimplePeer implements SimplePeerInterface{
|
|||
console.info(`connect => ${user.userId}`);
|
||||
});
|
||||
|
||||
this.PeerConnexionArray.get(user.userId).on('data', (chunk: Buffer) => {
|
||||
let data = JSON.parse(chunk.toString('utf8'));
|
||||
if(data.type === "stream"){
|
||||
this.stream(user.userId, data.stream);
|
||||
}
|
||||
});
|
||||
|
||||
this.addMedia(user.userId);
|
||||
}
|
||||
|
||||
|
@ -205,6 +212,11 @@ export class SimplePeer implements SimplePeerInterface{
|
|||
* @param stream
|
||||
*/
|
||||
private stream(userId : any, stream: MediaStream) {
|
||||
if(!stream){
|
||||
this.MediaManager.disabledVideoByUserId(userId);
|
||||
this.MediaManager.disabledMicrophoneByUserId(userId);
|
||||
return;
|
||||
}
|
||||
this.MediaManager.addStreamRemoteVideo(userId, stream);
|
||||
}
|
||||
|
||||
|
@ -216,6 +228,14 @@ export class SimplePeer implements SimplePeerInterface{
|
|||
try {
|
||||
let transceiver : any = null;
|
||||
if(!this.MediaManager.localStream){
|
||||
//send fake signal
|
||||
if(!this.PeerConnexionArray.has(userId)){
|
||||
return;
|
||||
}
|
||||
this.PeerConnexionArray.get(userId).write(new Buffer(JSON.stringify({
|
||||
type: "stream",
|
||||
stream: null
|
||||
})));
|
||||
return;
|
||||
}
|
||||
this.MediaManager.localStream.getTracks().forEach(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue