diff options
-rw-r--r-- | Cargo.lock | 308 | ||||
-rw-r--r-- | Cargo.toml | 4 | ||||
-rw-r--r-- | src/main.rs | 48 | ||||
-rw-r--r-- | src/requests/device.rs | 42 | ||||
-rw-r--r-- | src/requests/start.rs | 73 | ||||
-rw-r--r-- | webol-cli.toml | 2 |
6 files changed, 404 insertions, 73 deletions
@@ -63,7 +63,7 @@ version = "1.0.0" | |||
63 | source = "registry+https://github.com/rust-lang/crates.io-index" | 63 | source = "registry+https://github.com/rust-lang/crates.io-index" |
64 | checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b" | 64 | checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b" |
65 | dependencies = [ | 65 | dependencies = [ |
66 | "windows-sys", | 66 | "windows-sys 0.48.0", |
67 | ] | 67 | ] |
68 | 68 | ||
69 | [[package]] | 69 | [[package]] |
@@ -73,7 +73,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
73 | checksum = "f0699d10d2f4d628a98ee7b57b289abbc98ff3bad977cb3152709d4bf2330628" | 73 | checksum = "f0699d10d2f4d628a98ee7b57b289abbc98ff3bad977cb3152709d4bf2330628" |
74 | dependencies = [ | 74 | dependencies = [ |
75 | "anstyle", | 75 | "anstyle", |
76 | "windows-sys", | 76 | "windows-sys 0.48.0", |
77 | ] | 77 | ] |
78 | 78 | ||
79 | [[package]] | 79 | [[package]] |
@@ -148,6 +148,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
148 | checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec" | 148 | checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec" |
149 | 149 | ||
150 | [[package]] | 150 | [[package]] |
151 | name = "byteorder" | ||
152 | version = "1.5.0" | ||
153 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
154 | checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" | ||
155 | |||
156 | [[package]] | ||
151 | name = "bytes" | 157 | name = "bytes" |
152 | version = "1.5.0" | 158 | version = "1.5.0" |
153 | source = "registry+https://github.com/rust-lang/crates.io-index" | 159 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -234,6 +240,19 @@ dependencies = [ | |||
234 | ] | 240 | ] |
235 | 241 | ||
236 | [[package]] | 242 | [[package]] |
243 | name = "console" | ||
244 | version = "0.15.7" | ||
245 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
246 | checksum = "c926e00cc70edefdc64d3a5ff31cc65bb97a3460097762bd23afb4d8145fccf8" | ||
247 | dependencies = [ | ||
248 | "encode_unicode", | ||
249 | "lazy_static", | ||
250 | "libc", | ||
251 | "unicode-width", | ||
252 | "windows-sys 0.45.0", | ||
253 | ] | ||
254 | |||
255 | [[package]] | ||
237 | name = "core-foundation" | 256 | name = "core-foundation" |
238 | version = "0.9.3" | 257 | version = "0.9.3" |
239 | source = "registry+https://github.com/rust-lang/crates.io-index" | 258 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -269,6 +288,12 @@ dependencies = [ | |||
269 | ] | 288 | ] |
270 | 289 | ||
271 | [[package]] | 290 | [[package]] |
291 | name = "data-encoding" | ||
292 | version = "2.4.0" | ||
293 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
294 | checksum = "c2e66c9d817f1720209181c316d28635c050fa304f9c79e47a520882661b7308" | ||
295 | |||
296 | [[package]] | ||
272 | name = "digest" | 297 | name = "digest" |
273 | version = "0.10.7" | 298 | version = "0.10.7" |
274 | source = "registry+https://github.com/rust-lang/crates.io-index" | 299 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -296,7 +321,7 @@ dependencies = [ | |||
296 | "libc", | 321 | "libc", |
297 | "option-ext", | 322 | "option-ext", |
298 | "redox_users", | 323 | "redox_users", |
299 | "windows-sys", | 324 | "windows-sys 0.48.0", |
300 | ] | 325 | ] |
301 | 326 | ||
302 | [[package]] | 327 | [[package]] |
@@ -306,6 +331,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
306 | checksum = "0688c2a7f92e427f44895cd63841bff7b29f8d7a1648b9e7e07a4a365b2e1257" | 331 | checksum = "0688c2a7f92e427f44895cd63841bff7b29f8d7a1648b9e7e07a4a365b2e1257" |
307 | 332 | ||
308 | [[package]] | 333 | [[package]] |
334 | name = "encode_unicode" | ||
335 | version = "0.3.6" | ||
336 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
337 | checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" | ||
338 | |||
339 | [[package]] | ||
309 | name = "encoding_rs" | 340 | name = "encoding_rs" |
310 | version = "0.8.33" | 341 | version = "0.8.33" |
311 | source = "registry+https://github.com/rust-lang/crates.io-index" | 342 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -321,7 +352,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
321 | checksum = "ac3e13f66a2f95e32a39eaa81f6b95d42878ca0e1db0c7543723dfe12557e860" | 352 | checksum = "ac3e13f66a2f95e32a39eaa81f6b95d42878ca0e1db0c7543723dfe12557e860" |
322 | dependencies = [ | 353 | dependencies = [ |
323 | "libc", | 354 | "libc", |
324 | "windows-sys", | 355 | "windows-sys 0.48.0", |
325 | ] | 356 | ] |
326 | 357 | ||
327 | [[package]] | 358 | [[package]] |
@@ -371,36 +402,49 @@ dependencies = [ | |||
371 | 402 | ||
372 | [[package]] | 403 | [[package]] |
373 | name = "futures-core" | 404 | name = "futures-core" |
374 | version = "0.3.28" | 405 | version = "0.3.29" |
375 | source = "registry+https://github.com/rust-lang/crates.io-index" | 406 | source = "registry+https://github.com/rust-lang/crates.io-index" |
376 | checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c" | 407 | checksum = "eb1d22c66e66d9d72e1758f0bd7d4fd0bee04cad842ee34587d68c07e45d088c" |
377 | 408 | ||
378 | [[package]] | 409 | [[package]] |
379 | name = "futures-io" | 410 | name = "futures-io" |
380 | version = "0.3.28" | 411 | version = "0.3.29" |
381 | source = "registry+https://github.com/rust-lang/crates.io-index" | 412 | source = "registry+https://github.com/rust-lang/crates.io-index" |
382 | checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964" | 413 | checksum = "8bf34a163b5c4c52d0478a4d757da8fb65cabef42ba90515efee0f6f9fa45aaa" |
414 | |||
415 | [[package]] | ||
416 | name = "futures-macro" | ||
417 | version = "0.3.29" | ||
418 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
419 | checksum = "53b153fd91e4b0147f4aced87be237c98248656bb01050b96bf3ee89220a8ddb" | ||
420 | dependencies = [ | ||
421 | "proc-macro2", | ||
422 | "quote", | ||
423 | "syn", | ||
424 | ] | ||
383 | 425 | ||
384 | [[package]] | 426 | [[package]] |
385 | name = "futures-sink" | 427 | name = "futures-sink" |
386 | version = "0.3.28" | 428 | version = "0.3.29" |
387 | source = "registry+https://github.com/rust-lang/crates.io-index" | 429 | source = "registry+https://github.com/rust-lang/crates.io-index" |
388 | checksum = "f43be4fe21a13b9781a69afa4985b0f6ee0e1afab2c6f454a8cf30e2b2237b6e" | 430 | checksum = "e36d3378ee38c2a36ad710c5d30c2911d752cb941c00c72dbabfb786a7970817" |
389 | 431 | ||
390 | [[package]] | 432 | [[package]] |
391 | name = "futures-task" | 433 | name = "futures-task" |
392 | version = "0.3.28" | 434 | version = "0.3.29" |
393 | source = "registry+https://github.com/rust-lang/crates.io-index" | 435 | source = "registry+https://github.com/rust-lang/crates.io-index" |
394 | checksum = "76d3d132be6c0e6aa1534069c705a74a5997a356c0dc2f86a47765e5617c5b65" | 436 | checksum = "efd193069b0ddadc69c46389b740bbccdd97203899b48d09c5f7969591d6bae2" |
395 | 437 | ||
396 | [[package]] | 438 | [[package]] |
397 | name = "futures-util" | 439 | name = "futures-util" |
398 | version = "0.3.28" | 440 | version = "0.3.29" |
399 | source = "registry+https://github.com/rust-lang/crates.io-index" | 441 | source = "registry+https://github.com/rust-lang/crates.io-index" |
400 | checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533" | 442 | checksum = "a19526d624e703a3179b3d322efec918b6246ea0fa51d41124525f00f1cc8104" |
401 | dependencies = [ | 443 | dependencies = [ |
402 | "futures-core", | 444 | "futures-core", |
403 | "futures-io", | 445 | "futures-io", |
446 | "futures-macro", | ||
447 | "futures-sink", | ||
404 | "futures-task", | 448 | "futures-task", |
405 | "memchr", | 449 | "memchr", |
406 | "pin-project-lite", | 450 | "pin-project-lite", |
@@ -567,6 +611,28 @@ dependencies = [ | |||
567 | ] | 611 | ] |
568 | 612 | ||
569 | [[package]] | 613 | [[package]] |
614 | name = "indicatif" | ||
615 | version = "0.17.7" | ||
616 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
617 | checksum = "fb28741c9db9a713d93deb3bb9515c20788cef5815265bee4980e87bde7e0f25" | ||
618 | dependencies = [ | ||
619 | "console", | ||
620 | "instant", | ||
621 | "number_prefix", | ||
622 | "portable-atomic", | ||
623 | "unicode-width", | ||
624 | ] | ||
625 | |||
626 | [[package]] | ||
627 | name = "instant" | ||
628 | version = "0.1.12" | ||
629 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
630 | checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" | ||
631 | dependencies = [ | ||
632 | "cfg-if", | ||
633 | ] | ||
634 | |||
635 | [[package]] | ||
570 | name = "ipnet" | 636 | name = "ipnet" |
571 | version = "2.8.0" | 637 | version = "2.8.0" |
572 | source = "registry+https://github.com/rust-lang/crates.io-index" | 638 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -663,7 +729,7 @@ checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2" | |||
663 | dependencies = [ | 729 | dependencies = [ |
664 | "libc", | 730 | "libc", |
665 | "wasi", | 731 | "wasi", |
666 | "windows-sys", | 732 | "windows-sys 0.48.0", |
667 | ] | 733 | ] |
668 | 734 | ||
669 | [[package]] | 735 | [[package]] |
@@ -705,6 +771,12 @@ dependencies = [ | |||
705 | ] | 771 | ] |
706 | 772 | ||
707 | [[package]] | 773 | [[package]] |
774 | name = "number_prefix" | ||
775 | version = "0.4.0" | ||
776 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
777 | checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3" | ||
778 | |||
779 | [[package]] | ||
708 | name = "object" | 780 | name = "object" |
709 | version = "0.32.1" | 781 | version = "0.32.1" |
710 | source = "registry+https://github.com/rust-lang/crates.io-index" | 782 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -855,6 +927,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
855 | checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" | 927 | checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" |
856 | 928 | ||
857 | [[package]] | 929 | [[package]] |
930 | name = "portable-atomic" | ||
931 | version = "1.5.1" | ||
932 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
933 | checksum = "3bccab0e7fd7cc19f820a1c8c91720af652d0c88dc9664dd72aef2614f04af3b" | ||
934 | |||
935 | [[package]] | ||
936 | name = "ppv-lite86" | ||
937 | version = "0.2.17" | ||
938 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
939 | checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" | ||
940 | |||
941 | [[package]] | ||
858 | name = "proc-macro2" | 942 | name = "proc-macro2" |
859 | version = "1.0.69" | 943 | version = "1.0.69" |
860 | source = "registry+https://github.com/rust-lang/crates.io-index" | 944 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -873,6 +957,36 @@ dependencies = [ | |||
873 | ] | 957 | ] |
874 | 958 | ||
875 | [[package]] | 959 | [[package]] |
960 | name = "rand" | ||
961 | version = "0.8.5" | ||
962 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
963 | checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" | ||
964 | dependencies = [ | ||
965 | "libc", | ||
966 | "rand_chacha", | ||
967 | "rand_core", | ||
968 | ] | ||
969 | |||
970 | [[package]] | ||
971 | name = "rand_chacha" | ||
972 | version = "0.3.1" | ||
973 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
974 | checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" | ||
975 | dependencies = [ | ||
976 | "ppv-lite86", | ||
977 | "rand_core", | ||
978 | ] | ||
979 | |||
980 | [[package]] | ||
981 | name = "rand_core" | ||
982 | version = "0.6.4" | ||
983 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
984 | checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" | ||
985 | dependencies = [ | ||
986 | "getrandom", | ||
987 | ] | ||
988 | |||
989 | [[package]] | ||
876 | name = "redox_syscall" | 990 | name = "redox_syscall" |
877 | version = "0.2.16" | 991 | version = "0.2.16" |
878 | source = "registry+https://github.com/rust-lang/crates.io-index" | 992 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -976,7 +1090,7 @@ dependencies = [ | |||
976 | "errno", | 1090 | "errno", |
977 | "libc", | 1091 | "libc", |
978 | "linux-raw-sys", | 1092 | "linux-raw-sys", |
979 | "windows-sys", | 1093 | "windows-sys 0.48.0", |
980 | ] | 1094 | ] |
981 | 1095 | ||
982 | [[package]] | 1096 | [[package]] |
@@ -991,7 +1105,7 @@ version = "0.1.22" | |||
991 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1105 | source = "registry+https://github.com/rust-lang/crates.io-index" |
992 | checksum = "0c3733bf4cf7ea0880754e19cb5a462007c4a8c1914bff372ccc95b464f1df88" | 1106 | checksum = "0c3733bf4cf7ea0880754e19cb5a462007c4a8c1914bff372ccc95b464f1df88" |
993 | dependencies = [ | 1107 | dependencies = [ |
994 | "windows-sys", | 1108 | "windows-sys 0.48.0", |
995 | ] | 1109 | ] |
996 | 1110 | ||
997 | [[package]] | 1111 | [[package]] |
@@ -1061,6 +1175,17 @@ dependencies = [ | |||
1061 | ] | 1175 | ] |
1062 | 1176 | ||
1063 | [[package]] | 1177 | [[package]] |
1178 | name = "sha1" | ||
1179 | version = "0.10.6" | ||
1180 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1181 | checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" | ||
1182 | dependencies = [ | ||
1183 | "cfg-if", | ||
1184 | "cpufeatures", | ||
1185 | "digest", | ||
1186 | ] | ||
1187 | |||
1188 | [[package]] | ||
1064 | name = "sha2" | 1189 | name = "sha2" |
1065 | version = "0.10.8" | 1190 | version = "0.10.8" |
1066 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1191 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -1097,7 +1222,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
1097 | checksum = "7b5fac59a5cb5dd637972e5fca70daf0523c9067fcdc4842f053dae04a18f8e9" | 1222 | checksum = "7b5fac59a5cb5dd637972e5fca70daf0523c9067fcdc4842f053dae04a18f8e9" |
1098 | dependencies = [ | 1223 | dependencies = [ |
1099 | "libc", | 1224 | "libc", |
1100 | "windows-sys", | 1225 | "windows-sys 0.48.0", |
1101 | ] | 1226 | ] |
1102 | 1227 | ||
1103 | [[package]] | 1228 | [[package]] |
@@ -1148,7 +1273,7 @@ dependencies = [ | |||
1148 | "fastrand", | 1273 | "fastrand", |
1149 | "redox_syscall 0.3.5", | 1274 | "redox_syscall 0.3.5", |
1150 | "rustix", | 1275 | "rustix", |
1151 | "windows-sys", | 1276 | "windows-sys 0.48.0", |
1152 | ] | 1277 | ] |
1153 | 1278 | ||
1154 | [[package]] | 1279 | [[package]] |
@@ -1199,7 +1324,19 @@ dependencies = [ | |||
1199 | "num_cpus", | 1324 | "num_cpus", |
1200 | "pin-project-lite", | 1325 | "pin-project-lite", |
1201 | "socket2 0.5.5", | 1326 | "socket2 0.5.5", |
1202 | "windows-sys", | 1327 | "tokio-macros", |
1328 | "windows-sys 0.48.0", | ||
1329 | ] | ||
1330 | |||
1331 | [[package]] | ||
1332 | name = "tokio-macros" | ||
1333 | version = "2.1.0" | ||
1334 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1335 | checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" | ||
1336 | dependencies = [ | ||
1337 | "proc-macro2", | ||
1338 | "quote", | ||
1339 | "syn", | ||
1203 | ] | 1340 | ] |
1204 | 1341 | ||
1205 | [[package]] | 1342 | [[package]] |
@@ -1213,6 +1350,18 @@ dependencies = [ | |||
1213 | ] | 1350 | ] |
1214 | 1351 | ||
1215 | [[package]] | 1352 | [[package]] |
1353 | name = "tokio-tungstenite" | ||
1354 | version = "0.20.1" | ||
1355 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1356 | checksum = "212d5dcb2a1ce06d81107c3d0ffa3121fe974b73f068c8282cb1c32328113b6c" | ||
1357 | dependencies = [ | ||
1358 | "futures-util", | ||
1359 | "log", | ||
1360 | "tokio", | ||
1361 | "tungstenite", | ||
1362 | ] | ||
1363 | |||
1364 | [[package]] | ||
1216 | name = "tokio-util" | 1365 | name = "tokio-util" |
1217 | version = "0.7.9" | 1366 | version = "0.7.9" |
1218 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1367 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -1267,6 +1416,25 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
1267 | checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" | 1416 | checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" |
1268 | 1417 | ||
1269 | [[package]] | 1418 | [[package]] |
1419 | name = "tungstenite" | ||
1420 | version = "0.20.1" | ||
1421 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1422 | checksum = "9e3dac10fd62eaf6617d3a904ae222845979aec67c615d1c842b4002c7666fb9" | ||
1423 | dependencies = [ | ||
1424 | "byteorder", | ||
1425 | "bytes", | ||
1426 | "data-encoding", | ||
1427 | "http", | ||
1428 | "httparse", | ||
1429 | "log", | ||
1430 | "rand", | ||
1431 | "sha1", | ||
1432 | "thiserror", | ||
1433 | "url", | ||
1434 | "utf-8", | ||
1435 | ] | ||
1436 | |||
1437 | [[package]] | ||
1270 | name = "typenum" | 1438 | name = "typenum" |
1271 | version = "1.17.0" | 1439 | version = "1.17.0" |
1272 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1440 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -1300,6 +1468,12 @@ dependencies = [ | |||
1300 | ] | 1468 | ] |
1301 | 1469 | ||
1302 | [[package]] | 1470 | [[package]] |
1471 | name = "unicode-width" | ||
1472 | version = "0.1.11" | ||
1473 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1474 | checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85" | ||
1475 | |||
1476 | [[package]] | ||
1303 | name = "url" | 1477 | name = "url" |
1304 | version = "2.4.1" | 1478 | version = "2.4.1" |
1305 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1479 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -1311,6 +1485,12 @@ dependencies = [ | |||
1311 | ] | 1485 | ] |
1312 | 1486 | ||
1313 | [[package]] | 1487 | [[package]] |
1488 | name = "utf-8" | ||
1489 | version = "0.7.6" | ||
1490 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1491 | checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" | ||
1492 | |||
1493 | [[package]] | ||
1314 | name = "utf8parse" | 1494 | name = "utf8parse" |
1315 | version = "0.2.1" | 1495 | version = "0.2.1" |
1316 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1496 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -1426,10 +1606,14 @@ dependencies = [ | |||
1426 | "clap", | 1606 | "clap", |
1427 | "config", | 1607 | "config", |
1428 | "dirs", | 1608 | "dirs", |
1609 | "futures-util", | ||
1610 | "indicatif", | ||
1429 | "once_cell", | 1611 | "once_cell", |
1430 | "reqwest", | 1612 | "reqwest", |
1431 | "serde", | 1613 | "serde", |
1432 | "serde_json", | 1614 | "serde_json", |
1615 | "tokio", | ||
1616 | "tokio-tungstenite", | ||
1433 | ] | 1617 | ] |
1434 | 1618 | ||
1435 | [[package]] | 1619 | [[package]] |
@@ -1456,11 +1640,35 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" | |||
1456 | 1640 | ||
1457 | [[package]] | 1641 | [[package]] |
1458 | name = "windows-sys" | 1642 | name = "windows-sys" |
1643 | version = "0.45.0" | ||
1644 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1645 | checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" | ||
1646 | dependencies = [ | ||
1647 | "windows-targets 0.42.2", | ||
1648 | ] | ||
1649 | |||
1650 | [[package]] | ||
1651 | name = "windows-sys" | ||
1459 | version = "0.48.0" | 1652 | version = "0.48.0" |
1460 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1653 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1461 | checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" | 1654 | checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" |
1462 | dependencies = [ | 1655 | dependencies = [ |
1463 | "windows-targets", | 1656 | "windows-targets 0.48.5", |
1657 | ] | ||
1658 | |||
1659 | [[package]] | ||
1660 | name = "windows-targets" | ||
1661 | version = "0.42.2" | ||
1662 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1663 | checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" | ||
1664 | dependencies = [ | ||
1665 | "windows_aarch64_gnullvm 0.42.2", | ||
1666 | "windows_aarch64_msvc 0.42.2", | ||
1667 | "windows_i686_gnu 0.42.2", | ||
1668 | "windows_i686_msvc 0.42.2", | ||
1669 | "windows_x86_64_gnu 0.42.2", | ||
1670 | "windows_x86_64_gnullvm 0.42.2", | ||
1671 | "windows_x86_64_msvc 0.42.2", | ||
1464 | ] | 1672 | ] |
1465 | 1673 | ||
1466 | [[package]] | 1674 | [[package]] |
@@ -1469,53 +1677,95 @@ version = "0.48.5" | |||
1469 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1677 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1470 | checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" | 1678 | checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" |
1471 | dependencies = [ | 1679 | dependencies = [ |
1472 | "windows_aarch64_gnullvm", | 1680 | "windows_aarch64_gnullvm 0.48.5", |
1473 | "windows_aarch64_msvc", | 1681 | "windows_aarch64_msvc 0.48.5", |
1474 | "windows_i686_gnu", | 1682 | "windows_i686_gnu 0.48.5", |
1475 | "windows_i686_msvc", | 1683 | "windows_i686_msvc 0.48.5", |
1476 | "windows_x86_64_gnu", | 1684 | "windows_x86_64_gnu 0.48.5", |
1477 | "windows_x86_64_gnullvm", | 1685 | "windows_x86_64_gnullvm 0.48.5", |
1478 | "windows_x86_64_msvc", | 1686 | "windows_x86_64_msvc 0.48.5", |
1479 | ] | 1687 | ] |
1480 | 1688 | ||
1481 | [[package]] | 1689 | [[package]] |
1482 | name = "windows_aarch64_gnullvm" | 1690 | name = "windows_aarch64_gnullvm" |
1691 | version = "0.42.2" | ||
1692 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1693 | checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" | ||
1694 | |||
1695 | [[package]] | ||
1696 | name = "windows_aarch64_gnullvm" | ||
1483 | version = "0.48.5" | 1697 | version = "0.48.5" |
1484 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1698 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1485 | checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" | 1699 | checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" |
1486 | 1700 | ||
1487 | [[package]] | 1701 | [[package]] |
1488 | name = "windows_aarch64_msvc" | 1702 | name = "windows_aarch64_msvc" |
1703 | version = "0.42.2" | ||
1704 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1705 | checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" | ||
1706 | |||
1707 | [[package]] | ||
1708 | name = "windows_aarch64_msvc" | ||
1489 | version = "0.48.5" | 1709 | version = "0.48.5" |
1490 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1710 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1491 | checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" | 1711 | checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" |
1492 | 1712 | ||
1493 | [[package]] | 1713 | [[package]] |
1494 | name = "windows_i686_gnu" | 1714 | name = "windows_i686_gnu" |
1715 | version = "0.42.2" | ||
1716 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1717 | checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" | ||
1718 | |||
1719 | [[package]] | ||
1720 | name = "windows_i686_gnu" | ||
1495 | version = "0.48.5" | 1721 | version = "0.48.5" |
1496 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1722 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1497 | checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" | 1723 | checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" |
1498 | 1724 | ||
1499 | [[package]] | 1725 | [[package]] |
1500 | name = "windows_i686_msvc" | 1726 | name = "windows_i686_msvc" |
1727 | version = "0.42.2" | ||
1728 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1729 | checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" | ||
1730 | |||
1731 | [[package]] | ||
1732 | name = "windows_i686_msvc" | ||
1501 | version = "0.48.5" | 1733 | version = "0.48.5" |
1502 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1734 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1503 | checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" | 1735 | checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" |
1504 | 1736 | ||
1505 | [[package]] | 1737 | [[package]] |
1506 | name = "windows_x86_64_gnu" | 1738 | name = "windows_x86_64_gnu" |
1739 | version = "0.42.2" | ||
1740 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1741 | checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" | ||
1742 | |||
1743 | [[package]] | ||
1744 | name = "windows_x86_64_gnu" | ||
1507 | version = "0.48.5" | 1745 | version = "0.48.5" |
1508 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1746 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1509 | checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" | 1747 | checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" |
1510 | 1748 | ||
1511 | [[package]] | 1749 | [[package]] |
1512 | name = "windows_x86_64_gnullvm" | 1750 | name = "windows_x86_64_gnullvm" |
1751 | version = "0.42.2" | ||
1752 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1753 | checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" | ||
1754 | |||
1755 | [[package]] | ||
1756 | name = "windows_x86_64_gnullvm" | ||
1513 | version = "0.48.5" | 1757 | version = "0.48.5" |
1514 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1758 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1515 | checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" | 1759 | checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" |
1516 | 1760 | ||
1517 | [[package]] | 1761 | [[package]] |
1518 | name = "windows_x86_64_msvc" | 1762 | name = "windows_x86_64_msvc" |
1763 | version = "0.42.2" | ||
1764 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1765 | checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" | ||
1766 | |||
1767 | [[package]] | ||
1768 | name = "windows_x86_64_msvc" | ||
1519 | version = "0.48.5" | 1769 | version = "0.48.5" |
1520 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1770 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1521 | checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" | 1771 | checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" |
@@ -1527,7 +1777,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
1527 | checksum = "524e57b2c537c0f9b1e69f1965311ec12182b4122e45035b1508cd24d2adadb1" | 1777 | checksum = "524e57b2c537c0f9b1e69f1965311ec12182b4122e45035b1508cd24d2adadb1" |
1528 | dependencies = [ | 1778 | dependencies = [ |
1529 | "cfg-if", | 1779 | "cfg-if", |
1530 | "windows-sys", | 1780 | "windows-sys 0.48.0", |
1531 | ] | 1781 | ] |
1532 | 1782 | ||
1533 | [[package]] | 1783 | [[package]] |
@@ -13,7 +13,11 @@ path = "src/main.rs" | |||
13 | clap = { version = "4.4.6", features = ["derive"] } | 13 | clap = { version = "4.4.6", features = ["derive"] } |
14 | config = "0.13.3" | 14 | config = "0.13.3" |
15 | dirs = "5.0.1" | 15 | dirs = "5.0.1" |
16 | futures-util = "0.3.29" | ||
17 | indicatif = "0.17.7" | ||
16 | once_cell = "1.18.0" | 18 | once_cell = "1.18.0" |
17 | reqwest = { version = "0.11.22", features = ["blocking"] } | 19 | reqwest = { version = "0.11.22", features = ["blocking"] } |
18 | serde = "1.0.189" | 20 | serde = "1.0.189" |
19 | serde_json = "1.0.107" | 21 | serde_json = "1.0.107" |
22 | tokio = { version = "1.33.0", features = ["macros", "rt-multi-thread", "io-std"] } | ||
23 | tokio-tungstenite = "0.20.1" | ||
diff --git a/src/main.rs b/src/main.rs index ab7e476..3e1388b 100644 --- a/src/main.rs +++ b/src/main.rs | |||
@@ -1,3 +1,5 @@ | |||
1 | use std::fmt::Display; | ||
2 | |||
1 | use clap::{Parser, Subcommand}; | 3 | use clap::{Parser, Subcommand}; |
2 | use config::SETTINGS; | 4 | use config::SETTINGS; |
3 | use error::CliError; | 5 | use error::CliError; |
@@ -21,7 +23,9 @@ struct Args { | |||
21 | enum Commands { | 23 | enum Commands { |
22 | Start { | 24 | Start { |
23 | /// id of the device | 25 | /// id of the device |
24 | id: String | 26 | id: String, |
27 | #[arg(short, long)] | ||
28 | ping: Option<bool> | ||
25 | }, | 29 | }, |
26 | Device { | 30 | Device { |
27 | #[command(subcommand)] | 31 | #[command(subcommand)] |
@@ -34,7 +38,8 @@ enum DeviceCmd { | |||
34 | Add { | 38 | Add { |
35 | id: String, | 39 | id: String, |
36 | mac: String, | 40 | mac: String, |
37 | broadcast_addr: String | 41 | broadcast_addr: String, |
42 | ip: String | ||
38 | }, | 43 | }, |
39 | Get { | 44 | Get { |
40 | id: String, | 45 | id: String, |
@@ -42,27 +47,29 @@ enum DeviceCmd { | |||
42 | Edit { | 47 | Edit { |
43 | id: String, | 48 | id: String, |
44 | mac: String, | 49 | mac: String, |
45 | broadcast_addr: String | 50 | broadcast_addr: String, |
51 | ip: String | ||
46 | }, | 52 | }, |
47 | } | 53 | } |
48 | 54 | ||
49 | fn main() -> Result<(), CliError> { | 55 | #[tokio::main] |
56 | async fn main() -> Result<(), CliError> { | ||
50 | let cli = Args::parse(); | 57 | let cli = Args::parse(); |
51 | 58 | ||
52 | match cli.commands { | 59 | match cli.commands { |
53 | Commands::Start { id } => { | 60 | Commands::Start { id, ping } => { |
54 | start(id)?; | 61 | start(id, ping.unwrap_or(true)).await?; |
55 | }, | 62 | }, |
56 | Commands::Device { devicecmd } => { | 63 | Commands::Device { devicecmd } => { |
57 | match devicecmd { | 64 | match devicecmd { |
58 | DeviceCmd::Add { id, mac, broadcast_addr } => { | 65 | DeviceCmd::Add { id, mac, broadcast_addr, ip } => { |
59 | device::put(id, mac, broadcast_addr)?; | 66 | device::put(id, mac, broadcast_addr, ip).await?; |
60 | }, | 67 | }, |
61 | DeviceCmd::Get { id } => { | 68 | DeviceCmd::Get { id } => { |
62 | device::get(id)?; | 69 | device::get(id).await?; |
63 | }, | 70 | }, |
64 | DeviceCmd::Edit { id, mac, broadcast_addr } => { | 71 | DeviceCmd::Edit { id, mac, broadcast_addr, ip } => { |
65 | device::post(id, mac, broadcast_addr)?; | 72 | device::post(id, mac, broadcast_addr, ip).await?; |
66 | }, | 73 | }, |
67 | } | 74 | } |
68 | } | 75 | } |
@@ -87,14 +94,29 @@ fn default_headers() -> Result<HeaderMap, CliError> { | |||
87 | Ok(map) | 94 | Ok(map) |
88 | } | 95 | } |
89 | 96 | ||
90 | fn format_url(path: &str) -> Result<String, CliError> { | 97 | fn format_url(path: &str, protocol: Protocols) -> Result<String, CliError> { |
91 | Ok(format!( | 98 | Ok(format!( |
92 | "{}/{}", | 99 | "{}://{}/{}", |
100 | protocol, | ||
93 | SETTINGS.get_string("server").map_err(CliError::Config)?, | 101 | SETTINGS.get_string("server").map_err(CliError::Config)?, |
94 | path | 102 | path |
95 | )) | 103 | )) |
96 | } | 104 | } |
97 | 105 | ||
106 | enum Protocols { | ||
107 | Http, | ||
108 | Websocket, | ||
109 | } | ||
110 | |||
111 | impl Display for Protocols { | ||
112 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
113 | match self { | ||
114 | Self::Http => f.write_str("http"), | ||
115 | Self::Websocket => f.write_str("ws") | ||
116 | } | ||
117 | } | ||
118 | } | ||
119 | |||
98 | #[derive(Debug, Deserialize)] | 120 | #[derive(Debug, Deserialize)] |
99 | struct ErrorResponse { | 121 | struct ErrorResponse { |
100 | error: String | 122 | error: String |
diff --git a/src/requests/device.rs b/src/requests/device.rs index 525745a..f7754a4 100644 --- a/src/requests/device.rs +++ b/src/requests/device.rs | |||
@@ -1,55 +1,63 @@ | |||
1 | use crate::{error::CliError, default_headers, format_url}; | 1 | use crate::{error::CliError, default_headers, format_url, Protocols}; |
2 | 2 | ||
3 | pub fn put(id: String, mac: String, broadcast_addr: String) -> Result<(), CliError> { | 3 | pub async fn put(id: String, mac: String, broadcast_addr: String, ip: String) -> Result<(), CliError> { |
4 | let res = reqwest::blocking::Client::new() | 4 | let res = reqwest::Client::new() |
5 | .put(format_url("device")?) | 5 | .put(format_url("device", Protocols::Http)?) |
6 | .headers(default_headers()?) | 6 | .headers(default_headers()?) |
7 | .body( | 7 | .body( |
8 | format!( | 8 | format!( |
9 | r#"{{"id": "{}", "mac": "{}", "broadcast_addr": "{}"}}"#, | 9 | r#"{{"id": "{}", "mac": "{}", "broadcast_addr": "{}", "ip": "{}"}}"#, |
10 | id, | 10 | id, |
11 | mac, | 11 | mac, |
12 | broadcast_addr | 12 | broadcast_addr, |
13 | ip | ||
13 | ) | 14 | ) |
14 | ) | 15 | ) |
15 | .send() | 16 | .send() |
17 | .await | ||
16 | .map_err(CliError::Reqwest)? | 18 | .map_err(CliError::Reqwest)? |
17 | .text(); | 19 | .text() |
20 | .await; | ||
18 | 21 | ||
19 | println!("{:?}", res); | 22 | println!("{:?}", res); |
20 | Ok(()) | 23 | Ok(()) |
21 | } | 24 | } |
22 | 25 | ||
23 | pub fn get(id: String) -> Result<(), CliError> { | 26 | pub async fn get(id: String) -> Result<(), CliError> { |
24 | let res = reqwest::blocking::Client::new() | 27 | let res = reqwest::Client::new() |
25 | .get(format_url("device")?) | 28 | .get(format_url("device", Protocols::Http)?) |
26 | .headers(default_headers()?) | 29 | .headers(default_headers()?) |
27 | .body( | 30 | .body( |
28 | format!(r#"{{"id": "{}"}}"#, id) | 31 | format!(r#"{{"id": "{}"}}"#, id) |
29 | ) | 32 | ) |
30 | .send() | 33 | .send() |
34 | .await | ||
31 | .map_err(CliError::Reqwest)? | 35 | .map_err(CliError::Reqwest)? |
32 | .text(); | 36 | .text() |
37 | .await; | ||
33 | 38 | ||
34 | println!("{:?}", res); | 39 | println!("{:?}", res); |
35 | Ok(()) | 40 | Ok(()) |
36 | } | 41 | } |
37 | 42 | ||
38 | pub fn post(id: String, mac: String, broadcast_addr: String) -> Result<(), CliError> { | 43 | pub async fn post(id: String, mac: String, broadcast_addr: String, ip: String) -> Result<(), CliError> { |
39 | let res = reqwest::blocking::Client::new() | 44 | let res = reqwest::Client::new() |
40 | .post(format_url("device")?) | 45 | .post(format_url("device", Protocols::Http)?) |
41 | .headers(default_headers()?) | 46 | .headers(default_headers()?) |
42 | .body( | 47 | .body( |
43 | format!( | 48 | format!( |
44 | r#"{{"id": "{}", "mac": "{}", "broadcast_addr": "{}"}}"#, | 49 | r#"{{"id": "{}", "mac": "{}", "broadcast_addr": "{}", "ip": "{}"}}"#, |
45 | id, | 50 | id, |
46 | mac, | 51 | mac, |
47 | broadcast_addr | 52 | broadcast_addr, |
53 | ip | ||
48 | ) | 54 | ) |
49 | ) | 55 | ) |
50 | .send() | 56 | .send() |
57 | .await | ||
51 | .map_err(CliError::Reqwest)? | 58 | .map_err(CliError::Reqwest)? |
52 | .text(); | 59 | .text() |
60 | .await; | ||
53 | 61 | ||
54 | println!("{:?}", res); | 62 | println!("{:?}", res); |
55 | Ok(()) | 63 | Ok(()) |
diff --git a/src/requests/start.rs b/src/requests/start.rs index 30f65b9..d0c4411 100644 --- a/src/requests/start.rs +++ b/src/requests/start.rs | |||
@@ -1,37 +1,57 @@ | |||
1 | use std::time::Duration; | ||
2 | |||
3 | use futures_util::{StreamExt, SinkExt}; | ||
4 | use indicatif::{ProgressBar, ProgressStyle}; | ||
1 | use reqwest::StatusCode; | 5 | use reqwest::StatusCode; |
2 | use serde::Deserialize; | 6 | use serde::Deserialize; |
7 | use tokio_tungstenite::{connect_async, tungstenite::Message}; | ||
3 | 8 | ||
4 | use crate::{config::SETTINGS, error::CliError, default_headers, ErrorResponse}; | 9 | use crate::{error::CliError, default_headers, ErrorResponse, format_url, Protocols}; |
5 | 10 | ||
6 | pub fn start(id: String) -> Result<(), CliError> { | 11 | pub async fn start(id: String, ping: bool) -> Result<(), CliError> { |
7 | let res = reqwest::blocking::Client::new() | 12 | |
8 | .post( | 13 | let send_start = ProgressBar::new(1); |
9 | format!( | 14 | |
10 | "{}/start", | 15 | // TODO: calculate average start-time on server |
11 | SETTINGS.get_string("server").map_err(CliError::Config)? | 16 | send_start.set_style( |
12 | ) | 17 | ProgressStyle::with_template("{spinner:.green} ({elapsed}) {wide_msg}") |
13 | ) | 18 | .unwrap() |
19 | .tick_chars("|/-\\\\") | ||
20 | ); | ||
21 | |||
22 | let url = format_url("start", Protocols::Http)?; | ||
23 | |||
24 | send_start.set_message(format!("connect to {}", url)); | ||
25 | send_start.enable_steady_tick(Duration::from_millis(125)); | ||
26 | |||
27 | let res = reqwest::Client::new() | ||
28 | .post(url) | ||
14 | .headers(default_headers()?) | 29 | .headers(default_headers()?) |
15 | .body( | 30 | .body( |
16 | format!(r#"{{"id": "{}"}}"#, id) | 31 | format!(r#"{{"id": "{}", "ping": {}}}"#, id, ping) |
17 | ) | 32 | ) |
18 | .send() | 33 | .send() |
34 | .await | ||
19 | .map_err(CliError::Reqwest)?; | 35 | .map_err(CliError::Reqwest)?; |
20 | 36 | ||
21 | match res.status() { | 37 | match res.status() { |
22 | StatusCode::OK => { | 38 | StatusCode::OK => { |
23 | let body = serde_json::from_str::<StartResponse>( | 39 | let body = serde_json::from_str::<StartResponse>( |
24 | &res.text().map_err(CliError::Reqwest)? | 40 | &res.text().await.map_err(CliError::Reqwest)? |
25 | ) | 41 | ) |
26 | .map_err(CliError::Serde)?; | 42 | .map_err(CliError::Serde)?; |
27 | 43 | ||
28 | if body.boot { | 44 | if body.boot { |
29 | println!("successfully started {}", body.id); | 45 | send_start.println("connected, sent start packet"); |
46 | } | ||
47 | |||
48 | if ping { | ||
49 | send_start.println(status_socket(body.uuid, &send_start).await?.to_string()); | ||
30 | } | 50 | } |
31 | }, | 51 | }, |
32 | _ => { | 52 | _ => { |
33 | let body = serde_json::from_str::<ErrorResponse>( | 53 | let body = serde_json::from_str::<ErrorResponse>( |
34 | &res.text().map_err(CliError::Reqwest)? | 54 | &res.text().await.map_err(CliError::Reqwest)? |
35 | ) | 55 | ) |
36 | .map_err(CliError::Serde)?; | 56 | .map_err(CliError::Serde)?; |
37 | 57 | ||
@@ -42,8 +62,35 @@ pub fn start(id: String) -> Result<(), CliError> { | |||
42 | Ok(()) | 62 | Ok(()) |
43 | } | 63 | } |
44 | 64 | ||
65 | async fn status_socket(uuid: String, pb: &ProgressBar) -> Result<bool, CliError> { | ||
66 | pb.set_message("setup websocket"); | ||
67 | |||
68 | let (mut ws_stream, _response) = connect_async(format_url("status", Protocols::Websocket)?) | ||
69 | .await | ||
70 | .expect("Failed to connect"); | ||
71 | pb.println("connected to websocket"); | ||
72 | |||
73 | pb.set_message("send uuid message"); | ||
74 | ws_stream.send(Message::Text(uuid)).await.unwrap(); | ||
75 | pb.println("sent uuid message"); | ||
76 | |||
77 | pb.set_message("wait for message"); | ||
78 | let msg = ws_stream.next().await.unwrap(); | ||
79 | |||
80 | pb.println(format!("msg: {:?}", msg)); | ||
81 | |||
82 | ws_stream.close(None).await.unwrap(); | ||
83 | pb.println("connection closed"); | ||
84 | // TODO: Check for correct UUID and timeout | ||
85 | pb.set_message("verifying message"); | ||
86 | if msg.is_ok() { return Ok(true) } | ||
87 | |||
88 | Ok(false) | ||
89 | } | ||
90 | |||
45 | #[derive(Debug, Deserialize)] | 91 | #[derive(Debug, Deserialize)] |
46 | struct StartResponse { | 92 | struct StartResponse { |
47 | boot: bool, | 93 | boot: bool, |
48 | id: String, | 94 | id: String, |
95 | uuid: String, | ||
49 | } | 96 | } |
diff --git a/webol-cli.toml b/webol-cli.toml index 3eabc97..7ffb99d 100644 --- a/webol-cli.toml +++ b/webol-cli.toml | |||
@@ -1,2 +1,2 @@ | |||
1 | server = "http://localhost:7229" | 1 | server = "192.168.178.28:7229" |
2 | key = "aaa" | 2 | key = "aaa" |