Skip to content

Commit 8609d8c

Browse files
committed
Mobile view, touch pad & gestures
1 parent 12a44de commit 8609d8c

File tree

8 files changed

+661
-120
lines changed

8 files changed

+661
-120
lines changed

cmd/agent.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func main() {
6262
errors := make(chan error, 2)
6363
go func() {
6464
log.Printf("Server started on port %s", *httpPort)
65-
errors <- http.ListenAndServeTLS(fmt.Sprintf(":%s", *httpPort),"certs/localhost.crt","certs/localhost.key", mux)
65+
errors <- http.ListenAndServeTLS(fmt.Sprintf(":%s", *httpPort), "certs/localhost.crt", "certs/localhost.key", mux)
6666
}()
6767

6868
go func() {

internal/rtc/connection.go

Lines changed: 60 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ import (
99
"strconv"
1010
"strings"
1111

12+
"github.com/go-vgo/robotgo"
1213
"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"
1714
"github.com/imtiyazs/webrtc-remote-desktop/internal/config"
18-
"github.com/go-vgo/robotgo"
15+
"github.com/imtiyazs/webrtc-remote-desktop/internal/encoders"
1916
"github.com/imtiyazs/webrtc-remote-desktop/internal/rdisplay"
17+
"github.com/pion/sdp"
18+
"github.com/pion/webrtc/v2"
19+
"github.com/tidwall/sjson"
2020
)
2121

2222
// RemoteScreenPeerConn is a webrtc.PeerConnection wrapper that implements the
@@ -124,7 +124,7 @@ func (p *RemoteScreenPeerConn) ProcessOffer(strOffer string) (string, error) {
124124
if err != nil {
125125
return "", err
126126
}
127-
127+
128128
p.connection = peerConn
129129

130130
peerConn.OnICEConnectionStateChange(func(connState webrtc.ICEConnectionState) {
@@ -135,7 +135,7 @@ func (p *RemoteScreenPeerConn) ProcessOffer(strOffer string) (string, error) {
135135
if connState == webrtc.ICEConnectionStateDisconnected {
136136
p.Close()
137137
}
138-
138+
139139
log.Printf("Connection state: %s \n", connState.String())
140140
})
141141

@@ -197,13 +197,12 @@ func (p *RemoteScreenPeerConn) ProcessOffer(strOffer string) (string, error) {
197197
return "", err
198198
}
199199

200-
201200
// Register data channel creation handling
202201
peerConn.OnDataChannel(func(d *webrtc.DataChannel) {
203202

204203
type WSSMessage struct {
205204
Command string
206-
Data interface{}
205+
Data interface{}
207206
}
208207

209208
incomingMessage := &WSSMessage{}
@@ -219,9 +218,12 @@ func (p *RemoteScreenPeerConn) ProcessOffer(strOffer string) (string, error) {
219218
switch incomingMessage.Command {
220219
case "screensize":
221220
screen := p.grabber.Screen()
221+
mouseX, mouseY := robotgo.GetMousePos()
222222
screenSize := make(map[string]interface{})
223223
screenSize["width"] = screen.Bounds.Dx()
224224
screenSize["height"] = screen.Bounds.Dy()
225+
screenSize["mouseX"] = mouseX
226+
screenSize["mouseY"] = mouseY
225227

226228
// Create response
227229
response, _ := sjson.Set("", "command", incomingMessage.Command)
@@ -232,6 +234,41 @@ func (p *RemoteScreenPeerConn) ProcessOffer(strOffer string) (string, error) {
232234
}
233235
break
234236

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+
235272
case "mousemove":
236273
m, ok := incomingMessage.Data.(map[string]interface{})
237274
if !ok {
@@ -249,7 +286,21 @@ func (p *RemoteScreenPeerConn) ProcessOffer(strOffer string) (string, error) {
249286
return
250287
}
251288

289+
// Move mouse
252290
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+
253304
break
254305

255306
case "click":

web/css/iphone.css

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/* Portrait */
2+
@media only screen and (min-device-width: 375px) and (max-device-width: 812px) and (-webkit-min-device-pixel-ratio: 3) and (orientation: portrait) {
3+
.video-container {
4+
position: relative;
5+
width: 100%;
6+
height: 50%;
7+
background-color: #303030;
8+
}
9+
10+
.touch-container {
11+
display: none;
12+
background-color: #303030;
13+
height: 100%;
14+
width: 100%;
15+
}
16+
17+
.touchpad {
18+
background-color: rgba(255, 255, 255, 0.15);
19+
backdrop-filter: blur(10px);
20+
color: white;
21+
width: 100%;
22+
height: calc(100vh - 35px);
23+
border-radius: 20px 20px 0 0;
24+
padding: 10px;
25+
margin: 0px;
26+
}
27+
28+
.touch-btn-container {
29+
position: fixed;
30+
height: 100px;
31+
width: 108%;
32+
margin: 0px;
33+
bottom: 0;
34+
padding: 5px;
35+
z-index: 2;
36+
}
37+
38+
.screen-video {
39+
width: 100%;
40+
height: 100%;
41+
z-index: 2;
42+
}
43+
}
44+
45+
/* Landscape */
46+
@media only screen and (min-device-width: 375px) and (max-device-width: 812px) and (-webkit-min-device-pixel-ratio: 3) and (orientation: landscape) {
47+
.video-container {
48+
position: relative;
49+
width: 100%;
50+
height: 50%;
51+
background-color: #303030;
52+
}
53+
54+
.touch-container {
55+
display: none;
56+
background-color: #303030;
57+
height: 100%;
58+
width: 100%;
59+
}
60+
61+
.touchpad {
62+
background-color: rgba(255, 255, 255, 0.15);
63+
backdrop-filter: blur(10px);
64+
color: white;
65+
width: 100%;
66+
height: calc(100vh - 35px);
67+
border-radius: 20px 20px 0 0;
68+
padding: 10px;
69+
margin: 0px;
70+
}
71+
72+
.touch-btn-container {
73+
position: fixed;
74+
height: 100px;
75+
width: 108%;
76+
margin: 0px;
77+
bottom: 0;
78+
z-index: 2;
79+
padding: 5px;
80+
}
81+
82+
.screen-video {
83+
width: 100%;
84+
height: 100%;
85+
z-index: 2;
86+
}
87+
}

0 commit comments

Comments
 (0)