forked from yutopp/go-rtmp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
42 lines (34 loc) · 1.03 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
//
// Copyright (c) 2018- yutopp (yutopp@gmail.com)
//
// 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 (
"net"
"github.com/pkg/errors"
)
func Dial(protocol, addr string, config *ConnConfig) (*ClientConn, error) {
return DialWithDialer(&net.Dialer{}, 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 makeValidAddr(addr string) (string, error) {
host, port, err := net.SplitHostPort(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 net.JoinHostPort(host, port), nil
}