diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c72a277..997a138 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -38,6 +38,20 @@ jobs: - name: Cargo fmt run: cargo clippy -- -Dwarnings + wasm: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: ./tests/support/test_server/ + + - uses: dtolnay/rust-toolchain@master + with: + toolchain: ${{ env.TOOLCHAIN }} + targets: wasm32-unknown-unknown + + - name: Builb wasm + run: cargo build --target wasm32-unknown-unknown --no-default-features --features browser + apple_simulator_integration_tests: runs-on: macos-14 strategy: diff --git a/Cargo.lock b/Cargo.lock index 949066b..058a2c2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -43,9 +43,9 @@ dependencies = [ [[package]] name = "anstream" -version = "0.6.14" +version = "0.6.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "418c75fa768af9c03be99d17643f93f79bbba589895012a80e3452a19ddda15b" +checksum = "64e15c1ab1f89faffbf04a634d5e1962e9074f2741eef6d97f3c4e322426d526" dependencies = [ "anstyle", "anstyle-parse", @@ -58,36 +58,36 @@ dependencies = [ [[package]] name = "anstyle" -version = "1.0.7" +version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "038dfcf04a5feb68e9c60b21c9625a54c2c0616e79b72b0fd87075a056ae1d1b" +checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1" [[package]] name = "anstyle-parse" -version = "0.2.4" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c03a11a9034d92058ceb6ee011ce58af4a9bf61491aa7e1e59ecd24bd40d22d4" +checksum = "eb47de1e80c2b463c735db5b217a0ddc39d612e7ac9e2e96a5aed1f57616c1cb" dependencies = [ "utf8parse", ] [[package]] name = "anstyle-query" -version = "1.1.0" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad186efb764318d35165f1758e7dcef3b10628e26d41a44bc5550652e6804391" +checksum = "6d36fc52c7f6c869915e99412912f22093507da8d9e942ceaf66fe4b7c14422a" dependencies = [ - "windows-sys", + "windows-sys 0.52.0", ] [[package]] name = "anstyle-wincon" -version = "3.0.3" +version = "3.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61a38449feb7068f52bb06c12759005cf459ee52bb4adc1d5a7c4322d716fb19" +checksum = "5bf74e1b6e971609db8ca7a9ce79fd5768ab6ae46441c572e46cf596f59e57f8" dependencies = [ "anstyle", - "windows-sys", + "windows-sys 0.52.0", ] [[package]] @@ -156,6 +156,18 @@ dependencies = [ "tokio", ] +[[package]] +name = "async_io_stream" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6d7b9decdf35d8908a7e3ef02f64c5e9b1695e230154c0e8de3969142d9b94c" +dependencies = [ + "futures", + "pharos", + "rustc_version", + "tokio", +] + [[package]] name = "atomic-take" version = "1.1.0" @@ -176,7 +188,7 @@ checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" dependencies = [ "addr2line", "cc", - "cfg-if", + "cfg-if 1.0.0", "libc", "miniz_oxide", "object", @@ -230,15 +242,15 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.7.0" +version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fca2be1d5c43812bae364ee3f30b3afcb7877cf59f4aeb94c66f313a41d2fac9" +checksum = "8318a53db07bb3f8dca91a600466bdb3f2eaadeedfdbcf02e1accbad9271ba50" [[package]] name = "camino" -version = "1.1.7" +version = "1.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0ec6b951b160caa93cc0c7b209e5a3bff7aae9062213451ac99493cd844c239" +checksum = "8b96ec4966b5813e2c0507c1f86115c8c5abaadc3980879c3424042a02fd1ad3" dependencies = [ "serde", ] @@ -268,9 +280,18 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.104" +version = "1.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74b6a57f98764a267ff415d50a25e6e166f3831a5071af4995296ea97d210490" +checksum = "57b6a275aa2903740dc87da01c62040406b8812552e97129a63ea8850a17c6e6" +dependencies = [ + "shlex", +] + +[[package]] +name = "cfg-if" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" [[package]] name = "cfg-if" @@ -294,9 +315,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.8" +version = "4.5.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84b3edb18336f4df585bc9aa31dd99c036dfa5dc5e9a2939a722a188f3a8970d" +checksum = "ed6719fffa43d0d87e5fd8caeab59be1554fb028cd30edc88fc4369b17971019" dependencies = [ "clap_builder", "clap_derive", @@ -304,9 +325,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.8" +version = "4.5.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1c09dd5ada6c6c78075d6fd0da3f90d8080651e2d6cc8eb2f1aaa4034ced708" +checksum = "216aec2b177652e3846684cbfe25c9964d18ec45234f0f5da5157b207ed1aab6" dependencies = [ "anstream", "anstyle", @@ -316,9 +337,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.5.8" +version = "4.5.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bac35c6dafb060fd4d275d9a4ffae97917c13a6327903a8be2153cd964f7085" +checksum = "501d359d5f3dcaf6ecdeee48833ae73ec6e42723a1e52419c79abf9507eec0a0" dependencies = [ "heck", "proc-macro2", @@ -328,15 +349,15 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.7.1" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b82cf0babdbd58558212896d1a4272303a57bdb245c2bf1147185fb45640e70" +checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97" [[package]] name = "colorchoice" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b6a852b24ab71dffc585bcb46eaf7959d175cb865a7152e35b348d1b2960422" +checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0" [[package]] name = "core-foundation" @@ -355,9 +376,9 @@ source = "git+https://github.com/servo/core-foundation-rs?rev=fb8fd65eef1b2ef247 [[package]] name = "cpufeatures" -version = "0.2.12" +version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504" +checksum = "51e852e6dc9a5bed1fae92dd2375037bf2b768725bf3be87811edee3249d09ad" dependencies = [ "libc", ] @@ -390,9 +411,9 @@ dependencies = [ [[package]] name = "env_filter" -version = "0.1.0" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a009aa4810eb158359dda09d0c87378e4bbb89b5a801f016885a4707ba24f7ea" +checksum = "4f2c92ceda6ceec50f43169f9ee8424fe2db276791afde7b2cd8bc084cb376ab" dependencies = [ "log", "regex", @@ -400,9 +421,9 @@ dependencies = [ [[package]] name = "env_logger" -version = "0.11.3" +version = "0.11.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38b35839ba51819680ba087cd351788c9a3c476841207e0b8cee0b04722343b9" +checksum = "e13fa619b91fb2381732789fc5de83b45675e882f66623b7d8cb4f643017018d" dependencies = [ "anstream", "anstyle", @@ -418,14 +439,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" dependencies = [ "libc", - "windows-sys", + "windows-sys 0.52.0", ] [[package]] name = "fastrand" -version = "2.1.0" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fc0510504f03c51ada170672ac806f1f105a88aa97a5281117e1ddc3368e51a" +checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" [[package]] name = "flexstr" @@ -590,9 +611,11 @@ version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", + "js-sys", "libc", "wasi", + "wasm-bindgen", ] [[package]] @@ -607,6 +630,18 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" +[[package]] +name = "gloo-timers" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbb143cf96099802033e0d4f4963b19fd2e0b728bcf076cd9cf7f6634f092994" +dependencies = [ + "futures-channel", + "futures-core", + "js-sys", + "wasm-bindgen", +] + [[package]] name = "goblin" version = "0.8.2" @@ -688,9 +723,9 @@ dependencies = [ [[package]] name = "is_terminal_polyfill" -version = "1.70.0" +version = "1.70.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800" +checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" [[package]] name = "itoa" @@ -700,18 +735,18 @@ checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" [[package]] name = "js-sys" -version = "0.3.69" +version = "0.3.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" +checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" dependencies = [ "wasm-bindgen", ] [[package]] name = "libc" -version = "0.2.155" +version = "0.2.158" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" +checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" [[package]] name = "linux-raw-sys" @@ -774,14 +809,14 @@ dependencies = [ [[package]] name = "mio" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4569e456d394deccd22ce1c1913e6ea0e54519f577285001215d33557431afe4" +checksum = "80e04d1dcff3aae0704555fe5fee3bcfaf3d1fdf8a7e521d5b9d2b42acb52cec" dependencies = [ "hermit-abi", "libc", "wasi", - "windows-sys", + "windows-sys 0.52.0", ] [[package]] @@ -822,9 +857,9 @@ dependencies = [ [[package]] name = "object" -version = "0.36.1" +version = "0.36.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "081b846d1d56ddfc18fdf1a922e4f6e07a11768ea1b92dec44e42b72712ccfce" +checksum = "27b64972346851a39438c60b341ebc01bba47464ae329e55cf343eb93964efd9" dependencies = [ "memchr", ] @@ -837,12 +872,12 @@ checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "openssl" -version = "0.10.64" +version = "0.10.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95a0481286a310808298130d22dd1fef0fa571e05a8f44ec801801e84b216b1f" +checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" dependencies = [ "bitflags", - "cfg-if", + "cfg-if 1.0.0", "foreign-types", "libc", "once_cell", @@ -878,9 +913,9 @@ dependencies = [ [[package]] name = "openssl-sys" -version = "0.9.102" +version = "0.9.103" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c597637d56fbc83893a35eb0dd04b2b8e7a50c91e64e9493e398b5df4fb45fa2" +checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" dependencies = [ "cc", "libc", @@ -905,7 +940,7 @@ version = "0.9.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "libc", "redox_syscall", "smallvec", @@ -924,19 +959,34 @@ version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" +[[package]] +name = "pharos" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9567389417feee6ce15dd6527a8a1ecac205ef62c2932bcf3d9f6fc5b78b414" +dependencies = [ + "futures", + "rustc_version", +] + [[package]] name = "phoenix_channels_client" version = "0.9.0" dependencies = [ "arc-swap", + "async_io_stream", "atomic-take", "bytes", + "cfg-if 0.1.10", "chrono", "env_logger", "flexstr", "futures", "fxhash", + "getrandom", + "gloo-timers", "httparse", + "js-sys", "log", "native-tls", "serde", @@ -947,6 +997,10 @@ dependencies = [ "uniffi", "url", "uuid", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-time", + "ws_stream_wasm", ] [[package]] @@ -975,9 +1029,12 @@ checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" [[package]] name = "ppv-lite86" -version = "0.2.17" +version = "0.2.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] [[package]] name = "proc-macro2" @@ -990,9 +1047,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.36" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" dependencies = [ "proc-macro2", ] @@ -1029,18 +1086,18 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.5.2" +version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c82cf8cff14456045f55ec4241383baeff27af886adb72ffb2162f99911de0fd" +checksum = "2a908a6e00f1fdd0dfd9c0eb08ce85126f6d8bbda50017e74bc4a4b7d4a926a4" dependencies = [ "bitflags", ] [[package]] name = "regex" -version = "1.10.5" +version = "1.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b91213439dad192326a0d7c6ee3955910425f441d7038e0d6933b0aec5c4517f" +checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619" dependencies = [ "aho-corasick", "memchr", @@ -1071,17 +1128,26 @@ version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +[[package]] +name = "rustc_version" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" +dependencies = [ + "semver", +] + [[package]] name = "rustix" -version = "0.38.34" +version = "0.38.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +checksum = "a85d50532239da68e9addb745ba38ff4612a242c1c7ceea689c4bc7c2f43c36f" dependencies = [ "bitflags", "errno", "libc", "linux-raw-sys", - "windows-sys", + "windows-sys 0.52.0", ] [[package]] @@ -1096,7 +1162,7 @@ version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fbc91545643bcf3a0bbb6569265615222618bdf33ce4ffbbd13c4bbd4c093534" dependencies = [ - "windows-sys", + "windows-sys 0.52.0", ] [[package]] @@ -1155,20 +1221,26 @@ dependencies = [ "serde", ] +[[package]] +name = "send_wrapper" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd0b0ec5f1c1ca621c432a25813d8d60c88abe6d3e08a3eb9cf37d97a0fe3d73" + [[package]] name = "serde" -version = "1.0.203" +version = "1.0.209" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7253ab4de971e72fb7be983802300c30b5a7f0c2e56fab8abfc6a214307c0094" +checksum = "99fce0ffe7310761ca6bf9faf5115afbc19688edd00171d81b1bb1b116c63e09" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.203" +version = "1.0.209" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba" +checksum = "a5831b979fd7b5439637af1752d535ff49f4860c0f341d1baeb6faf0f4242170" dependencies = [ "proc-macro2", "quote", @@ -1177,11 +1249,12 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.120" +version = "1.0.127" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e0d21c9a8cae1235ad58a00c11cb40d4b1e5c784f1ef2c537876ed6ffd8b7c5" +checksum = "8043c06d9f82bd7271361ed64f415fe5e12a77fdb52e573e7f06a516dea329ad" dependencies = [ "itoa", + "memchr", "ryu", "serde", ] @@ -1192,11 +1265,17 @@ version = "0.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "cpufeatures", "digest", ] +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + [[package]] name = "signal-hook-registry" version = "1.4.2" @@ -1239,7 +1318,7 @@ version = "0.5.6" source = "git+https://github.com/QuentinPerez/socket2.git?rev=ca3a93088857b40c27e98d1690f242a7ba8da4dc#ca3a93088857b40c27e98d1690f242a7ba8da4dc" dependencies = [ "libc", - "windows-sys", + "windows-sys 0.52.0", ] [[package]] @@ -1256,9 +1335,9 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[package]] name = "syn" -version = "2.0.68" +version = "2.0.76" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "901fa70d88b9d6c98022e23b4136f9f3e54e4662c3bc1bd1d84a42a9a0f0c1e9" +checksum = "578e081a14e0cefc3279b0472138c513f37b41a08d5a3cca9b6e4e8ceb6cd525" dependencies = [ "proc-macro2", "quote", @@ -1267,14 +1346,15 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.10.1" +version = "3.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1" +checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "fastrand", + "once_cell", "rustix", - "windows-sys", + "windows-sys 0.59.0", ] [[package]] @@ -1288,18 +1368,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.61" +version = "1.0.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c546c80d6be4bc6a00c0f01730c08df82eaa7a7a61f11d656526506112cc1709" +checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.61" +version = "1.0.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533" +checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" dependencies = [ "proc-macro2", "quote", @@ -1308,9 +1388,9 @@ dependencies = [ [[package]] name = "tinyvec" -version = "1.6.1" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c55115c6fbe2d2bef26eb09ad74bde02d8255476fc0c7b515ef09fbb35742d82" +checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" dependencies = [ "tinyvec_macros", ] @@ -1323,9 +1403,7 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.39.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d040ac2b29ab03b09d4129c2f5bbd012a3ac2f79d38ff506a4bf8dd34b0eac8a" +version = "1.39.2" dependencies = [ "backtrace", "bytes", @@ -1336,14 +1414,13 @@ dependencies = [ "signal-hook-registry", "socket2", "tokio-macros", - "windows-sys", + "web-time", + "windows-sys 0.52.0", ] [[package]] name = "tokio-macros" version = "2.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" dependencies = [ "proc-macro2", "quote", @@ -1363,15 +1440,16 @@ dependencies = [ [[package]] name = "tokio-tungstenite" version = "0.23.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6989540ced10490aaf14e6bad2e3d33728a2813310a0c71d1574304c49631cd" dependencies = [ + "async_io_stream", "futures-util", + "getrandom", "log", "native-tls", "tokio", "tokio-native-tls", "tungstenite", + "ws_stream_wasm", ] [[package]] @@ -1440,12 +1518,13 @@ dependencies = [ [[package]] name = "uniffi" -version = "0.28.0" +version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f31bff6daf87277a9014bcdefbc2842b0553392919d1096843c5aad899ca4588" +checksum = "2db87def739fe4183947f8419d572d1849a4a09355eba4e988a2105cfd0ac6a7" dependencies = [ "anyhow", "camino", + "cargo_metadata", "clap", "uniffi_bindgen", "uniffi_build", @@ -1455,9 +1534,9 @@ dependencies = [ [[package]] name = "uniffi_bindgen" -version = "0.28.0" +version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96061d7e01b185aa405f7c9b134741ab3e50cc6796a47d6fd8ab9a5364b5feed" +checksum = "7a112599c9556d1581e4a3d72019a74c2c3e122cc27f4af12577a429c4d5e614" dependencies = [ "anyhow", "askama", @@ -1479,9 +1558,9 @@ dependencies = [ [[package]] name = "uniffi_build" -version = "0.28.0" +version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d6b86f9b221046af0c533eafe09ece04e2f1ded04ccdc9bba0ec09aec1c52bd" +checksum = "e2b12684401d2a8508ca9c72a95bbc45906417e42fc80942abaf033bbf01aa33" dependencies = [ "anyhow", "camino", @@ -1490,9 +1569,9 @@ dependencies = [ [[package]] name = "uniffi_checksum_derive" -version = "0.28.0" +version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fcfa22f55829d3aaa7acfb1c5150224188fe0f27c59a8a3eddcaa24d1ffbe58" +checksum = "a22dbe67c1c957ac6e7611bdf605a6218aa86b0eebeb8be58b70ae85ad7d73dc" dependencies = [ "quote", "syn", @@ -1500,9 +1579,9 @@ dependencies = [ [[package]] name = "uniffi_core" -version = "0.28.0" +version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3210d57d6ab6065ab47a2898dacdb7c606fd6a4156196831fa3bf82e34ac58a6" +checksum = "5a0c35aaad30e3a9e6d4fe34e358d64dbc92ee09045b48591b05fc9f12e0905b" dependencies = [ "anyhow", "async-compat", @@ -1516,9 +1595,9 @@ dependencies = [ [[package]] name = "uniffi_macros" -version = "0.28.0" +version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b58691741080935437dc862122e68d7414432a11824ac1137868de46181a0bd2" +checksum = "db66474c5c61b0f7afc3b4995fecf9b72b340daa5ca0ef3da7778d75eb5482ea" dependencies = [ "bincode", "camino", @@ -1534,9 +1613,9 @@ dependencies = [ [[package]] name = "uniffi_meta" -version = "0.28.0" +version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7663eacdbd9fbf4a88907ddcfe2e6fa85838eb6dc2418a7d91eebb3786f8e20b" +checksum = "d898893f102e0e39b8bcb7e3d2188f4156ba280db32db9e8af1f122d057e9526" dependencies = [ "anyhow", "bytes", @@ -1546,9 +1625,9 @@ dependencies = [ [[package]] name = "uniffi_testing" -version = "0.28.0" +version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f922465f7566f25f8fe766920205fdfa9a3fcdc209c6bfb7557f0b5bf45b04dd" +checksum = "2c6aa4f0cf9d12172d84fc00a35a6c1f3522b526daad05ae739f709f6941b9b6" dependencies = [ "anyhow", "camino", @@ -1559,9 +1638,9 @@ dependencies = [ [[package]] name = "uniffi_udl" -version = "0.28.0" +version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cef408229a3a407fafa4c36dc4f6ece78a6fb258ab28d2b64bddd49c8cb680f6" +checksum = "6b044e9c519e0bb51e516ab6f6d8f4f4dcf900ce30d5ad07c03f924e2824f28e" dependencies = [ "anyhow", "textwrap", @@ -1610,9 +1689,9 @@ checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" [[package]] name = "version_check" -version = "0.9.4" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" [[package]] name = "wasi" @@ -1622,19 +1701,20 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.92" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" +checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", + "once_cell", "wasm-bindgen-macro", ] [[package]] name = "wasm-bindgen-backend" -version = "0.2.92" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" +checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" dependencies = [ "bumpalo", "log", @@ -1645,11 +1725,23 @@ dependencies = [ "wasm-bindgen-shared", ] +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e9300f63a621e96ed275155c108eb6f843b6a26d053f122ab69724559dc8ed" +dependencies = [ + "cfg-if 1.0.0", + "js-sys", + "wasm-bindgen", + "web-sys", +] + [[package]] name = "wasm-bindgen-macro" -version = "0.2.92" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" +checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -1657,9 +1749,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.92" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" +checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" dependencies = [ "proc-macro2", "quote", @@ -1670,9 +1762,29 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.92" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" + +[[package]] +name = "web-sys" +version = "0.3.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" +checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "web-time" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb" +dependencies = [ + "js-sys", + "wasm-bindgen", +] [[package]] name = "weedle2" @@ -1701,6 +1813,15 @@ dependencies = [ "windows-targets", ] +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets", +] + [[package]] name = "windows-targets" version = "0.52.6" @@ -1765,7 +1886,42 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" -[[patch.unused]] -name = "mio" -version = "0.8.11" -source = "git+https://github.com/simlay/mio.git?rev=7b8b2e605ad64bcabf1f0af4366aa404a8b6bbdc#7b8b2e605ad64bcabf1f0af4366aa404a8b6bbdc" +[[package]] +name = "ws_stream_wasm" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7999f5f4217fe3818726b66257a4475f71e74ffd190776ad053fa159e50737f5" +dependencies = [ + "async_io_stream", + "futures", + "js-sys", + "log", + "pharos", + "rustc_version", + "send_wrapper", + "thiserror", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", +] + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] diff --git a/Cargo.toml b/Cargo.toml index 650625d..a7d4927 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ homepage = "https://github.com/liveview-native/phoenix-channels" documentation = "https://github.com/liveview-native/phoenix-channels" categories = ["asynchronous", "web-programming:websocket"] keywords = ["phoenix", "channels", "elixir"] -license = "Apache-2.0" +license = "MIT" readme = "README.md" edition = "2021" @@ -36,10 +36,11 @@ strip = true # Strip symbols from binary* # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [features] -default = [] +default = ["tokio-tungstenite/connect"] nightly = [] native-tls = ["tokio-tungstenite/native-tls-vendored", "dep:native-tls"] uniffi-build = ["uniffi/build", "uniffi/cli"] +browser = ["tokio-tungstenite/js-connect", "getrandom/js", "ws_stream_wasm", "async_io_stream/tokio_io", "wasm-bindgen", "js-sys", "wasm-bindgen-futures", "gloo-timers", "web-time"] [dependencies] @@ -55,11 +56,21 @@ serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" thiserror = "1.0" tokio = { version = "1.39", features = ["sync", "macros", "time" ] } -tokio-tungstenite = "0.23.0" -uniffi = { version = "0.28", features = ["tokio"] } url = "2.5" uuid = { version = "1.10.0", features = ["v4"] } -native-tls = { version = "0.2", features = ["vendored"], optional = true} +uniffi = { version = "0.28", features = ["tokio"] } +native-tls = { version = "0.2", features = ["vendored"], optional = true } +tokio-tungstenite = { version = "0.23.1", default-features = false, features = ["handshake", "stream"] } +cfg-if = "0.1" + +getrandom = { version = "0.2", optional = true } +ws_stream_wasm = { version = "0.7.4", optional = true } +async_io_stream = { version = "0.3.3", optional = true } +web-time = { version = "1.1.0", optional = true } +wasm-bindgen = { version = "0.2.92", optional = true } +js-sys = { version = "0.3.69", optional = true } +wasm-bindgen-futures = { version = "0.4.42", optional = true } +gloo-timers = { version = "0.3.0", features = ["futures"], optional = true } [dev-dependencies] chrono = "0.4.31" @@ -75,8 +86,9 @@ security-framework-sys = { git = "https://github.com/kornelski/rust-security-fra # https://github.com/servo/core-foundation-rs/pull/679 core-foundation-sys = { git = "https://github.com/servo/core-foundation-rs", rev = "fb8fd65eef1b2ef247055e944cf258d53f2a517a" } -# https://github.com/tokio-rs/mio/pull/1773 and backport PR. -mio = { git = "https://github.com/simlay/mio.git", rev = "7b8b2e605ad64bcabf1f0af4366aa404a8b6bbdc" } - # https://github.com/rust-lang/socket2/pull/503 socket2 = { git = "https://github.com/QuentinPerez/socket2.git", rev = "ca3a93088857b40c27e98d1690f242a7ba8da4dc" } + +#tokio-tungstenite = { git = "https://github.com/simlay/tokio-tungstenite.git", branch = "add-browser-wasm-support" } +tokio-tungstenite = { path = "../tokio-tungstenite/" } +tokio = { path = "../tokio/tokio/" } diff --git a/src/ffi.rs b/src/ffi.rs index a3475ed..ff6da0c 100644 --- a/src/ffi.rs +++ b/src/ffi.rs @@ -15,8 +15,8 @@ pub mod web_socket; use std::ops::{Add, Sub}; use std::time::SystemTime; +use crate::Instant; use tokio::time::error::Elapsed; -use tokio::time::Instant; use url::Url; use crate::ffi::observable_status::StatusesError; diff --git a/src/ffi/socket.rs b/src/ffi/socket.rs index 3ee4d72..043d1b3 100644 --- a/src/ffi/socket.rs +++ b/src/ffi/socket.rs @@ -340,13 +340,11 @@ impl Socket { /// worker from the task runtime (though it will continue to run in the background) pub async fn connect(&self, timeout: Duration) -> Result<(), ConnectError> { let (connected_tx, connected_rx) = oneshot::channel(); - let created_at = Instant::now(); let deadline = Instant::now() + timeout; match self .state_command_tx .send(StateCommand::Connect(Connect { - created_at, timeout, connected_tx, })) diff --git a/src/lib.rs b/src/lib.rs index e43f2c4..638bbcc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,12 +1,23 @@ #![doc = include_str!("../README.md")] #![cfg_attr(feature = "nightly", feature(slice_take))] // doc warnings that aren't on by default -#![warn(missing_docs)] -#![warn(rustdoc::unescaped_backticks)] +//#![warn(missing_docs)] +//#![warn(rustdoc::unescaped_backticks)] mod ffi; mod rust; +#[cfg(feature = "browser")] +mod wasm_helpers; + +cfg_if::cfg_if! { + if #[cfg(not(all(target_family = "wasm", target_os = "unknown")))] { + pub (crate) type Instant = tokio::time::Instant; + } else { + pub (crate) type Instant = tokio::time::Instant; + } +} + // All types should be at the root as `uniffi` only exposes one namespace to foreign code pub use ffi::channel::statuses::{ChannelStatusJoinError, ChannelStatuses}; pub use ffi::channel::{ @@ -25,5 +36,4 @@ pub use ffi::web_socket::error::WebSocketError; pub use ffi::web_socket::protocol::WebSocketMessage; pub use ffi::{PhoenixError, URLParseError}; pub use url; - uniffi::setup_scaffolding!("phoenix_channels_client"); diff --git a/src/rust/socket/listener.rs b/src/rust/socket/listener.rs index 318b9d8..9a039dc 100644 --- a/src/rust/socket/listener.rs +++ b/src/rust/socket/listener.rs @@ -8,19 +8,26 @@ use std::pin::Pin; use std::sync::Arc; use std::time::Duration; +use crate::Instant; + use futures::stream::FuturesUnordered; use futures::SinkExt; use futures::StreamExt; use log::{debug, error, trace}; use serde_json::Value; -use tokio::net::TcpStream; + use tokio::sync::{broadcast, mpsc, oneshot}; use tokio::task::JoinHandle; use tokio::time; -use tokio::time::{Instant, Interval, Sleep}; +use tokio::time::{Interval, Sleep}; use tokio_tungstenite::{tungstenite, MaybeTlsStream, WebSocketStream}; use url::Url; +#[cfg(not(target_family = "wasm"))] +type StreamType = tokio::net::TcpStream; +#[cfg(target_family = "wasm")] +type StreamType = async_io_stream::IoStream>; + use crate::ffi::channel::Channel; use crate::ffi::message::PhoenixEvent; use crate::ffi::socket::Socket; @@ -65,8 +72,13 @@ impl Listener { channel_state_command_rx, channel_send_command_rx, ); - - tokio::spawn(listener.listen()) + cfg_if::cfg_if! { + if #[cfg(all(target_family = "wasm", target_os = "unknown"))] { + tokio::task::spawn_local(listener.listen()) + } else { + tokio::task::spawn(listener.listen()) + } + } } fn init( @@ -191,10 +203,7 @@ impl Listener { async fn connect(&self, state: State, connect: Connect) -> State { let (connect_result, next_state) = match state { State::NeverConnected | State::Disconnected => { - match self - .socket_connect(connect.created_at, connect.reconnect()) - .await - { + match self.socket_connect(connect.reconnect()).await { Ok(state) => (Ok(()), state), Err((connect_error, reconnect)) => (Err(connect_error), reconnect.wait()), } @@ -513,7 +522,17 @@ impl Listener { topic: Arc, join_reference: JoinReference, ) -> JoinKey { + //#[cfg(not(feature = "browser"))] time::sleep_until(deadline).await; + /* + #[cfg(feature = "browser")] + { + let now = Instant::now(); + if now > deadline { + gloo_timers::future::sleep(now - deadline).await; + } + } + */ JoinKey { topic, @@ -668,7 +687,7 @@ impl Listener { } async fn reconnect(&self, reconnect: Reconnect) -> State { - match self.socket_connect(Instant::now(), reconnect).await { + match self.socket_connect(reconnect).await { Ok(state) => state, Err((_connect_error, reconnect)) => reconnect.wait(), } @@ -676,7 +695,6 @@ impl Listener { async fn socket_connect( &self, - created_at: Instant, reconnect: Reconnect, ) -> Result { let url = self.url.clone(); @@ -712,21 +730,75 @@ impl Listener { None } }; - #[cfg(feature = "native-tls")] + #[cfg(all(not(target_family = "wasm"), feature = "native-tls"))] let connector = tokio_tungstenite::connect_async_tls_with_config( request.body(()).expect("Failed to build http request"), None, false, connector, ); - #[cfg(not(feature = "native-tls"))] + #[cfg(all(not(target_family = "wasm"), not(feature = "native-tls")))] let connector = tokio_tungstenite::connect_async_with_config( request.body(()).expect("Failed to build http request"), None, false, ); - match time::timeout_at(created_at + reconnect.connect_timeout, connector).await { + #[cfg(target_family = "wasm")] + let connector = tokio_tungstenite::connect( + request.body(()).expect("Failed to build http request"), + None, + false, + ); + #[cfg(not(target_family = "wasm"))] + let timeout = time::sleep(reconnect.connect_timeout); + + #[cfg(target_family = "wasm")] + let timeout = { + let timeout_ms = u32::try_from(reconnect.connect_timeout.as_millis()) + .expect("Failed to convert durration intu 32"); + gloo_timers::future::TimeoutFuture::new(timeout_ms) + }; + + tokio::select! { + _ = timeout => { + Err((ConnectError::Timeout, reconnect)) + }, + connector = connector => { + match connector { + Ok((socket, _response)) => { + let duration = Duration::from_secs(30); + let mut heartbeat = time::interval(duration); + heartbeat.set_missed_tick_behavior(time::MissedTickBehavior::Skip); + + self.connectivity_tx.send(Connectivity::Connected).ok(); + + Ok(State::Connected(Connected { + socket, + heartbeat, + sent_heartbeat_reference: None, + join_by_reference_by_topic: Default::default(), + join_timeouts: Default::default(), + broadcast_by_topic: Default::default(), + joined_channel_txs_by_join_reference_by_topic: Default::default(), + reply_tx_by_reference_by_join_reference_by_topic: Default::default(), + connect_timeout: reconnect.connect_timeout, + })) + } + Err(error) => { + let arc_error = Arc::new(error); + debug!("Error connecting to {}: {}", self.url, arc_error); + self.socket_status.error(arc_error.clone()); + + Err((arc_error.into(), reconnect)) + } + } + + } + } + + /* + match timeout.await { Ok(connect_result) => match connect_result { Ok((socket, _response)) => { let duration = Duration::from_secs(30); @@ -757,6 +829,7 @@ impl Listener { }, Err(_) => Err((ConnectError::Timeout, reconnect)), } + */ } async fn shutdown(&self, state: State) -> State { @@ -816,13 +889,11 @@ impl Debug for State { State::Disconnected { .. } => write!(f, "Disconnected"), State::ShuttingDown => write!(f, "ShuttingDown"), State::Connected(connected) => f.debug_tuple("Connected").field(connected).finish(), - State::WaitingToReconnect { - sleep, reconnect, .. - } => f + State::WaitingToReconnect { reconnect, .. } => f .debug_struct("WaitingToReconnect") .field( "duration_until_sleep_over", - &(sleep.deadline() - Instant::now()), + &(Instant::now()), //&(sleep.deadline() - Instant::now()), ) .field("reconnect", reconnect) .finish(), @@ -855,7 +926,7 @@ pub(crate) type ObservableStatus = #[must_use] struct Connected { - socket: WebSocketStream>, + socket: WebSocketStream>, heartbeat: Interval, sent_heartbeat_reference: Option, join_by_reference_by_topic: HashMap, HashMap>, @@ -1279,8 +1350,6 @@ pub(crate) struct Cast { } pub struct Connect { - /// When the connect was created - pub created_at: Instant, /// How long after `created_at` must the connect complete pub timeout: Duration, pub connected_tx: oneshot::Sender>, diff --git a/src/wasm_helpers.rs b/src/wasm_helpers.rs new file mode 100644 index 0000000..ad09f68 --- /dev/null +++ b/src/wasm_helpers.rs @@ -0,0 +1,29 @@ +use wasm_bindgen::prelude::*; +#[wasm_bindgen(inline_js = " + function wait(ms) { + return new Promise((_, reject) => { + setTimeout(() => reject(new Error('timeout succeeded')), ms); + }); + } + export fn js_timeout(ms, promise) { + await Promise.race([wait(ms), promise()]) + } + ")] +extern "C" { + #[wasm_bindgen(catch)] + async fn js_timeout(promise: js_sys::Promise) -> Result; +} + +use std::future::{Future, IntoFuture}; +use std::time::Duration; + +/* +pub(crate) async fn timeout(duration: Duration, future: F) -> Result +where + F: Future, +{ + let promise = wasm_bindgen_futures::future_to_promise(future); + let out = js_timeout(promise).await; + todo!() +} +*/ diff --git a/tests/support/test_server/lib/test_server/endpoint.ex b/tests/support/test_server/lib/test_server/endpoint.ex index 5578f79..8f5a66f 100644 --- a/tests/support/test_server/lib/test_server/endpoint.ex +++ b/tests/support/test_server/lib/test_server/endpoint.ex @@ -11,6 +11,7 @@ defmodule TestServer.Endpoint do config, https: false, http: [port: 9002], + check_origin: false, secret_key_base: String.duplicate("abcdefgh", 8), debug_errors: false, server: true