@desklink/host 0.5.3 → 0.5.6

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.
Files changed (76) hide show
  1. package/README.md +33 -19
  2. package/dist/bridge.js +3 -3
  3. package/dist/bridge.js.map +1 -1
  4. package/dist/engineProcess.d.ts +5 -0
  5. package/dist/engineProcess.d.ts.map +1 -1
  6. package/dist/engineProcess.js +6 -3
  7. package/dist/engineProcess.js.map +1 -1
  8. package/dist/protocol.d.ts +39 -0
  9. package/dist/protocol.d.ts.map +1 -1
  10. package/dist/protocol.js.map +1 -1
  11. package/docs/BOUNDARY.md +4 -2
  12. package/docs/PROTOCOL.md +70 -7
  13. package/engine/Cargo.lock +6 -8
  14. package/engine/Cargo.toml +13 -1
  15. package/engine/src/audio.rs +398 -0
  16. package/engine/src/clipboard.rs +0 -34
  17. package/engine/src/convert.rs +0 -170
  18. package/engine/src/cursor.rs +0 -23
  19. package/engine/src/input.rs +0 -65
  20. package/engine/src/input_mac.rs +0 -11
  21. package/engine/src/keeper.rs +0 -137
  22. package/engine/src/keymap.rs +0 -107
  23. package/engine/src/keymap_mac.rs +0 -25
  24. package/engine/src/mac.rs +1 -28
  25. package/engine/src/main.rs +22 -0
  26. package/engine/src/peer.rs +297 -0
  27. package/engine/src/portal.rs +0 -18
  28. package/engine/src/protocol.rs +22 -162
  29. package/engine/src/session.rs +176 -3
  30. package/engine/src/win.rs +1 -0
  31. package/engine/src/x11.rs +0 -13
  32. package/engine/vendor/rtc-ice/Cargo.toml +137 -0
  33. package/engine/vendor/rtc-ice/DESKLINK-PATCH.md +111 -0
  34. package/engine/vendor/rtc-ice/LICENSE-APACHE +201 -0
  35. package/engine/vendor/rtc-ice/LICENSE-MIT +21 -0
  36. package/engine/vendor/rtc-ice/README.md +30 -0
  37. package/engine/vendor/rtc-ice/examples/ping_pong.rs +376 -0
  38. package/engine/vendor/rtc-ice/src/agent/agent_config.rs +126 -0
  39. package/engine/vendor/rtc-ice/src/agent/agent_proto.rs +172 -0
  40. package/engine/vendor/rtc-ice/src/agent/agent_selector.rs +647 -0
  41. package/engine/vendor/rtc-ice/src/agent/agent_stats.rs +292 -0
  42. package/engine/vendor/rtc-ice/src/agent/agent_test.rs +3594 -0
  43. package/engine/vendor/rtc-ice/src/agent/mod.rs +1753 -0
  44. package/engine/vendor/rtc-ice/src/attributes/control/control_test.rs +168 -0
  45. package/engine/vendor/rtc-ice/src/attributes/control/mod.rs +142 -0
  46. package/engine/vendor/rtc-ice/src/attributes/mod.rs +6 -0
  47. package/engine/vendor/rtc-ice/src/attributes/priority/mod.rs +37 -0
  48. package/engine/vendor/rtc-ice/src/attributes/priority/priority_test.rs +39 -0
  49. package/engine/vendor/rtc-ice/src/attributes/use_candidate/mod.rs +33 -0
  50. package/engine/vendor/rtc-ice/src/attributes/use_candidate/use_candidate_test.rs +19 -0
  51. package/engine/vendor/rtc-ice/src/candidate/candidate_host.rs +53 -0
  52. package/engine/vendor/rtc-ice/src/candidate/candidate_pair.rs +215 -0
  53. package/engine/vendor/rtc-ice/src/candidate/candidate_pair_test.rs +201 -0
  54. package/engine/vendor/rtc-ice/src/candidate/candidate_peer_reflexive.rs +49 -0
  55. package/engine/vendor/rtc-ice/src/candidate/candidate_relay.rs +53 -0
  56. package/engine/vendor/rtc-ice/src/candidate/candidate_relay_test.rs +114 -0
  57. package/engine/vendor/rtc-ice/src/candidate/candidate_server_reflexive.rs +53 -0
  58. package/engine/vendor/rtc-ice/src/candidate/candidate_server_reflexive_test.rs +91 -0
  59. package/engine/vendor/rtc-ice/src/candidate/candidate_test.rs +540 -0
  60. package/engine/vendor/rtc-ice/src/candidate/mod.rs +679 -0
  61. package/engine/vendor/rtc-ice/src/dl_trace.rs +49 -0
  62. package/engine/vendor/rtc-ice/src/lib.rs +88 -0
  63. package/engine/vendor/rtc-ice/src/mdns/mdns_test.rs +150 -0
  64. package/engine/vendor/rtc-ice/src/mdns/mod.rs +69 -0
  65. package/engine/vendor/rtc-ice/src/network_type/mod.rs +162 -0
  66. package/engine/vendor/rtc-ice/src/network_type/network_type_test.rs +95 -0
  67. package/engine/vendor/rtc-ice/src/rand/mod.rs +91 -0
  68. package/engine/vendor/rtc-ice/src/rand/rand_test.rs +115 -0
  69. package/engine/vendor/rtc-ice/src/state/mod.rs +106 -0
  70. package/engine/vendor/rtc-ice/src/state/state_test.rs +46 -0
  71. package/engine/vendor/rtc-ice/src/stats/mod.rs +166 -0
  72. package/engine/vendor/rtc-ice/src/tcp_type/mod.rs +47 -0
  73. package/engine/vendor/rtc-ice/src/tcp_type/tcp_type_test.rs +18 -0
  74. package/engine/vendor/rtc-ice/src/url/mod.rs +266 -0
  75. package/engine/vendor/rtc-ice/src/url/url_test.rs +142 -0
  76. package/package.json +8 -3
@@ -0,0 +1,266 @@
1
+ #[cfg(test)]
2
+ mod url_test;
3
+
4
+ use std::borrow::Cow;
5
+ use std::convert::From;
6
+ use std::fmt;
7
+
8
+ use shared::error::*;
9
+
10
+ /// The type of server used in the ice.URL structure.
11
+ #[derive(Default, PartialEq, Eq, Debug, Copy, Clone)]
12
+ #[non_exhaustive]
13
+ pub enum SchemeType {
14
+ /// The URL represents a STUN server.
15
+ Stun,
16
+
17
+ /// The URL represents a STUNS (secure) server.
18
+ Stuns,
19
+
20
+ /// The URL represents a TURN server.
21
+ Turn,
22
+
23
+ /// The URL represents a TURNS (secure) server.
24
+ Turns,
25
+
26
+ #[default]
27
+ /// Default public constant to use for "enum" like struct comparisons when no value was defined.
28
+ /// A scheme or transport this crate does not recognise.
29
+ Unknown,
30
+ }
31
+
32
+ impl From<&str> for SchemeType {
33
+ /// Defines a procedure for creating a new `SchemeType` from a raw
34
+ /// string naming the scheme type.
35
+ fn from(raw: &str) -> Self {
36
+ match raw {
37
+ "stun" => Self::Stun,
38
+ "stuns" => Self::Stuns,
39
+ "turn" => Self::Turn,
40
+ "turns" => Self::Turns,
41
+ _ => Self::Unknown,
42
+ }
43
+ }
44
+ }
45
+
46
+ impl fmt::Display for SchemeType {
47
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
48
+ let s = match *self {
49
+ SchemeType::Stun => "stun",
50
+ SchemeType::Stuns => "stuns",
51
+ SchemeType::Turn => "turn",
52
+ SchemeType::Turns => "turns",
53
+ SchemeType::Unknown => "unknown",
54
+ };
55
+ write!(f, "{s}")
56
+ }
57
+ }
58
+
59
+ /// The transport protocol type that is used in the `ice::url::Url` structure.
60
+ #[derive(Default, PartialEq, Eq, Debug, Copy, Clone)]
61
+ #[non_exhaustive]
62
+ pub enum ProtoType {
63
+ /// The URL uses a UDP transport.
64
+ #[default]
65
+ Udp,
66
+
67
+ /// The URL uses a TCP transport.
68
+ Tcp,
69
+
70
+ /// A transport this crate does not recognise.
71
+ Unknown,
72
+ }
73
+
74
+ // defines a procedure for creating a new ProtoType from a raw
75
+ // string naming the transport protocol type.
76
+ impl From<&str> for ProtoType {
77
+ // NewSchemeType defines a procedure for creating a new SchemeType from a raw
78
+ // string naming the scheme type.
79
+ fn from(raw: &str) -> Self {
80
+ match raw {
81
+ "udp" => Self::Udp,
82
+ "tcp" => Self::Tcp,
83
+ _ => Self::Unknown,
84
+ }
85
+ }
86
+ }
87
+
88
+ impl fmt::Display for ProtoType {
89
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
90
+ let s = match *self {
91
+ Self::Udp => "udp",
92
+ Self::Tcp => "tcp",
93
+ Self::Unknown => "unknown",
94
+ };
95
+ write!(f, "{s}")
96
+ }
97
+ }
98
+
99
+ /// Represents a STUN (rfc7064) or TURN (rfc7065) URL.
100
+ #[derive(Debug, Clone, Default)]
101
+ pub struct Url {
102
+ /// The URL scheme: `stun`, `stuns`, `turn` or `turns`.
103
+ pub scheme: SchemeType,
104
+ /// The server host name or address.
105
+ pub host: String,
106
+ /// The server port; defaults to 3478, or 5349 for the secure schemes.
107
+ pub port: u16,
108
+ /// The TURN username, for `turn:`/`turns:` URLs.
109
+ pub username: String,
110
+ /// The TURN credential.
111
+ pub password: String,
112
+ /// The transport to reach the server over, from the URL's `?transport=` parameter.
113
+ pub proto: ProtoType,
114
+ }
115
+
116
+ impl fmt::Display for Url {
117
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
118
+ let host = if self.host.contains("::") {
119
+ "[".to_owned() + self.host.as_str() + "]"
120
+ } else {
121
+ self.host.clone()
122
+ };
123
+ if self.scheme == SchemeType::Turn || self.scheme == SchemeType::Turns {
124
+ write!(
125
+ f,
126
+ "{}:{}:{}?transport={}",
127
+ self.scheme, host, self.port, self.proto
128
+ )
129
+ } else {
130
+ write!(f, "{}:{}:{}", self.scheme, host, self.port)
131
+ }
132
+ }
133
+ }
134
+
135
+ impl Url {
136
+ /// Parses a STUN or TURN urls following the ABNF syntax described in
137
+ /// [IETF rfc-7064](https://tools.ietf.org/html/rfc7064) and
138
+ /// [IETF rfc-7065](https://tools.ietf.org/html/rfc7065) respectively.
139
+ pub fn parse_url(raw: &str) -> Result<Self> {
140
+ // work around for url crate
141
+ if raw.contains("//") {
142
+ return Err(Error::ErrInvalidUrl);
143
+ }
144
+
145
+ let mut s = raw.to_string();
146
+ let pos = raw.find(':');
147
+ if let Some(p) = pos {
148
+ s.replace_range(p..=p, "://");
149
+ } else {
150
+ return Err(Error::ErrSchemeType);
151
+ }
152
+
153
+ let raw_parts = url::Url::parse(&s)?;
154
+
155
+ let scheme = raw_parts.scheme().into();
156
+
157
+ let host = if let Some(host) = raw_parts.host_str() {
158
+ host.trim()
159
+ .trim_start_matches('[')
160
+ .trim_end_matches(']')
161
+ .to_owned()
162
+ } else {
163
+ return Err(Error::ErrHost);
164
+ };
165
+
166
+ let port = if let Some(port) = raw_parts.port() {
167
+ port
168
+ } else if scheme == SchemeType::Stun || scheme == SchemeType::Turn {
169
+ 3478
170
+ } else {
171
+ 5349
172
+ };
173
+
174
+ let mut q_args = raw_parts.query_pairs();
175
+ let proto = match scheme {
176
+ SchemeType::Stun => {
177
+ if q_args.count() > 0 {
178
+ return Err(Error::ErrStunQuery);
179
+ }
180
+ ProtoType::Udp
181
+ }
182
+ SchemeType::Stuns => {
183
+ if q_args.count() > 0 {
184
+ return Err(Error::ErrStunQuery);
185
+ }
186
+ ProtoType::Tcp
187
+ }
188
+ SchemeType::Turn => {
189
+ if q_args.count() > 1 {
190
+ return Err(Error::ErrInvalidQuery);
191
+ }
192
+ if let Some((key, value)) = q_args.next() {
193
+ if key == Cow::Borrowed("transport") {
194
+ let proto: ProtoType = value.as_ref().into();
195
+ if proto == ProtoType::Unknown {
196
+ return Err(Error::ErrProtoType);
197
+ }
198
+ proto
199
+ } else {
200
+ return Err(Error::ErrInvalidQuery);
201
+ }
202
+ } else {
203
+ ProtoType::Udp
204
+ }
205
+ }
206
+ SchemeType::Turns => {
207
+ if q_args.count() > 1 {
208
+ return Err(Error::ErrInvalidQuery);
209
+ }
210
+ if let Some((key, value)) = q_args.next() {
211
+ if key == Cow::Borrowed("transport") {
212
+ let proto: ProtoType = value.as_ref().into();
213
+ if proto == ProtoType::Unknown {
214
+ return Err(Error::ErrProtoType);
215
+ }
216
+ proto
217
+ } else {
218
+ return Err(Error::ErrInvalidQuery);
219
+ }
220
+ } else {
221
+ ProtoType::Tcp
222
+ }
223
+ }
224
+ SchemeType::Unknown => {
225
+ return Err(Error::ErrSchemeType);
226
+ }
227
+ };
228
+
229
+ Ok(Self {
230
+ scheme,
231
+ host,
232
+ port,
233
+ username: "".to_owned(),
234
+ password: "".to_owned(),
235
+ proto,
236
+ })
237
+ }
238
+
239
+ /*
240
+ fn parse_proto(raw:&str) ->Result<ProtoType> {
241
+ let qArgs= raw.split('=');
242
+ if qArgs.len() != 2 {
243
+ return Err(Error::ErrInvalidQuery.into());
244
+ }
245
+
246
+ var proto ProtoType
247
+ if rawProto := qArgs.Get("transport"); rawProto != "" {
248
+ if proto = NewProtoType(rawProto); proto == ProtoType(0) {
249
+ return ProtoType(Unknown), ErrProtoType
250
+ }
251
+ return proto, nil
252
+ }
253
+
254
+ if len(qArgs) > 0 {
255
+ return ProtoType(Unknown), ErrInvalidQuery
256
+ }
257
+
258
+ return proto, nil
259
+ }*/
260
+
261
+ /// Returns whether the this URL's scheme describes secure scheme or not.
262
+ #[must_use]
263
+ pub fn is_secure(&self) -> bool {
264
+ self.scheme == SchemeType::Stuns || self.scheme == SchemeType::Turns
265
+ }
266
+ }
@@ -0,0 +1,142 @@
1
+ use super::*;
2
+
3
+ #[test]
4
+ fn test_parse_url_success() -> Result<()> {
5
+ let tests = vec![
6
+ (
7
+ "stun:google.de",
8
+ "stun:google.de:3478",
9
+ SchemeType::Stun,
10
+ false,
11
+ "google.de",
12
+ 3478,
13
+ ProtoType::Udp,
14
+ ),
15
+ (
16
+ "stun:google.de:1234",
17
+ "stun:google.de:1234",
18
+ SchemeType::Stun,
19
+ false,
20
+ "google.de",
21
+ 1234,
22
+ ProtoType::Udp,
23
+ ),
24
+ (
25
+ "stuns:google.de",
26
+ "stuns:google.de:5349",
27
+ SchemeType::Stuns,
28
+ true,
29
+ "google.de",
30
+ 5349,
31
+ ProtoType::Tcp,
32
+ ),
33
+ (
34
+ "stun:[::1]:123",
35
+ "stun:[::1]:123",
36
+ SchemeType::Stun,
37
+ false,
38
+ "::1",
39
+ 123,
40
+ ProtoType::Udp,
41
+ ),
42
+ (
43
+ "turn:google.de",
44
+ "turn:google.de:3478?transport=udp",
45
+ SchemeType::Turn,
46
+ false,
47
+ "google.de",
48
+ 3478,
49
+ ProtoType::Udp,
50
+ ),
51
+ (
52
+ "turns:google.de",
53
+ "turns:google.de:5349?transport=tcp",
54
+ SchemeType::Turns,
55
+ true,
56
+ "google.de",
57
+ 5349,
58
+ ProtoType::Tcp,
59
+ ),
60
+ (
61
+ "turn:google.de?transport=udp",
62
+ "turn:google.de:3478?transport=udp",
63
+ SchemeType::Turn,
64
+ false,
65
+ "google.de",
66
+ 3478,
67
+ ProtoType::Udp,
68
+ ),
69
+ (
70
+ "turns:google.de?transport=tcp",
71
+ "turns:google.de:5349?transport=tcp",
72
+ SchemeType::Turns,
73
+ true,
74
+ "google.de",
75
+ 5349,
76
+ ProtoType::Tcp,
77
+ ),
78
+ ];
79
+
80
+ for (
81
+ raw_url,
82
+ expected_url_string,
83
+ expected_scheme,
84
+ expected_secure,
85
+ expected_host,
86
+ expected_port,
87
+ expected_proto,
88
+ ) in tests
89
+ {
90
+ let url = Url::parse_url(raw_url)?;
91
+
92
+ assert_eq!(url.scheme, expected_scheme, "testCase: {raw_url:?}");
93
+ assert_eq!(
94
+ expected_url_string,
95
+ url.to_string(),
96
+ "testCase: {raw_url:?}"
97
+ );
98
+ assert_eq!(url.is_secure(), expected_secure, "testCase: {raw_url:?}");
99
+ assert_eq!(url.host, expected_host, "testCase: {raw_url:?}");
100
+ assert_eq!(url.port, expected_port, "testCase: {raw_url:?}");
101
+ assert_eq!(url.proto, expected_proto, "testCase: {raw_url:?}");
102
+ }
103
+
104
+ Ok(())
105
+ }
106
+
107
+ #[test]
108
+ fn test_parse_url_failure() -> Result<()> {
109
+ let tests = vec![
110
+ ("", Error::ErrSchemeType),
111
+ (":::", Error::ErrUrlParse),
112
+ ("stun:[::1]:123:", Error::ErrPort),
113
+ ("stun:[::1]:123a", Error::ErrPort),
114
+ ("google.de", Error::ErrSchemeType),
115
+ ("stun:", Error::ErrHost),
116
+ ("stun:google.de:abc", Error::ErrPort),
117
+ ("stun:google.de?transport=udp", Error::ErrStunQuery),
118
+ ("stuns:google.de?transport=udp", Error::ErrStunQuery),
119
+ ("turn:google.de?trans=udp", Error::ErrInvalidQuery),
120
+ ("turns:google.de?trans=udp", Error::ErrInvalidQuery),
121
+ (
122
+ "turns:google.de?transport=udp&another=1",
123
+ Error::ErrInvalidQuery,
124
+ ),
125
+ ("turn:google.de?transport=ip", Error::ErrProtoType),
126
+ ];
127
+
128
+ for (raw_url, expected_err) in tests {
129
+ let result = Url::parse_url(raw_url);
130
+ if let Err(err) = result {
131
+ assert_eq!(
132
+ err.to_string(),
133
+ expected_err.to_string(),
134
+ "testCase: '{raw_url}', expected err '{expected_err}', but got err '{err}'"
135
+ );
136
+ } else {
137
+ panic!("expected error, but got ok");
138
+ }
139
+ }
140
+
141
+ Ok(())
142
+ }
package/package.json CHANGED
@@ -1,7 +1,12 @@
1
1
  {
2
2
  "name": "@desklink/host",
3
- "version": "0.5.3",
3
+ "version": "0.5.6",
4
4
  "license": "Apache-2.0",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/umeranjum17/desklink.git",
8
+ "directory": "packages/desktop-host"
9
+ },
5
10
  "description": "Per-user, on-demand desktop capture, encode and input engine with a versioned local control protocol",
6
11
  "type": "module",
7
12
  "main": "./dist/index.js",
@@ -33,7 +38,7 @@
33
38
  "ws": "8.21.3"
34
39
  },
35
40
  "optionalDependencies": {
36
- "@desklink/host-linux-x64-gnu": "0.5.3",
37
- "@desklink/host-darwin-arm64": "0.5.3"
41
+ "@desklink/host-linux-x64-gnu": "0.5.6",
42
+ "@desklink/host-darwin-arm64": "0.5.6"
38
43
  }
39
44
  }