fix: golangci

This commit is contained in:
zarazaex69
2026-05-03 10:24:18 +03:00
parent aaa0a5013a
commit a4e6079148
5 changed files with 64 additions and 48 deletions

View File

@@ -20,7 +20,7 @@ func controlFunc(network, _ string, c syscall.RawConn) error {
}
var err error
controlErr := c.Control(func(fd uintptr) {
if !Protector(int(fd)) { //nolint:gosec
if !Protector(int(fd)) {
err = &net.OpError{Op: "protect", Net: network, Err: net.ErrClosed}
}
})

View File

@@ -13,7 +13,10 @@ import (
"github.com/openlibrecommunity/olcrtc/internal/protect"
)
const apiBase = "https://bk.salutejazz.ru"
const (
apiBase = "https://bk.salutejazz.ru"
authTypeAnonymous = "ANONYMOUS"
)
// RoomInfo contains connection details for a SaluteJazz room.
type RoomInfo struct {
@@ -31,8 +34,8 @@ func createRoom(ctx context.Context) (*RoomInfo, error) {
clientID := uuid.New().String()
headers := map[string]string{
"X-Jazz-ClientId": clientID,
"X-Jazz-AuthType": "ANONYMOUS",
"X-Client-AuthType": "ANONYMOUS",
"X-Jazz-AuthType": authTypeAnonymous,
"X-Client-AuthType": authTypeAnonymous,
"Content-Type": "application/json",
}
@@ -164,8 +167,8 @@ func joinRoom(ctx context.Context, roomID, password string) (*RoomInfo, error) {
clientID := uuid.New().String()
headers := map[string]string{
"X-Jazz-ClientId": clientID,
"X-Jazz-AuthType": "ANONYMOUS",
"X-Client-AuthType": "ANONYMOUS",
"X-Jazz-AuthType": authTypeAnonymous,
"X-Client-AuthType": authTypeAnonymous,
"Content-Type": "application/json",
}

View File

@@ -22,6 +22,11 @@ import (
const (
maxDataChannelMessageSize = 12288
sendDelay = 2 * time.Millisecond
keyRoomID = "roomId"
keyEvent = "event"
keyRequestID = "requestId"
keyPayload = "payload"
)
var (
@@ -290,10 +295,10 @@ func (p *Peer) dialWebSocket() error {
func (p *Peer) sendJoin() error {
joinMsg := map[string]any{
"roomId": p.roomInfo.RoomID,
"event": "join",
"requestId": uuid.New().String(),
"payload": map[string]any{
keyRoomID: p.roomInfo.RoomID,
keyEvent: "join",
keyRequestID: uuid.New().String(),
keyPayload: map[string]any{
"password": p.roomInfo.Password,
"participantName": p.name,
"supportedFeatures": map[string]any{
@@ -416,8 +421,8 @@ func (p *Peer) handleSignaling(_ context.Context) {
p.updateWSDeadline()
event, _ := msg["event"].(string)
payload, _ := msg["payload"].(map[string]any)
event, _ := msg[keyEvent].(string)
payload, _ := msg[keyPayload].(map[string]any)
switch event {
case "join-response":
@@ -514,11 +519,11 @@ func (p *Peer) handleSubscriberOffer(payload map[string]any) {
p.wsMu.Lock()
_ = p.ws.WriteJSON(map[string]any{
"roomId": p.roomInfo.RoomID,
"event": "media-in",
keyRoomID: p.roomInfo.RoomID,
keyEvent: "media-in",
"groupId": p.groupID,
"requestId": uuid.New().String(),
"payload": map[string]any{
keyRequestID: uuid.New().String(),
keyPayload: map[string]any{
"method": "rtc:answer",
"description": map[string]any{
"type": "answer",
@@ -546,11 +551,11 @@ func (p *Peer) sendPublisherOffer() {
p.wsMu.Lock()
_ = p.ws.WriteJSON(map[string]any{
"roomId": p.roomInfo.RoomID,
"event": "media-in",
keyRoomID: p.roomInfo.RoomID,
keyEvent: "media-in",
"groupId": p.groupID,
"requestId": uuid.New().String(),
"payload": map[string]any{
keyRequestID: uuid.New().String(),
keyPayload: map[string]any{
"method": "rtc:offer",
"description": map[string]any{
"type": "offer",

View File

@@ -27,6 +27,10 @@ const (
defaultSendDelayLow = 2 * time.Millisecond
defaultSendDelayMax = 12 * time.Millisecond
defaultTelemetryInterval = 20 * time.Second
keyUID = "uid"
keyDescription = "description"
keyPcSeq = "pcSeq"
)
var (
@@ -470,19 +474,19 @@ func (p *Peer) Send(data []byte) error {
func (p *Peer) sendHello() error {
hello := map[string]interface{}{
"uid": uuid.New().String(),
keyUID: uuid.New().String(),
"hello": map[string]interface{}{
"participantMeta": map[string]interface{}{
"name": p.name,
"role": "SPEAKER",
"description": "",
keyDescription: "",
"sendAudio": false,
"sendVideo": p.hasLocalVideoTracks(),
},
"participantAttributes": map[string]interface{}{
"name": p.name,
"role": "SPEAKER",
"description": "",
keyDescription: "",
},
"sendAudio": false,
"sendVideo": p.hasLocalVideoTracks(),
@@ -528,7 +532,7 @@ func (p *Peer) handleSignaling(ctx context.Context) {
p.updateWSDeadline()
uid, _ := msg["uid"].(string)
uid, _ := msg[keyUID].(string)
p.handleMessageEvents(ctx, msg, uid)
if isConferenceEndMessage(msg) {
@@ -617,9 +621,9 @@ func (p *Peer) handleSdpOffer(offer map[string]interface{}, uid string, sendPub
p.wsMu.Lock()
_ = p.ws.WriteJSON(map[string]interface{}{
"uid": uuid.New().String(),
keyUID: uuid.New().String(),
"subscriberSdpAnswer": map[string]interface{}{
"pcSeq": int(pcSeq),
keyPcSeq: int(pcSeq),
"sdp": answer.SDP,
},
})
@@ -650,9 +654,9 @@ func (p *Peer) handleSdpOffer(offer map[string]interface{}, uid string, sendPub
p.wsMu.Lock()
_ = p.ws.WriteJSON(map[string]interface{}{
"uid": uuid.New().String(),
keyUID: uuid.New().String(),
"publisherSdpOffer": map[string]interface{}{
"pcSeq": 1,
keyPcSeq: 1,
"sdp": pubOffer.SDP,
"tracks": p.publisherTrackDescriptions(),
},
@@ -666,7 +670,7 @@ func (p *Peer) sendSetSlots() error {
defer p.wsMu.Unlock()
if err := p.ws.WriteJSON(map[string]interface{}{
"uid": uuid.New().String(),
keyUID: uuid.New().String(),
"setSlots": map[string]interface{}{
"slots": []map[string]int{
{"width": 1280, "height": 720},
@@ -792,7 +796,7 @@ func (p *Peer) publisherTrackDescriptions() []map[string]interface{} {
"label": track.ID(),
"codecs": map[string]interface{}{},
"groupId": 1,
"description": "",
keyDescription: "",
})
}
@@ -910,7 +914,7 @@ func (p *Peer) sendAck(uid string) {
defer p.wsMu.Unlock()
_ = p.ws.WriteJSON(map[string]interface{}{
"uid": uid,
keyUID: uid,
"ack": map[string]interface{}{
"status": map[string]interface{}{"code": "OK"},
},
@@ -967,7 +971,7 @@ func (p *Peer) sendPong(uid string) {
defer p.wsMu.Unlock()
_ = p.ws.WriteJSON(map[string]interface{}{
"uid": uid,
keyUID: uid,
"pong": map[string]interface{}{},
})
}
@@ -1128,13 +1132,13 @@ func (p *Peer) setupICEHandlers() {
init := c.ToJSON()
p.wsMu.Lock()
_ = p.ws.WriteJSON(map[string]interface{}{
"uid": uuid.New().String(),
keyUID: uuid.New().String(),
"webrtcIceCandidate": map[string]interface{}{
"candidate": init.Candidate,
"sdpMid": init.SDPMid,
"sdpMlineIndex": init.SDPMLineIndex,
"target": "SUBSCRIBER",
"pcSeq": 1,
keyPcSeq: 1,
},
})
p.wsMu.Unlock()
@@ -1147,13 +1151,13 @@ func (p *Peer) setupICEHandlers() {
init := c.ToJSON()
p.wsMu.Lock()
_ = p.ws.WriteJSON(map[string]interface{}{
"uid": uuid.New().String(),
keyUID: uuid.New().String(),
"webrtcIceCandidate": map[string]interface{}{
"candidate": init.Candidate,
"sdpMid": init.SDPMid,
"sdpMlineIndex": init.SDPMLineIndex,
"target": "PUBLISHER",
"pcSeq": 1,
keyPcSeq: 1,
},
})
p.wsMu.Unlock()
@@ -1169,7 +1173,7 @@ func (p *Peer) sendLeave(uid string) bool {
}
leave := map[string]interface{}{
"uid": uid,
keyUID: uid,
"leave": map[string]interface{}{},
}
@@ -1271,7 +1275,7 @@ func (p *Peer) sendAppPing() bool {
defer p.wsMu.Unlock()
if p.ws != nil {
if err := p.ws.WriteJSON(map[string]interface{}{
"uid": uuid.New().String(),
keyUID: uuid.New().String(),
"ping": map[string]interface{}{},
}); err != nil {
logger.Debugf("app ping error: %v", err)

View File

@@ -22,6 +22,10 @@ import (
const (
ffmpegFrameTimeout = 10 * time.Second
argCodecVideo = "-c:v"
argPixFmt = "-pix_fmt"
pixFmtYUV420P = "yuv420p"
)
var (
@@ -74,11 +78,11 @@ func h264CodecSpec() codecSpec {
},
depacketizer: func() rtp.Depacketizer { return &codecs.H264Packet{} },
encodeArgs: []string{
"-c:v", "libx264",
argCodecVideo, "libx264",
"-preset", "ultrafast",
"-tune", "zerolatency",
"-g", "1",
"-pix_fmt", "yuv420p",
argPixFmt, pixFmtYUV420P,
},
}
}
@@ -94,13 +98,13 @@ func vp9CodecSpec() codecSpec {
},
depacketizer: func() rtp.Depacketizer { return &codecs.VP9Packet{} },
encodeArgs: []string{
"-c:v", "libvpx-vp9",
argCodecVideo, "libvpx-vp9",
"-deadline", "realtime",
"-cpu-used", "8",
"-error-resilient", "1",
"-static-thresh", "0",
"-g", "1",
"-pix_fmt", "yuv420p",
argPixFmt, pixFmtYUV420P,
},
}
}
@@ -116,13 +120,13 @@ func vp8CodecSpec() codecSpec {
},
depacketizer: func() rtp.Depacketizer { return &codecs.VP8Packet{} },
encodeArgs: []string{
"-c:v", "libvpx",
argCodecVideo, "libvpx",
"-deadline", "realtime",
"-cpu-used", "8",
"-error-resilient", "1",
"-static-thresh", "0",
"-g", "1",
"-pix_fmt", "yuv420p",
argPixFmt, pixFmtYUV420P,
},
}
}
@@ -149,7 +153,7 @@ func buildEncoderArgs(spec codecSpec, vcodec string, width, height, fps int, bit
args := []string{
"-loglevel", "error", "-threads", "1",
"-f", "rawvideo",
"-pix_fmt", "gray",
argPixFmt, "gray",
"-video_size", strconv.Itoa(width) + "x" + strconv.Itoa(height),
"-framerate", strconv.Itoa(fps),
"-i", "pipe:0",
@@ -157,12 +161,12 @@ func buildEncoderArgs(spec codecSpec, vcodec string, width, height, fps int, bit
}
if strings.HasSuffix(vcodec, "_nvenc") {
args = append(args, "-c:v", vcodec, "-preset", "p1", "-tune", "ull", "-rc", "vbr")
args = append(args, argCodecVideo, vcodec, "-preset", "p1", "-tune", "ull", "-rc", "vbr")
} else {
args = append(args, spec.encodeArgs...)
}
args = append(args, "-g", "1", "-pix_fmt", "yuv420p", "-b:v", bitrate)
args = append(args, "-g", "1", argPixFmt, pixFmtYUV420P, "-b:v", bitrate)
if spec.mimeType == webrtc.MimeTypeH264 {
return append(args, "-f", "h264", "pipe:1")
@@ -366,7 +370,7 @@ func buildDecoderArgs(spec codecSpec, decoderName string, width, height int, out
"-i", "pipe:0",
"-an",
"-vf", vfFilter,
"-pix_fmt", outputPixFmt,
argPixFmt, outputPixFmt,
"-f", "rawvideo",
"pipe:1",
)