diff --git a/server/internal/http/legacy/session.go b/server/internal/http/legacy/session.go index d8aeed44..894d76a4 100644 --- a/server/internal/http/legacy/session.go +++ b/server/internal/http/legacy/session.go @@ -22,7 +22,8 @@ type session struct { profile types.MemberProfile client *http.Client - sessions map[string]*oldTypes.Member + lastHostID string + sessions map[string]*oldTypes.Member connClient *websocket.Conn connBackend *websocket.Conn diff --git a/server/internal/http/legacy/wstobackend.go b/server/internal/http/legacy/wstobackend.go index 122453ae..cc51a865 100644 --- a/server/internal/http/legacy/wstobackend.go +++ b/server/internal/http/legacy/wstobackend.go @@ -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: diff --git a/server/internal/http/legacy/wstoclient.go b/server/internal/http/legacy/wstoclient.go index fc2ac9b4..ecad171f 100644 --- a/server/internal/http/legacy/wstoclient.go +++ b/server/internal/http/legacy/wstoclient.go @@ -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, + }) } - - return send(&oldMessage.ControlTarget{ - Event: oldEvent.CONTROL_GIVE, - ID: request.HostID, - Target: request.ID, - }) } if request.ID != "" { - return send(&oldMessage.Control{ - Event: oldEvent.CONTROL_RELEASE, - ID: 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: