Skip to content

Commit

Permalink
Extract from Pion WebRTC
Browse files Browse the repository at this point in the history
New repo that contains applications that use 3rd party libraries
  • Loading branch information
Sean-Der committed Apr 7, 2019
1 parent cdb236c commit 9cf19de
Show file tree
Hide file tree
Showing 26 changed files with 185 additions and 243 deletions.
44 changes: 44 additions & 0 deletions .github/assert-contributors.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env bash
set -e

# Unshallow the repo, this check doesn't work with this enabled
# https://github.com/travis-ci/travis-ci/issues/3412
if [ -f $(git rev-parse --git-dir)/shallow ]; then
git fetch --unshallow || true
fi

SCRIPT_PATH=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )

EXCLUDED_CONTIBUTORS=('John R. Bradley')
MISSING_CONTIBUTORS=()

shouldBeIncluded () {
for i in "${EXCLUDED_CONTIBUTORS[@]}"
do
if [ "$i" == "$1" ] ; then
return 1
fi
done
return 0
}


IFS=$'\n' #Only split on newline
for contributor in $(git log --format='%aN' | sort -u)
do
if shouldBeIncluded $contributor; then
if ! grep -q "$contributor" "$SCRIPT_PATH/../README.md"; then
MISSING_CONTIBUTORS+=("$contributor")
fi
fi
done
unset IFS

if [ ${#MISSING_CONTIBUTORS[@]} -ne 0 ]; then
echo "Please add the following contributors to the README"
for i in "${MISSING_CONTIBUTORS[@]}"
do
echo "$i"
done
exit 1
fi
60 changes: 60 additions & 0 deletions .github/lint-commit-message.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/usr/bin/env bash
set -e

display_commit_message_error() {
cat << EndOfMessage
$1
-------------------------------------------------
The preceding commit message is invalid
it failed '$2' of the following checks
* Separate subject from body with a blank line
* Limit the subject line to 50 characters
* Capitalize the subject line
* Do not end the subject line with a period
* Wrap the body at 72 characters
EndOfMessage

exit 1
}

lint_commit_message() {
if [[ "$(echo "$1" | awk 'NR == 2 {print $1;}' | wc -c)" -ne 1 ]]; then
display_commit_message_error "$1" 'Separate subject from body with a blank line'
fi

if [[ "$(echo "$1" | head -n1 | wc -m)" -gt 50 ]]; then
display_commit_message_error "$1" 'Limit the subject line to 50 characters'
fi

if [[ ! $1 =~ ^[A-Z] ]]; then
display_commit_message_error "$1" 'Capitalize the subject line'
fi

if [[ "$(echo "$1" | awk 'NR == 1 {print substr($0,length($0),1)}')" == "." ]]; then
display_commit_message_error "$1" 'Do not end the subject line with a period'
fi

if [[ "$(echo "$1" | awk '{print length}' | sort -nr | head -1)" -gt 72 ]]; then
display_commit_message_error "$1" 'Wrap the body at 72 characters'
fi
}

if [ "$#" -eq 1 ]; then
if [ ! -f "$1" ]; then
echo "$0 was passed one argument, but was not a valid file"
exit 1
fi
lint_commit_message "$(sed -n '/# Please enter the commit message for your changes. Lines starting/q;p' "$1")"
else
# TRAVIS_COMMIT_RANGE is empty for initial branch commit
if [[ "${TRAVIS_COMMIT_RANGE}" != *"..."* ]]; then
parent=$(git log -n 1 --format="%P" ${TRAVIS_COMMIT_RANGE})
TRAVIS_COMMIT_RANGE="${TRAVIS_COMMIT_RANGE}...$parent"
fi

for commit in $(git rev-list ${TRAVIS_COMMIT_RANGE}); do
lint_commit_message "$(git log --format="%B" -n 1 $commit)"
done
fi
14 changes: 14 additions & 0 deletions .github/lint-filename.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash
set -e

SCRIPT_PATH=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )
GO_REGEX="^[a-zA-Z_]+\.go$"

find "$SCRIPT_PATH/.." -name "*.go" | while read fullpath; do
filename=$(basename -- "$fullpath")

if ! [[ $filename =~ $GO_REGEX ]]; then
echo "$filename is not a valid filename for Go code, only alpha and underscores are supported"
exit 1
fi
done
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sfu-ws/cert.pem
sfu-ws/key.pem
15 changes: 15 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
linters-settings:
govet:
check-shadowing: true
misspell:
locale: US

linters:
enable-all: true
disable:
- lll
- gochecknoinits
- gochecknoglobals

issues:
exclude-use-default: false
11 changes: 11 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
env:
- GO111MODULE=on

before_script:
- curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b $GOPATH/bin v1.15.0

script:
- golangci-lint run
- bash .github/assert-contributors.sh
- bash .github/lint-commit-message.sh
- bash .github/lint-filename.sh
42 changes: 14 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,52 +1,38 @@
<h1 align="center">
Examples
Examples WebRTC Applications
</h1>

We've build an extensive collection of examples covering common use-cases. You can modify and extend these examples to quickly get started.
The following are a collection of example applications built by Pion users. These applications show real world usage of Pion,
and should serve as a good starting point for your next project. For more minimal examples check out [examples](https://github.com/pion/webrtc/tree/master/examples) in the Pion WebRTC repository

### Overview
#### Media API
If you have a request please make an issue, we also love contributions more examples are always welcome.

Have any questions? Join [the Slack channel](https://pion.ly/slack) to follow development and speak with the maintainers.

## Examples
* [Gstreamer Receive](gstreamer-receive): The gstreamer-receive example shows how to receive media from the browser and play it live. This example uses GStreamer for rendering.
* [Gstreamer Send](gstreamer-send): Example gstreamer-send shows how to send video to your browser. This example uses GStreamer to process the video.
* [Gstreamer Send Offer](gstreamer-send-offer): Example gstreamer-send-offer is a variant of gstreamer-send that initiates the WebRTC connection by sending an offer.
* [Save to Disk](save-to-disk): The save-to-disk example shows how to record your webcam and save the footage to disk on the server side.
* [Janus Gateway](janus-gateway): Example janus-gateway is a collection of examples showing how to use Pion WebRTC with [janus-gateway](https://github.com/meetecho/janus-gateway).
* [SFU Minimal](sfu-minimal): The SFU example demonstrates how to broadcast a video to multiple peers. A broadcaster uploads the video once and the server forwards it to all other peers.
* [SFU Websocket](sfu-ws): The SFU example demonstrates how to broadcast a video to multiple peers. A broadcaster uploads the video once and the server forwards it to all other peers.

#### Data Channel API
* [Data Channels](data-channels): The data-channels example shows how you can send/recv DataChannel messages from a web browser.
* [Data Channels Create](data-channels-create): Example data-channels-create shows how you can send/recv DataChannel messages from a web browser. The difference with the data-channels example is that the data channel is initialized from the server side in this example.
* [Data Channels Close](data-channels-close): Example data-channels-close is a variant of data-channels that allow playing with the life cycle of data channels.
* [Data Channels Detach](data-channels-detach): The data-channels-detach example shows how you can send/recv DataChannel messages using the underlying DataChannel implementation directly. This provides a more idiomatic way of interacting with Data Channels.
* [Data Channels Detach Create](data-channels-detach-create): Example data-channels-detach-create shows how you can send/recv DataChannel messages using the underlying DataChannel implementation directly. This provides a more idiomatic way of interacting with Data Channels. The difference with the data-channels-detach example is that the data channel is initialized in this example.
* [Pion to Pion](pion-to-pion): Example pion-to-pion is an example of two pion instances communicating directly! It therefore has no corresponding web page.
* [ORTC](ortc): Example ortc shows how you an use the ORTC API for DataChannel communication.
* [ORTC QUIC](ortc-quic): Example ortc-quic shows how you an use the ORTC API for QUIC DataChannel communication.
* [Pion to Pion](pion-to-pion): Example pion-to-pion is an example of two pion instances communicating directly! It therefore has no corresponding web page.


### Usage
We've made it easy to run the browser based examples on your local machine.

1. Build and run the example server:
``` sh
go get github.com/pion/webrtc
cd $GOPATH/src/github.com/pion/webrtc/examples
go get github.com/webrtc-example-applications
cd $GOPATH/src/github.com/webrtc-example-applications
go run examples.go
```

2. Browse to [localhost](http://localhost) to browse through the examples.

Note that you can change the port of the server using the ``--address`` flag.

### WebAssembly
Some of our examples have support for WebAssembly. The same examples server documented above can be used to run the WebAssembly examples. However, you have to compile them first. This is done as follows:
### Contributing
Check out the **[contributing wiki](https://github.com/pion/webrtc/wiki/Contributing)** to join the group of amazing people making this project possible:

1. If the example supports WebAssembly it will contain a `main.go` file under the `jsfiddle` folder.
2. Build this `main.go` file as follows:
```
GOOS=js GOARCH=wasm go build -o demo.wasm
```
3. Start the example server. Refer to the [usage](#usage) section for how you can build the example server.
4. Browse to [localhost](http://localhost). The page should now give you the option to run the example using the WebAssembly binary.
### License
MIT License - see [LICENSE](LICENSE) for full text
8 changes: 0 additions & 8 deletions example.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,6 @@
<link rel="stylesheet" type="text/css" href="demo.css">
{{ if .JS }}
<script src="demo.js"></script>
{{ else }}
<script src="/wasm_exec.js"></script>
<script>
const go = new Go();
WebAssembly.instantiateStreaming(fetch("demo.wasm"), go.importObject).then((result) => {
go.run(result.instance);
});
</script>
{{ end }}
</head>
<body>
Expand Down
12 changes: 1 addition & 11 deletions examples.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ type Example struct {
Description string `json:"description"`
Type string `json:"type"`
IsJS bool
IsWASM bool
}

func main() {
Expand Down Expand Up @@ -50,15 +49,10 @@ func serve(addr string) error {
// DIY 'mux' to avoid additional dependencies
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
url := r.URL.Path
if url == "/wasm_exec.js" {
http.FileServer(http.Dir("./vendor-wasm/golang.org/misc/wasm/")).ServeHTTP(w, r)
return
}

// Split up the URL. Expected parts:
// 1: Base url
// 2: "example"
// 3: Example type: js or wasm
// 3: Example type: js
// 4: Example folder, e.g.: data-channels
// 5: Static file as part of the example
parts := strings.Split(url, "/")
Expand Down Expand Up @@ -134,10 +128,6 @@ func getExamples() (*Examples, error) {
if _, err := os.Stat(js); !os.IsNotExist(err) {
example.IsJS = true
}
wasm := filepath.Join(fiddle, "demo.wasm")
if _, err := os.Stat(wasm); !os.IsNotExist(err) {
example.IsWASM = true
}
}

return &examples, nil
Expand Down
2 changes: 1 addition & 1 deletion gstreamer-receive/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ This example requires you have GStreamer installed, these are the supported plat
`pacman -S mingw-w64-x86_64-gstreamer mingw-w64-x86_64-gst-libav mingw-w64-x86_64-gst-plugins-good mingw-w64-x86_64-gst-plugins-bad mingw-w64-x86_64-gst-plugins-ugly`
### Download gstreamer-receive
```
go get github.com/pion/webrtc/examples/gstreamer-receive
go get github.com/pion/webrtc-example-applications/gstreamer-receive
```

### Open gstreamer-receive example page
Expand Down
4 changes: 2 additions & 2 deletions gstreamer-receive/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"github.com/pion/rtcp"
"github.com/pion/webrtc"

gst "github.com/pion/webrtc/examples/internal/gstreamer-sink"
"github.com/pion/webrtc/examples/internal/signal"
gst "github.com/pion/example-webrtc-applications/internal/gstreamer-sink"
"github.com/pion/example-webrtc-applications/internal/signal"
)

// gstreamerReceiveMain is launched in a goroutine because the main thread is needed
Expand Down
4 changes: 2 additions & 2 deletions gstreamer-send-offer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (

"github.com/pion/webrtc"

gst "github.com/pion/webrtc/examples/internal/gstreamer-src"
"github.com/pion/webrtc/examples/internal/signal"
gst "github.com/pion/example-webrtc-applications/internal/gstreamer-src"
"github.com/pion/example-webrtc-applications/internal/signal"
)

func main() {
Expand Down
2 changes: 1 addition & 1 deletion gstreamer-send/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ This example requires you have GStreamer installed, these are the supported plat
`pacman -S mingw-w64-x86_64-gstreamer mingw-w64-x86_64-gst-libav mingw-w64-x86_64-gst-plugins-good mingw-w64-x86_64-gst-plugins-bad mingw-w64-x86_64-gst-plugins-ugly`
### Download gstreamer-send
```
go get github.com/pion/webrtc/examples/gstreamer-send
go get github.com/pion/webrtc-example-applications/gstreamer-send
```

### Open gstreamer-send example page
Expand Down
4 changes: 2 additions & 2 deletions gstreamer-send/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (

"github.com/pion/webrtc"

gst "github.com/pion/webrtc/examples/internal/gstreamer-src"
"github.com/pion/webrtc/examples/internal/signal"
gst "github.com/pion/example-webrtc-applications/internal/gstreamer-src"
"github.com/pion/example-webrtc-applications/internal/signal"
)

func main() {
Expand Down
1 change: 0 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ <h3>{{ .Title }}</h3>
<div class="content">
<p>{{ .Description }}</p>
{{ if .IsJS}}<p><a href="/example/js/{{ .Link }}/">Run JavaScript</a></p>{{ end }}
{{ if .IsWASM}}<p><a href="/example/wasm/{{ .Link }}/">Run WASM</a></p>{{ end }}
</div>
</div>
{{else}}
Expand Down
4 changes: 2 additions & 2 deletions janus-gateway/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ This example demonstrates how to download a video from a Janus streaming room. B
You should confirm that you can successfully watch `Opus/VP8 live stream coming from gstreamer (live)` in the stream demo web UI

### Running
run `main.go` in `github.com/pion/webrtc/examples/janus-gateway/streaming`
run `main.go` in `github.com/pion/webrtc-example-applications/janus-gateway/streaming`

If this worked you will see the following.
```
Expand All @@ -24,7 +24,7 @@ You will see output.ivf in the current folder.
This example demonstrates how to stream to a Janus video-room using pion-WebRTC

### Running
run `main.go` in `github.com/pion/webrtc/examples/janus-gateway/video-room`
run `main.go` in `github.com/pion/webrtc-example-applications/janus-gateway/video-room`

OSX
```sh
Expand Down
9 changes: 0 additions & 9 deletions janus-gateway/streaming/go.mod

This file was deleted.

20 changes: 0 additions & 20 deletions janus-gateway/streaming/go.sum

This file was deleted.

9 changes: 0 additions & 9 deletions janus-gateway/video-room/go.mod

This file was deleted.

Loading

0 comments on commit 9cf19de

Please sign in to comment.