Skip to content

Commit

Permalink
feat: supports continuous monitoring when live broadcast ends
Browse files Browse the repository at this point in the history
  • Loading branch information
chenfan0 committed Jul 7, 2024
1 parent a344ab0 commit 7439f26
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = {
],
rules: {
'@typescript-eslint/explicit-function-return-type': 'off',
'typescript-eslint/no-explicit-any': 'off'
'typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-explicit-any': 'off',
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"i18next": "^23.11.5",
"localforage": "^1.10.0",
"lucide-react": "^0.383.0",
"mitt": "^3.0.1",
"react-hook-form": "^7.51.5",
"react-i18next": "^14.1.2",
"react-use": "^17.5.0",
Expand Down
7 changes: 7 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ export const USER_CLOSE_WINDOW = 'USER_CLOSE_WINDOW'
export const FORCE_CLOSE_WINDOW = 'FORCE_CLOSE_WINDOW'

export const RECORD_DUMMY_PROCESS = { kill: () => {} }


export const RECORD_END_NOT_USER_STOP = 'RECORD_END_NOT_USER_STOP'
10 changes: 10 additions & 0 deletions src/renderer/src/components/StreamConfigList/StreamConfigList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import Dialog from '@/components/Dialog'
import StreamConfigCard from './components/StreamConfigCard'

import { SUCCESS_CODE, FFMPEG_ERROR_CODE, errorCodeToI18nMessage } from '../../../../code'
import emitter from '@/lib/bus'
import { RECORD_END_NOT_USER_STOP } from '../../../../const'

import { useStreamConfigStore } from '@/store/useStreamConfigStore'
import { useFfmpegProgressInfoStore } from '@/store/useFfmpegProgressInfoStore'
Expand Down Expand Up @@ -52,6 +54,7 @@ export default function StreamConfigList() {
// FFMPEG_ERROR_CODE.USER_KILL_PROCESS stop by user
const isStopByUser = code === FFMPEG_ERROR_CODE.USER_KILL_PROCESS
const isStopByStreamEnd = code === SUCCESS_CODE
let stopWithLineError = false

if (streamConfig.status === StreamStatus.RECORDING) {
await updateStreamConfig(
Expand Down Expand Up @@ -81,6 +84,7 @@ export default function StreamConfigList() {
// if not stop by user and still can get live urls
// mean the stream can no be record, hint change the stream line
message = 'error.stop_record.current_line_error'
stopWithLineError = true
} else {
// mean the stream is not live
// start monitor the stream
Expand All @@ -101,6 +105,12 @@ export default function StreamConfigList() {
{ ...streamConfig, status: StreamStatus.NOT_STARTED },
streamConfig.title
)

if (isStopByUser || stopWithLineError) {
return
}

emitter.emit(RECORD_END_NOT_USER_STOP, streamConfig.title)
})

window.api.onUserCloseWindow(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useRef, useState } from 'react'
import { useEffect, useRef, useState } from 'react'
import { useTranslation } from 'react-i18next'

import UseThemeIcon from '@/components/UseThemeIcon'
Expand All @@ -20,6 +20,8 @@ import StreamConfigSheet from '@renderer/components/StreamConfigSheet'

import { useToast } from '@renderer/hooks/useToast'
import { CRAWLER_ERROR_CODE, SUCCESS_CODE, errorCodeToI18nMessage } from '../../../../../code'
import { RECORD_END_NOT_USER_STOP } from '../../../../../const'
import emitter from '@/lib/bus'

interface OperationBarProps {
streamConfig: IStreamConfig
Expand Down Expand Up @@ -91,7 +93,7 @@ export default function OperationBar(props: OperationBarProps) {
)
toast({
title: streamConfig.title,
description: errMessage,
description: t(errMessage),
variant: 'destructive'
})
}
Expand All @@ -105,6 +107,22 @@ export default function OperationBar(props: OperationBarProps) {
clearTimeout(timer.current)
}

useEffect(() => {
const handleRecordEndNotUserStop = async (title: string) => {
if (title !== streamConfig.title) return
if (timer.current) {
clearTimeout(timer.current)
}
timer.current = setTimeout(() => {
handlePlayClick()
}, 2000)
}
emitter.on(RECORD_END_NOT_USER_STOP, handleRecordEndNotUserStop as any)
return () => {
emitter.off(RECORD_END_NOT_USER_STOP, handleRecordEndNotUserStop as any)
}
}, [streamConfig, timer])

return (
<>
<div className="flex absolute right-0 gap-2">
Expand Down
5 changes: 5 additions & 0 deletions src/renderer/src/lib/bus.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import mitt from 'mitt'

const emitter = mitt()

export default emitter
9 changes: 7 additions & 2 deletions src/renderer/src/locales/locales.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ export default {
forbidden: 'Request was denied, try using or changing the proxy',
invalid_proxy: 'Proxy address is invalid, please check the proxy address',
not_support: 'This streaming platform is not supported',
invalid_url: 'Stream URL is invalid'
invalid_url: 'Stream URL is invalid',
cookie_expired: 'Cookie has expired, please re-enter the cookie',
cookie_is_required:
'Current streaming platform requires a cookie, please enter the cookie'
},
stop_record: {
current_line_error: 'Stop recording (current line error, try using another line)',
Expand Down Expand Up @@ -174,7 +177,9 @@ export default {
forbidden: '请求被拒绝,尝试使用或者更换代理',
invalid_proxy: '代理地址不合法, 请检查代理地址',
not_support: '当前不支持该直播平台',
invalid_url: '直播间地址不合法'
invalid_url: '直播间地址不合法',
cookie_expired: 'Cookie已过期,请重新填写',
cookie_is_required: '当前直播平台需要Cookie,请填写Cookie'
},
stop_record: {
current_line_error: '停止录制(当前线路错误,尝试使用其他线路)',
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.web.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"src/renderer/src/**/*.tsx",
"src/preload/*.d.ts",
"./type.d.ts",
"./src/code.ts"
"./src/code.ts",
"./src/const.ts"
],
"compilerOptions": {
"composite": true,
Expand Down

0 comments on commit 7439f26

Please sign in to comment.