Skip to content

Commit

Permalink
RTC: Refine WHIP player and enable NAME_LOOKUP by default. v5.11.8
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Oct 31, 2023
1 parent e0b79ac commit b69984f
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 57 deletions.
20 changes: 18 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,6 @@ jobs:
-v $HOME/.bt/userInfo.json:/www/server/panel/data/userInfo.json \
-v $HOME/.bt/api.json:/www/server/panel/config/api.json -e BT_KEY=$BT_KEY \
--privileged -v /sys/fs/cgroup:/sys/fs/cgroup:ro \
--add-host srs.stack.local:127.0.0.1 \
-d --rm -v $(pwd):/g -w /g --name=bt ossrs/bt-plugin-dev:1
echo "BT docker started."
- name: Wait for systemd service start
Expand All @@ -496,7 +495,9 @@ jobs:
echo "Import platform image to BT ok."
docker exec bt docker tag platform:latest ossrs/srs-stack:$SRS_TAG
docker exec bt docker tag platform:latest ossrs/srs-stack:$SRS_MAJOR
docker exec bt docker tag platform:latest registry.cn-hangzhou.aliyuncs.com/ossrs/srs-stack:$SRS_TAG
docker exec bt docker tag platform:latest registry.cn-hangzhou.aliyuncs.com/ossrs/srs-stack:$SRS_MAJOR
echo "Tag platform image to BT ok."
docker exec bt docker images
Expand All @@ -514,6 +515,13 @@ jobs:
--www /www/wwwroot --site srs.stack.local
echo "Setup SRS Stack plugin ok."
echo "Setup the dns lookup for domain"
PIP=$(docker exec bt ifconfig eth0 |grep 'inet ' |awk '{print $2}') &&
docker exec bt bash -c "echo '$PIP srs.stack.local' >> /etc/hosts" &&
docker exec bt cat /etc/hosts && echo OK &&
docker exec bt docker exec srs-stack bash -c "echo '$PIP srs.stack.local' >> /etc/hosts" &&
docker exec bt docker exec srs-stack cat /etc/hosts
set +e
docker exec bt systemctl status srs-stack
docker exec bt journalctl -u srs-stack
Expand Down Expand Up @@ -625,7 +633,6 @@ jobs:
-v $(pwd)/build/srs_stack:/www/server/panel/plugin/srs_stack \
-v $HOME/.aapanel/api.json:/www/server/panel/config/api.json -e BT_KEY=$AAPANEL_KEY \
--privileged -v /sys/fs/cgroup:/sys/fs/cgroup:ro \
--add-host srs.stack.local:127.0.0.1 \
-d --rm -v $(pwd):/g -w /g --name=aapanel ossrs/aapanel-plugin-dev:1
echo "aaPanel docker started."
- name: Wait for systemd service start
Expand All @@ -651,7 +658,9 @@ jobs:
echo "Import platform image to aaPanel ok."
docker exec aapanel docker tag platform:latest ossrs/srs-stack:$SRS_TAG
docker exec aapanel docker tag platform:latest ossrs/srs-stack:$SRS_MAJOR
docker exec aapanel docker tag platform:latest registry.cn-hangzhou.aliyuncs.com/ossrs/srs-stack:$SRS_TAG
docker exec aapanel docker tag platform:latest registry.cn-hangzhou.aliyuncs.com/ossrs/srs-stack:$SRS_MAJOR
echo "Tag platform image to aaPanel ok."
docker exec aapanel docker images
Expand All @@ -669,6 +678,13 @@ jobs:
--www /www/wwwroot --site srs.stack.local
echo "Setup SRS Stack plugin ok."
echo "Setup the dns lookup for domain"
PIP=$(docker exec aapanel ifconfig eth0 |grep 'inet ' |awk '{print $2}') &&
docker exec aapanel bash -c "echo '$PIP srs.stack.local' >> /etc/hosts" &&
docker exec aapanel cat /etc/hosts && echo OK &&
docker exec aapanel docker exec srs-stack bash -c "echo '$PIP srs.stack.local' >> /etc/hosts" &&
docker exec aapanel docker exec srs-stack cat /etc/hosts
set +e
docker exec aapanel systemctl status srs-stack
docker exec aapanel journalctl -u srs-stack
Expand Down
59 changes: 39 additions & 20 deletions DEVELOPER.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,24 @@ resources, and ports, as well as development on Mac or using Docker.

## Develop All in macOS

Start redis and SRS by docker:
Start redis and SRS by docker, set the candidate explicitly:

```bash
docker rm -f redis srs 2>/dev/null &&
docker run --name redis --rm -it -v $HOME/data/redis:/data -p 6379:6379 -d redis &&
touch platform/containers/data/config/srs.server.conf platform/containers/data/config/srs.vhost.conf &&
docker run --name srs --rm -it \
-v $(pwd)/platform/containers/data/config:/usr/local/srs/containers/data/config \
-v $(pwd)/platform/containers/conf/srs.release-mac.conf:/usr/local/srs/conf/srs.conf \
-v $(pwd)/platform/containers/conf/srs.release-mac.conf:/usr/local/srs/conf/docker.conf \
-v $(pwd)/platform/containers/objs/nginx:/usr/local/srs/objs/nginx \
-p 1935:1935 -p 1985:1985 -p 8080:8080 -p 8000:8000/udp -p 10080:10080/udp \
-e SRS_RTC_SERVER_USE_AUTO_DETECT_NETWORK_IP=off -e SRS_RTC_SERVER_API_AS_CANDIDATES=off \
-d ossrs/srs:5
```

Or set the candidate explicitly:

```bash
docker rm -f redis srs 2>/dev/null &&
docker run --name redis --rm -it -v $HOME/data/redis:/data -p 6379:6379 -d redis &&
touch platform/containers/data/config/srs.server.conf platform/containers/data/config/srs.vhost.conf &&
docker run --name srs --rm -it \
-v $(pwd)/platform/containers/data/config:/usr/local/srs/containers/data/config \
-v $(pwd)/platform/containers/conf/srs.release-mac.conf:/usr/local/srs/conf/srs.conf \
-v $(pwd)/platform/containers/objs/nginx:/usr/local/srs/objs/nginx \
-p 1935:1935 -p 1985:1985 -p 8080:8080 -p 8000:8000/udp -p 10080:10080/udp \
--env CANDIDATE=$(ifconfig en0 |grep 'inet ' |awk '{print $2}') \
-d ossrs/srs:5
```

> Note: Use the intranet IP for WebRTC to set the candidate.
> Note: Stop service by `docker rm -f redis srs`
> Note: Also, you can run SRS by `(cd platform && ~/git/srs/trunk/objs/srs -c containers/conf/srs.release-local.conf)`
Expand Down Expand Up @@ -71,7 +59,7 @@ Build a docker image:

```bash
docker rm -f script 2>/dev/null &&
docker rmi srs-script-dev 2>/dev/null &&
docker rmi srs-script-dev 2>/dev/null || echo OK &&
docker build -t srs-script-dev -f scripts/setup-ubuntu/Dockerfile.script .
```

Expand Down Expand Up @@ -109,7 +97,7 @@ docker exec -it script docker images
Test the build script, in the docker container:

```bash
docker exec -it bt rm -f /data/config/.env &&
docker exec -it script rm -f /data/config/.env &&
docker exec -it script bash build/srs_stack/scripts/setup-ubuntu/uninstall.sh 2>/dev/null || echo OK &&
bash scripts/setup-ubuntu/build.sh --output $(pwd)/build --extract &&
docker exec -it script bash build/srs_stack/scripts/setup-ubuntu/install.sh --verbose
Expand All @@ -118,6 +106,7 @@ docker exec -it script bash build/srs_stack/scripts/setup-ubuntu/install.sh --ve
Run test for script:

```bash
rm -f test/srs-stack.test &&
docker exec -it script make -j -C test &&
bash scripts/tools/secret.sh --output test/.env &&
docker exec -it script ./test/srs-stack.test -test.v -endpoint http://localhost:2022 \
Expand Down Expand Up @@ -149,7 +138,6 @@ docker run -p 80:80 -p 443:443 -p 7800:7800 \
-v $(pwd)/build/srs_stack:/www/server/panel/plugin/srs_stack \
-v $HOME/.bt/api.json:/www/server/panel/config/api.json -e BT_KEY=$AAPANEL_KEY \
--privileged -v /sys/fs/cgroup:/sys/fs/cgroup:rw --cgroupns=host \
--add-host srs.stack.local:127.0.0.1 \
-d --rm -it -v $(pwd):/g -w /g --name=aapanel ossrs/aapanel-plugin-dev:1
```

Expand All @@ -170,9 +158,12 @@ Enter the docker container:

```bash
version=$(bash scripts/version.sh) &&
major=$(echo $version |awk -F '.' '{print $1}' |sed 's/v//g') &&
docker exec -it aapanel docker load -i platform.tar &&
docker exec -it aapanel docker tag platform:latest ossrs/srs-stack:$version &&
docker exec -it aapanel docker tag platform:latest ossrs/srs-stack:$major &&
docker exec -it aapanel docker tag platform:latest registry.cn-hangzhou.aliyuncs.com/ossrs/srs-stack:$version &&
docker exec -it aapanel docker tag platform:latest registry.cn-hangzhou.aliyuncs.com/ossrs/srs-stack:$major &&
docker exec -it aapanel docker images
```

Expand All @@ -196,9 +187,22 @@ docker exec -it aapanel bash /www/server/panel/plugin/srs_stack/setup.sh \
--www /www/wwwroot --site srs.stack.local
```

Setup the dns lookup for domain `srs.stack.local`:

```bash
PIP=$(docker exec -it aapanel ifconfig eth0 |grep 'inet ' |awk '{print $2}') &&
docker exec -it aapanel bash -c "echo '$PIP srs.stack.local' >> /etc/hosts" &&
docker exec -it aapanel cat /etc/hosts && echo OK &&
docker exec -it aapanel docker exec -it srs-stack bash -c "echo '$PIP srs.stack.local' >> /etc/hosts" &&
docker exec -it aapanel docker exec -it srs-stack cat /etc/hosts
```
> Note: We add host `srs.stack.local` to the ip of eth0, because we need to access it in the
> srs-stack docker in docker.
Run test for aaPanel:

```bash
rm -f test/srs-stack.test &&
docker exec -it aapanel make -j -C test &&
bash scripts/tools/secret.sh --output test/.env &&
docker exec -it aapanel ./test/srs-stack.test -test.v -endpoint http://srs.stack.local:80 \
Expand Down Expand Up @@ -236,7 +240,6 @@ docker run -p 80:80 -p 443:443 -p 7800:7800 \
-v $HOME/.bt/userInfo.json:/www/server/panel/data/userInfo.json \
-v $HOME/.bt/api.json:/www/server/panel/config/api.json -e BT_KEY=$BT_KEY \
--privileged -v /sys/fs/cgroup:/sys/fs/cgroup:rw --cgroupns=host \
--add-host srs.stack.local:127.0.0.1 \
-d --rm -it -v $(pwd):/g -w /g --name=bt ossrs/bt-plugin-dev:1
```

Expand All @@ -260,9 +263,12 @@ Enter the docker container:

```bash
version=$(bash scripts/version.sh) &&
major=$(echo $version |awk -F '.' '{print $1}' |sed 's/v//g') &&
docker exec -it bt docker load -i platform.tar &&
docker exec -it bt docker tag platform:latest ossrs/srs-stack:$version &&
docker exec -it bt docker tag platform:latest ossrs/srs-stack:$major &&
docker exec -it bt docker tag platform:latest registry.cn-hangzhou.aliyuncs.com/ossrs/srs-stack:$version &&
docker exec -it bt docker tag platform:latest registry.cn-hangzhou.aliyuncs.com/ossrs/srs-stack:$major &&
docker exec -it bt docker images
```

Expand All @@ -286,9 +292,22 @@ docker exec -it bt bash /www/server/panel/plugin/srs_stack/setup.sh \
--www /www/wwwroot --site srs.stack.local
```

Setup the dns lookup for domain `srs.stack.local`:

```bash
PIP=$(docker exec -it bt ifconfig eth0 |grep 'inet ' |awk '{print $2}') &&
docker exec -it bt bash -c "echo '$PIP srs.stack.local' >> /etc/hosts" &&
docker exec -it bt cat /etc/hosts && echo OK &&
docker exec -it bt docker exec -it srs-stack bash -c "echo '$PIP srs.stack.local' >> /etc/hosts" &&
docker exec -it bt docker exec -it srs-stack cat /etc/hosts
```
> Note: We add host `srs.stack.local` to the ip of eth0, because we need to access it in the
> srs-stack docker in docker.
Run test for BT:

```bash
rm -f test/srs-stack.test &&
docker exec -it bt make -j -C test &&
bash scripts/tools/secret.sh --output test/.env &&
docker exec -it bt ./test/srs-stack.test -test.v -endpoint http://srs.stack.local:80 \
Expand Down
5 changes: 5 additions & 0 deletions platform/candidate.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ func (v *CandidateWorker) Resolve(host string) (net.IP, error) {
}
}

// Ignore localhost.
if host == "localhost" {
return nil, nil
}

// Directly use the ip if not name.
if ip := net.ParseIP(host); ip != nil {
return ip, nil
Expand Down
2 changes: 1 addition & 1 deletion platform/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func doMain(ctx context.Context) error {
setEnvDefault("AUTO_SELF_SIGNED_CERTIFICATE", "off")

// For feature control.
setEnvDefault("NAME_LOOKUP", "off")
setEnvDefault("NAME_LOOKUP", "on")

logger.Tf(ctx, "load .env as MGMT_PASSWORD=%vB, "+
"SRS_PLATFORM_SECRET=%vB, CLOUD=%v, REGION=%v, SOURCE=%v, "+
Expand Down
3 changes: 2 additions & 1 deletion scripts/setup-aapanel/auto/zip.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ ret=$?; if [[ 0 -ne ${ret} ]]; then echo "mv failed, ret=$ret"; exit $ret; fi
echo "Move $INSTALL_FILE to ${OUTPUT}"

if [[ $EXTRACT == yes ]]; then
(cd ${OUTPUT} && rm -rf srs_stack && unzip -q $INSTALL_FILE)
if [[ -d $OUTPUT/srs_stack ]]; then rm -rf $OUTPUT/srs_stack/*; fi &&
(cd ${OUTPUT} && unzip -q $INSTALL_FILE)
ret=$?; if [[ 0 -ne ${ret} ]]; then echo "tar failed, ret=$ret"; exit $ret; fi
echo "Extract $INSTALL_FILE to ${OUTPUT}"
fi
Expand Down
3 changes: 2 additions & 1 deletion scripts/setup-bt/auto/zip.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ ret=$?; if [[ 0 -ne ${ret} ]]; then echo "mv failed, ret=$ret"; exit $ret; fi
echo "Move $INSTALL_FILE to ${OUTPUT}"

if [[ $EXTRACT == yes ]]; then
(cd ${OUTPUT} && rm -rf srs_stack && unzip -q $INSTALL_FILE)
if [[ -d $OUTPUT/srs_stack ]]; then rm -rf $OUTPUT/srs_stack/*; fi &&
(cd ${OUTPUT} && unzip -q $INSTALL_FILE)
ret=$?; if [[ 0 -ne ${ret} ]]; then echo "tar failed, ret=$ret"; exit $ret; fi
echo "Extract $INSTALL_FILE to ${OUTPUT}"
fi
Expand Down
16 changes: 8 additions & 8 deletions test/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,14 @@ func TestApi_SrsApiNoAuth(t *testing.T) {
return
}

// Should OK for RTC api.
offer := strings.ReplaceAll(exampleOffer, "\n", "\r\n")
streamID := fmt.Sprintf("stream-%v-%v", os.Getpid(), rand.Int())
if err := apiRequestNoAuth(ctx, fmt.Sprintf("/rtc/v1/whip/?app=live&stream=%v&secret=%v", streamID, pubSecret), offer, nil); err != nil {
r0 = errors.Wrapf(err, "should ok for rtc publish api")
return
}

// For health check api, should ok.
if err := apiRequestNoAuth(ctx, "/api/v1/versions", nil, nil); err != nil {
r0 = errors.Wrapf(err, "should ok for health check api")
Expand All @@ -511,14 +519,6 @@ func TestApi_SrsApiNoAuth(t *testing.T) {
r0 = errors.Errorf("should failed if no auth")
return
}

// Should OK for RTC api.
offer := strings.ReplaceAll(exampleOffer, "\n", "\r\n")
streamID := fmt.Sprintf("stream-%v-%v", os.Getpid(), rand.Int())
if err := apiRequestNoAuth(ctx, fmt.Sprintf("/rtc/v1/whip/?app=live&stream=%v&secret=%v", streamID, pubSecret), offer, nil); err != nil {
r0 = errors.Wrapf(err, "should ok for rtc publish api")
return
}
}

func TestApi_SrsApiWithAuth(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion ui/src/components/TutorialsButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function useTutorialsEn(mediumRef) {
'ba1895828b4f': {
author: 'Winlin Yang',
link: 'https://blog.ossrs.io/virtual-live-events-revolutionizing-the-way-we-experience-entertainment-ba1895828b4f',
title: 'Virtual Live Events: Revolutionizing the Way We Experience Entertainment'
title: 'Mastering Virtual Live Events: Harness the Power of Pre-Recorded Content for Seamless and Engaging Live Streaming Experiences'
},
'2aa792c35b25': {
author: 'Winlin Yang',
Expand Down
23 changes: 1 addition & 22 deletions ui/src/components/UrlGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,7 @@ export function buildUrls(defaultUrl, secret) {
// For WebRTC url.
if (true) {
const secretQuery = secret ? `&&secret=${secret.publish}` : '';
urls.flvUrl2 = `https://${defaultHostname}/${defaultApp}/${defaultStream}.flv`;
urls.m3u8Url2 = `https://${defaultHostname}/${defaultApp}/${defaultStream}.m3u8`;
urls.rtcPublisher = `/players/whip.html?schema=https&port=443&api=443&autostart=true&stream=${defaultStream}${secretQuery}`;
urls.flvPlayer2 = `/players/srs_player.html?schema=https&port=443&api=443&autostart=true&stream=${defaultStream}.flv`;
urls.hlsPlayer2 = `/players/srs_player.html?schema=https&port=443&api=443&autostart=true&stream=${defaultStream}.m3u8`;
urls.rtcPlayer2 = `/players/whep.html?schema=https&port=443&api=443&autostart=true&stream=${defaultStream}`;
urls.rtcPublisher = `/players/whip.html?schema=https&port=${defaultPort}&api=${defaultPort}&autostart=true&stream=${defaultStream}${secretQuery}`;
}

// For transcode stream and urls.
Expand Down Expand Up @@ -105,11 +100,6 @@ export default function useUrls() {
const [hlsPlayer, setHlsPlayer] = React.useState();
const [rtcPlayer, setRtcPlayer] = React.useState();
const [rtcPublisher, setRtcPublisher] = React.useState();
const [flvPlayer2, setFlvPlayer2] = React.useState();
const [hlsPlayer2, setHlsPlayer2] = React.useState();
const [rtcPlayer2, setRtcPlayer2] = React.useState();
const [flvUrl2, setFlvUrl2] = React.useState();
const [m3u8Url2, setM3u8Url2] = React.useState();

const [transcodeStreamName, setTranscodeStreamName] = React.useState();
const [transcodeStreamKey, setTranscodeStreamKey] = React.useState();
Expand Down Expand Up @@ -180,12 +170,7 @@ export default function useUrls() {

// For WebRTC url.
if (true) {
setFlvUrl2(urls.flvUrl2);
setM3u8Url2(urls.m3u8Url2);
setRtcPublisher(urls.rtcPublisher);
setFlvPlayer2(urls.flvPlayer2);
setHlsPlayer2(urls.hlsPlayer2);
setRtcPlayer2(urls.rtcPlayer2);
}

// For transcode stream and urls.
Expand Down Expand Up @@ -216,12 +201,6 @@ export default function useUrls() {
hlsPlayer,
rtcPlayer,
rtcPublisher,
// HTTPS URLS.
flvPlayer2,
hlsPlayer2,
rtcPlayer2,
flvUrl2,
m3u8Url2,
// For transcode.
transcodeStreamName,
transcodeStreamKey,
Expand Down
4 changes: 3 additions & 1 deletion ui/src/pages/ScenarioLive.js
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,9 @@ function ScenarioLiveImpl({copyToClipboard, urls}) {
</div>
<ol>
<li>{t('live.share.fw')} <code>UDP/8000</code></li>
{window.location.protocol === 'http:' && <li>{t('live.rtc.https')} <code>thisisunsafe</code></li>}
{window.location.hostname !== 'localhost' && window.location.protocol === 'http:' &&
<li>{t('live.rtc.https')} <code>thisisunsafe</code></li>
}
<li>
{t('live.rtc.tip')} <a href={rtcPublisher} target='_blank' rel='noreferrer'>{t('helper.link')}</a> &nbsp;
<div role='button' style={{display: 'inline-block'}} title={t('helper.copy')}>
Expand Down

0 comments on commit b69984f

Please sign in to comment.