mirror of
https://github.com/comma-hacks/webrtc.git
synced 2025-10-05 16:16:56 +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.container = av.open(':0', format='x11grab', options=options)
|
||||||
self.ui = evdev.UInput()
|
self.ui = evdev.UInput()
|
||||||
|
self.valid_actions = ["keyboard", "click", "rightclick", "mousemove", "joystick", "paste"]
|
||||||
|
|
||||||
async def recv(self):
|
async def recv(self):
|
||||||
pts, time_base = await self.next_timestamp()
|
pts, time_base = await self.next_timestamp()
|
||||||
@@ -36,28 +37,31 @@ class DesktopStreamTrack(VideoStreamTrack):
|
|||||||
frame.time_base = time_base
|
frame.time_base = time_base
|
||||||
return frame
|
return frame
|
||||||
|
|
||||||
def handle_message(self, data):
|
def handle_action(self, action, data):
|
||||||
if data["action"] == "mousemove":
|
if action == "mousemove":
|
||||||
x = numpy.interp(data["cursorPositionX"], (0, data["displayWidth"]), (0, self.resolution.width))
|
x = numpy.interp(data["cursorPositionX"], (0, data["displayWidth"]), (0, self.resolution.width))
|
||||||
y = numpy.interp(data["cursorPositionY"], (0, data["displayHeight"]), (0, self.resolution.height))
|
y = numpy.interp(data["cursorPositionY"], (0, data["displayHeight"]), (0, self.resolution.height))
|
||||||
pyautogui.moveTo(x, y, _pause=False)
|
pyautogui.moveTo(x, y, _pause=False)
|
||||||
elif data["action"] == "joystick":
|
elif action == "joystick":
|
||||||
x = numpy.interp(data["x"], (-38, 38), (0, self.resolution.width))
|
x = numpy.interp(data["x"], (-38, 38), (0, self.resolution.width))
|
||||||
y = numpy.interp(data["y"], (-38, 38), (self.resolution.height, 0))
|
y = numpy.interp(data["y"], (-38, 38), (self.resolution.height, 0))
|
||||||
print(f'{data["y"]} {self.resolution.height} {y}')
|
print(f'{data["y"]} {self.resolution.height} {y}')
|
||||||
pyautogui.moveTo(x, y, _pause=False)
|
pyautogui.moveTo(x, y, _pause=False)
|
||||||
elif data["action"] == "click":
|
elif action == "click":
|
||||||
pyautogui.click()
|
pyautogui.click()
|
||||||
elif data["action"] == "rightclick":
|
elif action == "rightclick":
|
||||||
pyautogui.rightClick()
|
pyautogui.rightClick()
|
||||||
elif data["action"] == "keyboard":
|
elif action == "keyboard":
|
||||||
try:
|
try:
|
||||||
keymap.reload()
|
# keymap.reload()
|
||||||
osKey = keymap.iOStoLinux[data["key"]]
|
osKey = keymap.iOStoLinux[data["key"]]
|
||||||
self.ui.write(evdev.ecodes.EV_KEY, osKey, data["direction"])
|
self.ui.write(evdev.ecodes.EV_KEY, osKey, data["direction"])
|
||||||
self.ui.syn()
|
self.ui.syn()
|
||||||
except KeyError:
|
except KeyError:
|
||||||
print(f"Unknown key: {data['key']}")
|
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:
|
def stop(self) -> None:
|
||||||
super().stop()
|
super().stop()
|
||||||
|
13
server.py
13
server.py
@@ -88,8 +88,17 @@ async def signal(pc, signaling):
|
|||||||
@channel.on('message')
|
@channel.on('message')
|
||||||
async def on_message(message):
|
async def on_message(message):
|
||||||
data = json.loads(message)
|
data = json.loads(message)
|
||||||
if desktop_track:
|
if "type" in data:
|
||||||
desktop_track.handle_message(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")
|
@pc.on("track")
|
||||||
def on_track(track):
|
def on_track(track):
|
||||||
|
Reference in New Issue
Block a user