Skip to content

Commit 0ff7d54

Browse files
authored
Websocket management (#53)
* Added a ConnectionManager for better readability. Added webtoken to our ws route, to utilize the uuid when opening ws-communication. Added simple reconnecting logic for client-unintended disconnects. Added a GetSessionAndUser API to solve the null reference problem of Users inside Session when calling the GetStatus API for now. * minor fix on refreshing the online states of users.Fixed Role.Author to Admin, to match with our Frontned. Added new MessageType UserRefreshed, to update the online states of currently available users in a session. Adjusted our Dtos to contain an user online state. * Fixed Role.Author to Admin, to match with our Frontned. Added new MessageType UserRefreshed, to update the online states of currently available users in a session. Adjusted our Dtos to contain an user online state. * Merged-task-estimation and ws management
1 parent 386c5de commit 0ff7d54

File tree

20 files changed

+921
-370
lines changed

20 files changed

+921
-370
lines changed

client/app/Components/Features/Session/Users/Stores/UserStore.ts

+52
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import produce from "immer";
22
import create from "zustand";
33
import { IUser } from "../../../../../../app/Interfaces/IUser";
4+
import { IUpdateDto } from "../../../../../Interfaces/IUpdateDto";
45

56
interface ISessionUserState {
67
users: IUser[];
78
setCurrentUsers(payload: IUser[]): void;
89
addUser(payload: IUser): void;
910
removeUser(id: String): void;
11+
changeOnlineStatus(payload: IUpdateDto): void;
1012
}
1113

1214
export const useSessionUserStore = create<ISessionUserState>()((set) => ({
@@ -15,6 +17,19 @@ export const useSessionUserStore = create<ISessionUserState>()((set) => ({
1517
set(
1618
produce((draft) => {
1719
draft.users.push(payload);
20+
draft.users.forEach((user: IUser) => {
21+
if(user.id.trim() === payload.id)
22+
{
23+
user.online = true;
24+
user.role = payload.role;
25+
user.token = "";
26+
}
27+
});
28+
draft.users = draft.users.filter((user: IUser) => {
29+
if(user.token === null || user.token === "") return true;
30+
});
31+
draft.users = uniqBy(draft.users, JSON.stringify);
32+
console.log("useradd:"+ JSON.stringify(draft.users));
1833
})
1934
),
2035
setCurrentUsers: (payload: IUser[]) =>
@@ -25,4 +40,41 @@ export const useSessionUserStore = create<ISessionUserState>()((set) => ({
2540
draft.users.filter((item: IUser) => item.id === id);
2641
})
2742
),
43+
changeOnlineStatus: (payload: IUpdateDto) => set(
44+
produce((draft) => {
45+
if(payload.availableClients != undefined && payload.availableClients.length != 0)
46+
{
47+
let onlineUsers = payload.availableClients;
48+
draft.users.forEach((user: IUser) => {
49+
for(var i = 0; i < onlineUsers.length; i++)
50+
{
51+
let onlineUser = onlineUsers[i];
52+
if(user.id.trim() === onlineUser)
53+
{
54+
user.online = true;
55+
break;
56+
}
57+
else {
58+
user.online = false;
59+
}
60+
}
61+
});
62+
draft.users = draft.users.filter((user: IUser) => {
63+
if(user.online === true)
64+
{
65+
return true
66+
}
67+
});
68+
console.log("Online Users:"+ JSON.stringify(draft.users));
69+
}
70+
})
71+
),
2872
}));
73+
74+
function uniqBy(user: IUser[], key: any) {
75+
let seen = new Set();
76+
return user.filter(item => {
77+
let k = key(item);
78+
return seen.has(k) ? false : seen.add(k);
79+
});
80+
}

client/app/Interfaces/IUpdateDto.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { IUser } from "./IUser";
2+
3+
export interface IUpdateDto extends Array<String> {
4+
user: IUser,
5+
availableClients: Array<String>
6+
}
7+

client/app/Interfaces/IUser.ts

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1+
import { Role } from "../Types/Role";
2+
13
export interface IUser {
24
id: String;
35
username: String;
46
imageUrl?: String;
7+
online?: boolean;
8+
role: Role;
9+
token: string;
510
}

client/app/Types/Type.ts

+1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ export enum Type {
66
TaskAverageAdded = 4,
77
TaskFinalValueAdded = 5,
88
UserJoined = 6,
9+
UserRefreshed = 7,
910
}

0 commit comments

Comments
 (0)