Update video style and start peer connexion

This commit is contained in:
gparant 2020-05-01 21:15:00 +02:00
parent dbf0bef149
commit e06b20fe96
7 changed files with 140 additions and 131 deletions

View file

@ -8,7 +8,7 @@ import {SECRET_KEY} from "../Enum/EnvironmentVariable"; //TODO fix import by "_E
import {ExtRooms, RefreshUserPositionFunction} from "../Model/Websocket/ExtRoom";
import {ExtRoomsInterface} from "../Model/Websocket/ExtRoomsInterface";
import {World} from "../Model/World";
import { uuid } from 'uuidv4';
import {Group} from "_Model/Group";
enum SockerIoEvent {
CONNECTION = "connection",
@ -44,10 +44,10 @@ export class IoSocketController{
this.shareUsersPosition();
//don't send only function because the context will be not this
this.World = new World((user1 : string, user2 : string) => {
this.connectedUser(user1, user2);
}, (user1 : string, user2 : string) => {
this.disConnectedUser(user1, user2);
this.World = new World((user1 : string, user2 : string, group: Group) => {
this.connectedUser(user1, user2, group);
}, (user1 : string, user2 : string, group: Group) => {
this.disConnectedUser(user1, user2, group);
});
}
@ -230,24 +230,27 @@ export class IoSocketController{
}
//connected user
connectedUser(user1 : string, user2 : string){
/* TODO manager room and group user to enter and leave */
let roomId = uuid();
let clients : Array<any> = Object.values(this.Io.sockets.sockets);
let User1 = clients.find((user : ExSocketInterface) => user.userId === user1);
let User2 = clients.find((user : ExSocketInterface) => user.userId === user2);
if(User1) {
this.joinWebRtcRoom(User1, roomId);
connectedUser(user1 : string, user2 : string, group : Group) {
if(!group){
return;
}
if(User2) {
this.joinWebRtcRoom(User2, roomId);
/* TODO manager room and group user to enter and leave */
let clients: Array<any> = Object.values(this.Io.sockets.sockets);
let User1 = clients.find((user: ExSocketInterface) => user.userId === user1);
let User2 = clients.find((user: ExSocketInterface) => user.userId === user2);
if (User1) {
this.joinWebRtcRoom(User1, group.getId());
}
if (User2) {
this.joinWebRtcRoom(User2, group.getId());
}
}
//connected user
disConnectedUser(user1 : string, user2 : string){
disConnectedUser(user1 : string, user2 : string, group : Group){
console.log("disConnectedUser => user1", user1);
console.log("disConnectedUser => user2", user2);
console.log("group", group);
}
}

View file

@ -1,19 +1,25 @@
import {MessageUserPosition} from "./Websocket/MessageUserPosition";
import { World } from "./World";
import { UserInterface } from "./UserInterface";
import {uuid} from "uuidv4";
export class Group {
static readonly MAX_PER_GROUP = 4;
private id: string;
private users: UserInterface[];
private connectCallback: (user1: string, user2: string) => void;
private disconnectCallback: (user1: string, user2: string) => void;
private connectCallback: (user1: string, user2: string, group: Group) => void;
private disconnectCallback: (user1: string, user2: string, group: Group) => void;
constructor(users: UserInterface[], connectCallback: (user1: string, user2: string) => void, disconnectCallback: (user1: string, user2: string) => void) {
constructor(users: UserInterface[],
connectCallback: (user1: string, user2: string, group: Group) => void,
disconnectCallback: (user1: string, user2: string, group: Group) => void
) {
this.users = [];
this.connectCallback = connectCallback;
this.disconnectCallback = disconnectCallback;
this.id = uuid();
users.forEach((user: UserInterface) => {
this.join(user);
@ -24,6 +30,10 @@ export class Group {
return this.users;
}
getId() : string{
return this.id;
}
isFull(): boolean {
return this.users.length >= Group.MAX_PER_GROUP;
}
@ -31,9 +41,10 @@ export class Group {
join(user: UserInterface): void
{
// Broadcast on the right event
this.users.forEach((groupUser: UserInterface) => {
this.connectCallback(user.id, groupUser.id);
});
for(let i = 0; i < this.users.length; i++){
let groupUser : UserInterface = this.users[i];
this.connectCallback(user.id, groupUser.id, this);
}
this.users.push(user);
user.group = this;
}

View file

@ -12,10 +12,10 @@ export class World {
private users: Map<string, UserInterface>;
private groups: Group[];
private connectCallback: (user1: string, user2: string) => void;
private disconnectCallback: (user1: string, user2: string) => void;
private connectCallback: (user1: string, user2: string, group: Group) => void;
private disconnectCallback: (user1: string, user2: string, group: Group) => void;
constructor(connectCallback: (user1: string, user2: string) => void, disconnectCallback: (user1: string, user2: string) => void)
constructor(connectCallback: (user1: string, user2: string, group: Group) => void, disconnectCallback: (user1: string, user2: string, group: Group) => void)
{
this.users = new Map<string, UserInterface>();
this.groups = [];
@ -48,7 +48,6 @@ export class World {
// If the user is not part of a group:
// should he join a group?
let closestUser: UserInterface|null = this.searchClosestAvailableUser(user);
if (closestUser !== null) {
// Is the closest user part of a group?
if (typeof closestUser.group === 'undefined') {
@ -60,9 +59,8 @@ export class World {
closestUser.group.join(user);
}
}
}
// TODO : vérifier qu'ils ne sont pas déja dans un groupe plein
// TODO : vérifier qu'ils ne sont pas déja dans un groupe plein
}
/**