Skip to content

Commit

Permalink
feat(webapp): add whip & whep loading
Browse files Browse the repository at this point in the history
  • Loading branch information
a-wing committed Dec 26, 2023
1 parent d65861a commit 58f6447
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
9 changes: 8 additions & 1 deletion webapp/components/player/whep-player.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import {
} from '../../store/atom'
import { WHEPClient } from '@binbat/whip-whep/whep'
import { useAtom } from 'jotai'
import SvgProgress from '../svg/progress'

export default function WhepPlayer(props: { streamId: string, status: UserStatus, width: string }) {
const refEnabled = useRef(false)
const refPC = useRef<RTCPeerConnection | null>(null)
const [loading, setLoading] = useState(true)
const [connectionState, setConnectionState] = useState("unknown")
const [userStream, setUserStream] = useState<UserStream>({
stream: new MediaStream,
Expand All @@ -34,6 +36,7 @@ export default function WhepPlayer(props: { streamId: string, status: UserStatus
}

const start = async (resource: string) => {
setLoading(false)
if (refPC.current) {
const whep = new WHEPClient();
const url = location.origin + "/whep/" + resource;
Expand All @@ -44,6 +47,7 @@ export default function WhepPlayer(props: { streamId: string, status: UserStatus
}

const restart = async (resource: string) => {
setLoading(true)
if (refPC.current) {
refPC.current.close()
}
Expand Down Expand Up @@ -79,7 +83,10 @@ export default function WhepPlayer(props: { streamId: string, status: UserStatus
return (
<div className='flex flex-col'>
<center>
<Player user={userStream} muted={false} width={props.width} display="auto" />
{ loading
? <SvgProgress/>
: <Player user={userStream} muted={false} width={props.width} display="auto" />
}
</center>

<details className='text-white'>
Expand Down
10 changes: 9 additions & 1 deletion webapp/components/player/whip-player.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
import Player from './player'
import { WHIPClient } from '@binbat/whip-whep/whip'
import { deviceScreen } from '../../lib/device'
import SvgProgress from '../svg/progress'

export default function WhipPlayer(props: { streamId: string, width: string }) {
const refEnabled = useRef(false)
Expand All @@ -19,6 +20,8 @@ export default function WhipPlayer(props: { streamId: string, width: string }) {
const [localStream] = useAtom(localStreamAtom)
const [localUserStatus, setLocalUserStatus] = useAtom(localUserStatusAtom)

const [loading, setLoading] = useState(true)

const [currentDeviceAudio] = useAtom(currentDeviceAudioAtom)
const [currentDeviceVideo] = useAtom(currentDeviceVideoAtom)

Expand Down Expand Up @@ -71,9 +74,11 @@ export default function WhipPlayer(props: { streamId: string, width: string }) {
refClient.current = whip
}
}
setLoading(false)
}

const restart = async (resource: string) => {
setLoading(true)
if (refPC.current) {
refPC.current.close()
}
Expand Down Expand Up @@ -136,7 +141,10 @@ export default function WhipPlayer(props: { streamId: string, width: string }) {
return (
<div className='flex flex-col'>
<center>
<Player user={localStream} muted={true} width={props.width} display="auto" />
{ loading
? <SvgProgress/>
: <Player user={localStream} muted={true} width={props.width} display="auto" />
}
</center>

<details className='text-white'>
Expand Down
7 changes: 7 additions & 0 deletions webapp/components/svg/progress.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function SvgProgress() {
return (
<svg className="animate-spin" width="128" height="128" viewBox="0 -960 960 960">
<path fill="#ffffff" d="M480-80q-82 0-155-31.5t-127.5-86Q143-252 111.5-325T80-480q0-83 31.5-155.5t86-127Q252-817 325-848.5T480-880q17 0 28.5 11.5T520-840q0 17-11.5 28.5T480-800q-133 0-226.5 93.5T160-480q0 133 93.5 226.5T480-160q133 0 226.5-93.5T800-480q0-17 11.5-28.5T840-520q17 0 28.5 11.5T880-480q0 82-31.5 155t-86 127.5q-54.5 54.5-127 86T480-80Z"/>
</svg>
)
}

0 comments on commit 58f6447

Please sign in to comment.