Skip to content

Commit

Permalink
Merge pull request gwuhaolin#212 from jaesung9507/rtmps_listen
Browse files Browse the repository at this point in the history
Add RTMPS Listen
  • Loading branch information
matthewgao authored Sep 14, 2022
2 parents 0e247e1 + 7942584 commit 42d7596
Show file tree
Hide file tree
Showing 3 changed files with 34 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
32 changes: 28 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,29 @@ func startHls() *hls.Server {

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

rtmpListen, err := net.Listen("tcp", rtmpAddr)
if err != nil {
log.Fatal(err)
var rtmpListen net.Listener
if isRtmps {
certPath := configure.Config.GetString("rtmps_cert")
keyPath := configure.Config.GetString("rtmps_key")
cert, err := tls.LoadX509KeyPair(certPath, keyPath)
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 +81,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 42d7596

Please sign in to comment.