diff --git a/README.md b/README.md index 4bc506ea4..36647a90c 100755 --- a/README.md +++ b/README.md @@ -182,6 +182,8 @@ The ports used by SRS: ## V4 changes +* v4.0, 2021-05-04, Add video room demo. 4.0.98 +* v4.0, 2021-05-03, Add RTC stream merging demo by FFmpeg. 4.0.97 * v4.0, 2021-05-02, Add one to one demo. 4.0.96 * v4.0, 2021-04-20, Support RTC2RTMP bridger and shared FastTimer. 4.0.95 * v4.0, 2021-04-20, Refine transcoder to support aac2opus and opus2aac. 4.0.94 diff --git a/trunk/3rdparty/copy_to_gits.sh b/trunk/3rdparty/copy_to_gits.sh new file mode 100755 index 000000000..d92d3a2ba --- /dev/null +++ b/trunk/3rdparty/copy_to_gits.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +if [[ ! -d signaling ]]; then + cd 3rdparty +fi +if [[ ! -d signaling ]]; then + echo "no 3rdparty" + exit -1 +fi +if [[ ! -d ~/git/signaling ]]; then + echo "no signaling" + exit -1 +fi + +echo "Copy signaling" +cp -R signaling/* ~/git/signaling/ && (cd ~/git/signaling && git st) + +echo "Copy httpx-static" +cp -R httpx-static/* ~/git/go-oryx/httpx-static/ && (cd ~/git/go-oryx && git st) + +echo "Copy srs-bench" +cp -R srs-bench/* ~/git/srs-bench/ && (cd ~/git/srs-bench && git st) diff --git a/trunk/3rdparty/httpx-static/README.md b/trunk/3rdparty/httpx-static/README.md index 3b6259475..d82b7b7a6 100644 --- a/trunk/3rdparty/httpx-static/README.md +++ b/trunk/3rdparty/httpx-static/README.md @@ -29,7 +29,7 @@ $GOPATH/bin/httpx-static -https 8443 -root `pwd`/html Open https://localhost:8443/ in browser. -> Remark: Click `ADVANCED` => `Proceed to localhost (unsafe)`. +> Remark: Click `ADVANCED` => `Proceed to localhost (unsafe)`, or type `thisisunsafe` in page. *HTTPS proxy*: Proxy http as https @@ -44,6 +44,25 @@ $GOPATH/bin/httpx-static -https 8443 -root `pwd`/html -proxy http://ossrs.net:19 Open https://localhost:8443/api/v1/summaries in browser. +## Docker + +Run httpx-static in docker: + +```bash +docker run --rm -p 80:80 -p 443:443 registry.cn-hangzhou.aliyuncs.com/ossrs/httpx:v1.0.2 +``` + +> Note: More images and version is [here](https://cr.console.aliyun.com/repository/cn-hangzhou/ossrs/httpx/images). + +To proxy to other dockers, in macOS: + +```bash +CANDIDATE=$(ifconfig en0 inet| grep 'inet '|awk '{print $2}') && +docker run --rm -p 80:80 -p 443:443 registry.cn-hangzhou.aliyuncs.com/ossrs/httpx:v1.0.5 \ + ./bin/httpx-static -http 80 -https 443 -ssk ./etc/server.key -ssc ./etc/server.crt \ + -proxy http://$CANDIDATE:8080/ +``` + ## History * v0.0.3, 2017-11-03, Support multiple proxy HTTP to HTTPS. diff --git a/trunk/3rdparty/signaling/Dockerfile b/trunk/3rdparty/signaling/Dockerfile new file mode 100644 index 000000000..393e57004 --- /dev/null +++ b/trunk/3rdparty/signaling/Dockerfile @@ -0,0 +1,24 @@ + +############################################################ +# build +############################################################ +FROM registry.cn-hangzhou.aliyuncs.com/ossrs/srs:dev AS build + +COPY . /tmp/signaling +RUN cd /tmp/signaling && make +RUN cp /tmp/signaling/objs/signaling /usr/local/bin/signaling +RUN cp -R /tmp/signaling/www /usr/local/ + +############################################################ +# dist +############################################################ +FROM centos:7 AS dist + +# HTTP/1989 +EXPOSE 1989 +# SRS binary, config files and srs-console. +COPY --from=build /usr/local/bin/signaling /usr/local/bin/ +COPY --from=build /usr/local/www /usr/local/www +# Default workdir and command. +WORKDIR /usr/local +CMD ["./bin/signaling"] diff --git a/trunk/3rdparty/signaling/README.md b/trunk/3rdparty/signaling/README.md index d786896a9..f20c724f9 100644 --- a/trunk/3rdparty/signaling/README.md +++ b/trunk/3rdparty/signaling/README.md @@ -4,21 +4,59 @@ WebRTC signaling for https://github.com/ossrs/srs ## Usage -Build and [run SRS](https://github.com/ossrs/srs/tree/4.0release#usage): +[Run SRS](https://github.com/ossrs/srs/tree/4.0release#usage) in docker: ```bash -git clone -b 4.0release https://gitee.com/ossrs/srs.git srs && -cd srs/trunk && ./configure && make && ./objs/srs -c conf/rtc.conf +docker run --rm --env CANDIDATE=$(ifconfig en0 inet| grep 'inet '|awk '{print $2}') \ + -p 1935:1935 -p 8080:8080 -p 1985:1985 -p 8000:8000/udp \ + registry.cn-hangzhou.aliyuncs.com/ossrs/srs:v4.0.95 \ + objs/srs -c conf/rtc.conf ``` -Build and run signaling: +> Note: More images and version is [here](https://cr.console.aliyun.com/repository/cn-hangzhou/ossrs/srs/images). + +Run signaling in docker: ```bash -cd srs/trunk/3rdparty/signaling && make && ./objs/signaling +docker run --rm -p 1989:1989 registry.cn-hangzhou.aliyuncs.com/ossrs/signaling:v1.0.4 ``` +> Note: More images and version is [here](https://cr.console.aliyun.com/repository/cn-hangzhou/ossrs/signaling/images). + Open the H5 demos: * [WebRTC: One to One over SFU(SRS)](http://localhost:1989/demos/one2one.html?autostart=true) +## Build from source + +Build and [run SRS](https://github.com/ossrs/srs/tree/4.0release#usage): + +```bash +cd ~/git && git clone -b 4.0release https://gitee.com/ossrs/srs.git srs && +cd ~/git/srs/trunk && ./configure && make && ./objs/srs -c conf/rtc.conf +``` + +Build and run signaling: + +```bash +cd ~/git/srs/trunk/3rdparty/signaling && make && ./objs/signaling +``` + +Open demos by localhost: http://localhost:1989/demos + +Build and run httpx-static for HTTPS/WSS: + +```bash +cd ~/git/srs/trunk/3rdparty/httpx-static && make && +./objs/httpx-static -http 80 -https 443 -ssk server.key -ssc server.crt \ + -proxy http://127.0.0.1:1989/sig -proxy http://127.0.0.1:1985/rtc \ + -proxy http://127.0.0.1:8080/ +``` + +Open demos by HTTPS or IP: + +* http://localhost/demos/ +* https://localhost/demos/ +* https://192.168.3.6/demos/ + Winlin 2021.05 diff --git a/trunk/3rdparty/signaling/auto/release.sh b/trunk/3rdparty/signaling/auto/release.sh new file mode 100755 index 000000000..c63c9e7b7 --- /dev/null +++ b/trunk/3rdparty/signaling/auto/release.sh @@ -0,0 +1,70 @@ +#!/bin/bash + +SRS_GIT=$HOME/git/signaling +SRS_TAG= + +# linux shell color support. +RED="\\033[31m" +GREEN="\\033[32m" +YELLOW="\\033[33m" +BLACK="\\033[0m" + +function NICE() { + echo -e "${GREEN}$@${BLACK}" +} + +function TRACE() { + echo -e "${BLACK}$@${BLACK}" +} + +function WARN() { + echo -e "${YELLOW}$@${BLACK}" +} + +function ERROR() { + echo -e "${RED}$@${BLACK}" +} + +################################################################################## +################################################################################## +################################################################################## +if [[ -z $SRS_TAG ]]; then + SRS_TAG=`(cd $SRS_GIT && git describe --tags --abbrev=0 --exclude release-* 2>/dev/null)` + if [[ $? -ne 0 ]]; then + echo "Invalid tag $SRS_TAG of $SRS_FILTER in $SRS_GIT" + exit -1 + fi +fi + +NICE "Build docker for $SRS_GIT, tag is $SRS_TAG" + +git ci -am "Release $SRS_TAG" + +# For aliyun hub. +NICE "aliyun hub release-v$SRS_TAG" + +echo "git push aliyun" +git push aliyun + +git tag -d release-v$SRS_TAG 2>/dev/null +echo "Cleanup tag $SRS_TAG for aliyun" + +git tag release-v$SRS_TAG; git push -f aliyun release-v$SRS_TAG +echo "Create new tag $SRS_TAG for aliyun" +echo "" + +NICE "aliyun hub release-vlatest" +git tag -d release-vlatest 2>/dev/null +echo "Cleanup tag latest for aliyun" + +git tag release-vlatest; git push -f aliyun release-vlatest +echo "Create new tag latest for aliyun" + +# For github.com +echo "git push origin" +git push origin + +echo "git push origin $SRS_TAG" +git push origin $SRS_TAG + +NICE "Update github ok" diff --git a/trunk/3rdparty/signaling/main.go b/trunk/3rdparty/signaling/main.go index 3338c08c8..e91ec43fc 100644 --- a/trunk/3rdparty/signaling/main.go +++ b/trunk/3rdparty/signaling/main.go @@ -96,7 +96,7 @@ func (v *Room) Remove(p *Participant) { } } -func (v *Room) Notify(ctx context.Context, peer *Participant, event string) { +func (v *Room) Notify(ctx context.Context, peer *Participant, event, param, data string) { var participants []*Participant func() { v.lock.RLock() @@ -112,12 +112,15 @@ func (v *Room) Notify(ctx context.Context, peer *Participant, event string) { res := struct { Action string `json:"action"` Event string `json:"event"` + Param string `json:"param,omitempty"` + Data string `json:"data,omitempty"` Room string `json:"room"` Self *Participant `json:"self"` Peer *Participant `json:"peer"` Participants []*Participant `json:"participants"` }{ - "notify", event, v.Name, r, peer, participants, + "notify", event, param, data, + v.Name, r, peer, participants, } b, err := json.Marshal(struct { @@ -187,10 +190,16 @@ func main() { var self *Participant go func() { <-ctx.Done() - if self != nil { - self.Room.Remove(self) - logger.Tf(ctx, "Remove client %v", self) + if self == nil { + return } + + // Notify other peers that we're quiting. + // @remark The ctx(of self) is done, so we must use a new context. + go self.Room.Notify(context.Background(), self, "leave", "", "") + + self.Room.Remove(self) + logger.Tf(ctx, "Remove client %v", self) }() inMessages := make(chan []byte, 0) @@ -228,7 +237,6 @@ func main() { } var res interface{} - var p *Participant if action.Message.Action == "join" { obj := struct { Message struct { @@ -241,7 +249,7 @@ func main() { } r, _ := rooms.LoadOrStore(obj.Message.Room, &Room{Name: obj.Message.Room}) - p = &Participant{Room: r.(*Room), Display: obj.Message.Display, Out: outMessages} + p := &Participant{Room: r.(*Room), Display: obj.Message.Display, Out: outMessages} if err := r.(*Room).Add(p); err != nil { return errors.Wrapf(err, "join") } @@ -258,7 +266,7 @@ func main() { action.Message.Action, obj.Message.Room, p, r.(*Room).Participants, } - go r.(*Room).Notify(ctx, p, action.Message.Action) + go r.(*Room).Notify(ctx, p, action.Message.Action, "", "") } else if action.Message.Action == "publish" { obj := struct { Message struct { @@ -276,7 +284,24 @@ func main() { // Now, the peer is publishing. p.Publishing = true - go r.(*Room).Notify(ctx, p, action.Message.Action) + go r.(*Room).Notify(ctx, p, action.Message.Action, "", "") + } else if action.Message.Action == "control" { + obj := struct { + Message struct { + Room string `json:"room"` + Display string `json:"display"` + Call string `json:"call"` + Data string `json:"data"` + } `json:"msg"` + }{} + if err := json.Unmarshal(m, &obj); err != nil { + return errors.Wrapf(err, "Unmarshal %s", m) + } + + r, _ := rooms.LoadOrStore(obj.Message.Room, &Room{Name: obj.Message.Room}) + p := r.(*Room).Get(obj.Message.Display) + + go r.(*Room).Notify(ctx, p, action.Message.Action, obj.Message.Call, obj.Message.Data) } else { return errors.Errorf("Invalid message %s", m) } diff --git a/trunk/3rdparty/signaling/www/demos/index.html b/trunk/3rdparty/signaling/www/demos/index.html index ed3b6e03a..7774d6844 100644 --- a/trunk/3rdparty/signaling/www/demos/index.html +++ b/trunk/3rdparty/signaling/www/demos/index.html @@ -7,7 +7,19 @@
- Run demo for WebRTC: One to One over SFU(SRS)
- 点击进入SRS一对一通话演示
+ Run demo for WebRTC: One to One over SFU(SRS)
+ 点击进入SRS一对一通话演示
+ Run demo for WebRTC: Video Room over SFU(SRS)
+ 点击进入SRS多人通话演示
+