Migrating front protobuf encode/decode to ts-proto lib
The ts-proto lib has the huge advantage of producing code the "Typescript" way and not the "Java" way. In particular, for "oneof" types in protobuf, it is generating "ADT" that can be used to check if we forgot or not to deal with a type.
This commit is contained in:
@@ -3,6 +3,7 @@ import type { PlayerInterface } from "../Phaser/Game/PlayerInterface";
|
||||
import type { RoomConnection } from "../Connexion/RoomConnection";
|
||||
import { getRandomColor } from "../WebRtc/ColorGenerator";
|
||||
import { localUserStore } from "../Connexion/LocalUserStore";
|
||||
import room from "../Api/iframe/room";
|
||||
|
||||
let idCount = 0;
|
||||
|
||||
@@ -19,7 +20,8 @@ function createPlayersStore() {
|
||||
connectToRoomConnection: (roomConnection: RoomConnection) => {
|
||||
players = new Map<number, PlayerInterface>();
|
||||
set(players);
|
||||
roomConnection.onUserJoins((message) => {
|
||||
// TODO: it would be cool to unsubscribe properly here
|
||||
roomConnection.userJoinedMessageStream.subscribe((message) => {
|
||||
update((users) => {
|
||||
users.set(message.userId, {
|
||||
userId: message.userId,
|
||||
@@ -33,9 +35,9 @@ function createPlayersStore() {
|
||||
return users;
|
||||
});
|
||||
});
|
||||
roomConnection.onUserLeft((userId) => {
|
||||
roomConnection.userLeftMessageStream.subscribe((message) => {
|
||||
update((users) => {
|
||||
users.delete(userId);
|
||||
users.delete(message.userId);
|
||||
return users;
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user