mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
cursor CreatePNGImage in event emitter.
This commit is contained in:
parent
d2eda6f25f
commit
2410295ad4
@ -8,7 +8,7 @@ type WebRTCPeer interface {
|
|||||||
|
|
||||||
SetVideoID(videoID string) error
|
SetVideoID(videoID string) error
|
||||||
SendCursorPosition(x, y int) error
|
SendCursorPosition(x, y int) error
|
||||||
SendCursorImage(cur *CursorImage) error
|
SendCursorImage(cur *CursorImage, img []byte) error
|
||||||
|
|
||||||
Destroy() error
|
Destroy() error
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ import (
|
|||||||
"demodesk/neko/internal/types"
|
"demodesk/neko/internal/types"
|
||||||
"demodesk/neko/internal/types/event"
|
"demodesk/neko/internal/types/event"
|
||||||
"demodesk/neko/internal/types/message"
|
"demodesk/neko/internal/types/message"
|
||||||
|
"demodesk/neko/internal/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
func New(desktop types.DesktopManager, capture types.CaptureManager, config *config.WebRTC) *WebRTCManagerCtx {
|
func New(desktop types.DesktopManager, capture types.CaptureManager, config *config.WebRTC) *WebRTCManagerCtx {
|
||||||
@ -26,7 +27,7 @@ func New(desktop types.DesktopManager, capture types.CaptureManager, config *con
|
|||||||
config: config,
|
config: config,
|
||||||
participants: 0,
|
participants: 0,
|
||||||
// TODO: Refactor.
|
// TODO: Refactor.
|
||||||
curImgListeners: map[uintptr]*func(cur *types.CursorImage){},
|
curImgListeners: map[uintptr]*func(cur *types.CursorImage, img []byte){},
|
||||||
curPosListeners: map[uintptr]*func(x, y int){},
|
curPosListeners: map[uintptr]*func(x, y int){},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -41,7 +42,7 @@ type WebRTCManagerCtx struct {
|
|||||||
config *config.WebRTC
|
config *config.WebRTC
|
||||||
participants uint32
|
participants uint32
|
||||||
// TODO: Refactor.
|
// TODO: Refactor.
|
||||||
curImgListeners map[uintptr]*func(cur *types.CursorImage)
|
curImgListeners map[uintptr]*func(cur *types.CursorImage, img []byte)
|
||||||
curPosListeners map[uintptr]*func(x, y int)
|
curPosListeners map[uintptr]*func(x, y int)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,8 +78,15 @@ func (manager *WebRTCManagerCtx) Start() {
|
|||||||
// TODO: Refactor.
|
// TODO: Refactor.
|
||||||
manager.desktop.OnCursorChanged(func(serial uint64) {
|
manager.desktop.OnCursorChanged(func(serial uint64) {
|
||||||
cur := manager.desktop.GetCursorImage()
|
cur := manager.desktop.GetCursorImage()
|
||||||
|
|
||||||
|
img, err := utils.CreatePNGImage(cur.Image)
|
||||||
|
if err != nil {
|
||||||
|
manager.logger.Warn().Err(err).Msg("failed to create cursor image")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
for _, emit := range manager.curImgListeners {
|
for _, emit := range manager.curImgListeners {
|
||||||
(*emit)(cur)
|
(*emit)(cur, img)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -256,8 +264,8 @@ func (manager *WebRTCManagerCtx) CreatePeer(session types.Session, videoID strin
|
|||||||
dataChannel: dataChannel,
|
dataChannel: dataChannel,
|
||||||
}
|
}
|
||||||
|
|
||||||
cursorChange := func(cur *types.CursorImage) {
|
cursorChange := func(cur *types.CursorImage, img []byte) {
|
||||||
if err := peer.SendCursorImage(cur); err != nil {
|
if err := peer.SendCursorImage(cur, img); err != nil {
|
||||||
manager.logger.Warn().Err(err).Msg("could not send cursor image")
|
manager.logger.Warn().Err(err).Msg("could not send cursor image")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -322,7 +330,12 @@ func (manager *WebRTCManagerCtx) CreatePeer(session types.Session, videoID strin
|
|||||||
|
|
||||||
// send initial cursor image
|
// send initial cursor image
|
||||||
cur := manager.desktop.GetCursorImage()
|
cur := manager.desktop.GetCursorImage()
|
||||||
cursorChange(cur)
|
img, err := utils.CreatePNGImage(cur.Image)
|
||||||
|
if err == nil {
|
||||||
|
cursorChange(cur, img)
|
||||||
|
} else {
|
||||||
|
manager.logger.Warn().Err(err).Msg("failed to create cursor image")
|
||||||
|
}
|
||||||
|
|
||||||
// send initial cursor position
|
// send initial cursor position
|
||||||
x, y := manager.desktop.GetCursorPosition()
|
x, y := manager.desktop.GetCursorPosition()
|
||||||
|
@ -6,7 +6,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"demodesk/neko/internal/types"
|
"demodesk/neko/internal/types"
|
||||||
"demodesk/neko/internal/utils"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -50,16 +49,11 @@ func (peer *WebRTCPeerCtx) SendCursorPosition(x, y int) error {
|
|||||||
return peer.dataChannel.Send(buffer.Bytes())
|
return peer.dataChannel.Send(buffer.Bytes())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (peer *WebRTCPeerCtx) SendCursorImage(cur *types.CursorImage) error {
|
func (peer *WebRTCPeerCtx) SendCursorImage(cur *types.CursorImage, img []byte) error {
|
||||||
if peer.dataChannel == nil {
|
if peer.dataChannel == nil {
|
||||||
return fmt.Errorf("no data channel")
|
return fmt.Errorf("no data channel")
|
||||||
}
|
}
|
||||||
|
|
||||||
img, err := utils.CreatePNGImage(cur.Image)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
data := PayloadCursorImage{
|
data := PayloadCursorImage{
|
||||||
PayloadHeader: PayloadHeader{
|
PayloadHeader: PayloadHeader{
|
||||||
Event: OP_CURSOR_IMAGE,
|
Event: OP_CURSOR_IMAGE,
|
||||||
|
Loading…
Reference in New Issue
Block a user