@@ -9,14 +9,14 @@ import (
9
9
"strconv"
10
10
"strings"
11
11
12
+ "github.com/go-vgo/robotgo"
12
13
"github.com/google/uuid"
13
- "github.com/tidwall/sjson"
14
- "github.com/pion/sdp"
15
- "github.com/pion/webrtc/v2"
16
- "github.com/imtiyazs/webrtc-remote-desktop/internal/encoders"
17
14
"github.com/imtiyazs/webrtc-remote-desktop/internal/config"
18
- "github.com/go-vgo/robotgo "
15
+ "github.com/imtiyazs/webrtc-remote-desktop/internal/encoders "
19
16
"github.com/imtiyazs/webrtc-remote-desktop/internal/rdisplay"
17
+ "github.com/pion/sdp"
18
+ "github.com/pion/webrtc/v2"
19
+ "github.com/tidwall/sjson"
20
20
)
21
21
22
22
// RemoteScreenPeerConn is a webrtc.PeerConnection wrapper that implements the
@@ -124,7 +124,7 @@ func (p *RemoteScreenPeerConn) ProcessOffer(strOffer string) (string, error) {
124
124
if err != nil {
125
125
return "" , err
126
126
}
127
-
127
+
128
128
p .connection = peerConn
129
129
130
130
peerConn .OnICEConnectionStateChange (func (connState webrtc.ICEConnectionState ) {
@@ -135,7 +135,7 @@ func (p *RemoteScreenPeerConn) ProcessOffer(strOffer string) (string, error) {
135
135
if connState == webrtc .ICEConnectionStateDisconnected {
136
136
p .Close ()
137
137
}
138
-
138
+
139
139
log .Printf ("Connection state: %s \n " , connState .String ())
140
140
})
141
141
@@ -197,13 +197,12 @@ func (p *RemoteScreenPeerConn) ProcessOffer(strOffer string) (string, error) {
197
197
return "" , err
198
198
}
199
199
200
-
201
200
// Register data channel creation handling
202
201
peerConn .OnDataChannel (func (d * webrtc.DataChannel ) {
203
202
204
203
type WSSMessage struct {
205
204
Command string
206
- Data interface {}
205
+ Data interface {}
207
206
}
208
207
209
208
incomingMessage := & WSSMessage {}
@@ -219,9 +218,12 @@ func (p *RemoteScreenPeerConn) ProcessOffer(strOffer string) (string, error) {
219
218
switch incomingMessage .Command {
220
219
case "screensize" :
221
220
screen := p .grabber .Screen ()
221
+ mouseX , mouseY := robotgo .GetMousePos ()
222
222
screenSize := make (map [string ]interface {})
223
223
screenSize ["width" ] = screen .Bounds .Dx ()
224
224
screenSize ["height" ] = screen .Bounds .Dy ()
225
+ screenSize ["mouseX" ] = mouseX
226
+ screenSize ["mouseY" ] = mouseY
225
227
226
228
// Create response
227
229
response , _ := sjson .Set ("" , "command" , incomingMessage .Command )
@@ -232,6 +234,41 @@ func (p *RemoteScreenPeerConn) ProcessOffer(strOffer string) (string, error) {
232
234
}
233
235
break
234
236
237
+ case "mousetouchmove" :
238
+ m , ok := incomingMessage .Data .(map [string ]interface {})
239
+ if ! ok {
240
+ return
241
+ }
242
+
243
+ // string to int
244
+ x , err := strconv .Atoi (m ["x" ].(string ))
245
+ if err != nil {
246
+ return
247
+ }
248
+
249
+ y , err := strconv .Atoi (m ["y" ].(string ))
250
+ if err != nil {
251
+ return
252
+ }
253
+
254
+ // Get current position first
255
+ mousePos := make (map [string ]interface {})
256
+ currentX , currentY := robotgo .GetMousePos ()
257
+ mousePos ["x" ] = currentX + x
258
+ mousePos ["y" ] = currentY + y
259
+
260
+ // Move mouse
261
+ robotgo .MoveMouse (currentX + x , currentY + y )
262
+
263
+ response , _ := sjson .Set ("" , "command" , incomingMessage .Command )
264
+ response , _ = sjson .Set (response , "data" , mousePos )
265
+ err = d .SendText (response )
266
+ if err != nil {
267
+ log .Fatal (err )
268
+ }
269
+
270
+ break
271
+
235
272
case "mousemove" :
236
273
m , ok := incomingMessage .Data .(map [string ]interface {})
237
274
if ! ok {
@@ -249,7 +286,21 @@ func (p *RemoteScreenPeerConn) ProcessOffer(strOffer string) (string, error) {
249
286
return
250
287
}
251
288
289
+ // Move mouse
252
290
robotgo .MoveMouse (x , y )
291
+
292
+ // Send current mouse pos
293
+ mousePos := make (map [string ]interface {})
294
+ x , y = robotgo .GetMousePos ()
295
+ mousePos ["x" ] = x
296
+ mousePos ["y" ] = y
297
+ response , _ := sjson .Set ("" , "command" , incomingMessage .Command )
298
+ response , _ = sjson .Set (response , "data" , mousePos )
299
+ err = d .SendText (response )
300
+ if err != nil {
301
+ log .Fatal (err )
302
+ }
303
+
253
304
break
254
305
255
306
case "click" :
0 commit comments