Skip to content

Commit

Permalink
Merge pull request #65 from jbreich/master
Browse files Browse the repository at this point in the history
Added rtmps protocol on client connection
  • Loading branch information
yutopp authored Jul 15, 2024
2 parents d42d059 + 34ccabd commit c7fee44
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 39 deletions.
24 changes: 17 additions & 7 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package rtmp

import (
"crypto/tls"
"net"

"github.com/pkg/errors"
Expand All @@ -17,6 +18,13 @@ func Dial(protocol, addr string, config *ConnConfig) (*ClientConn, error) {
return DialWithDialer(&net.Dialer{}, protocol, addr, config)
}

func TLSDial(protocol, addr string, config *ConnConfig, tlsConfig *tls.Config) (*ClientConn, error) {
return DialWithTLSDialer(&tls.Dialer{
NetDialer: &net.Dialer{},
Config: tlsConfig,
}, protocol, addr, config)
}

func DialWithDialer(dialer *net.Dialer, protocol, addr string, config *ConnConfig) (*ClientConn, error) {
if protocol != "rtmp" {
return nil, errors.Errorf("Unknown protocol: %s", protocol)
Expand All @@ -30,13 +38,15 @@ func DialWithDialer(dialer *net.Dialer, protocol, addr string, config *ConnConfi
return newClientConnWithSetup(rwc, config)
}

func makeValidAddr(addr string) (string, error) {
host, port, err := net.SplitHostPort(addr)
func DialWithTLSDialer(dialer *tls.Dialer, protocol, addr string, config *ConnConfig) (*ClientConn, error) {
if protocol != "rtmps" {
return nil, errors.Errorf("Unknown protocol: %s", protocol)
}

rwc, err := dialer.Dial("tcp", addr)
if err != nil {
if err, ok := err.(*net.AddrError); ok && err.Err == "missing port in address" {
return makeValidAddr(addr + ":1935") // Default RTMP port
}
return "", err
return nil, err
}
return net.JoinHostPort(host, port), nil

return newClientConnWithSetup(rwc, config)
}
32 changes: 0 additions & 32 deletions client_test.go

This file was deleted.

0 comments on commit c7fee44

Please # to comment.