From 771dc1f46feec5f24307d18feb515332b564a5c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Sat, 20 Jul 2024 16:12:36 +0200 Subject: [PATCH] legacy adapter - add http calls. --- server/internal/http/legacy/wstobackend.go | 33 +++++++++++----------- server/internal/http/legacy/wstoclient.go | 13 +++++---- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/server/internal/http/legacy/wstobackend.go b/server/internal/http/legacy/wstobackend.go index 1923d3b5..122453ae 100644 --- a/server/internal/http/legacy/wstobackend.go +++ b/server/internal/http/legacy/wstobackend.go @@ -3,17 +3,19 @@ package legacy import ( "encoding/json" "fmt" + "net/http" + + "github.com/pion/webrtc/v3" oldEvent "github.com/demodesk/neko/internal/http/legacy/event" oldMessage "github.com/demodesk/neko/internal/http/legacy/message" - "github.com/pion/webrtc/v3" + "github.com/demodesk/neko/internal/api/room" + "github.com/demodesk/neko/internal/plugins/chat" + "github.com/demodesk/neko/internal/plugins/filetransfer" "github.com/demodesk/neko/pkg/types" "github.com/demodesk/neko/pkg/types/event" "github.com/demodesk/neko/pkg/types/message" - - chat "github.com/demodesk/neko/internal/plugins/chat" - filetransfer "github.com/demodesk/neko/internal/plugins/filetransfer" ) func (s *session) wsToBackend(msg []byte, sendMsg func([]byte) error) error { @@ -97,8 +99,8 @@ func (s *session) wsToBackend(msg []byte, sendMsg func([]byte) error) error { return err } - // TODO: No WS equivalent, call HTTP API. - return fmt.Errorf("event not implemented: %s", header.Event) + // TODO: Not implemented for user - only for admins. + return s.apiReq(http.MethodPost, "/api/room/control/give/"+request.ID, nil, nil) case oldEvent.CONTROL_CLIPBOARD: request := &oldMessage.Clipboard{} @@ -204,12 +206,13 @@ func (s *session) wsToBackend(msg []byte, sendMsg func([]byte) error) error { return err } - // TODO: No WS equivalent, call HTTP API. - return fmt.Errorf("event not implemented: %s", header.Event) + return s.apiReq(http.MethodPost, "/api/room/broadcast/start", room.BroadcastStatusPayload{ + URL: request.URL, + IsActive: true, + }, nil) case oldEvent.BROADCAST_DESTROY: - // TODO: No WS equivalent, call HTTP API. - return fmt.Errorf("event not implemented: %s", header.Event) + return s.apiReq(http.MethodPost, "/api/room/broadcast/stop", nil, nil) // Admin Events case oldEvent.ADMIN_LOCK: @@ -233,12 +236,10 @@ func (s *session) wsToBackend(msg []byte, sendMsg func([]byte) error) error { return fmt.Errorf("event not implemented: %s", header.Event) case oldEvent.ADMIN_CONTROL: - // TODO: No WS equivalent, call HTTP API. - return fmt.Errorf("event not implemented: %s", header.Event) + return s.apiReq(http.MethodPost, "/api/room/control/take", nil, nil) case oldEvent.ADMIN_RELEASE: - // TODO: No WS equivalent, call HTTP API. - return fmt.Errorf("event not implemented: %s", header.Event) + return s.apiReq(http.MethodPost, "/api/room/control/reset", nil, nil) case oldEvent.ADMIN_GIVE: request := &oldMessage.Admin{} @@ -246,9 +247,7 @@ func (s *session) wsToBackend(msg []byte, sendMsg func([]byte) error) error { if err != nil { return err } - - // TODO: No WS equivalent, call HTTP API. - return fmt.Errorf("event not implemented: %s", header.Event) + return s.apiReq(http.MethodPost, "/api/room/control/give/"+request.ID, nil, nil) case oldEvent.ADMIN_BAN: request := &oldMessage.Admin{} diff --git a/server/internal/http/legacy/wstoclient.go b/server/internal/http/legacy/wstoclient.go index 32085236..9ccc0d19 100644 --- a/server/internal/http/legacy/wstoclient.go +++ b/server/internal/http/legacy/wstoclient.go @@ -5,13 +5,14 @@ import ( "errors" "fmt" + "github.com/pion/webrtc/v3" + oldEvent "github.com/demodesk/neko/internal/http/legacy/event" oldMessage "github.com/demodesk/neko/internal/http/legacy/message" oldTypes "github.com/demodesk/neko/internal/http/legacy/types" - "github.com/pion/webrtc/v3" - chat "github.com/demodesk/neko/internal/plugins/chat" - filetransfer "github.com/demodesk/neko/internal/plugins/filetransfer" + "github.com/demodesk/neko/internal/plugins/chat" + "github.com/demodesk/neko/internal/plugins/filetransfer" "github.com/demodesk/neko/pkg/types" "github.com/demodesk/neko/pkg/types/event" "github.com/demodesk/neko/pkg/types/message" @@ -41,14 +42,14 @@ func sendControlHost(request message.ControlHost, send func(payload any) error) if request.ID == request.HostID { return send(&oldMessage.Control{ Event: oldEvent.CONTROL_LOCKED, - ID: request.ID, + ID: request.HostID, }) } return send(&oldMessage.ControlTarget{ Event: oldEvent.CONTROL_GIVE, - ID: request.ID, - Target: request.HostID, + ID: request.HostID, + Target: request.ID, }) }