Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP]: Click and control #164

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .docker/firefox/policies.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
"datareporting.policy.dataSubmissionPolicyBypassNotification": true,
"dom.disable_window_flip": true,
"dom.disable_window_move_resize": true,
"dom.event.contextmenu.enabled": false,
"dom.event.contextmenu.enabled": true,
"extensions.getAddons.showPane": false,
"places.history.enabled": false,
"privacy.file_unique_origin": true,
Expand Down
1 change: 1 addition & 0 deletions server/cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func init() {
neko.Service.Remote,
neko.Service.Broadcast,
neko.Service.WebSocket,
neko.Service.SessionManager,
}

cobra.OnInitialize(func() {
Expand Down
34 changes: 33 additions & 1 deletion server/internal/session/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import (

"m1k1o/neko/internal/types"
"m1k1o/neko/internal/utils"

"github.com/spf13/cobra"
"github.com/spf13/viper"
)

func New(remote types.RemoteManager) *SessionManager {
Expand All @@ -31,6 +34,16 @@ type SessionManager struct {
emmiter events.EventEmmiter
// TODO: Handle locks in sessions as flags.
controlLocked bool
implicitControl bool
}

func (manager *SessionManager) Init(cmd *cobra.Command) error {
cmd.PersistentFlags().Bool("implicit_control", "", "if enabled members can gain control implicitly. Valid values: none, free, on_click")
if err := viper.BindPFlag("implicit_control", cmd.PersistentFlags().Lookup("implicit_control")); err != nil {
return err
}

manager.implicitControl = viper.GetBool("implicit_control")
}

func (manager *SessionManager) New(id string, admin bool, socket types.WebSocket) types.Session {
Expand Down Expand Up @@ -111,8 +124,23 @@ func (manager *SessionManager) SetControlLocked(locked bool) {
manager.controlLocked = locked
}

func (manager *SessionManager) CanControl(id string) bool {
func (manager *SessionManager) CanControl(id string, isClickEvent bool) bool {
session, ok := manager.Get(id)
if !manager.IsHost(id) {
ok = false
}
if !ok {
switch manager.sessions.ImplicitControl {
case types.session.ControlMode.OnMove:
ok = true
case types.session.ControlMode.OnClick:
if isClickEvent: {
// Switch host
manager.
}
}
}

return ok && (!manager.controlLocked || session.Admin())
}

Expand Down Expand Up @@ -252,3 +280,7 @@ func (manager *SessionManager) OnConnected(listener func(id string, session type
listener(payload[0].(string), payload[1].(*Session))
})
}

func (manager *SessionManager) ImplicitControl() bool {
return manager.implicitControl
}
11 changes: 0 additions & 11 deletions server/internal/types/config/webrtc.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ type WebRTC struct {
NAT1To1IPs []string
TCPMUX int
UDPMUX int

ImplicitControl bool
}

func (WebRTC) Init(cmd *cobra.Command) error {
Expand Down Expand Up @@ -67,12 +65,6 @@ func (WebRTC) Init(cmd *cobra.Command) error {
return err
}

// TODO: Should be moved to session config.
cmd.PersistentFlags().Bool("implicit_control", false, "if enabled members can gain control implicitly")
if err := viper.BindPFlag("implicit_control", cmd.PersistentFlags().Lookup("implicit_control")); err != nil {
return err
}

return nil
}

Expand Down Expand Up @@ -128,7 +120,4 @@ func (s *WebRTC) Set() {
s.EphemeralMin = min
s.EphemeralMax = max
}

// TODO: Should be moved to session config.
s.ImplicitControl = viper.GetBool("implicit_control")
}
14 changes: 14 additions & 0 deletions server/internal/types/session.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
package types
import (
"github.com/spf13/cobra"
)

type ControlMode string

const (
None ControlMode = ""
OnClick = "on_click"
OnMove = "on_click"
)

type Member struct {
ID string `json:"id"`
Expand Down Expand Up @@ -30,6 +41,7 @@ type Session interface {
}

type SessionManager interface {
Init(cmd *cobra.Command) error
New(id string, admin bool, socket WebSocket) Session
HasHost() bool
IsHost(id string) bool
Expand All @@ -51,4 +63,6 @@ type SessionManager interface {
OnDestroy(listener func(id string, session Session))
OnCreated(listener func(id string, session Session))
OnConnected(listener func(id string, session Session))
ImplicitControl() bool
ImplicitControlMode() ControlMode
}
1 change: 0 additions & 1 deletion server/internal/types/webrtc.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ type WebRTCManager interface {
CreatePeer(id string, session Session) (Peer, error)
ICELite() bool
ICEServers() []webrtc.ICEServer
ImplicitControl() bool
}

type Peer interface {
Expand Down
2 changes: 1 addition & 1 deletion server/internal/types/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type Stats struct {
LastUserLeftAt *time.Time `json:"last_user_left_at"`

ControlProtection bool `json:"control_protection"`
ImplicitControl bool `json:"implicit_control"`
ImplicitControl string `json:"implicit_control"`
}

type WebSocket interface {
Expand Down
10 changes: 6 additions & 4 deletions server/internal/webrtc/handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ type PayloadKey struct {
}

func (manager *WebRTCManager) handle(id string, msg webrtc.DataChannelMessage) error {
if (!manager.config.ImplicitControl && !manager.sessions.IsHost(id)) || (manager.config.ImplicitControl && !manager.sessions.CanControl(id)) {
return nil
}

buffer := bytes.NewBuffer(msg.Data)
header := &PayloadHeader{}
hbytes := make([]byte, 3)
Expand All @@ -55,6 +51,12 @@ func (manager *WebRTCManager) handle(id string, msg webrtc.DataChannelMessage) e
return err
}

isClickEvent = header.Event == OP_KEY_CLK
// Confirm we can can continue
if (!manager.sessions.CanControl(id, isClickEvent)) {
return nil
}

buffer = bytes.NewBuffer(msg.Data)

switch header.Event {
Expand Down