mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
refactor WebRTC antipatterns.
This commit is contained in:
parent
b1b5a70c64
commit
cca147859d
@ -48,6 +48,7 @@ func (session *Session) Address() string {
|
||||
if session.socket == nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
return session.socket.Address()
|
||||
}
|
||||
|
||||
@ -64,26 +65,21 @@ func (session *Session) SetMuted(muted bool) {
|
||||
session.muted = muted
|
||||
}
|
||||
|
||||
func (session *Session) SetName(name string) error {
|
||||
func (session *Session) SetName(name string) {
|
||||
session.name = name
|
||||
return nil
|
||||
}
|
||||
|
||||
func (session *Session) SetSocket(socket types.WebSocket) error {
|
||||
func (session *Session) SetSocket(socket types.WebSocket) {
|
||||
session.socket = socket
|
||||
return nil
|
||||
}
|
||||
|
||||
func (session *Session) SetPeer(peer types.Peer) error {
|
||||
func (session *Session) SetPeer(peer types.Peer) {
|
||||
session.peer = peer
|
||||
return nil
|
||||
}
|
||||
|
||||
func (session *Session) SetConnected(connected bool) {
|
||||
session.connected = connected
|
||||
if connected {
|
||||
func (session *Session) SetConnected() {
|
||||
session.connected = true
|
||||
session.manager.emmiter.Emit("connected", session.id, session)
|
||||
}
|
||||
}
|
||||
|
||||
func (session *Session) Disconnect(reason string) error {
|
||||
@ -105,6 +101,7 @@ func (session *Session) Send(v interface{}) error {
|
||||
if session.socket == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return session.socket.Send(v)
|
||||
}
|
||||
|
||||
@ -112,6 +109,7 @@ func (session *Session) SignalAnswer(sdp string) error {
|
||||
if session.peer == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return session.peer.SignalAnswer(sdp)
|
||||
}
|
||||
|
||||
|
@ -16,10 +16,10 @@ type Session interface {
|
||||
Connected() bool
|
||||
Member() *Member
|
||||
SetMuted(muted bool)
|
||||
SetName(name string) error
|
||||
SetConnected(connected bool)
|
||||
SetSocket(socket WebSocket) error
|
||||
SetPeer(peer Peer) error
|
||||
SetName(name string)
|
||||
SetConnected()
|
||||
SetSocket(socket WebSocket)
|
||||
SetPeer(peer Peer)
|
||||
Address() string
|
||||
Disconnect(message string) error
|
||||
Send(v interface{}) error
|
||||
|
@ -152,11 +152,11 @@ func (manager *WebRTCManager) CreatePeer(id string, session types.Session) (stri
|
||||
session.Disconnect("peer connection state failed")
|
||||
case webrtc.PeerConnectionStateConnected:
|
||||
manager.logger.Info().Str("id", id).Msg("peer connected")
|
||||
session.SetConnected(true)
|
||||
session.SetConnected()
|
||||
}
|
||||
})
|
||||
|
||||
if err := session.SetPeer(&Peer{
|
||||
session.SetPeer(&Peer{
|
||||
id: id,
|
||||
api: api,
|
||||
engine: &engine,
|
||||
@ -164,9 +164,7 @@ func (manager *WebRTCManager) CreatePeer(id string, session types.Session) (stri
|
||||
settings: &settings,
|
||||
connection: connection,
|
||||
configuration: configuration,
|
||||
}); err != nil {
|
||||
return "", manager.config.ICELite, manager.config.ICEServers, err
|
||||
}
|
||||
})
|
||||
|
||||
return description.SDP, manager.config.ICELite, manager.config.ICEServers, nil
|
||||
}
|
||||
|
@ -26,9 +26,7 @@ func (h *MessageHandler) signalProvide(id string, session types.Session) error {
|
||||
}
|
||||
|
||||
func (h *MessageHandler) signalAnswer(id string, session types.Session, payload *message.SignalAnswer) error {
|
||||
if err := session.SetName(payload.DisplayName); err != nil {
|
||||
return err
|
||||
}
|
||||
session.SetName(payload.DisplayName)
|
||||
|
||||
if err := session.SignalAnswer(payload.SDP); err != nil {
|
||||
return err
|
||||
|
Loading…
Reference in New Issue
Block a user