screen-relay 0.0.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/Makefile +165 -0
- package/README.md +112 -1
- package/THIRD-PARTY-NOTICES.md +75 -0
- package/dist/cli/client.d.ts +28 -0
- package/dist/cli/commands.d.ts +52 -0
- package/dist/cli/config.d.ts +32 -0
- package/dist/cli/format.d.ts +15 -0
- package/dist/cli/help.d.ts +5 -0
- package/dist/cli/host/common.d.ts +23 -0
- package/dist/cli/host/doctor.d.ts +2 -0
- package/dist/cli/host/packages.d.ts +13 -0
- package/dist/cli/host/session_commands.d.ts +8 -0
- package/dist/cli/host/setup.d.ts +22 -0
- package/dist/cli/host/state.d.ts +23 -0
- package/dist/cli/host/supervisor.d.ts +94 -0
- package/dist/cli/host/watcher.d.ts +4 -0
- package/dist/cli/host/windows.d.ts +82 -0
- package/dist/cli/main.d.ts +3 -0
- package/dist/cli/mode.d.ts +14 -0
- package/dist/cli/output.d.ts +24 -0
- package/dist/cli/parser.d.ts +6 -0
- package/dist/cli/relay.mjs +12631 -0
- package/dist/cli/skills.d.ts +21 -0
- package/dist/cli/theme.d.ts +14 -0
- package/dist/protocol/errors.d.ts +155 -0
- package/dist/protocol/index.d.ts +119 -0
- package/dist/protocol/index.js +418 -0
- package/dist/sdk/index.d.ts +78 -0
- package/dist/sdk/index.js +834 -0
- package/dist/sdk/transport.d.ts +20 -0
- package/dist/viewer/index.html +96 -0
- package/dist/viewer/viewer.js +1079 -0
- package/package.json +47 -7
- package/packages.tsv +38 -0
- package/skills/core/SKILL.md +171 -0
- package/skills/core/references/cli.md +119 -0
- package/skills/core/references/config.md +48 -0
- package/skills/core/references/macos.md +50 -0
- package/skills/core/references/sdk.md +69 -0
- package/skills/core/references/troubleshooting.md +33 -0
- package/skills/core/references/wayland.md +47 -0
- package/skills/screen-relay/SKILL.md +24 -0
- package/skills/vercel-sandbox/SKILL.md +68 -0
- package/src/engine/backends/linux/keycodes.hpp +35 -0
- package/src/engine/backends/linux/wayland/capture.cpp +298 -0
- package/src/engine/backends/linux/wayland/input.cpp +559 -0
- package/src/engine/backends/linux/wayland/keymap.cpp +118 -0
- package/src/engine/backends/linux/wayland/keymap.hpp +54 -0
- package/src/engine/backends/linux/wayland/protocols/virtual-keyboard-unstable-v1.xml +112 -0
- package/src/engine/backends/linux/wayland/protocols/wlr-screencopy-unstable-v1.xml +234 -0
- package/src/engine/backends/linux/wayland/protocols/wlr-virtual-pointer-unstable-v1.xml +152 -0
- package/src/engine/backends/linux/wayland/wayland.cpp +166 -0
- package/src/engine/backends/linux/wayland/wayland.hpp +60 -0
- package/src/engine/backends/linux/x11/capture.cpp +206 -0
- package/src/engine/backends/linux/x11/input.cpp +266 -0
- package/src/engine/backends/macos/capture.mm +367 -0
- package/src/engine/backends/macos/display.hpp +20 -0
- package/src/engine/backends/macos/display.mm +84 -0
- package/src/engine/backends/macos/input.mm +287 -0
- package/src/engine/backends/macos/keys.hpp +34 -0
- package/src/engine/backends/windows/capture.cpp +393 -0
- package/src/engine/backends/windows/input.cpp +274 -0
- package/src/engine/backends/windows/output.cpp +65 -0
- package/src/engine/backends/windows/output.hpp +26 -0
- package/src/engine/core/capture-bucket.hpp +40 -0
- package/src/engine/core/capture-source.hpp +59 -0
- package/src/engine/core/capture.cpp +565 -0
- package/src/engine/core/capture.hpp +58 -0
- package/src/engine/core/color.cpp +176 -0
- package/src/engine/core/color.hpp +16 -0
- package/src/engine/core/cpu-budget.hpp +196 -0
- package/src/engine/core/flow.hpp +317 -0
- package/src/engine/core/input.cpp +98 -0
- package/src/engine/core/input.hpp +115 -0
- package/src/engine/core/wait.cpp +125 -0
- package/src/engine/core/wait.hpp +41 -0
- package/src/engine/server/backend.cpp +65 -0
- package/src/engine/server/backend.hpp +18 -0
- package/src/engine/server/config.cpp +257 -0
- package/src/engine/server/config.hpp +24 -0
- package/src/engine/server/main.cpp +82 -0
- package/src/engine/server/metrics.cpp +47 -0
- package/src/engine/server/metrics.hpp +10 -0
- package/src/engine/server/screenshot.cpp +108 -0
- package/src/engine/server/screenshot.hpp +31 -0
- package/src/engine/server/server.cpp +535 -0
- package/src/engine/server/server.hpp +89 -0
- package/src/engine/server/wire.cpp +70 -0
- package/src/engine/server/wire.hpp +29 -0
- package/index.js +0 -2
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
#include "wire.hpp"
|
|
2
|
+
#include "config.hpp"
|
|
3
|
+
#include "core/capture-source.hpp"
|
|
4
|
+
#include "core/flow.hpp"
|
|
5
|
+
#include <libwebsockets.h>
|
|
6
|
+
#include <algorithm>
|
|
7
|
+
#include <cstring>
|
|
8
|
+
|
|
9
|
+
namespace relay {
|
|
10
|
+
namespace {
|
|
11
|
+
uint8_t* start(std::vector<uint8_t>& out, size_t pre, size_t size, uint8_t type, uint32_t generation) {
|
|
12
|
+
out.assign(pre + size, 0);
|
|
13
|
+
auto* p = out.data() + pre;
|
|
14
|
+
std::memcpy(p, "NSL1", 4); p[4] = 1; p[5] = type;
|
|
15
|
+
put(p+8, generation, 4);
|
|
16
|
+
return p;
|
|
17
|
+
}
|
|
18
|
+
} // namespace
|
|
19
|
+
uint16_t u16(const uint8_t* p) { return (uint16_t(p[0]) << 8) | p[1]; }
|
|
20
|
+
uint32_t u32(const uint8_t* p) { return (uint32_t(p[0]) << 24) | (uint32_t(p[1]) << 16) | (uint32_t(p[2]) << 8) | p[3]; }
|
|
21
|
+
void put(uint8_t* p, uint64_t value, unsigned count) {
|
|
22
|
+
while (count) { p[--count] = uint8_t(value); value >>= 8; }
|
|
23
|
+
}
|
|
24
|
+
InputEvent inputEvent(const uint8_t* p) {
|
|
25
|
+
const uint32_t raw = u32(p + 4);
|
|
26
|
+
const int64_t value = raw <= INT32_MAX ? int64_t(raw) : int64_t(raw) - (int64_t(1) << 32);
|
|
27
|
+
return {p[0], p[1], u16(p+2), int32_t(value), u16(p+8), u16(p+10), u16(p+12), u16(p+14)};
|
|
28
|
+
}
|
|
29
|
+
unsigned inputLength(const std::string& text, uint64_t& length) {
|
|
30
|
+
if (text.empty()) return HTTP_STATUS_LENGTH_REQUIRED;
|
|
31
|
+
if (!unsignedNumber(text, length) || !length || length % 16) return HTTP_STATUS_BAD_REQUEST;
|
|
32
|
+
return length > max_input_batch * 16 ? HTTP_STATUS_REQ_ENTITY_TOO_LARGE : 0;
|
|
33
|
+
}
|
|
34
|
+
bool viewerTarget(const std::string& target, bool& control, bool& viewOnly) {
|
|
35
|
+
control = target == "/control";
|
|
36
|
+
viewOnly = target == "/stream?view=1";
|
|
37
|
+
return control || viewOnly || target == "/stream";
|
|
38
|
+
}
|
|
39
|
+
bool frameMessage(std::vector<uint8_t>& out, size_t pre, uint32_t generation, uint32_t lastSequence, const EncodedFrame& f,
|
|
40
|
+
uint16_t width, uint16_t height) {
|
|
41
|
+
if (!f.sequence || f.sequence != lastSequence + 1 || !f.width || !f.height ||
|
|
42
|
+
f.width > width || f.height > height || f.annex_b.empty() || f.annex_b.size() > FlowControl::max_bytes ||
|
|
43
|
+
(!lastSequence && !f.keyframe)) return false;
|
|
44
|
+
auto* p = start(out, pre, 32 + f.annex_b.size(), 1, generation);
|
|
45
|
+
put(p+6, f.keyframe ? 1 : 0, 2); put(p+12, f.sequence, 4);
|
|
46
|
+
put(p+16, 12+f.annex_b.size(), 4); put(p+20, f.width, 2); put(p+22, f.height, 2); put(p+24, f.pts_us, 8);
|
|
47
|
+
std::memcpy(p+32, f.annex_b.data(), f.annex_b.size());
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
bool cursorMessage(std::vector<uint8_t>& out, size_t pre, uint32_t generation, const CursorImage& c) {
|
|
51
|
+
if (c.width > CursorImage::max_extent || c.height > CursorImage::max_extent ||
|
|
52
|
+
c.rgba.size() != size_t(c.width) * c.height * 4 ||
|
|
53
|
+
(c.width && c.height ? c.xhot >= c.width || c.yhot >= c.height
|
|
54
|
+
: c.width || c.height || c.xhot || c.yhot)) return false;
|
|
55
|
+
auto* p = start(out, pre, 28 + c.rgba.size(), 6, generation);
|
|
56
|
+
put(p+16, 8 + c.rgba.size(), 4);
|
|
57
|
+
put(p+20, c.width, 2); put(p+22, c.height, 2); put(p+24, c.xhot, 2); put(p+26, c.yhot, 2);
|
|
58
|
+
std::copy(c.rgba.begin(), c.rgba.end(), p+28);
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
void controlReady(std::vector<uint8_t>& out, size_t pre, uint32_t generation, uint16_t width, uint16_t height) {
|
|
62
|
+
auto* p = start(out, pre, 24, 4, generation);
|
|
63
|
+
put(p+16, 4, 4); put(p+20, width, 2); put(p+22, height, 2);
|
|
64
|
+
}
|
|
65
|
+
void inputReply(std::vector<uint8_t>& out, size_t pre, uint32_t generation, uint32_t sequence, InputStatus status) {
|
|
66
|
+
auto* p = start(out, pre, 21, 5, generation);
|
|
67
|
+
put(p+12, sequence, 4); put(p+16, 1, 4);
|
|
68
|
+
p[20] = uint8_t(status);
|
|
69
|
+
}
|
|
70
|
+
} // namespace relay
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include "core/capture.hpp"
|
|
4
|
+
#include "core/input.hpp"
|
|
5
|
+
#include <cstddef>
|
|
6
|
+
#include <cstdint>
|
|
7
|
+
#include <string>
|
|
8
|
+
#include <vector>
|
|
9
|
+
|
|
10
|
+
namespace relay {
|
|
11
|
+
constexpr size_t max_input_batch = 256;
|
|
12
|
+
uint16_t u16(const uint8_t* p);
|
|
13
|
+
uint32_t u32(const uint8_t* p);
|
|
14
|
+
void put(uint8_t* p, uint64_t value, unsigned count);
|
|
15
|
+
InputEvent inputEvent(const uint8_t* p);
|
|
16
|
+
/** Validates an /input Content-Length header and returns 0 or the HTTP error status. */
|
|
17
|
+
unsigned inputLength(const std::string& text, uint64_t& length);
|
|
18
|
+
/** Classifies a /stream, /stream?view=1, or /control request target and reports false for any other target. */
|
|
19
|
+
bool viewerTarget(const std::string& target, bool& control, bool& viewOnly);
|
|
20
|
+
/**
|
|
21
|
+
* The builders below fill out with pre zero bytes of caller padding followed by one NSL1 message.
|
|
22
|
+
* frameMessage and cursorMessage return false when the payload must not be sent.
|
|
23
|
+
*/
|
|
24
|
+
bool frameMessage(std::vector<uint8_t>& out, size_t pre, uint32_t generation, uint32_t lastSequence, const EncodedFrame& frame,
|
|
25
|
+
uint16_t width, uint16_t height);
|
|
26
|
+
bool cursorMessage(std::vector<uint8_t>& out, size_t pre, uint32_t generation, const CursorImage& cursor);
|
|
27
|
+
void controlReady(std::vector<uint8_t>& out, size_t pre, uint32_t generation, uint16_t width, uint16_t height);
|
|
28
|
+
void inputReply(std::vector<uint8_t>& out, size_t pre, uint32_t generation, uint32_t sequence, InputStatus status);
|
|
29
|
+
} // namespace relay
|
package/index.js
DELETED