mirror of
https://github.com/comma-hacks/webrtc.git
synced 2025-09-27 20:42:25 +08:00
cleanup remote desktop actions
This commit is contained in:
@@ -25,6 +25,7 @@ class DesktopStreamTrack(VideoStreamTrack):
|
||||
}
|
||||
self.container = av.open(':0', format='x11grab', options=options)
|
||||
self.ui = evdev.UInput()
|
||||
self.valid_actions = ["keyboard", "click", "rightclick", "mousemove", "joystick", "paste"]
|
||||
|
||||
async def recv(self):
|
||||
pts, time_base = await self.next_timestamp()
|
||||
@@ -36,28 +37,31 @@ class DesktopStreamTrack(VideoStreamTrack):
|
||||
frame.time_base = time_base
|
||||
return frame
|
||||
|
||||
def handle_message(self, data):
|
||||
if data["action"] == "mousemove":
|
||||
def handle_action(self, action, data):
|
||||
if action == "mousemove":
|
||||
x = numpy.interp(data["cursorPositionX"], (0, data["displayWidth"]), (0, self.resolution.width))
|
||||
y = numpy.interp(data["cursorPositionY"], (0, data["displayHeight"]), (0, self.resolution.height))
|
||||
pyautogui.moveTo(x, y, _pause=False)
|
||||
elif data["action"] == "joystick":
|
||||
elif action == "joystick":
|
||||
x = numpy.interp(data["x"], (-38, 38), (0, self.resolution.width))
|
||||
y = numpy.interp(data["y"], (-38, 38), (self.resolution.height, 0))
|
||||
print(f'{data["y"]} {self.resolution.height} {y}')
|
||||
pyautogui.moveTo(x, y, _pause=False)
|
||||
elif data["action"] == "click":
|
||||
elif action == "click":
|
||||
pyautogui.click()
|
||||
elif data["action"] == "rightclick":
|
||||
elif action == "rightclick":
|
||||
pyautogui.rightClick()
|
||||
elif data["action"] == "keyboard":
|
||||
elif action == "keyboard":
|
||||
try:
|
||||
keymap.reload()
|
||||
# keymap.reload()
|
||||
osKey = keymap.iOStoLinux[data["key"]]
|
||||
self.ui.write(evdev.ecodes.EV_KEY, osKey, data["direction"])
|
||||
self.ui.syn()
|
||||
except KeyError:
|
||||
print(f"Unknown key: {data['key']}")
|
||||
elif action == "paste":
|
||||
# might as well support the secureput protocol completely
|
||||
pyautogui.write(data["payload"]["string"])
|
||||
|
||||
def stop(self) -> None:
|
||||
super().stop()
|
||||
|
13
server.py
13
server.py
@@ -88,8 +88,17 @@ async def signal(pc, signaling):
|
||||
@channel.on('message')
|
||||
async def on_message(message):
|
||||
data = json.loads(message)
|
||||
if desktop_track:
|
||||
desktop_track.handle_message(data)
|
||||
if "type" in data:
|
||||
if data["type"] == "wrapped":
|
||||
data = json.loads(signaling.decrypt(data["payload"]["data"]))
|
||||
if desktop_track and data["type"] in desktop_track.valid_actions:
|
||||
desktop_track.handle_action(data["type"], data)
|
||||
else:
|
||||
print("ignored message")
|
||||
print(data)
|
||||
else:
|
||||
print("unsupported message")
|
||||
print(data)
|
||||
|
||||
@pc.on("track")
|
||||
def on_track(track):
|
||||
|
Reference in New Issue
Block a user