add emote & fix host id.

This commit is contained in:
Miroslav Šedivý 2024-07-21 00:19:04 +02:00
parent 2adb93bc8e
commit 4457df94a3
3 changed files with 63 additions and 21 deletions

View File

@ -22,6 +22,7 @@ type session struct {
profile types.MemberProfile
client *http.Client
lastHostID string
sessions map[string]*oldTypes.Member
connClient *websocket.Conn

View File

@ -5,6 +5,7 @@ import (
"fmt"
"net/http"
"github.com/gorilla/websocket"
"github.com/pion/webrtc/v3"
oldEvent "github.com/demodesk/neko/internal/http/legacy/event"
@ -167,8 +168,28 @@ func (s *session) wsToBackend(msg []byte, sendMsg func([]byte) error) error {
return err
}
// TODO: Emote plugin not implemented.
return fmt.Errorf("event not implemented: %s", header.Event)
// loopback emote
msg, err := json.Marshal(&oldMessage.EmoteSend{
Event: oldEvent.CHAT_EMOTE,
ID: s.id,
Emote: request.Emote,
})
if err != nil {
return err
}
// loopback emote
err = s.connClient.WriteMessage(websocket.TextMessage, msg)
if err != nil {
return err
}
// broadcast emote to other users
return send(event.SEND_BROADCAST, &message.SendBroadcast{
Sender: s.id,
Subject: "emote",
Body: request.Emote,
})
// File Transfer Events
case oldEvent.FILETRANSFER_REFRESH:

View File

@ -37,27 +37,36 @@ func sessionDataToMember(id string, session message.SessionData) (*oldTypes.Memb
}, nil
}
func sendControlHost(request message.ControlHost, send func(payload any) error) error {
func (s *session) sendControlHost(request message.ControlHost, send func(payload any) error) error {
if request.HasHost {
s.lastHostID = request.ID
if request.ID == request.HostID {
return send(&oldMessage.Control{
Event: oldEvent.CONTROL_LOCKED,
ID: request.HostID,
})
}
} else {
return send(&oldMessage.ControlTarget{
Event: oldEvent.CONTROL_GIVE,
ID: request.HostID,
Target: request.ID,
})
}
}
if request.ID != "" {
if request.ID == s.lastHostID {
return send(&oldMessage.Control{
Event: oldEvent.CONTROL_RELEASE,
ID: request.ID,
})
} else {
return send(&oldMessage.Control{
Event: oldEvent.ADMIN_RELEASE,
ID: request.ID,
})
}
}
return nil
@ -151,7 +160,7 @@ func (s *session) wsToClient(msg []byte, sendMsg func([]byte) error) error {
// ControlHost
//
err = sendControlHost(request.ControlHost, send)
err = s.sendControlHost(request.ControlHost, send)
if err != nil {
return err
}
@ -405,7 +414,7 @@ func (s *session) wsToClient(msg []byte, sendMsg func([]byte) error) error {
return err
}
return sendControlHost(*request, send)
return s.sendControlHost(*request, send)
case event.CONTROL_REQUEST:
request := &message.SessionID{}
@ -442,11 +451,22 @@ func (s *session) wsToClient(msg []byte, sendMsg func([]byte) error) error {
Content: request.Content.Text,
})
// TODO: emotes.
//case:
// send(&oldMessage.EmoteSend{
// Event: oldEvent.CHAT_EMOTE,
// })
case event.SEND_BROADCAST:
request := &message.SendBroadcast{}
err := json.Unmarshal(data.Payload, request)
if err != nil {
return err
}
if request.Subject == "emote" {
return send(&oldMessage.EmoteSend{
Event: oldEvent.CHAT_EMOTE,
ID: request.Sender,
Emote: request.Body.(string),
})
}
return nil
// File Transfer Events
case filetransfer.FILETRANSFER_UPDATE: