-
Notifications
You must be signed in to change notification settings - Fork 458
/
t_http_an__notify.go
149 lines (118 loc) · 3.63 KB
/
t_http_an__notify.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// Copyright 2020, Chef. All rights reserved.
// https://github.com/q191201771/lal
//
// Use of this source code is governed by a MIT-style license
// that can be found in the License file.
//
// Author: Chef (191201771@qq.com)
package base
// 文档见: https://pengrl.com/lal/#/HTTPNotify
// EventCommonInfo 所有事件共有的字段
type EventCommonInfo struct {
ServerId string `json:"server_id"`
}
// SessionEventCommonInfo session相关的事件的共有的字段
type SessionEventCommonInfo struct {
EventCommonInfo
SessionId string `json:"session_id"`
Protocol string `json:"protocol"`
BaseType string `json:"base_type"`
RemoteAddr string `json:"remote_addr"`
Url string `json:"url"`
AppName string `json:"app_name"`
StreamName string `json:"stream_name"`
UrlParam string `json:"url_param"`
HasInSession bool `json:"has_in_session"`
HasOutSession bool `json:"has_out_session"`
// TODO(chef): [opt] 这两个字段,实际需求出发点是有业务方需要在stop事件做流量统计,但是现在的实现为所有session事件都添加了,是否合适 202208
ReadBytesSum uint64 `json:"read_bytes_sum"`
WroteBytesSum uint64 `json:"wrote_bytes_sum"`
}
type UpdateInfo struct {
EventCommonInfo
Groups []StatGroup `json:"groups"`
}
type PubStartInfo struct {
SessionEventCommonInfo
}
type PubStopInfo struct {
SessionEventCommonInfo
}
type SubStartInfo struct {
SessionEventCommonInfo
}
type SubStopInfo struct {
SessionEventCommonInfo
}
type PullStartInfo struct {
SessionEventCommonInfo
}
type PullStopInfo struct {
SessionEventCommonInfo
}
type RtmpConnectInfo struct {
EventCommonInfo
SessionId string `json:"session_id"`
RemoteAddr string `json:"remote_addr"`
App string `json:"app"`
FlashVer string `json:"flashVer"`
TcUrl string `json:"tcUrl"`
}
type HlsMakeTsInfo struct {
EventCommonInfo
Event string `json:"event"`
StreamName string `json:"stream_name"`
Cwd string `json:"cwd"`
TsFile string `json:"ts_file"`
LiveM3u8File string `json:"live_m3u8_file"`
RecordM3u8File string `json:"record_m3u8_file"`
Id int `json:"id"`
Duration float64 `json:"duration"`
}
// ---------------------------------------------------------------------------------------------------------------------
func Session2PubStartInfo(session ISession) PubStartInfo {
return PubStartInfo{
session2EventCommonInfo(session),
}
}
func Session2PubStopInfo(session ISession) PubStopInfo {
return PubStopInfo{
session2EventCommonInfo(session),
}
}
func Session2SubStartInfo(session ISession) SubStartInfo {
return SubStartInfo{
session2EventCommonInfo(session),
}
}
func Session2SubStopInfo(session ISession) SubStopInfo {
return SubStopInfo{
session2EventCommonInfo(session),
}
}
func Session2PullStartInfo(session ISession) PullStartInfo {
return PullStartInfo{
session2EventCommonInfo(session),
}
}
func Session2PullStopInfo(session ISession) PullStopInfo {
return PullStopInfo{
session2EventCommonInfo(session),
}
}
// ---------------------------------------------------------------------------------------------------------------------
func session2EventCommonInfo(session ISession) SessionEventCommonInfo {
var info SessionEventCommonInfo
stat := session.GetStat()
info.SessionId = stat.SessionId
info.Protocol = stat.Protocol
info.BaseType = stat.BaseType
info.RemoteAddr = stat.RemoteAddr
info.Url = session.Url()
info.AppName = session.AppName()
info.StreamName = session.StreamName()
info.UrlParam = session.RawQuery()
info.ReadBytesSum = stat.ReadBytesSum
info.WroteBytesSum = stat.WroteBytesSum
return info
}