From aefb367505f56e3f0cbad6d6104c81e2410b5033 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Thu, 18 Mar 2021 13:38:27 +0100 Subject: [PATCH] fix initial image error & add cache max. --- internal/webrtc/cursor/image.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/internal/webrtc/cursor/image.go b/internal/webrtc/cursor/image.go index 037161b7..2d46aba8 100644 --- a/internal/webrtc/cursor/image.go +++ b/internal/webrtc/cursor/image.go @@ -17,6 +17,7 @@ func NewImage(desktop types.DesktopManager) *ImageCtx { desktop: desktop, listeners: map[uintptr]*func(entry *ImageEntry){}, cache: map[uint64]*ImageEntry{}, + maxSerial: 200, // TODO: Cleanup? } } @@ -28,6 +29,7 @@ type ImageCtx struct { cacheMu sync.Mutex cache map[uint64]*ImageEntry current *ImageEntry + maxSerial uint64 } type ImageEntry struct { @@ -43,6 +45,7 @@ func (manager *ImageCtx) Start() { return } + manager.current = entry for _, emit := range manager.listeners { (*emit)(entry) } @@ -61,7 +64,7 @@ func (manager *ImageCtx) Shutdown() { func (manager *ImageCtx) GetCached(serial uint64) (*ImageEntry, error) { // zero means no serial available - if serial == 0 { + if serial == 0 || serial > manager.maxSerial { return manager.fetchEntry() } @@ -126,6 +129,5 @@ func (manager *ImageCtx) fetchEntry() (*ImageEntry, error) { Image: img, } - manager.current = entry return entry, nil }