-
Notifications
You must be signed in to change notification settings - Fork 86
/
client.go
52 lines (41 loc) · 1.27 KB
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//
// Copyright (c) 2018- yutopp ([email protected])
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
//
package rtmp
import (
"crypto/tls"
"net"
"github.com/pkg/errors"
)
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)
}
rwc, err := dialer.Dial("tcp", addr)
if err != nil {
return nil, err
}
return newClientConnWithSetup(rwc, config)
}
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 {
return nil, err
}
return newClientConnWithSetup(rwc, config)
}