Skip to content
This repository was archived by the owner on Jan 25, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions examples/ws-rtsp-player/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html>
<head>
<title>Example of H.264 RTSP video streaming via WebSocket Proxy</title>
</head>

<body>
<div style="width: 640px; height: 480px; padding: 10px">
<media-stream-player
variant="normal"
format="RTP_H264"
rtspurl="rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov"
wsproxy="172.16.0.56/websockify/?ip=wowzaec2demo.streamlock.net&port=554"
/>
</div>
<script src="./media-stream-player.min.js"></script>
</body>
</html>
278 changes: 278 additions & 0 deletions examples/ws-rtsp-player/media-stream-player.min.js

Large diffs are not rendered by default.

18 changes: 16 additions & 2 deletions lib/BasicPlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ const DEFAULT_FORMAT = Format.JPEG

interface BasicPlayerProps {
readonly hostname: string
readonly wsproxy: string
readonly rtspurl: string
readonly vapixParams?: VapixParameters
readonly format?: Format
readonly autoPlay?: boolean
Expand All @@ -46,6 +48,8 @@ export const BasicPlayer = forwardRef<PlayerNativeElement, BasicPlayerProps>(
(
{
hostname,
wsproxy,
rtspurl,
vapixParams = {},
format = DEFAULT_FORMAT,
autoPlay = false,
Expand All @@ -57,6 +61,8 @@ export const BasicPlayer = forwardRef<PlayerNativeElement, BasicPlayerProps>(
) => {
const [play, setPlay] = useState(autoPlay)
const [host, setHost] = useState(hostname)
const [ws_proxy, setWSProxy] = useState(wsproxy)
const [rtsp_url, setRTSPURL] = useState(rtspurl)

/**
* Controls
Expand All @@ -75,25 +81,31 @@ export const BasicPlayer = forwardRef<PlayerNativeElement, BasicPlayerProps>(
setPlay(false)
} else {
setHost(hostname)
setWSProxy(wsproxy)
setRTSPURL(rtspurl)
setPlay(true)
}
}, [play, hostname])
}, [play, hostname, wsproxy, rtspurl])

useEffect(() => {
const cb = () => {
if (document.visibilityState === 'visible') {
setPlay(true)
setHost(hostname)
setWSProxy(wsproxy)
setRTSPURL(rtspurl)
} else if (document.visibilityState === 'hidden') {
setPlay(false)
setHost('')
setWSProxy('')
setRTSPURL('')
}
}

document.addEventListener('visibilitychange', cb)

return () => document.removeEventListener('visibilitychange', cb)
}, [hostname])
}, [hostname, wsproxy, rtspurl])

/**
* Aspect ratio
Expand Down Expand Up @@ -156,6 +168,8 @@ export const BasicPlayer = forwardRef<PlayerNativeElement, BasicPlayerProps>(
refresh={0}
play={play}
host={host}
wsproxy={ws_proxy}
rtspurl={rtsp_url}
format={format}
parameters={vapixParams}
onPlaying={onPlaying}
Expand Down
10 changes: 7 additions & 3 deletions lib/Controls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ interface ControlsProps {
readonly format: Format
readonly volume?: number
readonly setVolume?: (v: number) => void
readonly showSettings?: boolean
}

export const Controls: React.FC<ControlsProps> = ({
Expand All @@ -172,6 +173,7 @@ export const Controls: React.FC<ControlsProps> = ({
format,
volume,
setVolume,
showSettings = true,
}) => {
const controlArea = useRef(null)
const userActive = useUserActive(controlArea)
Expand Down Expand Up @@ -400,9 +402,11 @@ export const Controls: React.FC<ControlsProps> = ({
{totalDuration === Infinity ? '∙ LIVE' : progress.counter}
</ProgressIndicator>
</Progress>
<Button onClick={toggleSettings}>
<CogWheel title={labels?.settings} />
</Button>
{showSettings && (
<Button onClick={toggleSettings}>
<CogWheel title={labels?.settings} />
</Button>
)}
</ControlBar>
{settings && (
<Settings
Expand Down
62 changes: 62 additions & 0 deletions lib/MediaStreamPlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Format } from './types'

enum PlayerVariants {
BASIC = 'basic',
NORMAL = 'normal',
ADVANCED = 'advanced',
}
interface InitialAttributes {
Expand All @@ -29,6 +30,8 @@ interface InitialAttributes {
readonly textbackgroundcolor: string
readonly textpos: string
readonly secure: boolean
readonly wsproxy: string
readonly rtspurl: string
}

type SetStateType = React.Dispatch<React.SetStateAction<InitialAttributes>>
Expand Down Expand Up @@ -66,6 +69,8 @@ export class MediaStreamPlayer extends HTMLElement {
'textbackgroundcolor',
'textpos',
'secure',
'wsproxy',
'rtspurl',
]
}

Expand All @@ -90,6 +95,8 @@ export class MediaStreamPlayer extends HTMLElement {
textbackgroundcolor,
textpos,
secure,
wsproxy,
rtspurl,
} = this

return {
Expand All @@ -112,6 +119,8 @@ export class MediaStreamPlayer extends HTMLElement {
textbackgroundcolor,
textpos,
secure,
wsproxy,
rtspurl,
}
}

Expand Down Expand Up @@ -279,7 +288,40 @@ export class MediaStreamPlayer extends HTMLElement {
}
}

public get wsproxy() {
return this.getAttribute('wsproxy') ?? ''
}

public set wsproxy(value: string) {
this.setAttribute('wsproxy', value)
}

public get rtspurl() {
return this.getAttribute('rtspurl') ?? ''
}

public set rtspurl(value: string) {
this.setAttribute('rtspurl', value)
}

public connectedCallback() {
if (this.rtspurl) {
// RTSP over WS player, no AXIS specific infra required
ReactDOM.render(
<PlayerComponent
// eslint-disable-next-line react/jsx-no-bind
subscribeAttributesChanged={(cb) =>
this.attributeChangeSubscriber(cb)
}
initialAttributes={{
...this.allAttributes,
}}
/>,
this,
)
return
}

const userGroupUrl = new URL(
`http://${this.hostname}/axis-cgi/usergroup.cgi`,
)
Expand Down Expand Up @@ -343,6 +385,8 @@ const PlayerComponent: React.FC<PlayerComponentProps> = ({
const {
variant,
hostname,
wsproxy,
rtspurl,
autoplay,
autoretry,
format,
Expand Down Expand Up @@ -405,17 +449,35 @@ const PlayerComponent: React.FC<PlayerComponentProps> = ({
return (
<Player
hostname={hostname}
wsproxy={wsproxy}
rtspurl={rtspurl}
autoPlay={autoplay}
autoRetry={autoretry}
initialFormat={format as Format}
vapixParams={vapixParameters}
secure={secure}
/>
)
case PlayerVariants.NORMAL:
return (
<Player
hostname={hostname}
wsproxy={wsproxy}
rtspurl={rtspurl}
autoPlay={autoplay}
autoRetry={autoretry}
initialFormat={format as Format}
vapixParams={vapixParameters}
secure={secure}
settings={false}
/>
)
case PlayerVariants.BASIC:
return (
<BasicPlayer
hostname={hostname}
wsproxy={wsproxy}
rtspurl={rtspurl}
autoPlay={autoplay}
autoRetry={autoretry}
format={format as Format}
Expand Down
38 changes: 38 additions & 0 deletions lib/PlaybackArea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ export interface VideoProperties {
interface PlaybackAreaProps {
readonly forwardedRef?: Ref<PlayerNativeElement>
readonly host: string
readonly wsproxy: string
readonly rtspurl: string
readonly format: Format
readonly parameters?: VapixParameters
readonly play?: boolean
Expand Down Expand Up @@ -219,6 +221,8 @@ const searchParams = (api: AxisApi, parameters: VapixParameters = {}) => {

export const PlaybackArea: React.FC<PlaybackAreaProps> = ({
forwardedRef,
wsproxy,
rtspurl,
host,
format,
parameters = {},
Expand All @@ -235,6 +239,40 @@ export const PlaybackArea: React.FC<PlaybackAreaProps> = ({
}) => {
const timestamp = refresh.toString()

if (format === Format.RTP_H264 && rtspurl) {
const rtsp = rtspurl
let ws = ''
if (rtsp) {
const url = new URL(rtsp)
const rtsp_host = url.hostname
const rtsp_port = url.port || '554'

const ws_proto = secure ? Protocol.WSS : Protocol.WS
const port_suffix = window.location.port ? `:${window.location.port}` : ''
const ws_proxy = wsproxy || `${window.location.hostname}${port_suffix}`
ws = `${ws_proto}//${ws_proxy}`
}

return (
<WsRtspVideo
key={refresh}
forwardedRef={forwardedRef as Ref<HTMLVideoElement>}
{...{
ws,
rtsp,
play,
offset,
onPlaying,
onEnded,
onSdp,
onRtcp,
metadataHandler,
autoRetry,
}}
/>
)
}

if (format === Format.RTP_H264) {
const ws = wsUri(secure ? Protocol.WSS : Protocol.WS, host)
const rtsp = rtspUri(
Expand Down
Loading