legacy adapter - add http calls.

This commit is contained in:
Miroslav Šedivý 2024-07-20 16:12:36 +02:00
parent 260a1973f5
commit 771dc1f46f
2 changed files with 23 additions and 23 deletions

View File

@ -3,17 +3,19 @@ package legacy
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"net/http"
"github.com/pion/webrtc/v3"
oldEvent "github.com/demodesk/neko/internal/http/legacy/event" oldEvent "github.com/demodesk/neko/internal/http/legacy/event"
oldMessage "github.com/demodesk/neko/internal/http/legacy/message" 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"
"github.com/demodesk/neko/pkg/types/event" "github.com/demodesk/neko/pkg/types/event"
"github.com/demodesk/neko/pkg/types/message" "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 { 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 return err
} }
// TODO: No WS equivalent, call HTTP API. // TODO: Not implemented for user - only for admins.
return fmt.Errorf("event not implemented: %s", header.Event) return s.apiReq(http.MethodPost, "/api/room/control/give/"+request.ID, nil, nil)
case oldEvent.CONTROL_CLIPBOARD: case oldEvent.CONTROL_CLIPBOARD:
request := &oldMessage.Clipboard{} request := &oldMessage.Clipboard{}
@ -204,12 +206,13 @@ func (s *session) wsToBackend(msg []byte, sendMsg func([]byte) error) error {
return err return err
} }
// TODO: No WS equivalent, call HTTP API. return s.apiReq(http.MethodPost, "/api/room/broadcast/start", room.BroadcastStatusPayload{
return fmt.Errorf("event not implemented: %s", header.Event) URL: request.URL,
IsActive: true,
}, nil)
case oldEvent.BROADCAST_DESTROY: case oldEvent.BROADCAST_DESTROY:
// TODO: No WS equivalent, call HTTP API. return s.apiReq(http.MethodPost, "/api/room/broadcast/stop", nil, nil)
return fmt.Errorf("event not implemented: %s", header.Event)
// Admin Events // Admin Events
case oldEvent.ADMIN_LOCK: 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) return fmt.Errorf("event not implemented: %s", header.Event)
case oldEvent.ADMIN_CONTROL: case oldEvent.ADMIN_CONTROL:
// TODO: No WS equivalent, call HTTP API. return s.apiReq(http.MethodPost, "/api/room/control/take", nil, nil)
return fmt.Errorf("event not implemented: %s", header.Event)
case oldEvent.ADMIN_RELEASE: case oldEvent.ADMIN_RELEASE:
// TODO: No WS equivalent, call HTTP API. return s.apiReq(http.MethodPost, "/api/room/control/reset", nil, nil)
return fmt.Errorf("event not implemented: %s", header.Event)
case oldEvent.ADMIN_GIVE: case oldEvent.ADMIN_GIVE:
request := &oldMessage.Admin{} request := &oldMessage.Admin{}
@ -246,9 +247,7 @@ func (s *session) wsToBackend(msg []byte, sendMsg func([]byte) error) error {
if err != nil { if err != nil {
return err return err
} }
return s.apiReq(http.MethodPost, "/api/room/control/give/"+request.ID, nil, nil)
// TODO: No WS equivalent, call HTTP API.
return fmt.Errorf("event not implemented: %s", header.Event)
case oldEvent.ADMIN_BAN: case oldEvent.ADMIN_BAN:
request := &oldMessage.Admin{} request := &oldMessage.Admin{}

View File

@ -5,13 +5,14 @@ import (
"errors" "errors"
"fmt" "fmt"
"github.com/pion/webrtc/v3"
oldEvent "github.com/demodesk/neko/internal/http/legacy/event" oldEvent "github.com/demodesk/neko/internal/http/legacy/event"
oldMessage "github.com/demodesk/neko/internal/http/legacy/message" oldMessage "github.com/demodesk/neko/internal/http/legacy/message"
oldTypes "github.com/demodesk/neko/internal/http/legacy/types" oldTypes "github.com/demodesk/neko/internal/http/legacy/types"
"github.com/pion/webrtc/v3"
chat "github.com/demodesk/neko/internal/plugins/chat" "github.com/demodesk/neko/internal/plugins/chat"
filetransfer "github.com/demodesk/neko/internal/plugins/filetransfer" "github.com/demodesk/neko/internal/plugins/filetransfer"
"github.com/demodesk/neko/pkg/types" "github.com/demodesk/neko/pkg/types"
"github.com/demodesk/neko/pkg/types/event" "github.com/demodesk/neko/pkg/types/event"
"github.com/demodesk/neko/pkg/types/message" "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 { if request.ID == request.HostID {
return send(&oldMessage.Control{ return send(&oldMessage.Control{
Event: oldEvent.CONTROL_LOCKED, Event: oldEvent.CONTROL_LOCKED,
ID: request.ID, ID: request.HostID,
}) })
} }
return send(&oldMessage.ControlTarget{ return send(&oldMessage.ControlTarget{
Event: oldEvent.CONTROL_GIVE, Event: oldEvent.CONTROL_GIVE,
ID: request.ID, ID: request.HostID,
Target: request.HostID, Target: request.ID,
}) })
} }