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")
thread1.start()
startThread("Chzzk-StreamInfo-1", threadRunner1)
// 85초 대기 후 두 번째 스레드 시작
CoroutineScope(Dispatchers.Default).launch {
delay(85000) // 85초 대기
delay(95000) // start with 95 secs after.
if (running) {
val thread2 = Thread(threadRunner2, "Chzzk-StreamInfo-2")
thread2.start()
startThread("Chzzk-StreamInfo-2", threadRunner2)
}
}
}
@ -208,6 +224,7 @@ class UserHandler(
CoroutineScope(Dispatchers.Default).launch {
if(!_isActive) {
_isActive = true
when(TimerConfigService.getConfig(UserService.getUser(channel.channelId)!!)?.option) {
TimerType.UPTIME.value -> dispatcher.post(
TimerEvent(
@ -238,6 +255,7 @@ class UserHandler(
logger.info("${user.username} is offline.")
streamStartTime = null
listener.closeAsync()
_isActive = false
CoroutineScope(Dispatchers.Default).launch {
val events = listOf(
@ -257,9 +275,9 @@ class UserHandler(
null
)
)
events.forEach { dispatcher.post(it) }
}
}
_isActive = value
}
}

View File

@ -121,18 +121,23 @@ fun Routing.wsSongListRoutes() {
data.url
))
} 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,
null
))
val songList = SongListService.getSong(user)
if(songList.isNotEmpty()) {
val song = songList[0]
SongListService.deleteSong(user, song.uid, song.name)
dispatcher.post(
SongEvent(
user.token!!,
SongType.NEXT,
null,
null,
null,
null,
null,
null
)
)
}
}
}
is Frame.Ping -> send(Frame.Pong(frame.data))