From b69984f7c7af8a8407a0de122ed5689b1f259d06 Mon Sep 17 00:00:00 2001 From: winlin Date: Tue, 31 Oct 2023 19:12:33 +0800 Subject: [PATCH] RTC: Refine WHIP player and enable NAME_LOOKUP by default. v5.11.8 --- .github/workflows/test.yml | 20 +++++++++- DEVELOPER.md | 59 ++++++++++++++++++---------- platform/candidate.go | 5 +++ platform/main.go | 2 +- scripts/setup-aapanel/auto/zip.sh | 3 +- scripts/setup-bt/auto/zip.sh | 3 +- test/api_test.go | 16 ++++---- ui/src/components/TutorialsButton.js | 2 +- ui/src/components/UrlGenerator.js | 23 +---------- ui/src/pages/ScenarioLive.js | 4 +- 10 files changed, 80 insertions(+), 57 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d8bd746d..f9abbcb8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/DEVELOPER.md b/DEVELOPER.md index ea2395b1..2d6dc183 100644 --- a/DEVELOPER.md +++ b/DEVELOPER.md @@ -5,7 +5,7 @@ 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 && @@ -13,28 +13,16 @@ 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)` @@ -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 . ``` @@ -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 @@ -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 \ @@ -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 ``` @@ -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 ``` @@ -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 \ @@ -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 ``` @@ -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 ``` @@ -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 \ diff --git a/platform/candidate.go b/platform/candidate.go index 36caf94b..826210b7 100644 --- a/platform/candidate.go +++ b/platform/candidate.go @@ -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 diff --git a/platform/main.go b/platform/main.go index 7cf0fe4e..0861a09d 100644 --- a/platform/main.go +++ b/platform/main.go @@ -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, "+ diff --git a/scripts/setup-aapanel/auto/zip.sh b/scripts/setup-aapanel/auto/zip.sh index 78548931..a84f8819 100755 --- a/scripts/setup-aapanel/auto/zip.sh +++ b/scripts/setup-aapanel/auto/zip.sh @@ -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 diff --git a/scripts/setup-bt/auto/zip.sh b/scripts/setup-bt/auto/zip.sh index 2a0f2d1c..4a685663 100755 --- a/scripts/setup-bt/auto/zip.sh +++ b/scripts/setup-bt/auto/zip.sh @@ -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 diff --git a/test/api_test.go b/test/api_test.go index 4f2bcc9d..8366b0ac 100644 --- a/test/api_test.go +++ b/test/api_test.go @@ -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") @@ -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) { diff --git a/ui/src/components/TutorialsButton.js b/ui/src/components/TutorialsButton.js index bc7050fa..c4546879 100644 --- a/ui/src/components/TutorialsButton.js +++ b/ui/src/components/TutorialsButton.js @@ -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', diff --git a/ui/src/components/UrlGenerator.js b/ui/src/components/UrlGenerator.js index 2220015d..38fb65aa 100644 --- a/ui/src/components/UrlGenerator.js +++ b/ui/src/components/UrlGenerator.js @@ -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. @@ -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(); @@ -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. @@ -216,12 +201,6 @@ export default function useUrls() { hlsPlayer, rtcPlayer, rtcPublisher, - // HTTPS URLS. - flvPlayer2, - hlsPlayer2, - rtcPlayer2, - flvUrl2, - m3u8Url2, // For transcode. transcodeStreamName, transcodeStreamKey, diff --git a/ui/src/pages/ScenarioLive.js b/ui/src/pages/ScenarioLive.js index 8df0ef30..91bcee1c 100644 --- a/ui/src/pages/ScenarioLive.js +++ b/ui/src/pages/ScenarioLive.js @@ -533,7 +533,9 @@ function ScenarioLiveImpl({copyToClipboard, urls}) {
  1. {t('live.share.fw')} UDP/8000
  2. - {window.location.protocol === 'http:' &&
  3. {t('live.rtc.https')} thisisunsafe
  4. } + {window.location.hostname !== 'localhost' && window.location.protocol === 'http:' && +
  5. {t('live.rtc.https')} thisisunsafe
  6. + }
  7. {t('live.rtc.tip')} {t('helper.link')}