Skip to content

Commit

Permalink
Add RTMPS Listen
Browse files Browse the repository at this point in the history
  • Loading branch information
jaesung9507 committed Aug 9, 2022
1 parent 0e247e1 commit 47bfeea
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
3 changes: 3 additions & 0 deletions configure/liveconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ func initDefault() {

// Flags
pflag.String("rtmp_addr", ":1935", "RTMP server listen address")
pflag.Bool("enable_rtmps", false, "enable server session RTMPS")
pflag.String("rtmps_cert", "server.crt", "cert file path required for RTMPS")
pflag.String("rtmps_key", "server.key", "key file path required for RTMPS")
pflag.String("httpflv_addr", ":7001", "HTTP-FLV server listen address")
pflag.String("hls_addr", ":7002", "HLS server listen address")
pflag.String("api_addr", ":8090", "HTTP manage interface server listen address")
Expand Down
3 changes: 3 additions & 0 deletions livego.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
# # RTMP Options
# rtmp_noauth: false
# rtmp_addr: ":1935"
# enable_rtmps: true
# rtmps_cert: server.crt
# rtmps_key: server.key
# read_timeout: 10
# write_timeout: 10

Expand Down
34 changes: 30 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"crypto/tls"
"fmt"
"net"
"path"
Expand Down Expand Up @@ -40,10 +41,31 @@ func startHls() *hls.Server {

func startRtmp(stream *rtmp.RtmpStream, hlsServer *hls.Server) {
rtmpAddr := configure.Config.GetString("rtmp_addr")
isRtmps := configure.Config.GetBool("enable_rtmps")

var rtmpListen net.Listener
if isRtmps {
certPath := configure.Config.GetString("rtmps_cert")
keyPath := configure.Config.GetString("rtmps_key")
log.Info(certPath)
log.Info(keyPath)
cert, err := tls.LoadX509KeyPair(certPath, keyPath)
if err != nil {
log.Fatal(err)
}

rtmpListen, err := net.Listen("tcp", rtmpAddr)
if err != nil {
log.Fatal(err)
rtmpListen, err = tls.Listen("tcp", rtmpAddr, &tls.Config{
Certificates: []tls.Certificate{cert},
})
if err != nil {
log.Fatal(err)
}
} else {
var err error
rtmpListen, err = net.Listen("tcp", rtmpAddr)
if err != nil {
log.Fatal(err)
}
}

var rtmpServer *rtmp.Server
Expand All @@ -61,7 +83,11 @@ func startRtmp(stream *rtmp.RtmpStream, hlsServer *hls.Server) {
log.Error("RTMP server panic: ", r)
}
}()
log.Info("RTMP Listen On ", rtmpAddr)
if isRtmps {
log.Info("RTMPS Listen On ", rtmpAddr)
} else {
log.Info("RTMP Listen On ", rtmpAddr)
}
rtmpServer.Serve(rtmpListen)
}

Expand Down

0 comments on commit 47bfeea

Please sign in to comment.