Merge world and webrtc conexion

This commit is contained in:
gparant 2020-04-29 01:40:32 +02:00
parent 3151113db3
commit 2bfa57b0ba
7 changed files with 123 additions and 68 deletions

View file

@ -7,7 +7,6 @@ import {API_URL} from "./Enum/EnvironmentVariable";
enum EventMessage{
WEBRTC_SIGNAL = "webrtc-signal",
WEBRTC_START = "webrtc-start",
WEBRTC_ROOM = "webrtc-room",
JOIN_ROOM = "join-room",
USER_POSITION = "user-position",
MESSAGE_ERROR = "message-error"
@ -127,8 +126,6 @@ export interface ConnexionInterface {
positionOfAllUser(): void;
/*webrtc*/
sendWebrtcRomm(roomId: string): void;
sendWebrtcSignal(signal: any, roomId: string, userId?: string, receiverId?: string): void;
receiveWebrtcSignal(callBack: Function): void;
@ -239,10 +236,6 @@ export class Connexion implements ConnexionInterface {
}));
}
sendWebrtcRomm(roomId: string) {
this.socket.emit(EventMessage.WEBRTC_ROOM, JSON.stringify({roomId: roomId}));
}
receiveWebrtcStart(callback: Function) {
this.socket.on(EventMessage.WEBRTC_START, callback);
}

View file

@ -258,7 +258,6 @@ export class GameScene extends Phaser.Scene implements GameSceneInterface{
//init colision
this.physics.add.collider(this.CurrentPlayer, player, (CurrentPlayer: CurrentGamerInterface, MapPlayer: GamerInterface) => {
CurrentPlayer.say("Hello, how are you ? ");
this.GameManager.SimplePeer.activePhone();
});
}
}

View file

@ -3,14 +3,13 @@ import {MediaManager} from "./MediaManager";
let Peer = require('simple-peer');
export interface SimplePeerInterface {
activePhone(): void;
disablePhone(): void;
}
export class SimplePeer {
Connexion: ConnexionInterface;
MediaManager: MediaManager;
RoomId: string;
Users: Array<any>;
PeerConnexionArray: Array<any> = new Array<any>();
@ -18,12 +17,25 @@ export class SimplePeer {
this.Connexion = Connexion;
this.RoomId = roomId;
this.MediaManager = new MediaManager();
this.initialise();
}
/**
* permit to listen when user could start visio
*/
private initialise(){
//receive message start
this.Connexion.receiveWebrtcStart((message: string) => {
this.receiveWebrtcStart(message);
});
//when button to call is clicked, start video
this.MediaManager.getElementActivePhone().addEventListener("click", () => {
this.startWebRtc();
this.disablePhone();
});
}
/**
* server has two person connected, start the meet
*/
@ -31,13 +43,9 @@ export class SimplePeer {
this.MediaManager.activeVisio();
return this.MediaManager.getCamera().then((stream: MediaStream) => {
this.MediaManager.localStream = stream;
//send message to join a room
this.Connexion.sendWebrtcRomm(this.RoomId);
//receive message start
this.Connexion.receiveWebrtcStart((message: string) => {
this.receiveWebrtcStart(message);
});
//create pear connexion
this.createPeerConnexion();
//receive signal by gemer
this.Connexion.receiveWebrtcSignal((message: string) => {
@ -54,17 +62,16 @@ export class SimplePeer {
*/
receiveWebrtcStart(message: string) {
let data = JSON.parse(message);
this.RoomId = data.roomId;
this.Users = data.clients;
//create pear connexion of user stared
this.createPeerConnexion(data);
//active button for player
this.activePhone();
}
/**
*
* @param users
*/
createPeerConnexion(users : Array<any>) {
users.forEach((user: any) => {
createPeerConnexion() {
this.Users.forEach((user: any) => {
if(this.PeerConnexionArray[user.userId]){
return;
}