mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
legacy: fix error reporting.
This commit is contained in:
parent
4adf1d7182
commit
c8debe9b13
@ -1,11 +1,17 @@
|
|||||||
package legacy
|
package legacy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
oldEvent "github.com/demodesk/neko/internal/http/legacy/event"
|
||||||
|
oldMessage "github.com/demodesk/neko/internal/http/legacy/message"
|
||||||
|
|
||||||
"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/message"
|
||||||
"github.com/demodesk/neko/pkg/utils"
|
"github.com/demodesk/neko/pkg/utils"
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
)
|
)
|
||||||
@ -55,6 +61,11 @@ func (h *LegacyHandler) Route(r types.Router) {
|
|||||||
token, err := s.create(password)
|
token, err := s.create(password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("couldn't create a new session: %v", err)
|
log.Printf("couldn't create a new session: %v", err)
|
||||||
|
s.toClient(&oldMessage.SystemMessage{
|
||||||
|
Event: oldEvent.SYSTEM_DISCONNECT,
|
||||||
|
Title: "couldn't create a new session",
|
||||||
|
Message: err.Error(),
|
||||||
|
})
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
defer s.destroy()
|
defer s.destroy()
|
||||||
@ -63,21 +74,31 @@ func (h *LegacyHandler) Route(r types.Router) {
|
|||||||
connBackend, _, err := DefaultDialer.Dial("ws://127.0.0.1:8080/api/ws?token="+token, nil)
|
connBackend, _, err := DefaultDialer.Dial("ws://127.0.0.1:8080/api/ws?token="+token, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("couldn't dial to the remote backend: %v", err)
|
log.Printf("couldn't dial to the remote backend: %v", err)
|
||||||
|
s.toClient(&oldMessage.SystemMessage{
|
||||||
|
Event: oldEvent.SYSTEM_DISCONNECT,
|
||||||
|
Title: "couldn't dial to the remote backend",
|
||||||
|
Message: err.Error(),
|
||||||
|
})
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
defer connBackend.Close()
|
defer connBackend.Close()
|
||||||
s.connBackend = connBackend
|
s.connBackend = connBackend
|
||||||
|
|
||||||
// request signal
|
// request signal
|
||||||
if err = connBackend.WriteMessage(websocket.TextMessage, []byte(`{"event":"signal/request", "payload":{}}`)); err != nil {
|
if err = s.toBackend(event.SIGNAL_REQUEST, message.SignalRequest{}); err != nil {
|
||||||
log.Printf("couldn't request signal: %v", err)
|
log.Printf("couldn't request signal: %v", err)
|
||||||
|
s.toClient(&oldMessage.SystemMessage{
|
||||||
|
Event: oldEvent.SYSTEM_DISCONNECT,
|
||||||
|
Title: "couldn't request signal",
|
||||||
|
Message: err.Error(),
|
||||||
|
})
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// copy messages between the client and the backend
|
// copy messages between the client and the backend
|
||||||
errClient := make(chan error, 1)
|
errClient := make(chan error, 1)
|
||||||
errBackend := make(chan error, 1)
|
errBackend := make(chan error, 1)
|
||||||
replicateWebsocketConn := func(dst, src *websocket.Conn, errc chan error, rewriteTextMessage func([]byte, func([]byte) error) error) {
|
replicateWebsocketConn := func(dst, src *websocket.Conn, errc chan error, rewriteTextMessage func([]byte) error) {
|
||||||
for {
|
for {
|
||||||
msgType, msg, err := src.ReadMessage()
|
msgType, msg, err := src.ReadMessage()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -92,23 +113,24 @@ func (h *LegacyHandler) Route(r types.Router) {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
if msgType == websocket.TextMessage {
|
if msgType == websocket.TextMessage {
|
||||||
doBreak := false
|
err = rewriteTextMessage(msg)
|
||||||
err = rewriteTextMessage(msg, func(msg []byte) error {
|
|
||||||
err := dst.WriteMessage(msgType, msg)
|
|
||||||
if err != nil {
|
|
||||||
doBreak = true
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
})
|
|
||||||
|
|
||||||
if doBreak {
|
if err == nil {
|
||||||
errc <- err
|
continue
|
||||||
break
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if errors.Is(err, ErrBackendRespone) {
|
||||||
log.Printf("websocketproxy: Error when rewriting message: %v", err)
|
s.toClient(&oldMessage.SystemMessage{
|
||||||
|
Event: oldEvent.SYSTEM_ERROR,
|
||||||
|
Title: "backend response error",
|
||||||
|
Message: err.Error(),
|
||||||
|
})
|
||||||
continue
|
continue
|
||||||
|
} else if errors.Is(err, ErrWebsocketSend) {
|
||||||
|
errc <- err
|
||||||
|
break
|
||||||
|
} else {
|
||||||
|
log.Printf("websocketproxy: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,11 @@ import (
|
|||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
ErrWebsocketSend = fmt.Errorf("failed to send message to websocket")
|
||||||
|
ErrBackendRespone = fmt.Errorf("error response from backend")
|
||||||
|
)
|
||||||
|
|
||||||
type session struct {
|
type session struct {
|
||||||
url string
|
url string
|
||||||
id string
|
id string
|
||||||
@ -65,6 +70,14 @@ func (s *session) apiReq(method, path string, request, response any) error {
|
|||||||
|
|
||||||
if res.StatusCode < 200 || res.StatusCode >= 300 {
|
if res.StatusCode < 200 || res.StatusCode >= 300 {
|
||||||
body, _ := io.ReadAll(res.Body)
|
body, _ := io.ReadAll(res.Body)
|
||||||
|
// try to unmarsal as json error message
|
||||||
|
var apiErr struct {
|
||||||
|
Message string `json:"message"`
|
||||||
|
}
|
||||||
|
if err := json.Unmarshal(body, &apiErr); err == nil {
|
||||||
|
return fmt.Errorf("%w: %s", ErrBackendRespone, apiErr.Message)
|
||||||
|
}
|
||||||
|
// return raw body if failed to unmarshal
|
||||||
return fmt.Errorf("unexpected status code: %d, body: %s", res.StatusCode, body)
|
return fmt.Errorf("unexpected status code: %d, body: %s", res.StatusCode, body)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,6 +88,44 @@ func (s *session) apiReq(method, path string, request, response any) error {
|
|||||||
return json.NewDecoder(res.Body).Decode(response)
|
return json.NewDecoder(res.Body).Decode(response)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// send message to client (in old format)
|
||||||
|
func (s *session) toClient(payload any) error {
|
||||||
|
msg, err := json.Marshal(payload)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = s.connClient.WriteMessage(websocket.TextMessage, msg)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("%w: %s", ErrWebsocketSend, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// send message to backend (in new format)
|
||||||
|
func (s *session) toBackend(event string, payload any) error {
|
||||||
|
rawPayload, err := json.Marshal(payload)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
msg, err := json.Marshal(&types.WebSocketMessage{
|
||||||
|
Event: event,
|
||||||
|
Payload: rawPayload,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = s.connBackend.WriteMessage(websocket.TextMessage, msg)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("%w: %s", ErrWebsocketSend, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (s *session) create(password string) (string, error) {
|
func (s *session) create(password string) (string, error) {
|
||||||
data := api.SessionDataPayload{}
|
data := api.SessionDataPayload{}
|
||||||
|
|
||||||
|
@ -19,30 +19,13 @@ import (
|
|||||||
"github.com/demodesk/neko/pkg/types/message"
|
"github.com/demodesk/neko/pkg/types/message"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *session) wsToBackend(msg []byte, sendMsg func([]byte) error) error {
|
func (s *session) wsToBackend(msg []byte) error {
|
||||||
header := oldMessage.Message{}
|
header := oldMessage.Message{}
|
||||||
err := json.Unmarshal(msg, &header)
|
err := json.Unmarshal(msg, &header)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
send := func(event string, payload any) error {
|
|
||||||
rawPayload, err := json.Marshal(payload)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
msg, err := json.Marshal(&types.WebSocketMessage{
|
|
||||||
Event: event,
|
|
||||||
Payload: rawPayload,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return sendMsg(msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
switch header.Event {
|
switch header.Event {
|
||||||
// Signal Events
|
// Signal Events
|
||||||
case oldEvent.SIGNAL_OFFER:
|
case oldEvent.SIGNAL_OFFER:
|
||||||
@ -52,7 +35,7 @@ func (s *session) wsToBackend(msg []byte, sendMsg func([]byte) error) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return send(event.SIGNAL_OFFER, &message.SignalDescription{
|
return s.toBackend(event.SIGNAL_OFFER, &message.SignalDescription{
|
||||||
SDP: request.SDP,
|
SDP: request.SDP,
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -65,7 +48,7 @@ func (s *session) wsToBackend(msg []byte, sendMsg func([]byte) error) error {
|
|||||||
|
|
||||||
// TODO: Set Display Name here.
|
// TODO: Set Display Name here.
|
||||||
|
|
||||||
return send(event.SIGNAL_ANSWER, &message.SignalDescription{
|
return s.toBackend(event.SIGNAL_ANSWER, &message.SignalDescription{
|
||||||
SDP: request.SDP,
|
SDP: request.SDP,
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -82,16 +65,16 @@ func (s *session) wsToBackend(msg []byte, sendMsg func([]byte) error) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return send(event.SIGNAL_CANDIDATE, &message.SignalCandidate{
|
return s.toBackend(event.SIGNAL_CANDIDATE, &message.SignalCandidate{
|
||||||
ICECandidateInit: candidate,
|
ICECandidateInit: candidate,
|
||||||
})
|
})
|
||||||
|
|
||||||
// Control Events
|
// Control Events
|
||||||
case oldEvent.CONTROL_RELEASE:
|
case oldEvent.CONTROL_RELEASE:
|
||||||
return send(event.CONTROL_RELEASE, nil)
|
return s.toBackend(event.CONTROL_RELEASE, nil)
|
||||||
|
|
||||||
case oldEvent.CONTROL_REQUEST:
|
case oldEvent.CONTROL_REQUEST:
|
||||||
return send(event.CONTROL_REQUEST, nil)
|
return s.toBackend(event.CONTROL_REQUEST, nil)
|
||||||
|
|
||||||
case oldEvent.CONTROL_GIVE:
|
case oldEvent.CONTROL_GIVE:
|
||||||
request := &oldMessage.Control{}
|
request := &oldMessage.Control{}
|
||||||
@ -109,7 +92,7 @@ func (s *session) wsToBackend(msg []byte, sendMsg func([]byte) error) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return send(event.CLIPBOARD_SET, &message.ClipboardData{
|
return s.toBackend(event.CLIPBOARD_SET, &message.ClipboardData{
|
||||||
Text: request.Text,
|
Text: request.Text,
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -121,7 +104,7 @@ func (s *session) wsToBackend(msg []byte, sendMsg func([]byte) error) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if request.Layout != nil {
|
if request.Layout != nil {
|
||||||
err = send(event.KEYBOARD_MAP, &message.KeyboardMap{
|
err = s.toBackend(event.KEYBOARD_MAP, &message.KeyboardMap{
|
||||||
KeyboardMap: types.KeyboardMap{
|
KeyboardMap: types.KeyboardMap{
|
||||||
Layout: *request.Layout,
|
Layout: *request.Layout,
|
||||||
},
|
},
|
||||||
@ -133,7 +116,7 @@ func (s *session) wsToBackend(msg []byte, sendMsg func([]byte) error) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if request.CapsLock != nil || request.NumLock != nil || request.ScrollLock != nil {
|
if request.CapsLock != nil || request.NumLock != nil || request.ScrollLock != nil {
|
||||||
err = send(event.KEYBOARD_MODIFIERS, &message.KeyboardModifiers{
|
err = s.toBackend(event.KEYBOARD_MODIFIERS, &message.KeyboardModifiers{
|
||||||
KeyboardModifiers: types.KeyboardModifiers{
|
KeyboardModifiers: types.KeyboardModifiers{
|
||||||
CapsLock: request.CapsLock,
|
CapsLock: request.CapsLock,
|
||||||
NumLock: request.NumLock,
|
NumLock: request.NumLock,
|
||||||
@ -156,7 +139,7 @@ func (s *session) wsToBackend(msg []byte, sendMsg func([]byte) error) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return send(chat.CHAT_MESSAGE, &chat.Content{
|
return s.toBackend(chat.CHAT_MESSAGE, &chat.Content{
|
||||||
Text: request.Content,
|
Text: request.Content,
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -184,7 +167,7 @@ func (s *session) wsToBackend(msg []byte, sendMsg func([]byte) error) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// broadcast emote to other users
|
// broadcast emote to other users
|
||||||
return send(event.SEND_BROADCAST, &message.SendBroadcast{
|
return s.toBackend(event.SEND_BROADCAST, &message.SendBroadcast{
|
||||||
Sender: s.id,
|
Sender: s.id,
|
||||||
Subject: "emote",
|
Subject: "emote",
|
||||||
Body: request.Emote,
|
Body: request.Emote,
|
||||||
@ -192,7 +175,7 @@ func (s *session) wsToBackend(msg []byte, sendMsg func([]byte) error) error {
|
|||||||
|
|
||||||
// File Transfer Events
|
// File Transfer Events
|
||||||
case oldEvent.FILETRANSFER_REFRESH:
|
case oldEvent.FILETRANSFER_REFRESH:
|
||||||
return send(filetransfer.FILETRANSFER_UPDATE, nil)
|
return s.toBackend(filetransfer.FILETRANSFER_UPDATE, nil)
|
||||||
|
|
||||||
// Screen Events
|
// Screen Events
|
||||||
case oldEvent.SCREEN_RESOLUTION:
|
case oldEvent.SCREEN_RESOLUTION:
|
||||||
@ -210,7 +193,7 @@ func (s *session) wsToBackend(msg []byte, sendMsg func([]byte) error) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return send(event.SCREEN_SET, &message.ScreenSize{
|
return s.toBackend(event.SCREEN_SET, &message.ScreenSize{
|
||||||
ScreenSize: types.ScreenSize{
|
ScreenSize: types.ScreenSize{
|
||||||
Width: request.Width,
|
Width: request.Width,
|
||||||
Height: request.Height,
|
Height: request.Height,
|
||||||
|
@ -37,7 +37,7 @@ func sessionDataToMember(id string, session message.SessionData) (*oldTypes.Memb
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *session) sendControlHost(request message.ControlHost, send func(payload any) error) error {
|
func (s *session) sendControlHost(request message.ControlHost) error {
|
||||||
lastHostID := s.lastHostID
|
lastHostID := s.lastHostID
|
||||||
|
|
||||||
if request.HasHost {
|
if request.HasHost {
|
||||||
@ -45,19 +45,19 @@ func (s *session) sendControlHost(request message.ControlHost, send func(payload
|
|||||||
|
|
||||||
if request.ID == request.HostID {
|
if request.ID == request.HostID {
|
||||||
if request.ID == lastHostID || lastHostID == "" {
|
if request.ID == lastHostID || lastHostID == "" {
|
||||||
return send(&oldMessage.Control{
|
return s.toClient(&oldMessage.Control{
|
||||||
Event: oldEvent.CONTROL_LOCKED,
|
Event: oldEvent.CONTROL_LOCKED,
|
||||||
ID: request.HostID,
|
ID: request.HostID,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
return send(&oldMessage.AdminTarget{
|
return s.toClient(&oldMessage.AdminTarget{
|
||||||
Event: oldEvent.ADMIN_CONTROL,
|
Event: oldEvent.ADMIN_CONTROL,
|
||||||
ID: request.ID,
|
ID: request.ID,
|
||||||
Target: lastHostID,
|
Target: lastHostID,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return send(&oldMessage.ControlTarget{
|
return s.toClient(&oldMessage.ControlTarget{
|
||||||
Event: oldEvent.CONTROL_GIVE,
|
Event: oldEvent.CONTROL_GIVE,
|
||||||
ID: request.HostID,
|
ID: request.HostID,
|
||||||
Target: request.ID,
|
Target: request.ID,
|
||||||
@ -69,12 +69,12 @@ func (s *session) sendControlHost(request message.ControlHost, send func(payload
|
|||||||
s.lastHostID = ""
|
s.lastHostID = ""
|
||||||
|
|
||||||
if request.ID == lastHostID {
|
if request.ID == lastHostID {
|
||||||
return send(&oldMessage.Control{
|
return s.toClient(&oldMessage.Control{
|
||||||
Event: oldEvent.CONTROL_RELEASE,
|
Event: oldEvent.CONTROL_RELEASE,
|
||||||
ID: request.ID,
|
ID: request.ID,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
return send(&oldMessage.Control{
|
return s.toClient(&oldMessage.Control{
|
||||||
Event: oldEvent.ADMIN_RELEASE,
|
Event: oldEvent.ADMIN_RELEASE,
|
||||||
ID: request.ID,
|
ID: request.ID,
|
||||||
})
|
})
|
||||||
@ -84,22 +84,13 @@ func (s *session) sendControlHost(request message.ControlHost, send func(payload
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *session) wsToClient(msg []byte, sendMsg func([]byte) error) error {
|
func (s *session) wsToClient(msg []byte) error {
|
||||||
data := types.WebSocketMessage{}
|
data := types.WebSocketMessage{}
|
||||||
err := json.Unmarshal(msg, &data)
|
err := json.Unmarshal(msg, &data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
send := func(payload any) error {
|
|
||||||
msg, err := json.Marshal(payload)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return sendMsg(msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
switch data.Event {
|
switch data.Event {
|
||||||
// System Events
|
// System Events
|
||||||
case event.SYSTEM_DISCONNECT:
|
case event.SYSTEM_DISCONNECT:
|
||||||
@ -109,15 +100,11 @@ func (s *session) wsToClient(msg []byte, sendMsg func([]byte) error) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return send(&oldMessage.SystemMessage{
|
return s.toClient(&oldMessage.SystemMessage{
|
||||||
Event: oldEvent.SYSTEM_DISCONNECT,
|
Event: oldEvent.SYSTEM_DISCONNECT,
|
||||||
Message: request.Message,
|
Message: request.Message,
|
||||||
})
|
})
|
||||||
|
|
||||||
// case:
|
|
||||||
// send(&oldMessage.SystemMessage{
|
|
||||||
// Event: oldEvent.SYSTEM_ERROR,
|
|
||||||
// })
|
|
||||||
case event.SYSTEM_INIT:
|
case event.SYSTEM_INIT:
|
||||||
request := &message.SystemInit{}
|
request := &message.SystemInit{}
|
||||||
err := json.Unmarshal(data.Payload, request)
|
err := json.Unmarshal(data.Payload, request)
|
||||||
@ -143,7 +130,7 @@ func (s *session) wsToClient(msg []byte, sendMsg func([]byte) error) error {
|
|||||||
s.sessions[id] = member
|
s.sessions[id] = member
|
||||||
}
|
}
|
||||||
|
|
||||||
err = send(&oldMessage.MembersList{
|
err = s.toClient(&oldMessage.MembersList{
|
||||||
Event: oldEvent.MEMBER_LIST,
|
Event: oldEvent.MEMBER_LIST,
|
||||||
Members: membersList,
|
Members: membersList,
|
||||||
})
|
})
|
||||||
@ -155,7 +142,7 @@ func (s *session) wsToClient(msg []byte, sendMsg func([]byte) error) error {
|
|||||||
// ScreenSize
|
// ScreenSize
|
||||||
//
|
//
|
||||||
|
|
||||||
err = send(&oldMessage.ScreenResolution{
|
err = s.toClient(&oldMessage.ScreenResolution{
|
||||||
Event: oldEvent.SCREEN_RESOLUTION,
|
Event: oldEvent.SCREEN_RESOLUTION,
|
||||||
Width: request.ScreenSize.Width,
|
Width: request.ScreenSize.Width,
|
||||||
Height: request.ScreenSize.Height,
|
Height: request.ScreenSize.Height,
|
||||||
@ -172,7 +159,7 @@ func (s *session) wsToClient(msg []byte, sendMsg func([]byte) error) error {
|
|||||||
// ControlHost
|
// ControlHost
|
||||||
//
|
//
|
||||||
|
|
||||||
err = s.sendControlHost(request.ControlHost, send)
|
err = s.sendControlHost(request.ControlHost)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -207,7 +194,7 @@ func (s *session) wsToClient(msg []byte, sendMsg func([]byte) error) error {
|
|||||||
s.lockedFileTransfer = true
|
s.lockedFileTransfer = true
|
||||||
}
|
}
|
||||||
|
|
||||||
return send(&oldMessage.SystemInit{
|
return s.toClient(&oldMessage.SystemInit{
|
||||||
Event: oldEvent.SYSTEM_INIT,
|
Event: oldEvent.SYSTEM_INIT,
|
||||||
ImplicitHosting: request.Settings.ImplicitHosting,
|
ImplicitHosting: request.Settings.ImplicitHosting,
|
||||||
Locks: locks,
|
Locks: locks,
|
||||||
@ -251,7 +238,7 @@ func (s *session) wsToClient(msg []byte, sendMsg func([]byte) error) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = send(&oldMessage.ScreenConfigurations{
|
err = s.toClient(&oldMessage.ScreenConfigurations{
|
||||||
Event: oldEvent.SCREEN_CONFIGURATIONS,
|
Event: oldEvent.SCREEN_CONFIGURATIONS,
|
||||||
Configurations: screenSizesList,
|
Configurations: screenSizesList,
|
||||||
})
|
})
|
||||||
@ -263,7 +250,7 @@ func (s *session) wsToClient(msg []byte, sendMsg func([]byte) error) error {
|
|||||||
// BroadcastStatus
|
// BroadcastStatus
|
||||||
//
|
//
|
||||||
|
|
||||||
return send(&oldMessage.BroadcastStatus{
|
return s.toClient(&oldMessage.BroadcastStatus{
|
||||||
Event: oldEvent.BROADCAST_STATUS,
|
Event: oldEvent.BROADCAST_STATUS,
|
||||||
URL: request.BroadcastStatus.URL,
|
URL: request.BroadcastStatus.URL,
|
||||||
IsActive: request.BroadcastStatus.IsActive,
|
IsActive: request.BroadcastStatus.IsActive,
|
||||||
@ -302,7 +289,7 @@ func (s *session) wsToClient(msg []byte, sendMsg func([]byte) error) error {
|
|||||||
|
|
||||||
delete(s.sessions, request.ID)
|
delete(s.sessions, request.ID)
|
||||||
|
|
||||||
return send(&oldMessage.MemberDisconnected{
|
return s.toClient(&oldMessage.MemberDisconnected{
|
||||||
Event: oldEvent.MEMBER_DISCONNECTED,
|
Event: oldEvent.MEMBER_DISCONNECTED,
|
||||||
ID: request.ID,
|
ID: request.ID,
|
||||||
})
|
})
|
||||||
@ -323,7 +310,7 @@ func (s *session) wsToClient(msg []byte, sendMsg func([]byte) error) error {
|
|||||||
s.sessions[request.ID] = nil
|
s.sessions[request.ID] = nil
|
||||||
|
|
||||||
// oldEvent.MEMBER_CONNECTED if not sent already
|
// oldEvent.MEMBER_CONNECTED if not sent already
|
||||||
return send(&oldMessage.Member{
|
return s.toClient(&oldMessage.Member{
|
||||||
Event: oldEvent.MEMBER_CONNECTED,
|
Event: oldEvent.MEMBER_CONNECTED,
|
||||||
Member: member,
|
Member: member,
|
||||||
})
|
})
|
||||||
@ -333,7 +320,7 @@ func (s *session) wsToClient(msg []byte, sendMsg func([]byte) error) error {
|
|||||||
delete(s.sessions, request.ID)
|
delete(s.sessions, request.ID)
|
||||||
|
|
||||||
// oldEvent.MEMBER_DISCONNECTED if nor sent already
|
// oldEvent.MEMBER_DISCONNECTED if nor sent already
|
||||||
return send(&oldMessage.MemberDisconnected{
|
return s.toClient(&oldMessage.MemberDisconnected{
|
||||||
Event: oldEvent.MEMBER_DISCONNECTED,
|
Event: oldEvent.MEMBER_DISCONNECTED,
|
||||||
ID: request.ID,
|
ID: request.ID,
|
||||||
})
|
})
|
||||||
@ -349,7 +336,7 @@ func (s *session) wsToClient(msg []byte, sendMsg func([]byte) error) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return send(&oldMessage.SignalOffer{
|
return s.toClient(&oldMessage.SignalOffer{
|
||||||
Event: oldEvent.SIGNAL_OFFER,
|
Event: oldEvent.SIGNAL_OFFER,
|
||||||
SDP: request.SDP,
|
SDP: request.SDP,
|
||||||
})
|
})
|
||||||
@ -361,7 +348,7 @@ func (s *session) wsToClient(msg []byte, sendMsg func([]byte) error) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return send(&oldMessage.SignalAnswer{
|
return s.toClient(&oldMessage.SignalAnswer{
|
||||||
Event: oldEvent.SIGNAL_ANSWER,
|
Event: oldEvent.SIGNAL_ANSWER,
|
||||||
DisplayName: s.profile.Name, // DisplayName
|
DisplayName: s.profile.Name, // DisplayName
|
||||||
SDP: request.SDP,
|
SDP: request.SDP,
|
||||||
@ -379,7 +366,7 @@ func (s *session) wsToClient(msg []byte, sendMsg func([]byte) error) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return send(&oldMessage.SignalCandidate{
|
return s.toClient(&oldMessage.SignalCandidate{
|
||||||
Event: oldEvent.SIGNAL_CANDIDATE,
|
Event: oldEvent.SIGNAL_CANDIDATE,
|
||||||
Data: string(json),
|
Data: string(json),
|
||||||
})
|
})
|
||||||
@ -401,7 +388,7 @@ func (s *session) wsToClient(msg []byte, sendMsg func([]byte) error) error {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return send(&oldMessage.SignalProvide{
|
return s.toClient(&oldMessage.SignalProvide{
|
||||||
Event: oldEvent.SIGNAL_PROVIDE,
|
Event: oldEvent.SIGNAL_PROVIDE,
|
||||||
ID: s.id, // SessionId
|
ID: s.id, // SessionId
|
||||||
SDP: request.SDP,
|
SDP: request.SDP,
|
||||||
@ -417,7 +404,7 @@ func (s *session) wsToClient(msg []byte, sendMsg func([]byte) error) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return send(&oldMessage.Clipboard{
|
return s.toClient(&oldMessage.Clipboard{
|
||||||
Event: oldEvent.CONTROL_CLIPBOARD,
|
Event: oldEvent.CONTROL_CLIPBOARD,
|
||||||
Text: request.Text,
|
Text: request.Text,
|
||||||
})
|
})
|
||||||
@ -429,7 +416,7 @@ func (s *session) wsToClient(msg []byte, sendMsg func([]byte) error) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return s.sendControlHost(*request, send)
|
return s.sendControlHost(*request)
|
||||||
|
|
||||||
case event.CONTROL_REQUEST:
|
case event.CONTROL_REQUEST:
|
||||||
request := &message.SessionID{}
|
request := &message.SessionID{}
|
||||||
@ -440,13 +427,13 @@ func (s *session) wsToClient(msg []byte, sendMsg func([]byte) error) error {
|
|||||||
|
|
||||||
if s.id == request.ID {
|
if s.id == request.ID {
|
||||||
// if i am the one that is requesting, send CONTROL_REQUEST to me
|
// if i am the one that is requesting, send CONTROL_REQUEST to me
|
||||||
return send(&oldMessage.Control{
|
return s.toClient(&oldMessage.Control{
|
||||||
Event: oldEvent.CONTROL_REQUEST,
|
Event: oldEvent.CONTROL_REQUEST,
|
||||||
ID: request.ID,
|
ID: request.ID,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
// if not, let me know someone else is requesting
|
// if not, let me know someone else is requesting
|
||||||
return send(&oldMessage.Control{
|
return s.toClient(&oldMessage.Control{
|
||||||
Event: oldEvent.CONTROL_REQUESTING,
|
Event: oldEvent.CONTROL_REQUESTING,
|
||||||
ID: request.ID,
|
ID: request.ID,
|
||||||
})
|
})
|
||||||
@ -460,7 +447,7 @@ func (s *session) wsToClient(msg []byte, sendMsg func([]byte) error) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return send(&oldMessage.ChatSend{
|
return s.toClient(&oldMessage.ChatSend{
|
||||||
Event: oldEvent.CHAT_MESSAGE,
|
Event: oldEvent.CHAT_MESSAGE,
|
||||||
ID: request.ID,
|
ID: request.ID,
|
||||||
Content: request.Content.Text,
|
Content: request.Content.Text,
|
||||||
@ -474,7 +461,7 @@ func (s *session) wsToClient(msg []byte, sendMsg func([]byte) error) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if request.Subject == "emote" {
|
if request.Subject == "emote" {
|
||||||
return send(&oldMessage.EmoteSend{
|
return s.toClient(&oldMessage.EmoteSend{
|
||||||
Event: oldEvent.CHAT_EMOTE,
|
Event: oldEvent.CHAT_EMOTE,
|
||||||
ID: request.Sender,
|
ID: request.Sender,
|
||||||
Emote: request.Body.(string),
|
Emote: request.Body.(string),
|
||||||
@ -507,7 +494,7 @@ func (s *session) wsToClient(msg []byte, sendMsg func([]byte) error) error {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return send(&oldMessage.FileTransferList{
|
return s.toClient(&oldMessage.FileTransferList{
|
||||||
Event: oldEvent.FILETRANSFER_LIST,
|
Event: oldEvent.FILETRANSFER_LIST,
|
||||||
Cwd: request.RootDir,
|
Cwd: request.RootDir,
|
||||||
Files: files,
|
Files: files,
|
||||||
@ -521,7 +508,7 @@ func (s *session) wsToClient(msg []byte, sendMsg func([]byte) error) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return send(&oldMessage.ScreenResolution{
|
return s.toClient(&oldMessage.ScreenResolution{
|
||||||
Event: oldEvent.SCREEN_RESOLUTION,
|
Event: oldEvent.SCREEN_RESOLUTION,
|
||||||
ID: request.ID,
|
ID: request.ID,
|
||||||
Width: request.ScreenSize.Width,
|
Width: request.ScreenSize.Width,
|
||||||
@ -537,7 +524,7 @@ func (s *session) wsToClient(msg []byte, sendMsg func([]byte) error) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return send(&oldMessage.BroadcastStatus{
|
return s.toClient(&oldMessage.BroadcastStatus{
|
||||||
Event: oldEvent.BROADCAST_STATUS,
|
Event: oldEvent.BROADCAST_STATUS,
|
||||||
URL: request.URL,
|
URL: request.URL,
|
||||||
IsActive: request.IsActive,
|
IsActive: request.IsActive,
|
||||||
@ -555,12 +542,12 @@ func (s *session) wsToClient(msg []byte, sendMsg func([]byte) error) error {
|
|||||||
s.lockedControls = request.LockedControls
|
s.lockedControls = request.LockedControls
|
||||||
|
|
||||||
if request.LockedControls {
|
if request.LockedControls {
|
||||||
err = send(&oldMessage.AdminLock{
|
err = s.toClient(&oldMessage.AdminLock{
|
||||||
Event: oldEvent.ADMIN_LOCK,
|
Event: oldEvent.ADMIN_LOCK,
|
||||||
Resource: "control",
|
Resource: "control",
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
err = send(&oldMessage.AdminLock{
|
err = s.toClient(&oldMessage.AdminLock{
|
||||||
Event: oldEvent.ADMIN_UNLOCK,
|
Event: oldEvent.ADMIN_UNLOCK,
|
||||||
Resource: "control",
|
Resource: "control",
|
||||||
})
|
})
|
||||||
@ -575,12 +562,12 @@ func (s *session) wsToClient(msg []byte, sendMsg func([]byte) error) error {
|
|||||||
s.lockedLogins = request.LockedLogins
|
s.lockedLogins = request.LockedLogins
|
||||||
|
|
||||||
if request.LockedLogins {
|
if request.LockedLogins {
|
||||||
err = send(&oldMessage.AdminLock{
|
err = s.toClient(&oldMessage.AdminLock{
|
||||||
Event: oldEvent.ADMIN_LOCK,
|
Event: oldEvent.ADMIN_LOCK,
|
||||||
Resource: "login",
|
Resource: "login",
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
err = send(&oldMessage.AdminLock{
|
err = s.toClient(&oldMessage.AdminLock{
|
||||||
Event: oldEvent.ADMIN_UNLOCK,
|
Event: oldEvent.ADMIN_UNLOCK,
|
||||||
Resource: "login",
|
Resource: "login",
|
||||||
})
|
})
|
||||||
@ -608,12 +595,12 @@ func (s *session) wsToClient(msg []byte, sendMsg func([]byte) error) error {
|
|||||||
s.lockedFileTransfer = !filetransferSettings.Enabled
|
s.lockedFileTransfer = !filetransferSettings.Enabled
|
||||||
|
|
||||||
if !filetransferSettings.Enabled {
|
if !filetransferSettings.Enabled {
|
||||||
err = send(&oldMessage.AdminLock{
|
err = s.toClient(&oldMessage.AdminLock{
|
||||||
Event: oldEvent.ADMIN_LOCK,
|
Event: oldEvent.ADMIN_LOCK,
|
||||||
Resource: "file_transfer",
|
Resource: "file_transfer",
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
err = send(&oldMessage.AdminLock{
|
err = s.toClient(&oldMessage.AdminLock{
|
||||||
Event: oldEvent.ADMIN_UNLOCK,
|
Event: oldEvent.ADMIN_UNLOCK,
|
||||||
Resource: "file_transfer",
|
Resource: "file_transfer",
|
||||||
})
|
})
|
||||||
@ -628,19 +615,19 @@ func (s *session) wsToClient(msg []byte, sendMsg func([]byte) error) error {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
case:
|
case:
|
||||||
send(&oldMessage.AdminTarget{
|
s.toClient(&oldMessage.AdminTarget{
|
||||||
Event: oldEvent.ADMIN_BAN,
|
Event: oldEvent.ADMIN_BAN,
|
||||||
})
|
})
|
||||||
case:
|
case:
|
||||||
send(&oldMessage.AdminTarget{
|
s.toClient(&oldMessage.AdminTarget{
|
||||||
Event: oldEvent.ADMIN_KICK,
|
Event: oldEvent.ADMIN_KICK,
|
||||||
})
|
})
|
||||||
case:
|
case:
|
||||||
send(&oldMessage.AdminTarget{
|
s.toClient(&oldMessage.AdminTarget{
|
||||||
Event: oldEvent.ADMIN_MUTE,
|
Event: oldEvent.ADMIN_MUTE,
|
||||||
})
|
})
|
||||||
case:
|
case:
|
||||||
send(&oldMessage.AdminTarget{
|
s.toClient(&oldMessage.AdminTarget{
|
||||||
Event: oldEvent.ADMIN_UNMUTE,
|
Event: oldEvent.ADMIN_UNMUTE,
|
||||||
})
|
})
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user