Migrating userId to "int32" to save some space and adding userMoves message in protobuf
This commit is contained in:
parent
4b55b54a07
commit
e9ca8721a6
31 changed files with 295 additions and 445 deletions
|
@ -7,7 +7,9 @@ import {Movable} from "_Model/Movable";
|
|||
export class Group implements Movable {
|
||||
static readonly MAX_PER_GROUP = 4;
|
||||
|
||||
private id: string;
|
||||
private static nextId: number = 1;
|
||||
|
||||
private id: number;
|
||||
private users: Set<User>;
|
||||
private connectCallback: ConnectCallback;
|
||||
private disconnectCallback: DisconnectCallback;
|
||||
|
@ -17,7 +19,8 @@ export class Group implements Movable {
|
|||
this.users = new Set<User>();
|
||||
this.connectCallback = connectCallback;
|
||||
this.disconnectCallback = disconnectCallback;
|
||||
this.id = uuid();
|
||||
this.id = Group.nextId;
|
||||
Group.nextId++;
|
||||
|
||||
users.forEach((user: User) => {
|
||||
this.join(user);
|
||||
|
@ -28,7 +31,7 @@ export class Group implements Movable {
|
|||
return Array.from(this.users.values());
|
||||
}
|
||||
|
||||
getId() : string{
|
||||
getId() : number {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ export class User implements Movable {
|
|||
public group?: Group;
|
||||
|
||||
public constructor(
|
||||
public id: string,
|
||||
public id: number,
|
||||
public position: PointInterface,
|
||||
public silent: boolean,
|
||||
|
||||
|
|
|
@ -8,7 +8,8 @@ export interface ExSocketInterface extends Socket, Identificable {
|
|||
token: string;
|
||||
roomId: string;
|
||||
webRtcRoomId: string;
|
||||
userId: string;
|
||||
userId: number; // A temporary (autoincremented) identifier for this user
|
||||
userUuid: string; // A unique identifier for this user
|
||||
name: string;
|
||||
characterLayers: string[];
|
||||
position: PointInterface;
|
||||
|
|
|
@ -2,5 +2,5 @@ import {PositionInterface} from "_Model/PositionInterface";
|
|||
|
||||
export interface GroupUpdateInterface {
|
||||
position: PositionInterface,
|
||||
groupId: string,
|
||||
groupId: number,
|
||||
}
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
export interface Identificable {
|
||||
userId: string;
|
||||
userId: number;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import {PointInterface} from "_Model/Websocket/PointInterface";
|
||||
|
||||
export class MessageUserJoined {
|
||||
constructor(public userId: string, public name: string, public characterLayers: string[], public position: PointInterface) {
|
||||
constructor(public userId: number, public name: string, public characterLayers: string[], public position: PointInterface) {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import {PointInterface} from "./PointInterface";
|
||||
|
||||
export class MessageUserMoved {
|
||||
constructor(public userId: string, public position: PointInterface) {
|
||||
constructor(public userId: number, public position: PointInterface) {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,6 @@ export class Point implements PointInterface{
|
|||
}
|
||||
|
||||
export class MessageUserPosition {
|
||||
constructor(public userId: string, public name: string, public characterLayers: string[], public position: PointInterface) {
|
||||
constructor(public userId: number, public name: string, public characterLayers: string[], public position: PointInterface) {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
export interface UserInGroupInterface {
|
||||
userId: string,
|
||||
userId: number,
|
||||
name: string,
|
||||
initiator: boolean
|
||||
}
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
import * as tg from "generic-type-guard";
|
||||
import {isPointInterface} from "./PointInterface";
|
||||
import {isViewport} from "./ViewportMessage";
|
||||
|
||||
|
||||
export const isUserMovesInterface =
|
||||
new tg.IsInterface().withProperties({
|
||||
position: isPointInterface,
|
||||
viewport: isViewport,
|
||||
}).get();
|
||||
export type UserMovesInterface = tg.GuardedType<typeof isUserMovesInterface>;
|
|
@ -7,12 +7,12 @@ export const isSignalData =
|
|||
|
||||
export const isWebRtcSignalMessageInterface =
|
||||
new tg.IsInterface().withProperties({
|
||||
receiverId: tg.isString,
|
||||
receiverId: tg.isNumber,
|
||||
signal: isSignalData
|
||||
}).get();
|
||||
export const isWebRtcScreenSharingStartMessageInterface =
|
||||
new tg.IsInterface().withProperties({
|
||||
userId: tg.isString,
|
||||
userId: tg.isNumber,
|
||||
roomId: tg.isString
|
||||
}).get();
|
||||
export type WebRtcSignalMessageInterface = tg.GuardedType<typeof isWebRtcSignalMessageInterface>;
|
||||
|
|
|
@ -11,15 +11,15 @@ import {PositionNotifier} from "./PositionNotifier";
|
|||
import {ViewportInterface} from "_Model/Websocket/ViewportMessage";
|
||||
import {Movable} from "_Model/Movable";
|
||||
|
||||
export type ConnectCallback = (user: string, group: Group) => void;
|
||||
export type DisconnectCallback = (user: string, group: Group) => void;
|
||||
export type ConnectCallback = (user: number, group: Group) => void;
|
||||
export type DisconnectCallback = (user: number, group: Group) => void;
|
||||
|
||||
export class World {
|
||||
private readonly minDistance: number;
|
||||
private readonly groupRadius: number;
|
||||
|
||||
// Users, sorted by ID
|
||||
private readonly users: Map<string, User>;
|
||||
private readonly users: Map<number, User>;
|
||||
private readonly groups: Set<Group>;
|
||||
|
||||
private readonly connectCallback: ConnectCallback;
|
||||
|
@ -37,7 +37,7 @@ export class World {
|
|||
onMoves: MovesCallback,
|
||||
onLeaves: LeavesCallback)
|
||||
{
|
||||
this.users = new Map<string, User>();
|
||||
this.users = new Map<number, User>();
|
||||
this.groups = new Set<Group>();
|
||||
this.connectCallback = connectCallback;
|
||||
this.disconnectCallback = disconnectCallback;
|
||||
|
@ -51,7 +51,7 @@ export class World {
|
|||
return Array.from(this.groups.values());
|
||||
}
|
||||
|
||||
public getUsers(): Map<string, User> {
|
||||
public getUsers(): Map<number, User> {
|
||||
return this.users;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue