mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-10 02:54:15 +00:00
support profiles
This commit is contained in:
parent
32bdad1608
commit
6552b734c8
@ -1,430 +0,0 @@
|
||||
import React from "react"
|
||||
import * as antd from "antd"
|
||||
|
||||
import { Icons, createIconRender } from "components/Icons"
|
||||
|
||||
import Livestream from "../../../../models/livestream"
|
||||
|
||||
import "./index.less"
|
||||
|
||||
const CategoryView = (props) => {
|
||||
const category = props.category
|
||||
|
||||
const [categoryData, setCategoryData] = React.useState(null)
|
||||
|
||||
const loadData = async () => {
|
||||
const categoryData = await Livestream.getCategories(category).catch((err) => {
|
||||
console.error(err)
|
||||
|
||||
app.message.error("Failed to load category")
|
||||
|
||||
return null
|
||||
})
|
||||
|
||||
setCategoryData(categoryData)
|
||||
}
|
||||
|
||||
React.useEffect(() => {
|
||||
if (props.category) {
|
||||
loadData()
|
||||
}
|
||||
}, [props.category])
|
||||
|
||||
return <div className="category">
|
||||
{
|
||||
categoryData?.icon &&
|
||||
<div className="icon">
|
||||
{createIconRender(categoryData.icon)}
|
||||
</div>
|
||||
}
|
||||
|
||||
<div className="label">
|
||||
{categoryData?.label ?? "No category"}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
const StreamingKeyView = (props) => {
|
||||
const [streamingKeyVisibility, setStreamingKeyVisibility] = React.useState(false)
|
||||
|
||||
const toogleVisibility = (to) => {
|
||||
setStreamingKeyVisibility(to ?? !streamingKeyVisibility)
|
||||
}
|
||||
|
||||
return <div className="streamingKeyString">
|
||||
{streamingKeyVisibility ?
|
||||
<>
|
||||
<Icons.EyeOff onClick={() => toogleVisibility()} />
|
||||
<code>
|
||||
{props.streamingKey ?? "No streaming key available"}
|
||||
</code>
|
||||
</> :
|
||||
<div
|
||||
onClick={() => toogleVisibility()}
|
||||
>
|
||||
<Icons.Eye />
|
||||
Click to show key
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
|
||||
const LivestreamsCategoriesSelector = (props) => {
|
||||
const [categories, setCategories] = React.useState([])
|
||||
const [loading, setLoading] = React.useState(true)
|
||||
|
||||
const loadData = async () => {
|
||||
setLoading(true)
|
||||
|
||||
const categories = await Livestream.getCategories().catch((err) => {
|
||||
console.error(err)
|
||||
|
||||
app.message.error("Failed to load categories")
|
||||
|
||||
return null
|
||||
})
|
||||
|
||||
console.log(`Loaded categories >`, categories)
|
||||
|
||||
setLoading(false)
|
||||
|
||||
if (categories) {
|
||||
setCategories(categories)
|
||||
}
|
||||
}
|
||||
|
||||
React.useEffect(() => {
|
||||
loadData()
|
||||
}, [])
|
||||
|
||||
if (loading) {
|
||||
return <antd.Skeleton active />
|
||||
}
|
||||
|
||||
return <antd.Select
|
||||
placeholder="Select a category"
|
||||
defaultValue={props.defaultValue}
|
||||
onChange={(value) => props.updateStreamInfo("category", value)}
|
||||
>
|
||||
{
|
||||
categories.map((category) => {
|
||||
return <antd.Select.Option value={category?.key ?? "unknown"}>{category?.label ?? "No category"}</antd.Select.Option>
|
||||
})
|
||||
}
|
||||
</antd.Select>
|
||||
}
|
||||
|
||||
const StreamInfoEditor = (props) => {
|
||||
const [streamInfo, setStreamInfo] = React.useState(props.defaultStreamInfo ?? {})
|
||||
|
||||
const updateStreamInfo = (key, value) => {
|
||||
setStreamInfo({
|
||||
...streamInfo,
|
||||
[key]: value,
|
||||
})
|
||||
}
|
||||
|
||||
const saveStreamInfo = async () => {
|
||||
if (typeof props.onSave === "function") {
|
||||
return await props.onSave(streamInfo)
|
||||
}
|
||||
|
||||
// peform default save
|
||||
const result = await Livestream.updateLivestreamInfo(streamInfo).catch((err) => {
|
||||
console.error(err)
|
||||
|
||||
app.message.error("Failed to update stream info")
|
||||
|
||||
return false
|
||||
})
|
||||
|
||||
if (result) {
|
||||
app.message.success("Stream info updated")
|
||||
}
|
||||
|
||||
if (typeof props.onSaveComplete === "function") {
|
||||
await props.onSaveComplete(result)
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
return <div className="streamInfoEditor">
|
||||
<div className="field">
|
||||
<span>
|
||||
<Icons.MdTitle />Title
|
||||
</span>
|
||||
<div className="value">
|
||||
<antd.Input
|
||||
placeholder="Stream title"
|
||||
value={streamInfo.title}
|
||||
onChange={(e) => updateStreamInfo("title", e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="field">
|
||||
<span>
|
||||
<Icons.MdTextFields /> Description
|
||||
</span>
|
||||
<div className="value">
|
||||
<antd.Input
|
||||
placeholder="Stream description"
|
||||
value={streamInfo.description}
|
||||
onChange={(e) => updateStreamInfo("description", e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="field">
|
||||
<span>
|
||||
<Icons.MdCategory /> Category
|
||||
</span>
|
||||
<div className="value">
|
||||
<LivestreamsCategoriesSelector
|
||||
defaultValue={streamInfo.category}
|
||||
updateStreamInfo={updateStreamInfo}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<antd.Button
|
||||
type="primary"
|
||||
onClick={saveStreamInfo}
|
||||
>
|
||||
Save
|
||||
</antd.Button>
|
||||
</div>
|
||||
}
|
||||
|
||||
export default (props) => {
|
||||
const [streamInfo, setStreamInfo] = React.useState({})
|
||||
const [addresses, setAddresses] = React.useState({})
|
||||
|
||||
const [isConnected, setIsConnected] = React.useState(false)
|
||||
const [streamingKey, setStreamingKey] = React.useState(null)
|
||||
|
||||
const onClickEditInfo = () => {
|
||||
app.ModalController.open(() => <StreamInfoEditor
|
||||
defaultStreamInfo={streamInfo}
|
||||
onSaveComplete={(result) => {
|
||||
if (result) {
|
||||
app.ModalController.close()
|
||||
|
||||
fetchStreamInfo()
|
||||
}
|
||||
}}
|
||||
/>)
|
||||
}
|
||||
|
||||
const regenerateStreamingKey = async () => {
|
||||
antd.Modal.confirm({
|
||||
title: "Regenerate streaming key",
|
||||
content: "Are you sure you want to regenerate the streaming key? After this, all other generated keys will be deleted.",
|
||||
onOk: async () => {
|
||||
const result = await Livestream.regenerateStreamingKey().catch((err) => {
|
||||
app.message.error(`Failed to regenerate streaming key`)
|
||||
console.error(err)
|
||||
|
||||
return null
|
||||
})
|
||||
|
||||
if (result) {
|
||||
setStreamingKey(result.key)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const fetchStreamingKey = async () => {
|
||||
const streamingKey = await Livestream.getStreamingKey().catch((err) => {
|
||||
console.error(err)
|
||||
return false
|
||||
})
|
||||
|
||||
if (streamingKey) {
|
||||
setStreamingKey(streamingKey.key)
|
||||
}
|
||||
}
|
||||
|
||||
const fetchAddresses = async () => {
|
||||
const addresses = await Livestream.getAddresses().catch((error) => {
|
||||
app.message.error(`Failed to fetch addresses`)
|
||||
console.error(error)
|
||||
|
||||
return null
|
||||
})
|
||||
|
||||
if (addresses) {
|
||||
setAddresses(addresses)
|
||||
}
|
||||
}
|
||||
|
||||
const fetchStreamInfo = async () => {
|
||||
const result = await Livestream.getStreamInfo().catch((err) => {
|
||||
console.error(err)
|
||||
return false
|
||||
})
|
||||
|
||||
console.log("Stream info", result)
|
||||
|
||||
if (result) {
|
||||
setStreamInfo(result)
|
||||
}
|
||||
}
|
||||
|
||||
React.useEffect(() => {
|
||||
fetchAddresses()
|
||||
fetchStreamInfo()
|
||||
fetchStreamingKey()
|
||||
}, [])
|
||||
|
||||
return <div className="streamingControlPanel">
|
||||
<div className="header">
|
||||
<div className="preview">
|
||||
<img src="/assets/new_file.png" />
|
||||
</div>
|
||||
|
||||
<div className="details">
|
||||
<div className="status">
|
||||
<antd.Tag
|
||||
color={isConnected ? "Blue" : "Red"}
|
||||
icon={isConnected ? <Icons.MdOutlineVideocam /> : <Icons.MdOutlineVideocamOff />}
|
||||
>
|
||||
{isConnected ? "Connected" : "Disconnected"}
|
||||
</antd.Tag>
|
||||
</div>
|
||||
<div className="title">
|
||||
<span>
|
||||
Title
|
||||
</span>
|
||||
<h2>
|
||||
{streamInfo?.title ?? "No title"}
|
||||
</h2>
|
||||
</div>
|
||||
|
||||
<div className="description">
|
||||
<span>
|
||||
Description
|
||||
</span>
|
||||
|
||||
<p>
|
||||
{streamInfo?.description ?? "No description"}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="category">
|
||||
<span>
|
||||
Category
|
||||
</span>
|
||||
<CategoryView category={streamInfo?.category} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<antd.Button
|
||||
type="primary"
|
||||
icon={<Icons.Edit2 />}
|
||||
onClick={onClickEditInfo}
|
||||
>
|
||||
Edit info
|
||||
</antd.Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="config">
|
||||
<div className="panel">
|
||||
<h2><Icons.MdSettingsInputAntenna /> Emission</h2>
|
||||
|
||||
<div className="content">
|
||||
<span>Ingestion URL</span>
|
||||
|
||||
<code>
|
||||
{addresses.ingestURL ?? "No ingest URL available"}
|
||||
</code>
|
||||
</div>
|
||||
|
||||
<div className="content">
|
||||
<div className="title">
|
||||
<div>
|
||||
<span>Streaming key </span>
|
||||
</div>
|
||||
<div>
|
||||
<antd.Button onClick={() => regenerateStreamingKey()}>
|
||||
<Icons.RefreshCw />
|
||||
Regenerate
|
||||
</antd.Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="value">
|
||||
<StreamingKeyView streamingKey={streamingKey} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="panel">
|
||||
<h2><Icons.Tool />Additional options</h2>
|
||||
|
||||
<div className="content">
|
||||
<span>Enable DVR</span>
|
||||
|
||||
<div className="value">
|
||||
<antd.Switch
|
||||
checked={streamInfo?.dvr ?? false}
|
||||
onChange={false}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="content">
|
||||
<span>Private mode</span>
|
||||
|
||||
<div className="value">
|
||||
<antd.Switch
|
||||
checked={streamInfo?.private ?? false}
|
||||
onChange={false}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="panel">
|
||||
<h2><Icons.Link /> URL Information</h2>
|
||||
|
||||
<div className="content">
|
||||
<span>AAC URL (Only Audio)</span>
|
||||
|
||||
<code>
|
||||
{addresses.aacURL ?? "No AAC URL available"}
|
||||
</code>
|
||||
</div>
|
||||
|
||||
<div className="content">
|
||||
<span>HLS URL</span>
|
||||
|
||||
<code>
|
||||
{addresses.hlsURL ?? "No HLS URL available"}
|
||||
</code>
|
||||
</div>
|
||||
|
||||
<div className="content">
|
||||
<span>FLV URL</span>
|
||||
|
||||
<code>
|
||||
{addresses.flvURL ?? "No FLV URL available"}
|
||||
</code>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="panel">
|
||||
<h2><Icons.Activity /> Statistics</h2>
|
||||
|
||||
<div className="content">
|
||||
<antd.Result>
|
||||
<h1>
|
||||
Cannot connect with statistics
|
||||
</h1>
|
||||
</antd.Result>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
import FeedTab from "./components/feed"
|
||||
import ControlPanelTab from "./components/controlPanel"
|
||||
import FeedTab from "./tabs/feed"
|
||||
import ControlPanelTab from "./tabs/livestreamControlPanel"
|
||||
|
||||
export default [
|
||||
{
|
||||
|
@ -0,0 +1,49 @@
|
||||
import React from "react"
|
||||
import * as antd from "antd"
|
||||
|
||||
import Livestream from "models/livestream"
|
||||
|
||||
export default (props) => {
|
||||
const [categories, setCategories] = React.useState([])
|
||||
const [loading, setLoading] = React.useState(true)
|
||||
|
||||
const loadData = async () => {
|
||||
setLoading(true)
|
||||
|
||||
const categories = await Livestream.getCategories().catch((err) => {
|
||||
console.error(err)
|
||||
|
||||
app.message.error("Failed to load categories")
|
||||
|
||||
return null
|
||||
})
|
||||
|
||||
console.log(`Loaded categories >`, categories)
|
||||
|
||||
setLoading(false)
|
||||
|
||||
if (categories) {
|
||||
setCategories(categories)
|
||||
}
|
||||
}
|
||||
|
||||
React.useEffect(() => {
|
||||
loadData()
|
||||
}, [])
|
||||
|
||||
if (loading) {
|
||||
return <antd.Skeleton active />
|
||||
}
|
||||
|
||||
return <antd.Select
|
||||
placeholder="Select a category"
|
||||
defaultValue={props.defaultValue}
|
||||
onChange={(value) => props.updateStreamInfo("category", value)}
|
||||
>
|
||||
{
|
||||
categories.map((category) => {
|
||||
return <antd.Select.Option value={category?.key ?? "unknown"}>{category?.label ?? "No category"}</antd.Select.Option>
|
||||
})
|
||||
}
|
||||
</antd.Select>
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
import React from "react"
|
||||
import { createIconRender } from "components/Icons"
|
||||
|
||||
import Livestream from "models/livestream"
|
||||
|
||||
export default (props) => {
|
||||
const category = props.category
|
||||
|
||||
const [categoryData, setCategoryData] = React.useState(null)
|
||||
|
||||
const loadData = async () => {
|
||||
const categoryData = await Livestream.getCategories(category).catch((err) => {
|
||||
console.error(err)
|
||||
|
||||
app.message.error("Failed to load category")
|
||||
|
||||
return null
|
||||
})
|
||||
|
||||
setCategoryData(categoryData)
|
||||
}
|
||||
|
||||
React.useEffect(() => {
|
||||
if (props.category) {
|
||||
loadData()
|
||||
}
|
||||
}, [props.category])
|
||||
|
||||
return <div className="category">
|
||||
{
|
||||
categoryData?.icon &&
|
||||
<div className="icon">
|
||||
{createIconRender(categoryData.icon)}
|
||||
</div>
|
||||
}
|
||||
|
||||
<div className="label">
|
||||
{categoryData?.label ?? "No category"}
|
||||
</div>
|
||||
</div>
|
||||
}
|
@ -0,0 +1,143 @@
|
||||
import React from "react"
|
||||
import * as antd from "antd"
|
||||
import { Icons } from "components/Icons"
|
||||
import UploadButton from "components/UploadButton"
|
||||
|
||||
import CategoriesSelector from "../CategoriesSelector"
|
||||
|
||||
import "./index.less"
|
||||
|
||||
export default (props) => {
|
||||
const [profileData, setProfileData] = React.useState(props.profileData ?? {})
|
||||
|
||||
const updateStreamInfo = (key, value) => {
|
||||
setProfileData((oldData) => {
|
||||
return {
|
||||
...oldData,
|
||||
info: {
|
||||
...oldData.info,
|
||||
[key]: value,
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const handleClickSave = async () => {
|
||||
if (typeof props.onSave === "function") {
|
||||
return await props.onSave(profileData)
|
||||
}
|
||||
}
|
||||
|
||||
const handleClickDelete = async () => {
|
||||
if (typeof props.onDelete === "function") {
|
||||
return await props.onDelete(profileData._id)
|
||||
}
|
||||
}
|
||||
|
||||
return <div className="profileEditor">
|
||||
<div className="field">
|
||||
<span>
|
||||
<Icons.MdTag /> Profile Name
|
||||
</span>
|
||||
|
||||
<div className="value">
|
||||
<antd.Input
|
||||
placeholder="Profile name"
|
||||
value={profileData.profile_name}
|
||||
onChange={(e) => setProfileData((oldData) => {
|
||||
return {
|
||||
...oldData,
|
||||
profile_name: e.target.value,
|
||||
}
|
||||
})}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="field">
|
||||
<span>
|
||||
<Icons.MdImage /> Thumbnail
|
||||
</span>
|
||||
|
||||
<div className="value thumbnail">
|
||||
{
|
||||
profileData.info?.thumbnail && <img src={profileData.info.thumbnail} />
|
||||
}
|
||||
|
||||
<div className="controls">
|
||||
<UploadButton
|
||||
multiple={false}
|
||||
onUploadDone={(file) => {
|
||||
console.log(`Uploaded file >`, file)
|
||||
|
||||
updateStreamInfo("thumbnail", file.url)
|
||||
}}
|
||||
/>
|
||||
|
||||
{
|
||||
profileData.info?.thumbnail && <antd.Button
|
||||
type="text"
|
||||
icon={<Icons.Trash />}
|
||||
onClick={() => updateStreamInfo("thumbnail", null)}
|
||||
danger
|
||||
>
|
||||
Delete
|
||||
</antd.Button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="field">
|
||||
<span>
|
||||
<Icons.MdTitle />Title
|
||||
</span>
|
||||
|
||||
<div className="value">
|
||||
<antd.Input
|
||||
placeholder="Stream title"
|
||||
value={profileData.info.title}
|
||||
onChange={(e) => updateStreamInfo("title", e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="field">
|
||||
<span>
|
||||
<Icons.MdTextFields /> Description
|
||||
</span>
|
||||
|
||||
<div className="value">
|
||||
<antd.Input
|
||||
placeholder="Stream description"
|
||||
value={profileData.info.description}
|
||||
onChange={(e) => updateStreamInfo("description", e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="field">
|
||||
<span>
|
||||
<Icons.MdCategory /> Category
|
||||
</span>
|
||||
|
||||
<div className="value">
|
||||
<CategoriesSelector
|
||||
defaultValue={profileData.info.category}
|
||||
updateStreamInfo={updateStreamInfo}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<antd.Button
|
||||
type="primary"
|
||||
onClick={handleClickSave}
|
||||
>
|
||||
Save
|
||||
</antd.Button>
|
||||
|
||||
<antd.Button
|
||||
type="text"
|
||||
onClick={handleClickDelete}
|
||||
danger
|
||||
>
|
||||
Delete
|
||||
</antd.Button>
|
||||
</div>
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
.profileEditor {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
.field {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
margin-bottom: 20px;
|
||||
|
||||
.value {
|
||||
margin-top: 5px;
|
||||
margin-left: 20px;
|
||||
|
||||
.ant-select {
|
||||
min-width: 200px;
|
||||
}
|
||||
|
||||
&.thumbnail {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
width: 100%;
|
||||
|
||||
gap: 10px;
|
||||
|
||||
img {
|
||||
border-radius: 12px;
|
||||
|
||||
max-width: 600px;
|
||||
max-height: 400px;
|
||||
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
.controls {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
|
||||
gap: 10px;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
import React from "react"
|
||||
import * as antd from "antd"
|
||||
import { Icons } from "components/Icons"
|
||||
//import { useTranslation } from "react-i18next"
|
||||
|
||||
const ProfilesDropboxCustomRender = (props) => {
|
||||
return <>
|
||||
{props.menu}
|
||||
|
||||
<antd.Divider style={{ margin: '8px 0' }} />
|
||||
|
||||
<antd.Space style={{ padding: '0 8px 4px' }}>
|
||||
<antd.Input
|
||||
placeholder="Profile name"
|
||||
ref={props.inputRef}
|
||||
value={props.inputValue}
|
||||
onChange={props.onInputChange}
|
||||
/>
|
||||
<antd.Button
|
||||
type="text"
|
||||
icon={<Icons.Plus />}
|
||||
onClick={props.onClickAdd}
|
||||
>
|
||||
Create
|
||||
</antd.Button>
|
||||
</antd.Space>
|
||||
</>
|
||||
}
|
||||
|
||||
export default (props) => {
|
||||
const [inputValue, setInputValue] = React.useState("")
|
||||
|
||||
const onInputChange = (e) => {
|
||||
setInputValue(e.target.value)
|
||||
}
|
||||
|
||||
const onAddNewProfile = async () => {
|
||||
const value = inputValue.trim()
|
||||
|
||||
if (!value) {
|
||||
return
|
||||
}
|
||||
|
||||
setInputValue("")
|
||||
|
||||
props.onCreateProfile(value)
|
||||
}
|
||||
|
||||
return <antd.Select
|
||||
loading={props.loading}
|
||||
placeholder="Select a streaming profile"
|
||||
value={props.value}
|
||||
onChange={(_id, item) => props.onChangeProfile(_id, item)}
|
||||
dropdownRender={(menu) => <ProfilesDropboxCustomRender
|
||||
inputValue={inputValue}
|
||||
onInputChange={onInputChange}
|
||||
onClickAdd={onAddNewProfile}
|
||||
menu={menu}
|
||||
/>}
|
||||
options={props.profiles.map((item) => ({
|
||||
label: item.profile_name,
|
||||
value: item._id,
|
||||
}))}
|
||||
/>
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
import React from "react"
|
||||
import { Icons } from "components/Icons"
|
||||
|
||||
import "./index.less"
|
||||
|
||||
export default (props) => {
|
||||
const [streamingKeyVisibility, setStreamingKeyVisibility] = React.useState(false)
|
||||
|
||||
const toogleVisibility = (to) => {
|
||||
setStreamingKeyVisibility(to ?? !streamingKeyVisibility)
|
||||
}
|
||||
|
||||
return <div className="streamingKeyString">
|
||||
{streamingKeyVisibility ?
|
||||
<>
|
||||
<Icons.EyeOff onClick={() => toogleVisibility()} />
|
||||
<code>
|
||||
{props.streamingKey ?? "No streaming key available"}
|
||||
</code>
|
||||
</> :
|
||||
<div
|
||||
onClick={() => toogleVisibility()}
|
||||
>
|
||||
<Icons.Eye />
|
||||
Click to show key
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
.streamingKeyString {
|
||||
display: inline-flex;
|
||||
flex-direction: row;
|
||||
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
color: var(--text-color);
|
||||
|
||||
svg {
|
||||
font-size: 1.5rem;
|
||||
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
div {
|
||||
display: inline-flex;
|
||||
flex-direction: row;
|
||||
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
}
|
344
packages/app/src/pages/tv/tabs/livestreamControlPanel/index.jsx
Executable file
344
packages/app/src/pages/tv/tabs/livestreamControlPanel/index.jsx
Executable file
@ -0,0 +1,344 @@
|
||||
import React from "react"
|
||||
import * as antd from "antd"
|
||||
import { Icons } from "components/Icons"
|
||||
|
||||
import ProfileSelector from "./components/ProfileSelector"
|
||||
import CategoryViewResolver from "./components/CategoryViewResolver"
|
||||
import StreamingKeyViewer from "./components/StreamingKeyViewer"
|
||||
import ProfileEditor from "./components/ProfileEditor"
|
||||
|
||||
import Livestream from "models/livestream"
|
||||
|
||||
import "./index.less"
|
||||
|
||||
export default (props) => {
|
||||
const [L_Profiles, R_Profiles, E_Profiles, M_Profiles] = app.cores.api.useRequest(Livestream.getProfiles)
|
||||
|
||||
const [selectedProfileId, setSelectedProfileId] = React.useState(null)
|
||||
|
||||
const [addresses, setAddresses] = React.useState({})
|
||||
|
||||
const [isConnected, setIsConnected] = React.useState(false)
|
||||
|
||||
const fetchAddresses = async () => {
|
||||
const addresses = await Livestream.getAddresses().catch((error) => {
|
||||
app.message.error(`Failed to fetch addresses`)
|
||||
console.error(error)
|
||||
|
||||
return null
|
||||
})
|
||||
|
||||
if (addresses) {
|
||||
setAddresses(addresses)
|
||||
}
|
||||
}
|
||||
|
||||
React.useEffect(() => {
|
||||
if (R_Profiles) {
|
||||
fetchAddresses()
|
||||
|
||||
if (!selectedProfileId) {
|
||||
setSelectedProfileId(R_Profiles[0]?._id)
|
||||
}
|
||||
}
|
||||
}, [R_Profiles])
|
||||
|
||||
if (E_Profiles) {
|
||||
console.error(E_Profiles)
|
||||
|
||||
return <antd.Result
|
||||
status="error"
|
||||
title="Failed to load profiles"
|
||||
subTitle="Failed to load profiles, please try again later"
|
||||
/>
|
||||
}
|
||||
|
||||
if (L_Profiles) {
|
||||
return <antd.Skeleton active />
|
||||
}
|
||||
|
||||
const profileData = R_Profiles.find((profile) => profile._id === selectedProfileId)
|
||||
|
||||
const handleCreateProfile = async (profile_name) => {
|
||||
if (!profile_name) {
|
||||
return false
|
||||
}
|
||||
|
||||
const result = await Livestream.postProfile({
|
||||
profile_name: profile_name,
|
||||
}).catch((err) => {
|
||||
console.error(err)
|
||||
|
||||
app.message.error("Failed to add new profile")
|
||||
|
||||
return false
|
||||
})
|
||||
|
||||
if (result) {
|
||||
app.message.success("New profile added")
|
||||
|
||||
await M_Profiles()
|
||||
|
||||
setSelectedProfileId(result._id)
|
||||
}
|
||||
}
|
||||
|
||||
const handleCurrentProfileDataUpdate = async (newProfileData) => {
|
||||
if (!profileData) {
|
||||
return
|
||||
}
|
||||
|
||||
const result = await Livestream.postProfile({
|
||||
...newProfileData,
|
||||
profile_id: profileData._id,
|
||||
}).catch((err) => {
|
||||
console.error(err)
|
||||
|
||||
app.message.error("Failed to update profile")
|
||||
|
||||
return false
|
||||
})
|
||||
|
||||
if (result) {
|
||||
app.message.success("Profile updated")
|
||||
|
||||
app.ModalController.close()
|
||||
|
||||
M_Profiles()
|
||||
}
|
||||
}
|
||||
|
||||
const handleCurrentProfileDelete = async () => {
|
||||
if (!profileData) {
|
||||
return
|
||||
}
|
||||
|
||||
// open confirm modal
|
||||
antd.Modal.confirm({
|
||||
title: "Delete profile",
|
||||
content: "Are you sure you want to delete this profile?",
|
||||
onOk: async () => {
|
||||
const result = await Livestream.deleteProfile(profileData._id).catch((err) => {
|
||||
console.error(err)
|
||||
|
||||
app.message.error("Failed to delete profile")
|
||||
|
||||
return false
|
||||
})
|
||||
|
||||
if (result) {
|
||||
app.message.success("Profile deleted")
|
||||
|
||||
app.ModalController.close()
|
||||
|
||||
setSelectedProfileId(null)
|
||||
|
||||
M_Profiles()
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const onClickEditInfo = () => {
|
||||
if (!profileData) {
|
||||
return
|
||||
}
|
||||
|
||||
app.ModalController.open(() => <ProfileEditor
|
||||
profileData={profileData}
|
||||
onDelete={handleCurrentProfileDelete}
|
||||
onSave={handleCurrentProfileDataUpdate}
|
||||
/>)
|
||||
}
|
||||
|
||||
const regenerateStreamingKey = async () => {
|
||||
if (!profileData) {
|
||||
return
|
||||
}
|
||||
|
||||
antd.Modal.confirm({
|
||||
title: "Regenerate streaming key",
|
||||
content: "Are you sure you want to regenerate the streaming key? After this, the old stream key will no longer be valid.",
|
||||
onOk: async () => {
|
||||
const result = await Livestream.regenerateStreamingKey(profileData._id).catch((err) => {
|
||||
app.message.error(`Failed to regenerate streaming key`)
|
||||
console.error(err)
|
||||
|
||||
return null
|
||||
})
|
||||
|
||||
if (result) {
|
||||
M_Profiles()
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
return <div className="streamingControlPanel">
|
||||
<div className="streamingControlPanel_header">
|
||||
<div className="streamingControlPanel_header_thumbnail">
|
||||
<img
|
||||
src={
|
||||
profileData?.info.thumbnail ?? "/assets/new_file.png"
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="streamingControlPanel_header_details">
|
||||
<div className="streamingControlPanel_header_details_status">
|
||||
<antd.Tag
|
||||
color={isConnected ? "Blue" : "Red"}
|
||||
icon={isConnected ? <Icons.MdOutlineVideocam /> : <Icons.MdOutlineVideocamOff />}
|
||||
>
|
||||
{isConnected ? "Connected" : "Disconnected"}
|
||||
</antd.Tag>
|
||||
</div>
|
||||
|
||||
<div className="streamingControlPanel_header_details_title">
|
||||
<span>
|
||||
Title
|
||||
</span>
|
||||
<h2>
|
||||
{profileData?.info.title ?? "No title"}
|
||||
</h2>
|
||||
</div>
|
||||
|
||||
<div className="streamingControlPanel_header_details_description">
|
||||
<span>
|
||||
Description
|
||||
</span>
|
||||
|
||||
<p>
|
||||
{profileData?.info.description ?? "No description"}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="streamingControlPanel_header_details_category">
|
||||
<span>
|
||||
Category
|
||||
</span>
|
||||
|
||||
<CategoryViewResolver category={profileData?.info.category} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="streamingControlPanel_header_actions">
|
||||
<ProfileSelector
|
||||
profiles={R_Profiles}
|
||||
value={selectedProfileId}
|
||||
loading={L_Profiles}
|
||||
onCreateProfile={handleCreateProfile}
|
||||
onChangeProfile={(profileID) => {
|
||||
setSelectedProfileId(profileID)
|
||||
}}
|
||||
/>
|
||||
|
||||
<antd.Button
|
||||
type="primary"
|
||||
icon={<Icons.Edit2 />}
|
||||
onClick={onClickEditInfo}
|
||||
>
|
||||
Edit profile
|
||||
</antd.Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="config">
|
||||
<div className="panel">
|
||||
<h2><Icons.MdSettingsInputAntenna /> Emission</h2>
|
||||
|
||||
<div className="content">
|
||||
<span>Ingestion URL</span>
|
||||
|
||||
<code>
|
||||
{addresses.ingestURL ?? "No ingest URL available"}
|
||||
</code>
|
||||
</div>
|
||||
|
||||
<div className="content">
|
||||
<div className="title">
|
||||
<div>
|
||||
<span>Streaming key </span>
|
||||
</div>
|
||||
<div>
|
||||
<antd.Button onClick={() => regenerateStreamingKey()}>
|
||||
<Icons.RefreshCw />
|
||||
Regenerate
|
||||
</antd.Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="value">
|
||||
<StreamingKeyViewer streamingKey={profileData?.stream_key} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="panel">
|
||||
<h2><Icons.Tool />Additional options</h2>
|
||||
|
||||
<div className="content">
|
||||
<span>Enable DVR</span>
|
||||
|
||||
<div className="value">
|
||||
<antd.Switch
|
||||
checked={profileData?.options?.dvr ?? false}
|
||||
onChange={false}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="content">
|
||||
<span>Private mode</span>
|
||||
|
||||
<div className="value">
|
||||
<antd.Switch
|
||||
checked={profileData?.options?.private ?? false}
|
||||
onChange={false}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="panel">
|
||||
<h2><Icons.Link /> URL Information</h2>
|
||||
|
||||
<div className="content">
|
||||
<span>AAC URL (Only Audio)</span>
|
||||
|
||||
<code>
|
||||
{addresses.aacURL ?? "No AAC URL available"}
|
||||
</code>
|
||||
</div>
|
||||
|
||||
<div className="content">
|
||||
<span>HLS URL</span>
|
||||
|
||||
<code>
|
||||
{addresses.hlsURL ?? "No HLS URL available"}
|
||||
</code>
|
||||
</div>
|
||||
|
||||
<div className="content">
|
||||
<span>FLV URL</span>
|
||||
|
||||
<code>
|
||||
{addresses.flvURL ?? "No FLV URL available"}
|
||||
</code>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="panel">
|
||||
<h2><Icons.Activity /> Statistics</h2>
|
||||
|
||||
<div className="content">
|
||||
<antd.Result>
|
||||
<h1>
|
||||
Cannot connect with statistics
|
||||
</h1>
|
||||
</antd.Result>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
@ -6,7 +6,7 @@
|
||||
|
||||
transition: all 0.3s ease-in-out;
|
||||
|
||||
.header {
|
||||
.streamingControlPanel_header {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
|
||||
@ -21,13 +21,20 @@
|
||||
|
||||
transition: all 0.3s ease-in-out;
|
||||
|
||||
.preview {
|
||||
.streamingControlPanel_header_thumbnail {
|
||||
align-self: center;
|
||||
justify-self: center;
|
||||
|
||||
border-radius: 12px;
|
||||
|
||||
height: 100%;
|
||||
width: 300px;
|
||||
width: 100%;
|
||||
|
||||
img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
height: 15vh;
|
||||
width: 20vw;
|
||||
|
||||
object-fit: cover;
|
||||
|
||||
border-radius: 12px;
|
||||
}
|
||||
@ -35,16 +42,32 @@
|
||||
margin-right: 40px;
|
||||
}
|
||||
|
||||
.details {
|
||||
.streamingControlPanel_header_details {
|
||||
display: inline-flex;
|
||||
flex-direction: column;
|
||||
|
||||
padding: 20px 0;
|
||||
width: 100%;
|
||||
|
||||
.status {
|
||||
.streamingControlPanel_header_details_status {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
color: var(--text-color);
|
||||
}
|
||||
|
||||
.streamingControlPanel_header_actions {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
|
||||
justify-items: center;
|
||||
|
||||
gap: 10px;
|
||||
|
||||
.ant-select {
|
||||
height: fit-content;
|
||||
min-width: 300px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -56,6 +79,8 @@
|
||||
|
||||
transition: all 0.3s ease-in-out;
|
||||
|
||||
gap: 20px;
|
||||
|
||||
code {
|
||||
padding: 5px 8px;
|
||||
font-size: 1rem;
|
||||
@ -76,7 +101,6 @@
|
||||
|
||||
align-items: flex-start;
|
||||
|
||||
|
||||
h1,
|
||||
h2,
|
||||
h3 {
|
||||
@ -87,9 +111,9 @@
|
||||
.title {
|
||||
display: inline-flex;
|
||||
flex-direction: row;
|
||||
|
||||
|
||||
justify-content: space-between;
|
||||
|
||||
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
@ -102,49 +126,4 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.streamingKeyString {
|
||||
display: inline-flex;
|
||||
flex-direction: row;
|
||||
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
color: var(--text-color);
|
||||
|
||||
svg {
|
||||
font-size: 1.5rem;
|
||||
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
div {
|
||||
display: inline-flex;
|
||||
flex-direction: row;
|
||||
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
}
|
||||
|
||||
.streamInfoEditor {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
.field {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
margin-bottom: 20px;
|
||||
|
||||
.value {
|
||||
margin-top: 5px;
|
||||
margin-left: 20px;
|
||||
|
||||
.ant-select {
|
||||
min-width: 200px;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user