Structure change (#4220)

* Structure change

* Remove duplicate folders from previous structure

* Cleanup websocket protocol

* Updating from based off PR

* Fixup - remove wrong files during conflict and get the websocket working

* renaming tsx to ts

Co-authored-by: Jeremy Letto <jeremy.letto@datasite.com>
This commit is contained in:
Joseph Chamish 2021-01-20 18:50:18 -05:00 committed by GitHub
parent a0deb73df6
commit 1ddc9cc929
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
123 changed files with 424 additions and 228 deletions

View file

@ -0,0 +1,44 @@
export default class NormalizeService {
// Flatten room gameTypes into map object
static normalizeRoomInfo(roomInfo) {
roomInfo.gametypeMap = {};
const { gametypeList, gametypeMap, gameList } = roomInfo;
gametypeList.reduce((map, type) => {
map[type.gameTypeId] = type.description;
return map;
}, gametypeMap);
gameList.forEach((game) => NormalizeService.normalizeGameObject(game, gametypeMap));
}
// Flatten gameTypes[] into gameType field
// Default sortable values ("" || 0 || -1)
static normalizeGameObject(game, gametypeMap) {
const { gameTypes, description } = game;
const hasType = gameTypes && gameTypes.length;
game.gameType = hasType ? gametypeMap[gameTypes[0]] : "";
game.description = description || "";
}
// Flatten logs[] into object mapped by targetType (room, game, chat)
static normalizeLogs(logs) {
return logs.reduce((obj, log) => {
const { targetType } = log;
obj[targetType] = obj[targetType] || [];
obj[targetType].push(log);
return obj;
}, {});
}
// messages sent by current user dont have their username prepended
static normalizeUserMessage(message) {
const { name } = message;
if (name) {
message.message = `${name}: ${message.message}`;
}
}
}

View file

@ -0,0 +1,50 @@
import { store, RoomsDispatch, RoomsSelectors } from "store";
import { WebClient } from "../WebClient";
import { NormalizeService } from "websocket";
export default class RoomService {
webClient: WebClient;
constructor(webClient) {
this.webClient = webClient;
}
clearStore() {
RoomsDispatch.clearStore();
}
joinRoom(roomInfo) {
NormalizeService.normalizeRoomInfo(roomInfo);
RoomsDispatch.joinRoom(roomInfo);
}
updateRooms(rooms) {
RoomsDispatch.updateRooms(rooms);
}
updateGames(roomId, gameList) {
const game = gameList[0];
if (!game.gameType) {
const { gametypeMap } = RoomsSelectors.getRoom(store.getState(), roomId);
NormalizeService.normalizeGameObject(game, gametypeMap);
}
RoomsDispatch.updateGames(roomId, gameList);
}
addMessage(roomId, message) {
NormalizeService.normalizeUserMessage(message);
RoomsDispatch.addMessage(roomId, message);
}
userJoined(roomId, user) {
RoomsDispatch.userJoined(roomId, user);
}
userLeft(roomId, name) {
RoomsDispatch.userLeft(roomId, name);
}
}

View file

@ -0,0 +1,94 @@
import { ServerDispatch, ServerConnectParams } from "store";
import { StatusEnum } from "types";
import { sanitizeHtml } from "websocket/utils";
import { WebClient } from "websocket/WebClient";
import { NormalizeService } from "websocket";
export default class SessionService {
webClient: WebClient;
constructor(webClient) {
this.webClient = webClient;
}
clearStore() {
ServerDispatch.clearStore();
}
connectServer(options: ServerConnectParams) {
ServerDispatch.connectServer();
this.webClient.updateStatus(StatusEnum.CONNECTING, "Connecting...");
this.webClient.connect(options);
}
disconnectServer() {
this.webClient.updateStatus(StatusEnum.DISCONNECTING, "Disconnecting...");
this.webClient.disconnect();
}
connectionClosed(reason) {
ServerDispatch.connectionClosed(reason);
}
updateBuddyList(buddyList) {
ServerDispatch.updateBuddyList(buddyList);
}
addToBuddyList(user) {
ServerDispatch.addToBuddyList(user);
}
removeFromBuddyList(userName) {
ServerDispatch.removeFromBuddyList(userName);
}
updateIgnoreList(ignoreList) {
ServerDispatch.updateIgnoreList(ignoreList);
}
addToIgnoreList(user) {
ServerDispatch.addToIgnoreList(user);
}
removeFromIgnoreList(userName) {
ServerDispatch.removeFromIgnoreList(userName);
}
updateInfo(name, version) {
ServerDispatch.updateInfo(name, version);
}
updateStatus(state, description) {
ServerDispatch.updateStatus(state, description);
if (state === StatusEnum.DISCONNECTED) {
this.connectionClosed({ reason: description });
}
}
updateUser(user) {
ServerDispatch.updateUser(user);
}
updateUsers(users) {
ServerDispatch.updateUsers(users);
}
userJoined(user) {
ServerDispatch.userJoined(user);
}
userLeft(userId) {
ServerDispatch.userLeft(userId);
}
viewLogs(logs) {
ServerDispatch.viewLogs(NormalizeService.normalizeLogs(logs));
}
serverMessage(message) {
ServerDispatch.serverMessage(sanitizeHtml(message));
}
}

View file

@ -0,0 +1,3 @@
export { default as NormalizeService } from "./NormalizeService";
export { default as RoomService } from "./RoomService";
export { default as SessionService } from "./SessionService";