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 profile types.MemberProfile
client *http.Client client *http.Client
lastHostID string
sessions map[string]*oldTypes.Member sessions map[string]*oldTypes.Member
connClient *websocket.Conn connClient *websocket.Conn

View File

@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"net/http" "net/http"
"github.com/gorilla/websocket"
"github.com/pion/webrtc/v3" "github.com/pion/webrtc/v3"
oldEvent "github.com/demodesk/neko/internal/http/legacy/event" 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 return err
} }
// TODO: Emote plugin not implemented. // loopback emote
return fmt.Errorf("event not implemented: %s", header.Event) 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 // File Transfer Events
case oldEvent.FILETRANSFER_REFRESH: case oldEvent.FILETRANSFER_REFRESH:

View File

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