[refactor] rename HttpSubSession -> BasicHttpSubSession

pull/189/head
q191201771 3 years ago
parent 6db521f41e
commit 26a10947e3

@ -15,17 +15,15 @@ import (
"github.com/q191201771/naza/pkg/connection"
)
// TODO(chef): refactor 更名为BasicHttpSubSession 202205
type HttpSubSession struct {
HttpSubSessionOption
type BasicHttpSubSession struct {
BasicHttpSubSessionOption
suffix string
conn connection.Connection
sessionStat BasicSessionStat
}
type HttpSubSessionOption struct {
type BasicHttpSubSessionOption struct {
Conn net.Conn
ConnModOption connection.ModOption
SessionType SessionType
@ -34,11 +32,11 @@ type HttpSubSessionOption struct {
WebSocketKey string
}
func NewHttpSubSession(option HttpSubSessionOption) *HttpSubSession {
s := &HttpSubSession{
HttpSubSessionOption: option,
conn: connection.New(option.Conn, option.ConnModOption),
sessionStat: NewBasicSessionStat(option.SessionType, ""),
func NewBasicHttpSubSession(option BasicHttpSubSessionOption) *BasicHttpSubSession {
s := &BasicHttpSubSession{
BasicHttpSubSessionOption: option,
conn: connection.New(option.Conn, option.ConnModOption),
sessionStat: NewBasicSessionStat(option.SessionType, ""),
}
return s
}
@ -47,19 +45,19 @@ func NewHttpSubSession(option HttpSubSessionOption) *HttpSubSession {
// IServerSessionLifecycle interface
// ---------------------------------------------------------------------------------------------------------------------
func (session *HttpSubSession) RunLoop() error {
func (session *BasicHttpSubSession) RunLoop() error {
buf := make([]byte, 128)
_, err := session.conn.Read(buf)
return err
}
func (session *HttpSubSession) Dispose() error {
func (session *BasicHttpSubSession) Dispose() error {
return session.conn.Close()
}
// ---------------------------------------------------------------------------------------------------------------------
func (session *HttpSubSession) WriteHttpResponseHeader(b []byte) {
func (session *BasicHttpSubSession) WriteHttpResponseHeader(b []byte) {
if session.IsWebSocket {
session.write(UpdateWebSocketHeader(session.WebSocketKey))
} else {
@ -67,7 +65,7 @@ func (session *HttpSubSession) WriteHttpResponseHeader(b []byte) {
}
}
func (session *HttpSubSession) Write(b []byte) {
func (session *BasicHttpSubSession) Write(b []byte) {
if session.IsWebSocket {
wsHeader := WsHeader{
Fin: true,
@ -87,7 +85,7 @@ func (session *HttpSubSession) Write(b []byte) {
// IObject interface
// ---------------------------------------------------------------------------------------------------------------------
func (session *HttpSubSession) UniqueKey() string {
func (session *BasicHttpSubSession) UniqueKey() string {
return session.sessionStat.UniqueKey()
}
@ -95,15 +93,15 @@ func (session *HttpSubSession) UniqueKey() string {
// ISessionUrlContext interface
// ---------------------------------------------------------------------------------------------------------------------
func (session *HttpSubSession) Url() string {
func (session *BasicHttpSubSession) Url() string {
return session.UrlCtx.Url
}
func (session *HttpSubSession) AppName() string {
func (session *BasicHttpSubSession) AppName() string {
return session.UrlCtx.PathWithoutLastItem
}
func (session *HttpSubSession) StreamName() string {
func (session *BasicHttpSubSession) StreamName() string {
var suffix string
switch session.SessionType {
case SessionTypeFlvSub:
@ -116,27 +114,27 @@ func (session *HttpSubSession) StreamName() string {
return strings.TrimSuffix(session.UrlCtx.LastItemOfPath, suffix)
}
func (session *HttpSubSession) RawQuery() string {
func (session *BasicHttpSubSession) RawQuery() string {
return session.UrlCtx.RawQuery
}
// ----- ISessionStat --------------------------------------------------------------------------------------------------
func (session *HttpSubSession) GetStat() StatSession {
func (session *BasicHttpSubSession) GetStat() StatSession {
return session.sessionStat.GetStat()
}
func (session *HttpSubSession) UpdateStat(intervalSec uint32) {
func (session *BasicHttpSubSession) UpdateStat(intervalSec uint32) {
session.sessionStat.UpdateStatWitchConn(session.conn, intervalSec)
}
func (session *HttpSubSession) IsAlive() (readAlive, writeAlive bool) {
func (session *BasicHttpSubSession) IsAlive() (readAlive, writeAlive bool) {
return session.sessionStat.IsAliveWitchConn(session.conn)
}
// ---------------------------------------------------------------------------------------------------------------------
func (session *HttpSubSession) write(b []byte) {
func (session *BasicHttpSubSession) write(b []byte) {
// TODO(chef) handle write error
_, _ = session.conn.Write(b)
}

@ -140,6 +140,8 @@ func (s *HttpServerManager) Dispose() error {
return nazaerrors.CombineErrors(es...)
}
// ---------------------------------------------------------------------------------------------------------------------
// 为传入的`Addr`地址创建http或https监听
//
func listen(ctx LocalAddrCtx) (net.Listener, error) {

@ -10,8 +10,6 @@ package base
// 文档见: https://pengrl.com/lal/#/HTTPAPI
// TODO(chef): refactor 重命名为t_http_an_api.go 202205
// ----- request -------------------------------------------------------------------------------------------------------
const (

@ -8,9 +8,7 @@
package base
// 文档见: https://pengrl.com/p/20101/
// TODO(chef): refactor 重命名为t_http_an_notify.go 202205
// 文档见: https://pengrl.com/lal/#/HTTPNotify
type SessionEventCommonInfo struct {
ServerId string `json:"server_id"`

@ -18,7 +18,7 @@ package base
//
// other: rtmp.ClientSession, (rtmp.ServerSession)
// rtsp.BaseInSession, rtsp.BaseOutSession, rtsp.ClientCommandSession, rtsp.ServerCommandSession
// base.HttpSubSession
// base.BasicHttpSubSession
// ---------------------------------------------------------------------------------------------------------------------

@ -19,7 +19,7 @@ import (
var flvHttpResponseHeader []byte
type SubSession struct {
core *base.HttpSubSession
core *base.BasicHttpSubSession
IsFresh bool
ShouldWaitVideoKeyFrame bool
}
@ -27,7 +27,7 @@ type SubSession struct {
func NewSubSession(conn net.Conn, urlCtx base.UrlContext, isWebSocket bool, websocketKey string) *SubSession {
uk := base.GenUkFlvSubSession()
s := &SubSession{
core: base.NewHttpSubSession(base.HttpSubSessionOption{
core: base.NewBasicHttpSubSession(base.BasicHttpSubSessionOption{
Conn: conn,
ConnModOption: func(option *connection.Option) {
option.WriteChanSize = SubSessionWriteChanSize

@ -18,14 +18,14 @@ import (
var tsHttpResponseHeader []byte
type SubSession struct {
core *base.HttpSubSession
core *base.BasicHttpSubSession
IsFresh bool
ShouldWaitBoundary bool
}
func NewSubSession(conn net.Conn, urlCtx base.UrlContext, isWebSocket bool, websocketKey string) *SubSession {
s := &SubSession{
core: base.NewHttpSubSession(base.HttpSubSessionOption{
core: base.NewBasicHttpSubSession(base.BasicHttpSubSessionOption{
Conn: conn,
ConnModOption: func(option *connection.Option) {
option.WriteChanSize = SubSessionWriteChanSize

@ -79,7 +79,7 @@ var (
_ base.IServerSessionLifecycle = &httpts.SubSession{}
// other
_ base.IServerSessionLifecycle = &base.HttpSubSession{}
_ base.IServerSessionLifecycle = &base.BasicHttpSubSession{}
_ base.IServerSessionLifecycle = &rtsp.ServerCommandSession{}
)
@ -98,7 +98,7 @@ var (
_ base.ISessionStat = &httpflv.SubSession{}
_ base.ISessionStat = &httpts.SubSession{}
// other
_ base.ISessionStat = &base.HttpSubSession{}
_ base.ISessionStat = &base.BasicHttpSubSession{}
_ base.ISessionStat = &rtmp.ClientSession{}
_ base.ISessionStat = &rtsp.BaseInSession{}
_ base.ISessionStat = &rtsp.BaseOutSession{}
@ -120,7 +120,7 @@ var (
_ base.ISessionUrlContext = &httpflv.SubSession{}
_ base.ISessionUrlContext = &httpts.SubSession{}
// other
_ base.ISessionUrlContext = &base.HttpSubSession{}
_ base.ISessionUrlContext = &base.BasicHttpSubSession{}
_ base.ISessionUrlContext = &rtmp.ClientSession{}
_ base.ISessionUrlContext = &rtsp.ClientCommandSession{}
)
@ -140,7 +140,7 @@ var (
_ base.IObject = &httpflv.SubSession{}
_ base.IObject = &httpts.SubSession{}
//// other
_ base.IObject = &base.HttpSubSession{}
_ base.IObject = &base.BasicHttpSubSession{}
_ base.IObject = &rtmp.ClientSession{}
_ base.IObject = &rtsp.BaseInSession{}
_ base.IObject = &rtsp.BaseOutSession{}

@ -24,8 +24,6 @@ import (
"github.com/q191201771/lal/pkg/sdp"
)
// TODO(chef): [refactor] 文件名修改为group__.go 202205
type IGroupObserver interface {
CleanupHlsIfNeeded(appName string, streamName string, path string)
Loading…
Cancel
Save