forked from yutopp/go-rtmp
-
Notifications
You must be signed in to change notification settings - Fork 1
/
server_conn.go
51 lines (40 loc) · 1.19 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
//
// 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 (
"github.com/pkg/errors"
"github.com/edgeware/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 {
if err := handshake.HandshakeWithClient(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()
}