Merge pull request #37 from dalbodeule/develop

some fix WSSongListRoutes.kt
This commit is contained in:
JinU Choi 2024-08-05 16:25:46 +09:00 committed by GitHub
commit d5dc7a61c9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -26,14 +26,14 @@ fun Routing.wsSongListRoutes() {
val dispatcher: CoroutinesEventBus by inject(CoroutinesEventBus::class.java) val dispatcher: CoroutinesEventBus by inject(CoroutinesEventBus::class.java)
fun addSession(uid: String, session: WebSocketServerSession) { fun addSession(sid: String, session: WebSocketServerSession) {
sessions.computeIfAbsent(uid) { ConcurrentLinkedQueue() }.add(session) sessions.computeIfAbsent(sid) { ConcurrentLinkedQueue() }.add(session)
} }
fun removeSession(uid: String, session: WebSocketServerSession) { fun removeSession(sid: String, session: WebSocketServerSession) {
sessions[uid]?.remove(session) sessions[sid]?.remove(session)
if(sessions[uid]?.isEmpty() == true) { if(sessions[sid]?.isEmpty() == true) {
sessions.remove(uid) sessions.remove(sid)
} }
} }
@ -75,7 +75,7 @@ fun Routing.wsSongListRoutes() {
if(data.maxUserLimit != null && data.maxUserLimit > 0) SongConfigService.updatePersonalLimit(user, data.maxUserLimit) if(data.maxUserLimit != null && data.maxUserLimit > 0) SongConfigService.updatePersonalLimit(user, data.maxUserLimit)
if(data.isStreamerOnly != null) SongConfigService.updateStreamerOnly(user, data.isStreamerOnly) if(data.isStreamerOnly != null) SongConfigService.updateStreamerOnly(user, data.isStreamerOnly)
if(data.url != null) { if(data.type == SongType.ADD.value && data.url != null) {
val youtubeVideo = getYoutubeVideo(data.url) val youtubeVideo = getYoutubeVideo(data.url)
if(youtubeVideo != null) { if(youtubeVideo != null) {
CoroutineScope(Dispatchers.Default).launch { CoroutineScope(Dispatchers.Default).launch {
@ -92,7 +92,7 @@ fun Routing.wsSongListRoutes() {
} }
} }
} }
if(data.remove != null && data.remove > 0) { else if(data.type == SongType.REMOVE.value && data.remove != null && data.remove > 0) {
val songs = SongListService.getSong(user) val songs = SongListService.getSong(user)
if(songs.size < data.remove) { if(songs.size < data.remove) {
val song = songs[data.remove] val song = songs[data.remove]
@ -110,6 +110,18 @@ fun Routing.wsSongListRoutes() {
) )
) )
} }
} else if(data.type == SongType.NEXT.value) {
val song = SongListService.getSong(user)[0]
SongListService.deleteSong(user, song.uid, song.name)
dispatcher.post(SongEvent(
user.token,
SongType.NEXT,
null,
null,
null,
null,
null,
))
} }
} }
is Frame.Ping -> send(Frame.Pong(frame.data)) is Frame.Ping -> send(Frame.Pong(frame.data))
@ -131,7 +143,7 @@ fun Routing.wsSongListRoutes() {
val user = UserService.getUser(it.uid) val user = UserService.getUser(it.uid)
if(user != null) { if(user != null) {
val session = SongConfigService.getConfig(user) val session = SongConfigService.getConfig(user)
sessions[session.token]?.forEach { ws -> sessions[session.token ?: ""]?.forEach { ws ->
ws.sendSerialized( ws.sendSerialized(
SongResponse( SongResponse(
it.type.value, it.type.value,
@ -148,18 +160,23 @@ fun Routing.wsSongListRoutes() {
} }
dispatcher.subscribe(TimerEvent::class) { dispatcher.subscribe(TimerEvent::class) {
if(it.type == TimerType.STREAM_OFF) { if(it.type == TimerType.STREAM_OFF) {
val user = UserService.getUser(it.uid)
SongConfigService.updateSession(user!!, null)
CoroutineScope(Dispatchers.Default).launch { CoroutineScope(Dispatchers.Default).launch {
sessions[it.uid]?.forEach { ws -> val user = UserService.getUser(it.uid)
ws.sendSerialized(SongResponse( if(user != null) {
it.type.value, val session = SongConfigService.getConfig(user)
it.uid,
null, sessions[session.token ?: ""]?.forEach { ws ->
null, ws.sendSerialized(
null, SongResponse(
null, it.type.value,
)) it.uid,
null,
null,
null,
null,
)
)
}
} }
} }
} }