debug: true
externalUrl: "localhost"
serveAddr: "0.0.0.0"
-servePort: "8000"
+servePort: 8000
maxFileSize: 838860800
stream:
turnServerAddr: "stun:stun.l.google.com:19302"
extAllowList:
- "mp4"
udpBufferByteSize: 300000
- signalPort: "8002"
- rtpReceivePort: "8004"
+ signalPort: 8002
+ signalPortExternal: 8002
+ rtpReceivePort: 8004
+ rtpReceivePortExternal: 8004
utils:
useCompress: false
--- /dev/null
+debug: false
+externalUrl: "webrtc.feebdaed.xyz"
+serveAddr: "0.0.0.0"
+servePort: 8000
+maxFileSize: 838860800
+stream:
+ turnServerAddr: "stun:stun.l.google.com:19302"
+ rtcpPLIInterval: 3
+ uploadDest: "./upload/"
+ extAllowList:
+ - "mp4"
+ udpBufferByteSize: 300000
+ signalPort: 8002
+ signalPortExternal: 8022
+ rtpReceivePort: 8004
+ rtpReceivePortExternal: 8024
+utils:
+ useCompress: false
Debug bool `yaml:"debug"`
ExternalUrl string `yaml:"externalUrl"`
ServeAddr string `yaml:"serveAddr"`
- ServePort string `yaml:"servePort"`
+ ServePort int `yaml:"servePort"`
MaxFileSize int64 `yaml:"maxFileSize"`
Stream struct {
- TurnServerAddr string `yaml:"turnServerAddr"`
- RtcpPLIInterval int `yaml:"rtcpPLIInterval"`
- UploadDest string `yaml:"uploadDest"`
- ExtAllowList []string `yaml:"extAllowList"`
- UdpBufferByteSize int `yaml:"udpBufferByteSize"`
- SignalPort string `yaml:"signalPort"`
- RtpReceivePort string `yaml:"rtpReceivePort"`
+ TurnServerAddr string `yaml:"turnServerAddr"`
+ RtcpPLIInterval int `yaml:"rtcpPLIInterval"`
+ UploadDest string `yaml:"uploadDest"`
+ ExtAllowList []string `yaml:"extAllowList"`
+ UdpBufferByteSize int `yaml:"udpBufferByteSize"`
+ SignalPort int `yaml:"signalPort"`
+ SignalPortExternal int `yaml:"signalPortExternal"`
+ RtpReceivePort int `yaml:"rtpReceivePort"`
+ RtpReceivePortExternal int `yaml:"rtpReceivePortExternal"`
} `yaml:"stream"`
Utils struct {
UseCompress bool `yaml:"useCompress"`
package controller
import (
+ "fmt"
"time"
"github.com/gin-gonic/contrib/sessions"
pkgstream.UDP_BUFFER_BYTE_SIZE = CONF.Stream.UdpBufferByteSize
pkgstream.SIGNAL_ADDR = CONF.ServeAddr
- pkgstream.SIGNAL_PORT = CONF.Stream.SignalPort
+ pkgstream.SIGNAL_PORT = fmt.Sprintf("%d", CONF.Stream.SignalPort)
+ pkgstream.SIGNAL_PORT_EXTERNAL = fmt.Sprintf("%d", CONF.Stream.SignalPortExternal)
pkgstream.RTP_RECEIVE_ADDR = CONF.ServeAddr
- pkgstream.RTP_RECEIVE_PORT = CONF.Stream.RtpReceivePort
+ pkgstream.RTP_RECEIVE_PORT = fmt.Sprintf("%d", CONF.Stream.RtpReceivePort)
+ pkgstream.RTP_RECEIVE_PORT_EXTERNAL = fmt.Sprintf("%d", CONF.Stream.RtpReceivePortExternal)
pkgutils.USE_COMPRESS = CONF.Utils.UseCompress
e.GET("/cctv", pkgstream.GetCCTVIndex)
+ e.GET("/api/cctv/turn/address", pkgstream.GetCCTVTurnServeAddr)
+
e.POST("/api/cctv/create", pkgstream.PostCCTVCreate)
e.POST("/api/cctv/delete", pkgstream.PostCCTVDelete)
server := solictl.CreateServer()
- server.Run(solictl.CONF.ServeAddr + ":" + solictl.CONF.ServePort)
+ server.Run(solictl.CONF.ServeAddr + ":" + fmt.Sprintf("%d", solictl.CONF.ServePort))
}
"io"
"log"
"net"
+ "net/http"
"time"
"github.com/gin-gonic/gin"
var RTP_RECEIVE_PORT string
+var RTP_RECEIVE_PORT_EXTERNAL string
+
var RTP_CONSUMERS = make(map[string]RTMPWebRTCPeer)
const RTP_HEADER_LENGTH_FIELD = 4
}
+func GetCCTVTurnServeAddr(c *gin.Context) {
+
+ c.JSON(http.StatusOK, SERVER_RE{Status: "success", Reply: TURN_SERVER_ADDR})
+
+}
+
func PostCCTVCreate(c *gin.Context) {
log.Println("Incoming HTTP Request")
- peerConnection, err := webrtc.NewPeerConnection(webrtc.Configuration{})
+ peerConnection, err := webrtc.NewPeerConnection(webrtc.Configuration{
+ // ICEServers: []webrtc.ICEServer{
+ // {
+ // URLs: []string{TURN_SERVER_ADDR},
+ // },
+ // },
+ })
if err != nil {
panic(err)
}
+ /*
+ peerConnection.OnICEConnectionStateChange(func(connectionState webrtc.ICEConnectionState) {
+ fmt.Printf("Connection State has changed %s \n", connectionState.String())
+ if connectionState == webrtc.ICEConnectionStateFailed {
+ if closeErr := peerConnection.Close(); closeErr != nil {
+ panic(closeErr)
+ }
+ }
+ })
+ */
videoTrack, err := webrtc.NewTrackLocalStaticSample(webrtc.RTPCodecCapability{MimeType: webrtc.MimeTypeH264}, "video", "pion")
if err != nil {
panic(err)
})
}
-func GetCCTVLocalTurnServeAddr(c *gin.Context) {
-
- c.JSON(http.StatusOK, SERVER_RE{Status: "success", Reply: TURN_SERVER_ADDR})
-
-}
-
func PostCCTVLocalOffer(c *gin.Context) {
if RECV_STARTED == 1 {
func GetPeersSignalAddress(c *gin.Context) {
- s_addr := EXTERNAL_URL + ":" + SIGNAL_PORT + PEERS_SIGNAL_PATH
+ s_addr := EXTERNAL_URL + ":" + SIGNAL_PORT_EXTERNAL + PEERS_SIGNAL_PATH
c.JSON(http.StatusOK, SERVER_RE{Status: "success", Reply: s_addr})
var SIGNAL_PORT string
+var SIGNAL_PORT_EXTERNAL string
+
var USER_SIGNAL = make(map[string]*websocket.Conn)
var UPGRADER = websocket.Upgrader{}
pc = {}
+TURN_SERVER_ADDRESS = ""
+
+
+CLIENT_REQ = {
+ "data":""
+}
+
async function initCCTV(){
- pc = new RTCPeerConnection()
+ let result = await axios.get("/api/cctv/turn/address")
+
+ if(result.data.status != "success"){
+
+ alert("failed to get turn server address")
+
+ return
+ }
+
+ TURN_SERVER_ADDRESS = result.data.reply
+
+ pc = new RTCPeerConnection({
+ iceServers: [
+ {
+ urls: TURN_SERVER_ADDRESS
+ }
+ ]
+ })
+
+ pc.oniceconnectionstatechange = function(e) {console.log(pc.iceConnectionState)}
+
+ pc.onicecandidate = async function(event){
+
+ if (event.candidate === null){
+
+
+ let req = {
+ data: JSON.stringify(pc.localDescription)
+ }
+
+ let resp = await axios.post("/api/cctv/create", req)
+
+ if (result.data.status != "success") {
+
+ alert("failed to start cctv offer")
+ }
+ try {
+ console.log(resp.data)
+ pc.setRemoteDescription(new RTCSessionDescription(resp.data))
+ } catch (e){
+ alert(e)
+ }
+
+ }
+
+
+ }
+
pc.ontrack = function (event) {
+
var el = document.createElement(event.track.kind)
el.srcObject = event.streams[0]
el.autoplay = true
pc.setLocalDescription(offer)
- console.log(offer)
-
- let req = {
- data: JSON.stringify(offer)
- }
-
- let resp = await axios.post("/api/cctv/create", req)
-
- pc.setRemoteDescription(resp.data)
-
console.log("init success")
}
}
+
+