Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added rtmps protocol on client connection #65

Merged
merged 1 commit into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

Loading