Archived
2
0

golang minor changes cleanup.

This commit is contained in:
Miroslav Šedivý 2021-07-22 20:58:15 +02:00
parent 609b3f0927
commit 46b8c9f42d
7 changed files with 18 additions and 24 deletions

View File

@ -43,7 +43,7 @@ func (manager *SessionManager) New(id string, admin bool, socket types.WebSocket
manager.mu.Lock()
manager.members[id] = session
if manager.remote.Streaming() != true && len(manager.members) > 0 {
if !manager.remote.Streaming() && len(manager.members) > 0 {
manager.remote.StartStream()
}
manager.mu.Unlock()
@ -148,7 +148,7 @@ func (manager *SessionManager) Destroy(id string) error {
err := session.destroy()
delete(manager.members, id)
if manager.remote.Streaming() != false && len(manager.members) <= 0 {
if manager.remote.Streaming() && len(manager.members) <= 0 {
manager.remote.StopStream()
}
manager.mu.Unlock()

View File

@ -1,8 +1,6 @@
package session
import (
"sync"
"github.com/rs/zerolog"
"n.eko.moe/neko/internal/types"
"n.eko.moe/neko/internal/types/event"
@ -19,7 +17,6 @@ type Session struct {
manager *SessionManager
socket types.WebSocket
peer types.Peer
mu sync.Mutex
}
func (session *Session) ID() string {

View File

@ -12,7 +12,7 @@ func ArrayIn(val interface{}, array interface{}) (exists bool, index int) {
case reflect.Slice:
s := reflect.ValueOf(array)
for i := 0; i < s.Len(); i++ {
if reflect.DeepEqual(val, s.Index(i).Interface()) == true {
if reflect.DeepEqual(val, s.Index(i).Interface()) {
index = i
exists = true
return

View File

@ -8,11 +8,13 @@ import (
"github.com/pion/webrtc/v3"
)
const OP_MOVE = 0x01
const OP_SCROLL = 0x02
const OP_KEY_DOWN = 0x03
const OP_KEY_UP = 0x04
const OP_KEY_CLK = 0x05
const (
OP_MOVE = 0x01
OP_SCROLL = 0x02
OP_KEY_DOWN = 0x03
OP_KEY_UP = 0x04
OP_KEY_CLK = 0x05
)
type PayloadHeader struct {
Event uint8
@ -63,7 +65,6 @@ func (manager *WebRTCManager) handle(id string, msg webrtc.DataChannelMessage) e
}
manager.remote.Move(int(payload.X), int(payload.Y))
break
case OP_SCROLL:
payload := &PayloadScroll{}
if err := binary.Read(buffer, binary.LittleEndian, payload); err != nil {
@ -77,7 +78,6 @@ func (manager *WebRTCManager) handle(id string, msg webrtc.DataChannelMessage) e
Msg("scroll")
manager.remote.Scroll(int(payload.X), int(payload.Y))
break
case OP_KEY_DOWN:
payload := &PayloadKey{}
if err := binary.Read(buffer, binary.LittleEndian, payload); err != nil {
@ -101,8 +101,6 @@ func (manager *WebRTCManager) handle(id string, msg webrtc.DataChannelMessage) e
manager.logger.Debug().Msgf("key down %d", payload.Key)
}
break
case OP_KEY_UP:
payload := &PayloadKey{}
err := binary.Read(buffer, binary.LittleEndian, payload)
@ -127,7 +125,6 @@ func (manager *WebRTCManager) handle(id string, msg webrtc.DataChannelMessage) e
manager.logger.Debug().Msgf("key up %d", payload.Key)
}
break
case OP_KEY_CLK:
// unused
break

View File

@ -240,19 +240,19 @@ func (m *WebRTCManager) createTrack(codecName string) (*webrtc.TrackLocalStaticS
switch codecName {
case "VP8":
codec = webrtc.RTPCodecParameters{RTPCodecCapability: webrtc.RTPCodecCapability{MimeType: "video/VP8", ClockRate: 90000, Channels: 0, SDPFmtpLine: "", RTCPFeedback: fb}, PayloadType: 96}
codec = webrtc.RTPCodecParameters{RTPCodecCapability: webrtc.RTPCodecCapability{MimeType: webrtc.MimeTypeVP8, ClockRate: 90000, Channels: 0, SDPFmtpLine: "", RTCPFeedback: fb}, PayloadType: 96}
case "VP9":
codec = webrtc.RTPCodecParameters{RTPCodecCapability: webrtc.RTPCodecCapability{MimeType: "video/VP9", ClockRate: 90000, Channels: 0, SDPFmtpLine: "", RTCPFeedback: fb}, PayloadType: 98}
codec = webrtc.RTPCodecParameters{RTPCodecCapability: webrtc.RTPCodecCapability{MimeType: webrtc.MimeTypeVP9, ClockRate: 90000, Channels: 0, SDPFmtpLine: "", RTCPFeedback: fb}, PayloadType: 98}
case "H264":
codec = webrtc.RTPCodecParameters{RTPCodecCapability: webrtc.RTPCodecCapability{MimeType: "video/H264", ClockRate: 90000, Channels: 0, SDPFmtpLine: "level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42001f", RTCPFeedback: fb}, PayloadType: 102}
codec = webrtc.RTPCodecParameters{RTPCodecCapability: webrtc.RTPCodecCapability{MimeType: webrtc.MimeTypeH264, ClockRate: 90000, Channels: 0, SDPFmtpLine: "level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42001f", RTCPFeedback: fb}, PayloadType: 102}
case "Opus":
codec = webrtc.RTPCodecParameters{RTPCodecCapability: webrtc.RTPCodecCapability{MimeType: "audio/opus", ClockRate: 48000, Channels: 2, SDPFmtpLine: "", RTCPFeedback: fb}, PayloadType: 111}
codec = webrtc.RTPCodecParameters{RTPCodecCapability: webrtc.RTPCodecCapability{MimeType: webrtc.MimeTypeOpus, ClockRate: 48000, Channels: 2, SDPFmtpLine: "", RTCPFeedback: fb}, PayloadType: 111}
case "G722":
codec = webrtc.RTPCodecParameters{RTPCodecCapability: webrtc.RTPCodecCapability{MimeType: "audio/G722", ClockRate: 8000, Channels: 0, SDPFmtpLine: "", RTCPFeedback: fb}, PayloadType: 9}
codec = webrtc.RTPCodecParameters{RTPCodecCapability: webrtc.RTPCodecCapability{MimeType: webrtc.MimeTypeG722, ClockRate: 8000, Channels: 0, SDPFmtpLine: "", RTCPFeedback: fb}, PayloadType: 9}
case "PCMU":
codec = webrtc.RTPCodecParameters{RTPCodecCapability: webrtc.RTPCodecCapability{MimeType: "audio/PCMU", ClockRate: 8000, Channels: 0, SDPFmtpLine: "", RTCPFeedback: fb}, PayloadType: 0}
codec = webrtc.RTPCodecParameters{RTPCodecCapability: webrtc.RTPCodecCapability{MimeType: webrtc.MimeTypePCMU, ClockRate: 8000, Channels: 0, SDPFmtpLine: "", RTCPFeedback: fb}, PayloadType: 0}
case "PCMA":
codec = webrtc.RTPCodecParameters{RTPCodecCapability: webrtc.RTPCodecCapability{MimeType: "audio/PCMA", ClockRate: 8000, Channels: 0, SDPFmtpLine: "", RTCPFeedback: fb}, PayloadType: 8}
codec = webrtc.RTPCodecParameters{RTPCodecCapability: webrtc.RTPCodecCapability{MimeType: webrtc.MimeTypePCMA, ClockRate: 8000, Channels: 0, SDPFmtpLine: "", RTCPFeedback: fb}, PayloadType: 8}
default:
return nil, codec, fmt.Errorf("unknown codec %s", codecName)
}

View File

@ -285,7 +285,7 @@ func (ws *WebSocketHandler) handle(connection *websocket.Conn, id string) {
}
case <-cancel:
return
case _ = <-ticker.C:
case <-ticker.C:
if err := connection.WriteMessage(websocket.PingMessage, nil); err != nil {
return
}