forked from yutopp/go-rtmp
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver_conn.go
69 lines (54 loc) · 1.55 KB
/
server_conn.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//
// 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 (
"log"
"github.com/pkg/errors"
"github.com/yutopp/go-rtmp/handshake"
)
// serverConn A wrapper of a connection. It prorives server-side specific features.
type serverConn struct {
conn *Conn
}
func newServerConn(conn *Conn) *serverConn {
return &serverConn{
conn: conn,
}
}
func (sc *serverConn) Serve() error {
hs := handshake.HandshakeServer{}
if err := hs.ReadC0C1(sc.conn.rwc); err != nil {
return err
}
log.Printf("< R Handshake C0+C1.")
log.Printf("> W Handshake S0+S1+S2.")
if err := hs.WriteS0S1S2(sc.conn.rwc); err != nil {
return err
}
if err := hs.ReadC2(sc.conn.rwc); err != nil {
return err
}
log.Printf("< R Handshake C2.")
// if err := handshake.PlainHandshakeWithClient(sc.conn.rwc, sc.conn.rwc, &handshake.Config{
// SkipHandshakeVerification: sc.conn.config.SkipHandshakeVerification,
// }); err != nil {
// return errors.Wrap(err, "Failed to handshake")
// }
ctrlStream, err := sc.conn.streams.Create(ControlStreamID)
if err != nil {
return errors.Wrap(err, "Failed to create control stream")
}
ctrlStream.handler.ChangeState(streamStateServerNotConnected)
sc.conn.streamer.controlStreamWriter = ctrlStream.Write
if sc.conn.handler != nil {
sc.conn.handler.OnServe(sc.conn)
}
return sc.conn.handleMessageLoop()
}
func (sc *serverConn) Close() error {
return sc.conn.Close()
}