Merge pull request #60 from dalbodeule/develop

debug some errors.
This commit is contained in:
JinU Choi 2024-08-13 07:18:05 +09:00 committed by GitHub
commit 4c15aac295
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 41 additions and 18 deletions

View File

@ -124,16 +124,32 @@ object ChzzkHandler {
} }
} }
fun startThread(name: String, runner: Runnable) {
CoroutineScope(Dispatchers.Default).launch {
while(running) {
try {
val thread = Thread(runner, name)
thread.start()
thread.join()
} catch(e: Exception) {
logger.error("Thread $name Exception: ${e.stackTraceToString()}")
}
if(running) {
logger.info("Thread $name restart in 5 seconds")
delay(5000)
}
}
}
}
// 첫 번째 스레드 시작 // 첫 번째 스레드 시작
val thread1 = Thread(threadRunner1, "Chzzk-StreamInfo-1") startThread("Chzzk-StreamInfo-1", threadRunner1)
thread1.start()
// 85초 대기 후 두 번째 스레드 시작 // 85초 대기 후 두 번째 스레드 시작
CoroutineScope(Dispatchers.Default).launch { CoroutineScope(Dispatchers.Default).launch {
delay(85000) // 85초 대기 delay(95000) // start with 95 secs after.
if (running) { if (running) {
val thread2 = Thread(threadRunner2, "Chzzk-StreamInfo-2") startThread("Chzzk-StreamInfo-2", threadRunner2)
thread2.start()
} }
} }
} }
@ -208,6 +224,7 @@ class UserHandler(
CoroutineScope(Dispatchers.Default).launch { CoroutineScope(Dispatchers.Default).launch {
if(!_isActive) { if(!_isActive) {
_isActive = true
when(TimerConfigService.getConfig(UserService.getUser(channel.channelId)!!)?.option) { when(TimerConfigService.getConfig(UserService.getUser(channel.channelId)!!)?.option) {
TimerType.UPTIME.value -> dispatcher.post( TimerType.UPTIME.value -> dispatcher.post(
TimerEvent( TimerEvent(
@ -238,6 +255,7 @@ class UserHandler(
logger.info("${user.username} is offline.") logger.info("${user.username} is offline.")
streamStartTime = null streamStartTime = null
listener.closeAsync() listener.closeAsync()
_isActive = false
CoroutineScope(Dispatchers.Default).launch { CoroutineScope(Dispatchers.Default).launch {
val events = listOf( val events = listOf(
@ -257,9 +275,9 @@ class UserHandler(
null null
) )
) )
events.forEach { dispatcher.post(it) } events.forEach { dispatcher.post(it) }
} }
} }
_isActive = value
} }
} }

View File

@ -121,9 +121,12 @@ fun Routing.wsSongListRoutes() {
data.url data.url
)) ))
} else if(data.type == SongType.NEXT.value) { } else if(data.type == SongType.NEXT.value) {
val song = SongListService.getSong(user)[0] val songList = SongListService.getSong(user)
if(songList.isNotEmpty()) {
val song = songList[0]
SongListService.deleteSong(user, song.uid, song.name) SongListService.deleteSong(user, song.uid, song.name)
dispatcher.post(SongEvent( dispatcher.post(
SongEvent(
user.token!!, user.token!!,
SongType.NEXT, SongType.NEXT,
null, null,
@ -132,7 +135,9 @@ fun Routing.wsSongListRoutes() {
null, null,
null, null,
null null
)) )
)
}
} }
} }
is Frame.Ping -> send(Frame.Pong(frame.data)) is Frame.Ping -> send(Frame.Pong(frame.data))