-
Notifications
You must be signed in to change notification settings - Fork 16
feat(be): implement participant presence in study rooms #3541
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
westsunh
wants to merge
80
commits into
main
Choose a base branch
from
t2640-study-group-2depth-socket
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
80 commits
Select commit
Hold shift + click to select a range
2ef1c53
feat(be): install websokets, redisAdapter, ioredis for studygroup
westsunh 8516f75
feat(be): add Redis module and Socket.IO adapter
westsunh fb9ddbe
feat(be): add WebSocket auth to JWT auth guard
westsunh fb3ff4b
feat(be): integrate Redis module into application
westsunh 2c5c395
feat(be): add Redis WebSocket adapter to main
westsunh 7642979
feat(be): add WebSocket gateway for study group
westsunh 30bd3a0
feat(be): add StudyGateway to StudyModule
westsunh cc23ef6
feat(be): add validateJoinableStudyGroup in study service
westsunh 5273f8b
feat(be): add StudyRoom handleJoin()
westsunh 71f6769
fix(be): add user data handling logic to websocket handler
westsunh 0d3dc42
fix(be): map user id instead of socket id
westsunh 3840feb
fix(be): fix spread to preserve data
westsunh 98da048
fix(be): add params type
westsunh 8b003fc
feat(be): add StudyRoom handleLeave()
westsunh c3c5dac
refactor(be): separate parsePayload logic
westsunh d81ac43
feat(be): setup BullMQ for study-room
westsunh d4b8eaf
feat(be): implement socket disconnect and reconnect recovery logic
westsunh d064f72
refactor(be): use socket data instead of payload for room:leave
westsunh a0bbb14
feat(be): implement room lifecycle handling with BullMQ
westsunh fe839ca
fix(be): resolve race conditions in reconnection and handle expired s…
westsunh 253358f
chore(be): refine logging and clean up unused code
westsunh 756c560
Merge branch 'main' into t2640-study-group-2depth-socket
westsunh 751a879
chore(be): remove unused res field and simplify socket leave logic
westsunh d056e13
feat(be): reassign host on host leave
westsunh fe3ee59
refactor(be): use DB endTime for study room expiration
westsunh 906486d
refactor(be): standardize key prefix structure for study
westsunh e11aafb
refactor(be): add safe Redis member parsing with error handling
westsunh 0659894
refactor(be): normalize socket data structure for study room
westsunh 0f5071c
refactor(be): improve study room join validation and lifecycle
westsunh 05332bf
refactor(be): remove unused study room member fields
westsunh 45bbfa2
docs(be): update JSDoc for study room leave
westsunh 599bac5
Merge branch 'main' of into t2640-study-group-2depth-socket
westsunh d895f9d
fix(be): add Redis password to BullMQ
westsunh 1c57e0d
refactor(be): prevent race condition in enterRoom
westsunh 5c374ec
refactor(be): improve room cleanup and edge case handling in StudyRoo…
westsunh c3a86a2
Merge branch 'main' of into t2640-study-group-2depth-socket
westsunh 11623ce
Merge branch 'main' into t2640-study-group-2depth-socket
Choi-Jung-Hyeon da3a676
feat(be): restrict WebSocket CORS origin by encironment
westsunh 261d8fc
refactor(be): move study-room constants to libs
westsunh 650b785
Merge branch 'main' into t2640-study-group-2depth-socket
Choi-Jung-Hyeon e9c33e2
Merge branch 'main' into t2640-study-group-2depth-socket
westsunh 4cc3df3
refactor(be): remove host and simplify room state
westsunh b150c63
Merge branch 't2640-study-group-2depth-socket' into t2640-study-group…
westsunh 90394e4
feat(be): install websokets, redisAdapter, ioredis for studygroup
westsunh 4c4fbc2
feat(be): add Redis module and Socket.IO adapter
westsunh 1ed587d
feat(be): add WebSocket auth to JWT auth guard
westsunh c1f24ea
feat(be): integrate Redis module into application
westsunh 701c79b
feat(be): add Redis WebSocket adapter to main
westsunh d491a99
feat(be): add WebSocket gateway for study group
westsunh a01d583
feat(be): add StudyGateway to StudyModule
westsunh cdcf088
feat(be): add validateJoinableStudyGroup in study service
westsunh f753892
feat(be): add StudyRoom handleJoin()
westsunh b916700
fix(be): add user data handling logic to websocket handler
westsunh bd7226e
fix(be): map user id instead of socket id
westsunh c62f77f
fix(be): fix spread to preserve data
westsunh 4fe37ed
fix(be): add params type
westsunh 1bec0a7
feat(be): add StudyRoom handleLeave()
westsunh 4307c1d
refactor(be): separate parsePayload logic
westsunh e87f111
feat(be): setup BullMQ for study-room
westsunh d9c8b3c
feat(be): implement socket disconnect and reconnect recovery logic
westsunh 6e03654
refactor(be): use socket data instead of payload for room:leave
westsunh 2fe4aaf
feat(be): implement room lifecycle handling with BullMQ
westsunh c95cbaa
fix(be): resolve race conditions in reconnection and handle expired s…
westsunh b78f66a
chore(be): refine logging and clean up unused code
westsunh 4834b38
chore(be): remove unused res field and simplify socket leave logic
westsunh 59490c6
feat(be): reassign host on host leave
westsunh b5951ba
refactor(be): use DB endTime for study room expiration
westsunh fb1dc28
refactor(be): standardize key prefix structure for study
westsunh 0d57c8e
refactor(be): add safe Redis member parsing with error handling
westsunh 10a0c70
refactor(be): normalize socket data structure for study room
westsunh 468f0ed
refactor(be): improve study room join validation and lifecycle
westsunh 9502c45
refactor(be): remove unused study room member fields
westsunh 964976c
docs(be): update JSDoc for study room leave
westsunh a349099
fix(be): add Redis password to BullMQ
westsunh 5b1c451
refactor(be): prevent race condition in enterRoom
westsunh 0fac57f
refactor(be): improve room cleanup and edge case handling in StudyRoo…
westsunh 246f926
feat(be): restrict WebSocket CORS origin by encironment
westsunh cfc9a4c
refactor(be): move study-room constants to libs
westsunh 14e6141
refactor(be): remove host and simplify room state
westsunh b300302
Merge branch 't2640-study-group-2depth-socket' into t2640-study-group…
westsunh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,7 +1,8 @@ | ||
| import { MailerModule } from '@nestjs-modules/mailer' | ||
| import { BullModule } from '@nestjs/bullmq' | ||
| import { CacheModule } from '@nestjs/cache-manager' | ||
| import { Module, type OnApplicationBootstrap } from '@nestjs/common' | ||
| import { ConfigModule } from '@nestjs/config' | ||
| import { ConfigModule, ConfigService } from '@nestjs/config' | ||
| import { APP_FILTER, APP_GUARD, HttpAdapterHost } from '@nestjs/core' | ||
| import type { Server } from 'http' | ||
| import { OpenTelemetryModule } from 'nestjs-otel' | ||
|
|
@@ -12,6 +13,7 @@ import { ClientExceptionFilter } from '@libs/exception' | |
| import { openTelemetryModuleOption } from '@libs/instrumentation' | ||
| import { pinoLoggerModuleOption } from '@libs/logger' | ||
| import { PrismaModule } from '@libs/prisma' | ||
| import { RedisModule } from '@libs/redis' | ||
| import { AnnouncementModule } from './announcement/announcement.module' | ||
| import { AppController } from './app.controller' | ||
| import { AppService } from './app.service' | ||
|
|
@@ -55,7 +57,20 @@ import { WorkbookModule } from './workbook/workbook.module' | |
| NotificationModule, | ||
| LoggerModule.forRoot(pinoLoggerModuleOption), | ||
| OpenTelemetryModule.forRoot(openTelemetryModuleOption), | ||
| StudyModule | ||
| StudyModule, | ||
| RedisModule, | ||
| BullModule.forRootAsync({ | ||
| inject: [ConfigService], | ||
| useFactory: (configService: ConfigService) => ({ | ||
| connection: { | ||
| host: configService.get<string>('REDIS_HOST'), | ||
| port: configService.get<number>('REDIS_PORT'), | ||
| password: configService.get<string>('REDIS_PASSWORD'), | ||
| db: 1 | ||
| }, | ||
| prefix: 'bull-client' | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. prefix 충돌 안하져? |
||
| }) | ||
| }) | ||
| ], | ||
| controllers: [AppController], | ||
| providers: [ | ||
|
|
||
This file contains hidden or 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
31 changes: 31 additions & 0 deletions
31
apps/backend/apps/client/src/study/interface/study-socket.interface.ts
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| // Room | ||
| export interface RoomState { | ||
| endAt: number | ||
| leaderId: number | null | ||
| } | ||
|
|
||
| export interface RoomMember { | ||
| userId: number | ||
| userName: string | ||
| joinedAt: number | ||
| } | ||
|
|
||
| // Socket Response | ||
| export interface SocketResponse<T = undefined> { | ||
| success: boolean | ||
| message?: string | ||
| data?: T | ||
| code?: string | ||
| } | ||
|
|
||
| export interface JoinResponse { | ||
| members: RoomMember[] | ||
| endAt: number | ||
| remainMs: number | ||
| leaderId: number | null | ||
| } | ||
|
|
||
| // PayLoad | ||
| export interface JoinPayload { | ||
| groupId: number | ||
| } |
41 changes: 41 additions & 0 deletions
41
apps/backend/apps/client/src/study/study-room.processor.ts
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import { Processor, WorkerHost } from '@nestjs/bullmq' | ||
| import { Logger } from '@nestjs/common' | ||
| import { Job } from 'bullmq' | ||
| import { | ||
| STUDY_ROOM_QUEUE, | ||
| JOB_RECONNECT_EXPIRE, | ||
| JOB_ROOM_REMINDER, | ||
| JOB_ROOM_END | ||
| } from '@libs/constants' | ||
| import { StudyRoomService } from './study-room.service' | ||
|
|
||
| @Processor(STUDY_ROOM_QUEUE) | ||
| export class StudyRoomProcessor extends WorkerHost { | ||
| private readonly logger = new Logger(StudyRoomProcessor.name) | ||
|
|
||
| constructor(private readonly studyRoomService: StudyRoomService) { | ||
| super() | ||
| } | ||
|
|
||
| async process(job: Job): Promise<void> { | ||
| switch (job.name) { | ||
| case JOB_ROOM_REMINDER: | ||
| await this.studyRoomService.reminderRoom(job.data.groupId) | ||
| break | ||
|
|
||
| case JOB_ROOM_END: | ||
| await this.studyRoomService.endRoom(job.data.groupId) | ||
| break | ||
|
|
||
| case JOB_RECONNECT_EXPIRE: | ||
| await this.studyRoomService.handleReconnectExpiry(job.data) | ||
| break | ||
|
|
||
| default: | ||
| this.logger.warn( | ||
| `Unknown job name: ${job.name}`, | ||
| JSON.stringify(job.data) | ||
| ) | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
하드코딩 머임!