Web: Socket: Removed socketUsersHelper and changes by namespaces

This commit is contained in:
Elyor Djalilov 2024-05-27 20:17:56 +05:00
parent b051b381cc
commit c9191231d7
3 changed files with 16 additions and 37 deletions

View File

@ -200,19 +200,21 @@ const SessionsTableRow = (props) => {
useEffect(() => {
const userIds = item.userId;
socketUsersHelper.emit({
socketHelper.emit({
command: "subscribe",
data: { roomParts: "onlineusers" },
data: { roomParts: "statuses-in-room" },
});
socketUsersHelper.emit({
socketHelper.emit({
command: "getSessionsInPortal",
data: { userIds },
});
socketUsersHelper.on("getSessionsInPortal", (data) => {
socketHelper.on("statuses-in-room", (data) => {
console.log(data);
});
}, [socketUsersHelper]);
}, [item.userId, socketHelper]);
const isChecked = checkedProps.checked;
const isOnline = status === "Online";

View File

@ -874,42 +874,22 @@ class SettingsStore {
this.publicRoomKey = key;
};
sockerFilesClient: SocketIOHelper | null = null;
socketUsersClient: SocketIOHelper | null = null;
socketFilesClient: SocketIOHelper | null = null;
get socketHelper() {
const socketUrl = isPublicRoom() && !this.publicRoomKey ? "" : "/socket.io"; // this.socketUrl;
if (!this.sockerFilesClient) {
this.sockerFilesClient = new SocketIOHelper(
if (!this.socketFilesClient) {
this.socketFilesClient = new SocketIOHelper(
socketUrl,
this.publicRoomKey,
"/files",
);
// TODO: comment this line
window.socketFilesClient = this.sockerFilesClient;
window.socketFilesClient = this.socketFilesClient;
}
return this.sockerFilesClient;
}
get socketUsersHelper() {
const socketUrl = isPublicRoom() && !this.publicRoomKey ? "" : "/socket.io"; // this.socketUrl;
if (!this.socketUsersClient) {
this.socketUsersClient = new SocketIOHelper(
socketUrl,
this.publicRoomKey,
"/onlineusers",
);
// TODO: comment this line
window.socketUsersClient = this.socketUsersClient;
}
return this.socketUsersClient;
return this.socketFilesClient;
}
getBuildVersionInfo = async () => {

View File

@ -78,17 +78,14 @@ class SocketIOHelper {
socketUrl: string | null = null;
ns: string | undefined;
constructor(url: string, publicRoomKey: string, ns: string = "/files") {
constructor(url: string, publicRoomKey: string) {
if (!url) return;
this.socketUrl = url;
this.ns = ns;
if (this.client) return;
const origin = window.location.origin + ns;
const origin = window.location.origin;
const config: TConfig = {
withCredentials: true,
@ -106,7 +103,7 @@ class SocketIOHelper {
this.client = io(origin, config);
this.client.on("connect", () => {
console.log(`socket ${ns} is connected`);
console.log(`socket is connected`);
if (this.callbacks?.length > 0) {
this.callbacks.forEach(({ eventName, callback }) => {
if (!this.client) return;
@ -132,7 +129,7 @@ class SocketIOHelper {
emit = ({ command, data, room = null }: TEmit) => {
if (!this.isEnabled) return;
console.log(`[WS] [NS:${this.ns}] emit`, command, data, room);
console.log(`[WS] emit`, command, data, room);
const ids =
!data || !data.roomParts