mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
set position in session.
This commit is contained in:
parent
60f459392a
commit
318b833b30
@ -16,6 +16,10 @@ type SessionCtx struct {
|
||||
profile types.MemberProfile
|
||||
state types.SessionState
|
||||
|
||||
positionX int
|
||||
positionY int
|
||||
positionMu sync.Mutex
|
||||
|
||||
websocketPeer types.WebSocketPeer
|
||||
websocketMu sync.Mutex
|
||||
|
||||
@ -53,6 +57,18 @@ func (session *SessionCtx) IsHost() bool {
|
||||
return session.manager.GetHost() == session
|
||||
}
|
||||
|
||||
// ---
|
||||
// cursor position
|
||||
// ---
|
||||
|
||||
func (session *SessionCtx) SetPosition(x, y int) {
|
||||
session.positionMu.Lock()
|
||||
defer session.positionMu.Unlock()
|
||||
|
||||
session.positionX = x
|
||||
session.positionY = y
|
||||
}
|
||||
|
||||
// ---
|
||||
// websocket
|
||||
// ---
|
||||
|
@ -23,6 +23,9 @@ type Session interface {
|
||||
State() SessionState
|
||||
IsHost() bool
|
||||
|
||||
// cursor position
|
||||
SetPosition(x, y int)
|
||||
|
||||
// websocket
|
||||
SetWebSocketPeer(websocketPeer WebSocketPeer)
|
||||
SetWebSocketConnected(websocketPeer WebSocketPeer, connected bool)
|
||||
|
@ -34,15 +34,36 @@ func (manager *WebRTCManagerCtx) handle(data []byte, session types.Session) erro
|
||||
|
||||
buffer = bytes.NewBuffer(data)
|
||||
|
||||
switch header.Event {
|
||||
case payload.OP_MOVE:
|
||||
// handle cursor move event
|
||||
if header.Event == payload.OP_MOVE {
|
||||
payload := &payload.Move{}
|
||||
if err := binary.Read(buffer, binary.BigEndian, payload); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
manager.desktop.Move(int(payload.X), int(payload.Y))
|
||||
manager.curPosition.Set(int(payload.X), int(payload.Y))
|
||||
x, y := int(payload.X), int(payload.Y)
|
||||
|
||||
// handle active cursor movement
|
||||
if session.IsHost() {
|
||||
manager.desktop.Move(x, y)
|
||||
manager.curPosition.Set(x, y)
|
||||
return nil
|
||||
}
|
||||
|
||||
// handle inactive cursor movement
|
||||
if session.Profile().CanHost {
|
||||
session.SetPosition(x, y)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// continue only if session is host
|
||||
if !session.IsHost() {
|
||||
return nil
|
||||
}
|
||||
|
||||
switch header.Event {
|
||||
case payload.OP_SCROLL:
|
||||
payload := &payload.Scroll{}
|
||||
if err := binary.Read(buffer, binary.BigEndian, payload); err != nil {
|
||||
|
@ -208,10 +208,6 @@ func (manager *WebRTCManagerCtx) CreatePeer(session types.Session, videoID strin
|
||||
})
|
||||
|
||||
dataChannel.OnMessage(func(message webrtc.DataChannelMessage) {
|
||||
if !session.IsHost() {
|
||||
return
|
||||
}
|
||||
|
||||
if err := manager.handle(message.Data, session); err != nil {
|
||||
logger.Err(err).Msg("data handle failed")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user