-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
208 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,17 @@ | ||
import { AppEvents } from "../../events"; | ||
import { getDataFromRedis } from "../../redis"; | ||
import { IO_SERVER } from "../../utils/configureSocketIO"; | ||
import { SocketHandlerParams } from "../../types/common"; | ||
|
||
export const groupCreatedHandler = async (users: string[]) => { | ||
export const groupCreatedHandler = async ( | ||
{ io }: SocketHandlerParams, | ||
users: string[] | ||
) => { | ||
let usersSocket: string[] = []; | ||
for (let i = 0; i < users.length; i++) { | ||
const socketId = await getDataFromRedis(`socket:${users[i]}`, true); | ||
if (socketId) { | ||
usersSocket.push(socketId); | ||
} | ||
} | ||
IO_SERVER.to(usersSocket).emit(AppEvents.GROUP_CREATED); | ||
io.to(usersSocket).emit(AppEvents.GROUP_CREATED); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
import { SocketEvents } from "../../events"; | ||
import { getDataFromRedis } from "../../redis"; | ||
import { IO_SERVER, SOCKET_PAYLOAD } from "../../utils/configureSocketIO"; | ||
import { SocketHandlerParams } from "../../types/common"; | ||
|
||
export const isNotTypingHandler = async ({ | ||
toUserId, | ||
}: { | ||
type Args = { | ||
toUserId: string; | ||
}) => { | ||
}; | ||
|
||
export const isNotTypingHandler = async ( | ||
{ io, payload, socket }: SocketHandlerParams, | ||
{ toUserId }: Args | ||
) => { | ||
const socketId = await getDataFromRedis(`socket:${toUserId}`, true); | ||
|
||
if (socketId && toUserId !== SOCKET_PAYLOAD.userId) { | ||
if (socketId && toUserId !== payload.userId) { | ||
socketId && | ||
IO_SERVER.to(socketId).emit( | ||
SocketEvents.IS_NOT_TYPING, | ||
SOCKET_PAYLOAD.userId | ||
); | ||
io.to(socketId).emit(SocketEvents.IS_NOT_TYPING, payload.userId); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,15 @@ | ||
import { SocketEvents } from "../../events"; | ||
import { getDataFromRedis } from "../../redis"; | ||
import { SOCKET } from "../../utils/configureSocketIO"; | ||
import { SocketHandlerParams } from "../../types/common"; | ||
|
||
export const isOnlineHandler = async (userId: string) => { | ||
export const isOnlineHandler = async ( | ||
{ socket, io, payload }: SocketHandlerParams, | ||
userId: string | ||
) => { | ||
const socketId = await getDataFromRedis(`socket:${userId}`, true); | ||
if (socketId) { | ||
SOCKET.emit(SocketEvents.IS_ONLINE, "online"); | ||
socket.emit(SocketEvents.IS_ONLINE, "online"); | ||
} else { | ||
SOCKET.emit(SocketEvents.IS_ONLINE, "offline"); | ||
socket.emit(SocketEvents.IS_ONLINE, "offline"); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,18 @@ | ||
import { SocketEvents } from "../../events"; | ||
import { getDataFromRedis } from "../../redis"; | ||
import { IO_SERVER, SOCKET_PAYLOAD } from "../../utils/configureSocketIO"; | ||
import { SocketHandlerParams } from "../../types/common"; | ||
|
||
export const isTypingHandler = async ({ toUserId }: { toUserId: string }) => { | ||
type Args = { | ||
toUserId: string; | ||
}; | ||
|
||
export const isTypingHandler = async ( | ||
{ io, payload, socket }: SocketHandlerParams, | ||
{ toUserId }: Args | ||
) => { | ||
const socketId = await getDataFromRedis(`socket:${toUserId}`, true); | ||
|
||
if (socketId && toUserId !== SOCKET_PAYLOAD.userId) { | ||
socketId && | ||
IO_SERVER.to(socketId).emit( | ||
SocketEvents.IS_TYPING, | ||
SOCKET_PAYLOAD.userId | ||
); | ||
if (socketId && toUserId !== payload.userId) { | ||
socketId && io.to(socketId).emit(SocketEvents.IS_TYPING, payload.userId); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,15 @@ | ||
import { SOCKET } from "../../utils/configureSocketIO"; | ||
import { SocketHandlerParams } from "../../types/common"; | ||
|
||
export const leaveGroupHandler = ({ groupIds }: { groupIds: string[] }) => { | ||
type LeaveGroup = { | ||
groupIds: string[]; | ||
}; | ||
|
||
export const leaveGroupHandler = ( | ||
{ socket }: SocketHandlerParams, | ||
{ groupIds }: LeaveGroup | ||
) => { | ||
groupIds?.forEach((id: string) => { | ||
SOCKET.leave(id); | ||
socket.leave(id); | ||
console.log("leaveGroup", id); | ||
}); | ||
}; |
Oops, something went wrong.