Switching WebRTC to protobuf + uws

This commit is contained in:
David Négrier 2020-09-29 16:01:22 +02:00
parent a9b1313d39
commit b485c9bf46
7 changed files with 253 additions and 129 deletions

View file

@ -87,7 +87,7 @@ export class Group implements Movable {
join(user: User): void
{
// Broadcast on the right event
this.connectCallback(user.id, this);
this.connectCallback(user, this);
this.users.add(user);
user.group = this;
}
@ -105,7 +105,7 @@ export class Group implements Movable {
}
// Broadcast on the right event
this.disconnectCallback(user.id, this);
this.disconnectCallback(user, this);
}
/**

View file

@ -4,6 +4,7 @@ import {Zone} from "_Model/Zone";
import {Movable} from "_Model/Movable";
import {PositionInterface} from "_Model/PositionInterface";
import {PositionNotifier} from "_Model/PositionNotifier";
import {ExSocketInterface} from "_Model/Websocket/ExSocketInterface";
export class User implements Movable {
public listenedZones: Set<Zone>;
@ -13,7 +14,8 @@ export class User implements Movable {
public id: number,
private position: PointInterface,
public silent: boolean,
private positionNotifier: PositionNotifier
private positionNotifier: PositionNotifier,
public readonly socket: ExSocketInterface
) {
this.listenedZones = new Set<Zone>();

View file

@ -11,8 +11,8 @@ import {PositionNotifier} from "./PositionNotifier";
import {ViewportInterface} from "_Model/Websocket/ViewportMessage";
import {Movable} from "_Model/Movable";
export type ConnectCallback = (user: number, group: Group) => void;
export type DisconnectCallback = (user: number, group: Group) => void;
export type ConnectCallback = (user: User, group: Group) => void;
export type DisconnectCallback = (user: User, group: Group) => void;
export class World {
private readonly minDistance: number;
@ -55,8 +55,8 @@ export class World {
return this.users;
}
public join(socket : Identificable, userPosition: PointInterface): void {
const user = new User(socket.userId, userPosition, false, this.positionNotifier);
public join(socket : ExSocketInterface, userPosition: PointInterface): void {
const user = new User(socket.userId, userPosition, false, this.positionNotifier, socket);
this.users.set(socket.userId, user);
// Let's call update position to trigger the join / leave room
//this.updatePosition(socket, userPosition);