mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
code fmt change.
This commit is contained in:
parent
00fc3afcd7
commit
d7671942a6
@ -14,9 +14,7 @@ import (
|
|||||||
|
|
||||||
type key int
|
type key int
|
||||||
|
|
||||||
const (
|
const keyMemberCtx key = iota
|
||||||
keyMemberCtx key = iota
|
|
||||||
)
|
|
||||||
|
|
||||||
type MembersHandler struct {
|
type MembersHandler struct {
|
||||||
members types.MemberManager
|
members types.MemberManager
|
||||||
|
@ -10,13 +10,11 @@ import (
|
|||||||
"demodesk/neko/internal/utils"
|
"demodesk/neko/internal/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
// maximum upload size of 32 MB
|
||||||
// Maximum upload of 32 MB files.
|
const maxUploadSize = 32 << 20
|
||||||
MAX_UPLOAD_SIZE = 32 << 20
|
|
||||||
)
|
|
||||||
|
|
||||||
func (h *RoomHandler) uploadDrop(w http.ResponseWriter, r *http.Request) {
|
func (h *RoomHandler) uploadDrop(w http.ResponseWriter, r *http.Request) {
|
||||||
err := r.ParseMultipartForm(MAX_UPLOAD_SIZE)
|
err := r.ParseMultipartForm(maxUploadSize)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.HttpBadRequest(w, "failed to parse multipart form")
|
utils.HttpBadRequest(w, "failed to parse multipart form")
|
||||||
return
|
return
|
||||||
@ -87,7 +85,7 @@ func (h *RoomHandler) uploadDrop(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h *RoomHandler) uploadDialogPost(w http.ResponseWriter, r *http.Request) {
|
func (h *RoomHandler) uploadDialogPost(w http.ResponseWriter, r *http.Request) {
|
||||||
err := r.ParseMultipartForm(MAX_UPLOAD_SIZE)
|
err := r.ParseMultipartForm(maxUploadSize)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.HttpBadRequest(w, "failed to parse multipart form")
|
utils.HttpBadRequest(w, "failed to parse multipart form")
|
||||||
return
|
return
|
||||||
|
@ -28,6 +28,7 @@ type ScreencastManagerCtx struct {
|
|||||||
image types.Sample
|
image types.Sample
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// timeout between intervals, when screencast pipeline is checked
|
||||||
const screencastTimeout = 5 * time.Second
|
const screencastTimeout = 5 * time.Second
|
||||||
|
|
||||||
func screencastNew(enabled bool, pipelineStr string) *ScreencastManagerCtx {
|
func screencastNew(enabled bool, pipelineStr string) *ScreencastManagerCtx {
|
||||||
|
@ -13,6 +13,15 @@ import (
|
|||||||
"demodesk/neko/internal/utils"
|
"demodesk/neko/internal/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// default port range - min
|
||||||
|
const defEprMin = 59000
|
||||||
|
|
||||||
|
// default port range - max
|
||||||
|
const defEprMax = 59100
|
||||||
|
|
||||||
|
// default stun server
|
||||||
|
const defStunSrv = "stun:stun.l.google.com:19302"
|
||||||
|
|
||||||
type WebRTC struct {
|
type WebRTC struct {
|
||||||
ICELite bool
|
ICELite bool
|
||||||
ICETrickle bool
|
ICETrickle bool
|
||||||
@ -24,12 +33,6 @@ type WebRTC struct {
|
|||||||
IpRetrievalUrl string
|
IpRetrievalUrl string
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
|
||||||
defEprMin = 59000
|
|
||||||
defEprMax = 59100
|
|
||||||
defStun = "stun:stun.l.google.com:19302"
|
|
||||||
)
|
|
||||||
|
|
||||||
func (WebRTC) Init(cmd *cobra.Command) error {
|
func (WebRTC) Init(cmd *cobra.Command) error {
|
||||||
cmd.PersistentFlags().Bool("webrtc.icelite", false, "configures whether or not the ICE agent should be a lite agent")
|
cmd.PersistentFlags().Bool("webrtc.icelite", false, "configures whether or not the ICE agent should be a lite agent")
|
||||||
if err := viper.BindPFlag("webrtc.icelite", cmd.PersistentFlags().Lookup("webrtc.icelite")); err != nil {
|
if err := viper.BindPFlag("webrtc.icelite", cmd.PersistentFlags().Lookup("webrtc.icelite")); err != nil {
|
||||||
@ -76,7 +79,7 @@ func (s *WebRTC) Set() {
|
|||||||
|
|
||||||
if len(s.ICEServers) == 0 {
|
if len(s.ICEServers) == 0 {
|
||||||
s.ICEServers = append(s.ICEServers, types.ICEServer{
|
s.ICEServers = append(s.ICEServers, types.ICEServer{
|
||||||
URLs: []string{defStun},
|
URLs: []string{defStunSrv},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,10 +6,11 @@ import (
|
|||||||
"demodesk/neko/internal/desktop/drop"
|
"demodesk/neko/internal/desktop/drop"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
// repeat move event multiple times
|
||||||
DROP_MOVE_REPEAT = 4
|
const dropMoveRepeat = 4
|
||||||
DROP_DELAY = 100 * time.Millisecond
|
|
||||||
)
|
// wait after each repeated move event
|
||||||
|
const dropMoveDelay = 100 * time.Millisecond
|
||||||
|
|
||||||
func (manager *DesktopManagerCtx) DropFiles(x int, y int, files []string) bool {
|
func (manager *DesktopManagerCtx) DropFiles(x int, y int, files []string) bool {
|
||||||
mu.Lock()
|
mu.Lock()
|
||||||
@ -31,9 +32,9 @@ func (manager *DesktopManagerCtx) DropFiles(x int, y int, files []string) bool {
|
|||||||
})
|
})
|
||||||
|
|
||||||
drop.Emmiter.Once("begin", func(payload ...interface{}) {
|
drop.Emmiter.Once("begin", func(payload ...interface{}) {
|
||||||
for i := 0; i < DROP_MOVE_REPEAT; i++ {
|
for i := 0; i < dropMoveRepeat; i++ {
|
||||||
manager.Move(x, y)
|
manager.Move(x, y)
|
||||||
time.Sleep(DROP_DELAY)
|
time.Sleep(dropMoveDelay)
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint
|
//nolint
|
||||||
|
@ -6,11 +6,14 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
// name of the window that is being controlled
|
||||||
FILE_CHOOSER_DIALOG_NAME = "Open File"
|
const fileChooserDialogName = "Open File"
|
||||||
FILE_CHOOSER_DIALOG_SHORT_SLEEP = "0.2"
|
|
||||||
FILE_CHOOSER_DIALOG_LONG_SLEEP = "0.4"
|
// short sleep value between fake user interactions
|
||||||
)
|
const fileChooserDialogShortSleep = "0.2"
|
||||||
|
|
||||||
|
// long sleep value between fake user interactions
|
||||||
|
const fileChooserDialogLongSleep = "0.4"
|
||||||
|
|
||||||
func (manager *DesktopManagerCtx) HandleFileChooserDialog(uri string) error {
|
func (manager *DesktopManagerCtx) HandleFileChooserDialog(uri string) error {
|
||||||
mu.Lock()
|
mu.Lock()
|
||||||
@ -19,19 +22,19 @@ func (manager *DesktopManagerCtx) HandleFileChooserDialog(uri string) error {
|
|||||||
// TODO: Use native API.
|
// TODO: Use native API.
|
||||||
err1 := exec.Command(
|
err1 := exec.Command(
|
||||||
"xdotool",
|
"xdotool",
|
||||||
"search", "--name", FILE_CHOOSER_DIALOG_NAME, "windowfocus",
|
"search", "--name", fileChooserDialogName, "windowfocus",
|
||||||
"sleep", FILE_CHOOSER_DIALOG_SHORT_SLEEP,
|
"sleep", fileChooserDialogShortSleep,
|
||||||
"key", "--clearmodifiers", "ctrl+l",
|
"key", "--clearmodifiers", "ctrl+l",
|
||||||
"type", "--args", "1", uri+"//",
|
"type", "--args", "1", uri+"//",
|
||||||
"sleep", FILE_CHOOSER_DIALOG_SHORT_SLEEP,
|
"sleep", fileChooserDialogShortSleep,
|
||||||
"key", "Delete", // remove autocomplete results
|
"key", "Delete", // remove autocomplete results
|
||||||
"sleep", FILE_CHOOSER_DIALOG_SHORT_SLEEP,
|
"sleep", fileChooserDialogShortSleep,
|
||||||
"key", "Return",
|
"key", "Return",
|
||||||
"sleep", FILE_CHOOSER_DIALOG_LONG_SLEEP,
|
"sleep", fileChooserDialogLongSleep,
|
||||||
"key", "Down",
|
"key", "Down",
|
||||||
"key", "--clearmodifiers", "ctrl+a",
|
"key", "--clearmodifiers", "ctrl+a",
|
||||||
"key", "Return",
|
"key", "Return",
|
||||||
"sleep", FILE_CHOOSER_DIALOG_LONG_SLEEP,
|
"sleep", fileChooserDialogLongSleep,
|
||||||
).Run()
|
).Run()
|
||||||
|
|
||||||
if err1 != nil {
|
if err1 != nil {
|
||||||
@ -41,7 +44,7 @@ func (manager *DesktopManagerCtx) HandleFileChooserDialog(uri string) error {
|
|||||||
// TODO: Use native API.
|
// TODO: Use native API.
|
||||||
err2 := exec.Command(
|
err2 := exec.Command(
|
||||||
"xdotool",
|
"xdotool",
|
||||||
"search", "--name", FILE_CHOOSER_DIALOG_NAME,
|
"search", "--name", fileChooserDialogName,
|
||||||
).Run()
|
).Run()
|
||||||
|
|
||||||
// if last command didn't return error, consider dialog as still open
|
// if last command didn't return error, consider dialog as still open
|
||||||
@ -61,7 +64,7 @@ func (manager *DesktopManagerCtx) CloseFileChooserDialog() {
|
|||||||
// TODO: Use native API.
|
// TODO: Use native API.
|
||||||
err := exec.Command(
|
err := exec.Command(
|
||||||
"xdotool",
|
"xdotool",
|
||||||
"search", "--name", FILE_CHOOSER_DIALOG_NAME, "windowfocus",
|
"search", "--name", fileChooserDialogName, "windowfocus",
|
||||||
).Run()
|
).Run()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -92,7 +95,7 @@ func (manager *DesktopManagerCtx) IsFileChooserDialogOpened() bool {
|
|||||||
// TODO: Use native API.
|
// TODO: Use native API.
|
||||||
err := exec.Command(
|
err := exec.Command(
|
||||||
"xdotool",
|
"xdotool",
|
||||||
"search", "--name", FILE_CHOOSER_DIALOG_NAME,
|
"search", "--name", fileChooserDialogName,
|
||||||
).Run()
|
).Run()
|
||||||
|
|
||||||
return err == nil
|
return err == nil
|
||||||
|
@ -95,19 +95,19 @@ func (manager *DesktopManagerCtx) GetKeyboardMap() (*types.KeyboardMap, error) {
|
|||||||
|
|
||||||
func (manager *DesktopManagerCtx) SetKeyboardModifiers(mod types.KeyboardModifiers) {
|
func (manager *DesktopManagerCtx) SetKeyboardModifiers(mod types.KeyboardModifiers) {
|
||||||
if mod.NumLock != nil {
|
if mod.NumLock != nil {
|
||||||
xorg.SetKeyboardModifier(xorg.KBD_NUM_LOCK, *mod.NumLock)
|
xorg.SetKeyboardModifier(xorg.KbdModNumLock, *mod.NumLock)
|
||||||
}
|
}
|
||||||
|
|
||||||
if mod.CapsLock != nil {
|
if mod.CapsLock != nil {
|
||||||
xorg.SetKeyboardModifier(xorg.KBD_CAPS_LOCK, *mod.CapsLock)
|
xorg.SetKeyboardModifier(xorg.KbdModCapsLock, *mod.CapsLock)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (manager *DesktopManagerCtx) GetKeyboardModifiers() types.KeyboardModifiers {
|
func (manager *DesktopManagerCtx) GetKeyboardModifiers() types.KeyboardModifiers {
|
||||||
modifiers := xorg.GetKeyboardModifiers()
|
modifiers := xorg.GetKeyboardModifiers()
|
||||||
|
|
||||||
NumLock := (modifiers & xorg.KBD_NUM_LOCK) != 0
|
NumLock := (modifiers & xorg.KbdModNumLock) != 0
|
||||||
CapsLock := (modifiers & xorg.KBD_CAPS_LOCK) != 0
|
CapsLock := (modifiers & xorg.KbdModCapsLock) != 0
|
||||||
|
|
||||||
return types.KeyboardModifiers{
|
return types.KeyboardModifiers{
|
||||||
NumLock: &NumLock,
|
NumLock: &NumLock,
|
||||||
|
@ -19,11 +19,11 @@ import (
|
|||||||
"demodesk/neko/internal/types"
|
"demodesk/neko/internal/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
type KbdModifiers uint8
|
type KbdMod uint8
|
||||||
|
|
||||||
const (
|
const (
|
||||||
KBD_CAPS_LOCK KbdModifiers = 2
|
KbdModCapsLock KbdMod = 2
|
||||||
KBD_NUM_LOCK KbdModifiers = 16
|
KbdModNumLock KbdMod = 16
|
||||||
)
|
)
|
||||||
|
|
||||||
var ScreenConfigurations = make(map[int]types.ScreenConfiguration)
|
var ScreenConfigurations = make(map[int]types.ScreenConfiguration)
|
||||||
@ -213,7 +213,7 @@ func GetScreenSize() *types.ScreenSize {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetKeyboardModifier(mod KbdModifiers, active bool) {
|
func SetKeyboardModifier(mod KbdMod, active bool) {
|
||||||
mu.Lock()
|
mu.Lock()
|
||||||
defer mu.Unlock()
|
defer mu.Unlock()
|
||||||
|
|
||||||
@ -225,11 +225,11 @@ func SetKeyboardModifier(mod KbdModifiers, active bool) {
|
|||||||
C.XSetKeyboardModifier(C.int(mod), num)
|
C.XSetKeyboardModifier(C.int(mod), num)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetKeyboardModifiers() KbdModifiers {
|
func GetKeyboardModifiers() KbdMod {
|
||||||
mu.Lock()
|
mu.Lock()
|
||||||
defer mu.Unlock()
|
defer mu.Unlock()
|
||||||
|
|
||||||
return KbdModifiers(C.XGetKeyboardModifiers())
|
return KbdMod(C.XGetKeyboardModifiers())
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetCursorImage() *types.CursorImage {
|
func GetCursorImage() *types.CursorImage {
|
||||||
|
@ -10,9 +10,7 @@ import (
|
|||||||
|
|
||||||
type key int
|
type key int
|
||||||
|
|
||||||
const (
|
const keySessionCtx key = iota
|
||||||
keySessionCtx key = iota
|
|
||||||
)
|
|
||||||
|
|
||||||
func SetSession(r *http.Request, session types.Session) *http.Request {
|
func SetSession(r *http.Request, session types.Session) *http.Request {
|
||||||
ctx := context.WithValue(r.Context(), keySessionCtx, session)
|
ctx := context.WithValue(r.Context(), keySessionCtx, session)
|
||||||
|
@ -15,6 +15,9 @@ import (
|
|||||||
"demodesk/neko/internal/websocket/handler"
|
"demodesk/neko/internal/websocket/handler"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// send pings to peer with this period - must be less than pongWait
|
||||||
|
const pingPeriod = 10 * time.Second
|
||||||
|
|
||||||
func New(
|
func New(
|
||||||
sessions types.SessionManager,
|
sessions types.SessionManager,
|
||||||
desktop types.DesktopManager,
|
desktop types.DesktopManager,
|
||||||
@ -32,9 +35,6 @@ func New(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send pings to peer with this period. Must be less than pongWait.
|
|
||||||
const pingPeriod = 10 * time.Second
|
|
||||||
|
|
||||||
type WebSocketManagerCtx struct {
|
type WebSocketManagerCtx struct {
|
||||||
logger zerolog.Logger
|
logger zerolog.Logger
|
||||||
sessions types.SessionManager
|
sessions types.SessionManager
|
||||||
|
Loading…
Reference in New Issue
Block a user