diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..6d9b73e
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+/vid/.gitkeep
diff --git a/README.md b/README.md
index 121fed2..79b4515 100644
--- a/README.md
+++ b/README.md
@@ -1,10 +1,16 @@
-# Signalling Pion Webrtc server via `POST` request
+# This server accepts video and audio via webrtc and converts them in Adaptive HLS
+This project is in Progress(ui,cdn integration), `Webrtc -> HLS` part is Complete.
-This project is in Progress.
+### Run Application
+
+#### Steps to follow for using this project
+1) Install or upgrade Golang ver. 1.15 or above
+2) Install or upgrade Ffmpeg ver. 4.3.1-5 or above (Currently available in `Debian Sid`)
+3) Download the project using Git command `git clone https://github.com/mohit810/streamingcdn`
+4) To start the server use the command `go run main.go` (Use terminal for running the server)
-### Software Req.
-1) Golang >= 1.15
-2) Ffmpeg >= 4.3.1-5 (Currently available in `Debian Sid`)
+* Congratulations!! Now the server is up and running.
+* As a starting point for testing you can use the [Web UI](https://github.com/mohit810/streamingcdn-web-ui)
### Current State
1) Users can connect via `POST` request and start streaming(1.5Mbps speed is hardcoded for the stream).
@@ -14,27 +20,19 @@ This project is in Progress.
1) Integrating FFmpeg.(Completed for now, further optimization will be done later)
2) Allowing multiple users to connect and start broadcasting.(not in priority, at this stage.)
3) CDN Integration ( Post UI development)
-4) Front-end UI Development in android, web, ios. ( Current priority is android & web)
+4) Front-end UI Development in android, web, ios. (Current priority is android)
+
### Final Goal
To receive the broadcast, Convert it into hls in various quality then push those to cdn to serve to the User.
Before using this solution you should set-up pion/webrtc/v3 ([Go Modules](https://blog.golang.org/using-go-modules) are mandatory for using Pion WebRTC. So make sure you set export GO111MODULE=on, and explicitly specify /v3 when importing.).
-### Open broadcast example page
-[localhost:8080](http://localhost:8080/)
-
-### Run Application
-#### Linux/macOS/windows
-Run `main.go`
-
-### Start a publisher
-
-* Paste your Twitch stream Key
-* Click `Publish a Broadcast` and now you don't have to do anything.
-* Communicating with server is done by the js itself.
-* If you want to know the request that is sent to server via `POST` method, refer to the screenshot attached below. The `application` will respond with an offer as a response to the `POST`.
+### POST API used by the broadcaster for connecting to the server
-![](https://github.com/mohit810/streamingcdn/blob/main/Screenshot.png)
+`{
+ "sdp":"",
+ "streamKey":""
+}`
## Big Thanks to the following
diff --git a/Screenshot.png b/Screenshot.png
deleted file mode 100644
index 2b83b6a..0000000
Binary files a/Screenshot.png and /dev/null differ
diff --git a/ffmpeg/ffmpeg.go b/ffmpeg/ffmpeg.go
index 821f61c..d6c785f 100644
--- a/ffmpeg/ffmpeg.go
+++ b/ffmpeg/ffmpeg.go
@@ -4,13 +4,13 @@ import (
"bufio"
"context"
"fmt"
+ "os"
"os/exec"
)
func StartFFmpeg(ctx context.Context) {
- //ffmpegPath := "ffmpeg"
- //srcPath := "/home/tester/go/src/practice/hlsconvertor/sample720.mp4"
- targetPath := "/home/tester/go/src/streamingcdn/vid" //replace according to ur need
+ goDir, _ := os.Getwd()
+ targetPath := goDir + "vid" //replace according to ur need
resOptions := []string{"360p", "480p", "720p", "1080p"}
variants, _ := generateHLSVariant(resOptions, "")
diff --git a/main.go b/main.go
index c591c69..82ffa84 100644
--- a/main.go
+++ b/main.go
@@ -2,7 +2,9 @@ package main
import (
"flag"
+ "fmt"
"net/http"
+ "os"
"strconv"
"github.com/julienschmidt/httprouter"
@@ -19,6 +21,9 @@ func main() {
flag.Parse()
r := httprouter.New()
signal.HTTPSDPServer(r)
+ fmt.Println("Server is Up and Running at Port:" + strconv.Itoa(*port))
+ wd, _ := os.Getwd()
+ fmt.Println(wd)
err := http.ListenAndServe(":"+strconv.Itoa(*port), r)
if err != nil {
panic(err)
diff --git a/public/demo.js b/public/demo.js
deleted file mode 100644
index f3fe78c..0000000
--- a/public/demo.js
+++ /dev/null
@@ -1,124 +0,0 @@
-let divSelectRoom = document.getElementById("selectRoom")
-let inputstreamKey = document.getElementById("streamkey")
-let signalingContainer = document.getElementById('signalingContainer')
-let createSessionButton = document.getElementsByClassName('createSessionButton')
-let remoteSessionDescription = document.getElementById('remoteSessionDescription')
-let localSessionDescription = document.getElementById('localSessionDescription')
-let video1 = document.getElementById('video1')
-
-let streamKey, encryptedSdp, PublisherFlag, uid
-
-/* eslint-env browser */
-var log = msg => {
- document.getElementById('logs').innerHTML += msg + '
'
-}
-
-const hdConstraints = {
- audio: true,
- video: {
- width: { max: 1920, ideal: 1280 },
- height: { max: 1080, ideal: 720 }
- }
-};
-
-let displayVideo = video => {
- var el = document.createElement('video')
- el.srcObject = video
- el.autoplay = true
- el.muted = true
- el.width = 160
- el.height = 120
-
- document.getElementById('localVideos').appendChild(el)
- return video
-}
-
-function postRequest () {
- var data = JSON.stringify({
- "sdp": encryptedSdp,
- "streamKey": streamKey
- })
- console.log(data);
- const url = `${window.location.origin}/sdp`;
- (async () => {
- const rawResponse = await fetch(url, {
- method : "POST",
- //body: new FormData(document.getElementById("inputform")),
- // -- or --
- body : data,
- headers :{
- 'Content-Type': 'application/json'
- }
- });
- const content = await rawResponse.json();
- remoteSessionDescription.value = content.sdp
- window.startSession()
-})();
-}
-window.createSession = isPublisher => {
- PublisherFlag = isPublisher
- if (inputstreamKey.value === '') {
- alert("please enter a room name.")
- } else{
- streamKey = inputstreamKey.value
- let pc = new RTCPeerConnection({
- iceServers: [
- {'urls': 'stun:stun.services.mozilla.com'},
- {'urls': 'stun:stun.l.google.com.19302'}
- ]
- })
- pc.oniceconnectionstatechange = e => log(pc.iceConnectionState)
- pc.onicecandidate = event => {
- if (event.candidate === null) {
- encryptedSdp = btoa(JSON.stringify(pc.localDescription))
- localSessionDescription.value = encryptedSdp
- postRequest();
- }
- }
-
- if (isPublisher) {
- navigator.mediaDevices.getUserMedia(hdConstraints)
- .then(stream => {
- stream.getTracks().forEach(function(track) {
- pc.addTrack(track, stream);
- });
- displayVideo(stream);
- pc.createOffer()
- .then(d => {
- pc.setLocalDescription(d)
- }).catch(log)
- }).catch(log)
- }else{
- pc.addTransceiver('audio', {'direction': 'recvonly'})
- pc.addTransceiver('video', {'direction': 'recvonly'})
- pc.createOffer()
- .then(d => pc.setLocalDescription(d))
- .catch(log)
-
- pc.ontrack = function (event) {
- var el = video1
- el.srcObject = event.streams[0]
- el.autoplay = true
- el.controls = true
- }
- }
- window.startSession = () => {
- let sd = remoteSessionDescription.value
- if (sd === '') {
- return alert('Session Description must not be empty')
- }
- try {
- pc.setRemoteDescription(new RTCSessionDescription(JSON.parse(atob(sd))))
- } catch (e) {
- alert(e)
- }
- }
-
- let btns = createSessionButton
- for (let i = 0; i < btns.length; i++) {
- btns[i].style = 'display: none'
- }
- divSelectRoom.style = "display: none"
- signalingContainer.style = 'display: block'
-}
-}
diff --git a/public/index.html b/public/index.html
deleted file mode 100644
index d3fe415..0000000
--- a/public/index.html
+++ /dev/null
@@ -1,27 +0,0 @@
-