From b1f365edbb7fef79f343d8b4996e3d5d68f085aa Mon Sep 17 00:00:00 2001 From: zertex Date: Fri, 22 Sep 2023 20:44:25 -0400 Subject: [PATCH 01/15] Update GuildDefaults to use new enums --- src/types/config/types/subconfigs/defaults/guild.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/types/config/types/subconfigs/defaults/guild.rs b/src/types/config/types/subconfigs/defaults/guild.rs index 966c7af..a709f82 100644 --- a/src/types/config/types/subconfigs/defaults/guild.rs +++ b/src/types/config/types/subconfigs/defaults/guild.rs @@ -1,13 +1,15 @@ use serde::{Deserialize, Serialize}; +use crate::types::{ExplicitContentFilterLevel, MessageNotificationLevel}; + #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct GuildDefaults { pub max_presences: u64, pub max_video_channel_users: u16, pub afk_timeout: u16, - pub default_message_notifications: u8, - pub explicit_content_filter: u8, + pub default_message_notifications: MessageNotificationLevel, + pub explicit_content_filter: ExplicitContentFilterLevel, } impl Default for GuildDefaults { @@ -16,8 +18,8 @@ impl Default for GuildDefaults { max_presences: 250_000, max_video_channel_users: 200, afk_timeout: 300, - default_message_notifications: 1, - explicit_content_filter: 0, + default_message_notifications: MessageNotificationLevel::OnlyMentions, + explicit_content_filter: ExplicitContentFilterLevel::Disabled, } } } From 30909212a6a53f884ab1110d09611162821d86b3 Mon Sep 17 00:00:00 2001 From: zertex Date: Fri, 22 Sep 2023 20:44:56 -0400 Subject: [PATCH 02/15] Make new enums derive sqlx::Type --- src/types/entities/guild.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/types/entities/guild.rs b/src/types/entities/guild.rs index bb4db0c..2a63ad0 100644 --- a/src/types/entities/guild.rs +++ b/src/types/entities/guild.rs @@ -343,6 +343,7 @@ pub struct VoiceRegion { } #[derive(Serialize_repr, Deserialize_repr, Debug, Default, Clone, Eq, PartialEq, Hash, Copy)] +#[cfg_attr(feature = "sqlx", derive(sqlx::Type))] #[repr(u8)] #[serde(rename_all = "SCREAMING_SNAKE_CASE")] /// See @@ -353,6 +354,7 @@ pub enum MessageNotificationLevel { } #[derive(Serialize_repr, Deserialize_repr, Debug, Default, Clone, Eq, PartialEq, Hash, Copy)] +#[cfg_attr(feature = "sqlx", derive(sqlx::Type))] #[repr(u8)] #[serde(rename_all = "SCREAMING_SNAKE_CASE")] /// See @@ -364,6 +366,7 @@ pub enum ExplicitContentFilterLevel { } #[derive(Serialize_repr, Deserialize_repr, Debug, Default, Clone, Eq, PartialEq, Hash, Copy)] +#[cfg_attr(feature = "sqlx", derive(sqlx::Type))] #[repr(u8)] #[serde(rename_all = "SCREAMING_SNAKE_CASE")] /// See @@ -377,6 +380,7 @@ pub enum VerificationLevel { } #[derive(Serialize_repr, Deserialize_repr, Debug, Default, Clone, Eq, PartialEq, Hash, Copy)] +#[cfg_attr(feature = "sqlx", derive(sqlx::Type))] #[repr(u8)] #[serde(rename_all = "SCREAMING_SNAKE_CASE")] /// See @@ -387,6 +391,7 @@ pub enum MFALevel { } #[derive(Serialize_repr, Deserialize_repr, Debug, Default, Clone, Eq, PartialEq, Hash, Copy)] +#[cfg_attr(feature = "sqlx", derive(sqlx::Type))] #[repr(u8)] #[serde(rename_all = "SCREAMING_SNAKE_CASE")] /// See @@ -399,6 +404,7 @@ pub enum NSFWLevel { } #[derive(Serialize_repr, Deserialize_repr, Debug, Default, Clone, Eq, PartialEq, Hash, Copy)] +#[cfg_attr(feature = "sqlx", derive(sqlx::Type))] #[repr(u8)] #[serde(rename_all = "SCREAMING_SNAKE_CASE")] /// See From f78f869f4cac6df206058b21f0419bb47addfee1 Mon Sep 17 00:00:00 2001 From: zertex Date: Fri, 22 Sep 2023 20:45:19 -0400 Subject: [PATCH 03/15] Feature lock UpdateMessage implementations --- src/types/events/guild.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/types/events/guild.rs b/src/types/events/guild.rs index 0c6bb05..89e4a75 100644 --- a/src/types/events/guild.rs +++ b/src/types/events/guild.rs @@ -29,6 +29,7 @@ pub struct GuildCreate { pub json: String, } +#[cfg(feature = "client")] impl UpdateMessage for GuildCreate { fn id(&self) -> Option { match &self.d { @@ -89,6 +90,7 @@ pub struct GuildUpdate { impl WebSocketEvent for GuildUpdate {} +#[cfg(feature = "client")] impl UpdateMessage for GuildUpdate { fn id(&self) -> Option { Some(self.guild.id) @@ -107,6 +109,7 @@ pub struct GuildDelete { pub json: String, } +#[cfg(feature = "client")] impl UpdateMessage for GuildDelete { fn id(&self) -> Option { Some(self.guild.id) From e0492bb2f6742d44b2e94f6a8e3d5cfe45b7b5d6 Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Sun, 17 Dec 2023 20:47:52 +0100 Subject: [PATCH 04/15] Add MANAGE_ENCRYPTION permission --- src/types/entities/role.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/types/entities/role.rs b/src/types/entities/role.rs index 6a8327e..6708a18 100644 --- a/src/types/entities/role.rs +++ b/src/types/entities/role.rs @@ -163,6 +163,8 @@ bitflags! { const USE_EXTERNAL_SOUNDS = 1 << 45; /// Allows sending voice messages const SEND_VOICE_MESSAGES = 1 << 46; + /// Allows creating encrypted voice channels + const MANAGE_ENCRYPTION = 1 << 63; } } From b87af21c314d0e028ca2eda3c5d9b239bf557dc6 Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Sun, 17 Dec 2023 22:16:53 +0100 Subject: [PATCH 05/15] Revert last commit --- src/types/entities/role.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/types/entities/role.rs b/src/types/entities/role.rs index 6708a18..6a8327e 100644 --- a/src/types/entities/role.rs +++ b/src/types/entities/role.rs @@ -163,8 +163,6 @@ bitflags! { const USE_EXTERNAL_SOUNDS = 1 << 45; /// Allows sending voice messages const SEND_VOICE_MESSAGES = 1 << 46; - /// Allows creating encrypted voice channels - const MANAGE_ENCRYPTION = 1 << 63; } } From de42299fd040ddbe42b9c1944cce5d220ae44f84 Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Thu, 11 Jan 2024 19:30:40 +0100 Subject: [PATCH 06/15] bump reqwest to 0.11.23 --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index fd7dffe..a37aa94 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,10 +24,10 @@ serde_json = { version = "1.0.105", features = ["raw_value"] } serde-aux = "4.2.0" serde_with = "3.3.0" serde_repr = "0.1.16" -reqwest = { git = "https://github.com/bitfl0wer/reqwest.git", branch = "wasm-headers", features = [ +reqwest = { features = [ "multipart", "json", -], version = "0.11.22" } # reqwest versions > 0.11.22 will have adequate support for WASM. Until there is such a version, we will use a fork of reqwest v.0.11.22 +], version = "0.11.23" } url = "2.4.0" chrono = { version = "0.4.26", features = ["serde"] } regex = "1.9.4" From 7fdb4bae4961afa76b31c820084d47366d46e741 Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Thu, 11 Jan 2024 19:36:36 +0100 Subject: [PATCH 07/15] bump package versions --- Cargo.lock | 277 +++++++++++++++++++++++++---------------------------- Cargo.toml | 44 ++++----- 2 files changed, 154 insertions(+), 167 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 036dc73..ce509ab 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -19,9 +19,9 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] name = "ahash" -version = "0.8.6" +version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91429305e9f0a25f6205c5b8e0d2db09e0708a7a6df0f42212bb56c32c8ac97a" +checksum = "77c3a9648d43b9cd48db467b3f87fdd6e146bcc88ab0180006cef2179fe11d01" dependencies = [ "cfg-if", "getrandom", @@ -62,13 +62,13 @@ dependencies = [ [[package]] name = "async-trait" -version = "0.1.74" +version = "0.1.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a66537f1bb974b254c98ed142ff995236e81b9d0fe4db0575f46612cb15eb0f9" +checksum = "c980ee35e870bd1a4d2c8294d4c04d0499e67bca1e4b5cefcc693c2fa00caea9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] @@ -130,9 +130,9 @@ checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" [[package]] name = "base64" -version = "0.21.5" +version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35636a1494ede3b646cc98f74f8e62c773a38a659ebc777a2cf26b9b74171df9" +checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" [[package]] name = "base64ct" @@ -202,7 +202,7 @@ name = "chorus" version = "0.13.0" dependencies = [ "async-trait", - "base64 0.21.5", + "base64 0.21.7", "bitflags 2.4.1", "chorus-macros", "chrono", @@ -246,7 +246,7 @@ checksum = "a81545a60b926f815517dadbbd40cd502294ae2baea25fa8194d854d607512b0" dependencies = [ "async-trait", "quote", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] @@ -276,9 +276,9 @@ dependencies = [ [[package]] name = "const-oid" -version = "0.9.5" +version = "0.9.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28c122c3980598d243d63d9a704629a2d748d101f278052ff068be5a4423ab6f" +checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" [[package]] name = "core-foundation" @@ -298,9 +298,9 @@ checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" [[package]] name = "cpufeatures" -version = "0.2.11" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce420fe07aecd3e67c5f910618fe65e94158f6dcc0adf44e00d69ce2bdfe0fd0" +checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504" dependencies = [ "libc", ] @@ -322,22 +322,18 @@ checksum = "19d374276b40fb8bbdee95aef7c7fa6b5316ec764510eb64b8dd0e2ed0d7e7f5" [[package]] name = "crossbeam-queue" -version = "0.3.8" +version = "0.3.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d1cfb3ea8a53f37c40dea2c7bedcbd88bdfae54f5e2175d6ecaff1c988353add" +checksum = "df0346b5d5e76ac2fe4e327c5fd1118d6be7c51dfb18f9b7922923f287471e35" dependencies = [ - "cfg-if", "crossbeam-utils", ] [[package]] name = "crossbeam-utils" -version = "0.8.16" +version = "0.8.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a22b2d63d4d1dc0b7f1b6b2747dd0088008a9be28b6ddf0b1e7d335e3037294" -dependencies = [ - "cfg-if", -] +checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345" [[package]] name = "crypto-common" @@ -376,7 +372,7 @@ dependencies = [ "proc-macro2", "quote", "strsim", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] @@ -387,7 +383,7 @@ checksum = "836a9bbc7ad63342d6d6e7b815ccab164bc77a2d95d84bc3117a8c0d5c98e2d5" dependencies = [ "darling_core", "quote", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] @@ -409,9 +405,9 @@ dependencies = [ [[package]] name = "deranged" -version = "0.3.10" +version = "0.3.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8eb30d70a07a3b04884d2677f06bec33509dc67ca60d92949e5535352d3191dc" +checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" dependencies = [ "powerfmt", "serde", @@ -541,9 +537,9 @@ dependencies = [ [[package]] name = "futures" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da0290714b38af9b4a7b094b8a37086d1b4e61f2df9122c3cad2577669145335" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" dependencies = [ "futures-channel", "futures-core", @@ -556,9 +552,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff4dd66668b557604244583e3e1e1eada8c5c2e96a6d0d6653ede395b78bbacb" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" dependencies = [ "futures-core", "futures-sink", @@ -566,15 +562,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb1d22c66e66d9d72e1758f0bd7d4fd0bee04cad842ee34587d68c07e45d088c" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" [[package]] name = "futures-executor" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f4fb8693db0cf099eadcca0efe2a5a22e4550f98ed16aba6c48700da29597bc" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" dependencies = [ "futures-core", "futures-task", @@ -594,38 +590,38 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8bf34a163b5c4c52d0478a4d757da8fb65cabef42ba90515efee0f6f9fa45aaa" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" [[package]] name = "futures-macro" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53b153fd91e4b0147f4aced87be237c98248656bb01050b96bf3ee89220a8ddb" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] name = "futures-sink" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e36d3378ee38c2a36ad710c5d30c2911d752cb941c00c72dbabfb786a7970817" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" [[package]] name = "futures-task" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "efd193069b0ddadc69c46389b740bbccdd97203899b48d09c5f7969591d6bae2" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" [[package]] name = "futures-util" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a19526d624e703a3179b3d322efec918b6246ea0fa51d41124525f00f1cc8104" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" dependencies = [ "futures-channel", "futures-core", @@ -651,9 +647,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.11" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe9006bed769170c11f845cf00c7c1e9092aeb3f268e007c3e760ac68008070f" +checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" dependencies = [ "cfg-if", "js-sys", @@ -670,9 +666,9 @@ checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" [[package]] name = "h2" -version = "0.3.22" +version = "0.3.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d6250322ef6e60f93f9a2162799302cd6f68f79f6e5d85c8c16f14d1d958178" +checksum = "b553656127a00601c8ae5590fcfdc118e4083a7924b6cf4ffc1ea4b99dc429d7" dependencies = [ "bytes", "fnv", @@ -718,7 +714,7 @@ version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "06683b93020a07e3dbcf5f8c0f6d40080d725bea7936fc01ad345c01b97dc270" dependencies = [ - "base64 0.21.5", + "base64 0.21.7", "bytes", "headers-core", "http", @@ -759,9 +755,9 @@ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] name = "hkdf" -version = "0.12.3" +version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "791a029f6b9fc27657f6f188ec6e5e43f6911f6f878e0dc5501396e09809d437" +checksum = "7b5f8eb2ad728638ea2c7d47a21db23b7b58a72ed6a38256b8a1849f15fbbdf7" dependencies = [ "hmac", ] @@ -777,11 +773,11 @@ dependencies = [ [[package]] name = "home" -version = "0.5.5" +version = "0.5.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5444c27eef6923071f7ebcc33e3444508466a76f7a2b93da00ed6e19f30c1ddb" +checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" dependencies = [ - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] @@ -831,9 +827,9 @@ checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" [[package]] name = "hyper" -version = "0.14.27" +version = "0.14.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffb1cfd654a8219eaef89881fdb3bb3b1cdc5fa75ded05d6933b2b382e395468" +checksum = "bf96e135eb83a2a8ddf766e426a841d8ddd7449d5f00d34ea02b41d2f19eef80" dependencies = [ "bytes", "futures-channel", @@ -846,7 +842,7 @@ dependencies = [ "httpdate", "itoa", "pin-project-lite", - "socket2 0.4.10", + "socket2", "tokio", "tower-service", "tracing", @@ -868,9 +864,9 @@ dependencies = [ [[package]] name = "iana-time-zone" -version = "0.1.58" +version = "0.1.59" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8326b86b6cff230b97d0d312a6c40a60726df3332e721f72a1b035f451663b20" +checksum = "b6a67363e2aa4443928ce15e57ebae94fd8949958fd1223c4cfc0cd473ad7539" dependencies = [ "android_system_properties", "core-foundation-sys", @@ -972,7 +968,7 @@ version = "8.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6971da4d9c3aa03c3d8f3ff0f4155b534aad021292003895a469716b2a230378" dependencies = [ - "base64 0.21.5", + "base64 0.21.7", "pem", "ring 0.16.20", "serde", @@ -991,9 +987,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.151" +version = "0.2.152" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "302d7ab3130588088d277783b1e2d2e10c9e9e4a16dd9050e6ec93fb3e7048f4" +checksum = "13e3bf6590cbc649f4d1a3eefc9d5d6eb746f5200ffb04e5e142700b8faa56e7" [[package]] name = "libm" @@ -1052,9 +1048,9 @@ dependencies = [ [[package]] name = "memchr" -version = "2.6.4" +version = "2.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" +checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" [[package]] name = "mime" @@ -1208,9 +1204,9 @@ dependencies = [ [[package]] name = "object" -version = "0.32.1" +version = "0.32.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cf5f9dd3933bd50a9e1f149ec995f39ae2c496d31fd772c1fd45ebc27e902b0" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" dependencies = [ "memchr", ] @@ -1223,9 +1219,9 @@ checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "openssl" -version = "0.10.61" +version = "0.10.62" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b8419dc8cc6d866deb801274bba2e6f8f6108c1bb7fcc10ee5ab864931dbb45" +checksum = "8cde4d2d9200ad5909f8dac647e29482e07c3a35de8a13fce7c9c7747ad9f671" dependencies = [ "bitflags 2.4.1", "cfg-if", @@ -1244,7 +1240,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] @@ -1255,9 +1251,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-sys" -version = "0.9.97" +version = "0.9.98" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3eaad34cdd97d81de97964fc7f29e2d104f483840d906ef56daa1912338460b" +checksum = "c1665caf8ab2dc9aef43d1c0023bd904633a6a05cb30b0ad59bec2ae986e57a7" dependencies = [ "cc", "libc", @@ -1363,9 +1359,9 @@ dependencies = [ [[package]] name = "pkg-config" -version = "0.3.27" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" +checksum = "69d3587f8a9e599cc7ec2c00e331f71c4e69a5f9a4b8a6efd5b07466b9736f9a" [[package]] name = "poem" @@ -1407,7 +1403,7 @@ dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] @@ -1434,18 +1430,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.70" +version = "1.0.76" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39278fbbf5fb4f646ce651690877f89d1c5811a3d4acb27700c1cb3cdb78fd3b" +checksum = "95fc56cda0b5c3325f5fbbd7ff9fda9e02bb00bb3dac51252d2f1bfa1cb8cc8c" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.33" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -1520,10 +1516,11 @@ checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" [[package]] name = "reqwest" -version = "0.11.22" -source = "git+https://github.com/bitfl0wer/reqwest.git?branch=wasm-headers#858197c528f074f00397f7e2675d3eb15cc10a75" +version = "0.11.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37b1ae8d9ac08420c66222fb9096fc5de435c3c48542bc5336c51892cffafb41" dependencies = [ - "base64 0.21.5", + "base64 0.21.7", "bytes", "encoding_rs", "futures-core", @@ -1672,7 +1669,7 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1c74cae0a4cf6ccbbf5f359f08efdf8ee7e1dc532573bf0db71968cb56b1448c" dependencies = [ - "base64 0.21.5", + "base64 0.21.7", ] [[package]] @@ -1702,11 +1699,11 @@ dependencies = [ [[package]] name = "schannel" -version = "0.1.22" +version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c3733bf4cf7ea0880754e19cb5a462007c4a8c1914bff372ccc95b464f1df88" +checksum = "fbc91545643bcf3a0bbb6569265615222618bdf33ce4ffbbd13c4bbd4c093534" dependencies = [ - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] @@ -1756,9 +1753,9 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.20" +version = "1.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090" +checksum = "b97ed7a9823b74f99c7742f5336af7be5ecd3eeafcb1507d1fa93347b1d589b0" [[package]] name = "send_wrapper" @@ -1768,9 +1765,9 @@ checksum = "cd0b0ec5f1c1ca621c432a25813d8d60c88abe6d3e08a3eb9cf37d97a0fe3d73" [[package]] name = "serde" -version = "1.0.193" +version = "1.0.195" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89" +checksum = "63261df402c67811e9ac6def069e4786148c4563f4b50fd4bf30aa370d626b02" dependencies = [ "serde_derive", ] @@ -1788,20 +1785,20 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.193" +version = "1.0.195" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" +checksum = "46fe8f8603d81ba86327b23a2e9cdf49e1255fb94a4c5f297f6ee0547178ea2c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] name = "serde_json" -version = "1.0.108" +version = "1.0.111" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d1c7e3eac408d115102c4c24ad393e0821bb3a5df4d506a80f85f7a742a526b" +checksum = "176e46fa42316f18edd598015a5166857fc835ec732f5215eac6b7bdbf0a84f4" dependencies = [ "itoa", "ryu", @@ -1810,13 +1807,13 @@ dependencies = [ [[package]] name = "serde_repr" -version = "0.1.17" +version = "0.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3081f5ffbb02284dda55132aa26daecedd7372a42417bbbab6f14ab7d6bb9145" +checksum = "0b2e6b945e9d3df726b65d6ee24060aff8e3533d431f677a9695db04eff9dfdb" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] @@ -1837,7 +1834,7 @@ version = "3.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "64cd236ccc1b7a29e7e2739f27c0b2dd199804abc4290e32f59f3b68d6405c23" dependencies = [ - "base64 0.21.5", + "base64 0.21.7", "chrono", "hex", "indexmap 1.9.3", @@ -1857,7 +1854,7 @@ dependencies = [ "darling", "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] @@ -1919,16 +1916,6 @@ version = "1.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" -[[package]] -name = "socket2" -version = "0.4.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f7916fc008ca5542385b89a3d3ce689953c143e9304a9bf8beec1de48994c0d" -dependencies = [ - "libc", - "winapi", -] - [[package]] name = "socket2" version = "0.5.5" @@ -2078,7 +2065,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e37195395df71fd068f6e2082247891bc11e3289624bbc776a0cdfa1ca7f1ea4" dependencies = [ "atoi", - "base64 0.21.5", + "base64 0.21.7", "bitflags 2.4.1", "byteorder", "bytes", @@ -2121,7 +2108,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d6ac0ac3b7ccd10cc96c7ab29791a7dd236bd94021f31eec7ba3d46a74aa1c24" dependencies = [ "atoi", - "base64 0.21.5", + "base64 0.21.7", "bitflags 2.4.1", "byteorder", "chrono", @@ -2215,9 +2202,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.39" +version = "2.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" dependencies = [ "proc-macro2", "quote", @@ -2247,42 +2234,42 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.8.1" +version = "3.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ef1adac450ad7f4b3c28589471ade84f25f731a7a0fe30d71dfa9f60fd808e5" +checksum = "01ce4141aa927a6d1bd34a041795abd0db1cccba5d5f24b009f694bdf3a1f3fa" dependencies = [ "cfg-if", "fastrand", "redox_syscall", "rustix", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] name = "thiserror" -version = "1.0.50" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9a7210f5c9a7156bb50aa36aed4c95afb51df0df00713949448cf9e97d382d2" +checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.50" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8" +checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] name = "time" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4a34ab300f2dee6e562c10a046fc05e358b29f9bf92277f30c3c8d82275f6f5" +checksum = "f657ba42c3f86e7680e53c8cd3af8abbe56b5491790b46e22e19c0d57463583e" dependencies = [ "deranged", "itoa", @@ -2300,9 +2287,9 @@ checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" [[package]] name = "time-macros" -version = "0.2.15" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ad70d68dba9e1f8aceda7aa6711965dfec1cac869f311a51bd08b3a2ccbce20" +checksum = "26197e33420244aeb70c3e8c78376ca46571bc4e701e4791c2cd9f57dcb3a43f" dependencies = [ "time-core", ] @@ -2324,9 +2311,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.35.0" +version = "1.35.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "841d45b238a16291a4e1584e61820b8ae57d696cc5015c459c229ccc6990cc1c" +checksum = "c89b4efa943be685f629b149f53829423f8f5531ea21249408e8e2f8671ec104" dependencies = [ "backtrace", "bytes", @@ -2334,7 +2321,7 @@ dependencies = [ "mio", "num_cpus", "pin-project-lite", - "socket2 0.5.5", + "socket2", "tokio-macros", "windows-sys 0.48.0", ] @@ -2347,7 +2334,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] @@ -2453,7 +2440,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] @@ -2631,7 +2618,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", "wasm-bindgen-shared", ] @@ -2665,7 +2652,7 @@ checksum = "f0eb82fcb7930ae6219a7ecfd55b217f5f0893484b7a13022ebb2b2bf20b5283" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -2698,7 +2685,7 @@ checksum = "794645f5408c9a039fd09f4d113cdfb2e7eba5ff1956b07bcf701cf4b394fe89" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] @@ -2719,9 +2706,9 @@ checksum = "22fc3756b8a9133049b26c7f61ab35416c130e8c09b660f5b3958b446f52cc50" [[package]] name = "wildmatch" -version = "2.1.1" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee583bdc5ff1cf9db20e9db5bb3ff4c3089a8f6b8b31aff265c9aba85812db86" +checksum = "495ec47bf3c1345005f40724f0269362c8556cbc43aed0526ed44cae1d35fceb" [[package]] name = "winapi" @@ -2747,11 +2734,11 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "windows-core" -version = "0.51.1" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1f8cf84f35d2db49a46868f947758c7a1138116f7fac3bc844f43ade1292e64" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" dependencies = [ - "windows-targets 0.48.5", + "windows-targets 0.52.0", ] [[package]] @@ -2888,9 +2875,9 @@ checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" [[package]] name = "winnow" -version = "0.5.26" +version = "0.5.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b67b5f0a4e7a27a64c651977932b9dc5667ca7fc31ac44b03ed37a0cf42fdfff" +checksum = "b7cf47b659b318dccbd69cc4797a39ae128f533dce7902a1096044d1967b9c16" dependencies = [ "memchr", ] @@ -2926,22 +2913,22 @@ dependencies = [ [[package]] name = "zerocopy" -version = "0.7.30" +version = "0.7.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "306dca4455518f1f31635ec308b6b3e4eb1b11758cefafc782827d0aa7acb5c7" +checksum = "74d4d3961e53fa4c9a25a8637fc2bfaf2595b3d3ae34875568a5cf64787716be" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.7.30" +version = "0.7.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be912bf68235a88fbefd1b73415cb218405958d1655b2ece9035a19920bdf6ba" +checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index a37aa94..bcde77c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,32 +18,32 @@ rt = ["tokio/rt"] client = [] [dependencies] -tokio = { version = "1.34.0", features = ["macros", "sync"] } -serde = { version = "1.0.188", features = ["derive", "rc"] } -serde_json = { version = "1.0.105", features = ["raw_value"] } -serde-aux = "4.2.0" -serde_with = "3.3.0" -serde_repr = "0.1.16" +tokio = { version = "1.35.1", features = ["macros", "sync"] } +serde = { version = "1.0.195", features = ["derive", "rc"] } +serde_json = { version = "1.0.111", features = ["raw_value"] } +serde-aux = "4.3.1" +serde_with = "3.4.0" +serde_repr = "0.1.18" reqwest = { features = [ "multipart", "json", ], version = "0.11.23" } -url = "2.4.0" -chrono = { version = "0.4.26", features = ["serde"] } -regex = "1.9.4" +url = "2.5.0" +chrono = { version = "0.4.31", features = ["serde"] } +regex = "1.10.2" custom_error = "1.9.2" -futures-util = "0.3.28" -http = "0.2.9" -base64 = "0.21.3" -bitflags = { version = "2.4.0", features = ["serde"] } +futures-util = "0.3.30" +http = "0.2.11" +base64 = "0.21.7" +bitflags = { version = "2.4.1", features = ["serde"] } lazy_static = "1.4.0" -poem = { version = "1.3.57", optional = true } -thiserror = "1.0.47" +poem = { version = "1.3.59", optional = true } +thiserror = "1.0.56" jsonwebtoken = "8.3.0" log = "0.4.20" -async-trait = "0.1.73" +async-trait = "0.1.77" chorus-macros = "0.2.0" -sqlx = { version = "0.7.1", features = [ +sqlx = { version = "0.7.3", features = [ "mysql", "sqlite", "json", @@ -56,7 +56,7 @@ safina-timer = "0.1.11" rand = "0.8.5" [target.'cfg(not(target_arch = "wasm32"))'.dependencies] -rustls = "0.21.8" +rustls = "0.21.10" rustls-native-certs = "0.6.3" tokio-tungstenite = { version = "0.20.1", features = [ "rustls-tls-native-roots", @@ -66,11 +66,11 @@ native-tls = "0.2.11" hostname = "0.3.1" [target.'cfg(target_arch = "wasm32")'.dependencies] -getrandom = { version = "0.2.11", features = ["js"] } +getrandom = { version = "0.2.12", features = ["js"] } ws_stream_wasm = "0.7.4" -wasm-bindgen-futures = "0.4.38" +wasm-bindgen-futures = "0.4.39" [dev-dependencies] lazy_static = "1.4.0" -wasm-bindgen-test = "0.3.38" -wasm-bindgen = "0.2.88" +wasm-bindgen-test = "0.3.39" +wasm-bindgen = "0.2.89" From d37415fc1372d63cfabbacbdcbf619915a973f9c Mon Sep 17 00:00:00 2001 From: kozabrada123 <59031733+kozabrada123@users.noreply.github.com> Date: Fri, 19 Jan 2024 14:55:23 +0100 Subject: [PATCH 08/15] feat: fix heartbeat time on WASM --- Cargo.lock | 15 +++++++++++++++ Cargo.toml | 3 ++- src/gateway/heartbeat.rs | 19 +++++++++++++++---- 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ce509ab..1dc6cda 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -235,6 +235,7 @@ dependencies = [ "wasm-bindgen", "wasm-bindgen-futures", "wasm-bindgen-test", + "wasmtimer", "ws_stream_wasm", ] @@ -2688,6 +2689,20 @@ dependencies = [ "syn 2.0.48", ] +[[package]] +name = "wasmtimer" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f656cd8858a5164932d8a90f936700860976ec21eb00e0fe2aa8cab13f6b4cf" +dependencies = [ + "futures", + "js-sys", + "parking_lot", + "pin-utils", + "slab", + "wasm-bindgen", +] + [[package]] name = "web-sys" version = "0.3.66" diff --git a/Cargo.toml b/Cargo.toml index bcde77c..eff3453 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -52,7 +52,6 @@ sqlx = { version = "0.7.3", features = [ "runtime-tokio-native-tls", "any", ], optional = true } -safina-timer = "0.1.11" rand = "0.8.5" [target.'cfg(not(target_arch = "wasm32"))'.dependencies] @@ -64,11 +63,13 @@ tokio-tungstenite = { version = "0.20.1", features = [ ] } native-tls = "0.2.11" hostname = "0.3.1" +safina-timer = "0.1.11" [target.'cfg(target_arch = "wasm32")'.dependencies] getrandom = { version = "0.2.12", features = ["js"] } ws_stream_wasm = "0.7.4" wasm-bindgen-futures = "0.4.39" +wasmtimer = "0.2.0" [dev-dependencies] lazy_static = "1.4.0" diff --git a/src/gateway/heartbeat.rs b/src/gateway/heartbeat.rs index 1176517..0ee3b61 100644 --- a/src/gateway/heartbeat.rs +++ b/src/gateway/heartbeat.rs @@ -1,9 +1,20 @@ use futures_util::SinkExt; use log::*; -use std::time::{self, Duration, Instant}; + +#[cfg(not(target_arch = "wasm32"))] +use std::time::Instant; +#[cfg(target_arch = "wasm32")] +use wasmtimer::std::Instant; + +#[cfg(not(target_arch = "wasm32"))] +use safina_timer::sleep_until; +#[cfg(target_arch = "wasm32")] +use wasmtimer::tokio::sleep_until; + +use std::time::Duration; + use tokio::sync::mpsc::{Receiver, Sender}; -use safina_timer::sleep_until; #[cfg(not(target_arch = "wasm32"))] use tokio::task; @@ -57,7 +68,7 @@ impl HeartbeatHandler { mut receive: Receiver, mut kill_receive: tokio::sync::broadcast::Receiver<()>, ) { - let mut last_heartbeat_timestamp: Instant = time::Instant::now(); + let mut last_heartbeat_timestamp: Instant = Instant::now(); let mut last_heartbeat_acknowledged = true; let mut last_seq_number: Option = None; @@ -123,7 +134,7 @@ impl HeartbeatHandler { break; } - last_heartbeat_timestamp = time::Instant::now(); + last_heartbeat_timestamp = Instant::now(); last_heartbeat_acknowledged = false; } } From e2b69487aa63e73db67f4196234fe8bc17a9fdcc Mon Sep 17 00:00:00 2001 From: kozabrada123 <59031733+kozabrada123@users.noreply.github.com> Date: Fri, 19 Jan 2024 15:06:27 +0100 Subject: [PATCH 09/15] fix error --- src/gateway/heartbeat.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/gateway/heartbeat.rs b/src/gateway/heartbeat.rs index 0ee3b61..2204113 100644 --- a/src/gateway/heartbeat.rs +++ b/src/gateway/heartbeat.rs @@ -71,7 +71,8 @@ impl HeartbeatHandler { let mut last_heartbeat_timestamp: Instant = Instant::now(); let mut last_heartbeat_acknowledged = true; let mut last_seq_number: Option = None; - + + #[cfg(not(target_arch = "wasm32"))] safina_timer::start_timer_thread(); loop { From c3017df1c26f0228397d8b30888f33db65b9f687 Mon Sep 17 00:00:00 2001 From: kozabrada123 <59031733+kozabrada123@users.noreply.github.com> Date: Fri, 19 Jan 2024 15:14:50 +0100 Subject: [PATCH 10/15] fix tests --- examples/gateway_observers.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/examples/gateway_observers.rs b/examples/gateway_observers.rs index a13c935..5ea6506 100644 --- a/examples/gateway_observers.rs +++ b/examples/gateway_observers.rs @@ -8,6 +8,11 @@ use chorus::{ use std::{sync::Arc, time::Duration}; use tokio::{self}; +#[cfg(not(target_arch = "wasm32"))] +use safina_timer::sleep_for; +#[cfg(target_arch = "wasm32")] +use wasmtimer::tokio::sleep_for; + // This example creates a simple gateway connection and a basic observer struct // Due to certain limitations all observers must impl debug @@ -54,10 +59,12 @@ async fn main() { let mut identify = GatewayIdentifyPayload::common(); identify.token = token; gateway.send_identify(identify).await; + + #[cfg(not(target_arch = "wasm32"))] safina_timer::start_timer_thread(); // Do something on the main thread so we don't quit loop { - safina_timer::sleep_for(Duration::MAX).await + sleep_for(Duration::MAX).await } } From 921a3ef9c0f0df4308a49273de6a122baf1777cb Mon Sep 17 00:00:00 2001 From: kozabrada123 <59031733+kozabrada123@users.noreply.github.com> Date: Fri, 19 Jan 2024 15:21:53 +0100 Subject: [PATCH 11/15] fix: gateway simple example --- examples/gateway_simple.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/examples/gateway_simple.rs b/examples/gateway_simple.rs index 2996283..de6bd5d 100644 --- a/examples/gateway_simple.rs +++ b/examples/gateway_simple.rs @@ -3,6 +3,11 @@ use std::time::Duration; use chorus::gateway::Gateway; use chorus::{self, types::GatewayIdentifyPayload}; +#[cfg(not(target_arch = "wasm32"))] +use safina_timer::sleep_for; +#[cfg(target_arch = "wasm32")] +use wasmtimer::tokio::sleep_for; + /// This example creates a simple gateway connection and a session with an Identify event #[tokio::main(flavor = "current_thread")] async fn main() { @@ -10,7 +15,7 @@ async fn main() { let websocket_url_spacebar = "wss://gateway.old.server.spacebar.chat/".to_string(); // Initiate the gateway connection, starting a listener in one thread and a heartbeat handler in another - let _ = Gateway::spawn(websocket_url_spacebar).await.unwrap(); + let gateway = Gateway::spawn(websocket_url_spacebar).await.unwrap(); // At this point, we are connected to the server and are sending heartbeats, however we still haven't authenticated @@ -26,10 +31,13 @@ async fn main() { identify.token = token; // Send off the event + gateway.send_identify(identify).await; + + #[cfg(not(target_arch = "wasm32"))] safina_timer::start_timer_thread(); // Do something on the main thread so we don't quit loop { - safina_timer::sleep_for(Duration::MAX).await + sleep_for(Duration::MAX).await } } From 72936d4f21c8961634b735469186196270d26073 Mon Sep 17 00:00:00 2001 From: kozabrada123 <59031733+kozabrada123@users.noreply.github.com> Date: Fri, 19 Jan 2024 15:31:40 +0100 Subject: [PATCH 12/15] right --- examples/gateway_observers.rs | 7 +++++-- examples/gateway_simple.rs | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/examples/gateway_observers.rs b/examples/gateway_observers.rs index 5ea6506..b265dc5 100644 --- a/examples/gateway_observers.rs +++ b/examples/gateway_observers.rs @@ -11,7 +11,7 @@ use tokio::{self}; #[cfg(not(target_arch = "wasm32"))] use safina_timer::sleep_for; #[cfg(target_arch = "wasm32")] -use wasmtimer::tokio::sleep_for; +use wasmtimer::tokio::sleep; // This example creates a simple gateway connection and a basic observer struct @@ -65,6 +65,9 @@ async fn main() { // Do something on the main thread so we don't quit loop { - sleep_for(Duration::MAX).await + #[cfg(not(target_arch = "wasm32"))] + sleep_for(Duration::MAX).await; + #[cfg(target_arch = "wasm32")] + sleep(Duration::MAX).await; } } diff --git a/examples/gateway_simple.rs b/examples/gateway_simple.rs index de6bd5d..aaa0195 100644 --- a/examples/gateway_simple.rs +++ b/examples/gateway_simple.rs @@ -6,7 +6,7 @@ use chorus::{self, types::GatewayIdentifyPayload}; #[cfg(not(target_arch = "wasm32"))] use safina_timer::sleep_for; #[cfg(target_arch = "wasm32")] -use wasmtimer::tokio::sleep_for; +use wasmtimer::tokio::sleep; /// This example creates a simple gateway connection and a session with an Identify event #[tokio::main(flavor = "current_thread")] @@ -38,6 +38,9 @@ async fn main() { // Do something on the main thread so we don't quit loop { - sleep_for(Duration::MAX).await + #[cfg(not(target_arch = "wasm32"))] + sleep_for(Duration::MAX).await; + #[cfg(target_arch = "wasm32")] + sleep(Duration::MAX).await; } } From 34cc344c8d7ab53aad51bee62aab8d5340924ac5 Mon Sep 17 00:00:00 2001 From: kozabrada123 <59031733+kozabrada123@users.noreply.github.com> Date: Fri, 19 Jan 2024 15:48:59 +0100 Subject: [PATCH 13/15] feat: switch safina_timer for tokio, fix sleep duration overflow in examples --- Cargo.lock | 10 ---------- Cargo.toml | 1 - examples/gateway_observers.rs | 10 ++-------- examples/gateway_simple.rs | 10 ++-------- src/gateway/heartbeat.rs | 7 ++----- 5 files changed, 6 insertions(+), 32 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1dc6cda..9e4e135 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -221,7 +221,6 @@ dependencies = [ "reqwest", "rustls", "rustls-native-certs", - "safina-timer", "serde", "serde-aux", "serde_json", @@ -1689,15 +1688,6 @@ version = "1.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" -[[package]] -name = "safina-timer" -version = "0.1.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1081a264d1a3e81b75c4bcd5696094fb6ce470c2ded14cbd47bcb5229079b9df" -dependencies = [ - "once_cell", -] - [[package]] name = "schannel" version = "0.1.23" diff --git a/Cargo.toml b/Cargo.toml index eff3453..bc1eb18 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -63,7 +63,6 @@ tokio-tungstenite = { version = "0.20.1", features = [ ] } native-tls = "0.2.11" hostname = "0.3.1" -safina-timer = "0.1.11" [target.'cfg(target_arch = "wasm32")'.dependencies] getrandom = { version = "0.2.12", features = ["js"] } diff --git a/examples/gateway_observers.rs b/examples/gateway_observers.rs index b265dc5..a26ecfb 100644 --- a/examples/gateway_observers.rs +++ b/examples/gateway_observers.rs @@ -9,7 +9,7 @@ use std::{sync::Arc, time::Duration}; use tokio::{self}; #[cfg(not(target_arch = "wasm32"))] -use safina_timer::sleep_for; +use tokio::time::sleep; #[cfg(target_arch = "wasm32")] use wasmtimer::tokio::sleep; @@ -60,14 +60,8 @@ async fn main() { identify.token = token; gateway.send_identify(identify).await; - #[cfg(not(target_arch = "wasm32"))] - safina_timer::start_timer_thread(); - // Do something on the main thread so we don't quit loop { - #[cfg(not(target_arch = "wasm32"))] - sleep_for(Duration::MAX).await; - #[cfg(target_arch = "wasm32")] - sleep(Duration::MAX).await; + sleep(Duration::from_secs(3600)).await; } } diff --git a/examples/gateway_simple.rs b/examples/gateway_simple.rs index aaa0195..affa850 100644 --- a/examples/gateway_simple.rs +++ b/examples/gateway_simple.rs @@ -4,7 +4,7 @@ use chorus::gateway::Gateway; use chorus::{self, types::GatewayIdentifyPayload}; #[cfg(not(target_arch = "wasm32"))] -use safina_timer::sleep_for; +use tokio::time::sleep; #[cfg(target_arch = "wasm32")] use wasmtimer::tokio::sleep; @@ -33,14 +33,8 @@ async fn main() { // Send off the event gateway.send_identify(identify).await; - #[cfg(not(target_arch = "wasm32"))] - safina_timer::start_timer_thread(); - // Do something on the main thread so we don't quit loop { - #[cfg(not(target_arch = "wasm32"))] - sleep_for(Duration::MAX).await; - #[cfg(target_arch = "wasm32")] - sleep(Duration::MAX).await; + sleep(Duration::from_secs(3600)).await; } } diff --git a/src/gateway/heartbeat.rs b/src/gateway/heartbeat.rs index 2204113..8e37697 100644 --- a/src/gateway/heartbeat.rs +++ b/src/gateway/heartbeat.rs @@ -2,12 +2,12 @@ use futures_util::SinkExt; use log::*; #[cfg(not(target_arch = "wasm32"))] -use std::time::Instant; +use tokio::time::Instant; #[cfg(target_arch = "wasm32")] use wasmtimer::std::Instant; #[cfg(not(target_arch = "wasm32"))] -use safina_timer::sleep_until; +use tokio::time::sleep_until; #[cfg(target_arch = "wasm32")] use wasmtimer::tokio::sleep_until; @@ -72,9 +72,6 @@ impl HeartbeatHandler { let mut last_heartbeat_acknowledged = true; let mut last_seq_number: Option = None; - #[cfg(not(target_arch = "wasm32"))] - safina_timer::start_timer_thread(); - loop { if kill_receive.try_recv().is_ok() { trace!("GW: Closing heartbeat task"); From 8243f103f90c878cd347edd631d80adf087ffabf Mon Sep 17 00:00:00 2001 From: kozabrada123 <59031733+kozabrada123@users.noreply.github.com> Date: Fri, 19 Jan 2024 15:53:24 +0100 Subject: [PATCH 14/15] Mess w/ the tests to see if it really works --- Cargo.lock | 29 +++++++++++++++-------------- Cargo.toml | 1 + src/gateway/heartbeat.rs | 5 +++++ tests/gateway.rs | 4 +++- 4 files changed, 24 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9e4e135..1bba5a2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -235,6 +235,7 @@ dependencies = [ "wasm-bindgen-futures", "wasm-bindgen-test", "wasmtimer", + "web-sys", "ws_stream_wasm", ] @@ -955,9 +956,9 @@ checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" [[package]] name = "js-sys" -version = "0.3.66" +version = "0.3.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cee9c64da59eae3b50095c18d3e74f8b73c0b86d2792824ff01bbce68ba229ca" +checksum = "9a1d36f1235bc969acba30b7f5990b864423a6068a10f7c90ae8f0112e3a59d1" dependencies = [ "wasm-bindgen", ] @@ -2590,9 +2591,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.89" +version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ed0d4f68a3015cc185aff4db9506a015f4b96f95303897bfa23f846db54064e" +checksum = "b1223296a201415c7fad14792dbefaace9bd52b62d33453ade1c5b5f07555406" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -2600,9 +2601,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.89" +version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b56f625e64f3a1084ded111c4d5f477df9f8c92df113852fa5a374dbda78826" +checksum = "fcdc935b63408d58a32f8cc9738a0bffd8f05cc7c002086c6ef20b7312ad9dcd" dependencies = [ "bumpalo", "log", @@ -2627,9 +2628,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.89" +version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0162dbf37223cd2afce98f3d0785506dcb8d266223983e4b5b525859e6e182b2" +checksum = "3e4c238561b2d428924c49815533a8b9121c664599558a5d9ec51f8a1740a999" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -2637,9 +2638,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.89" +version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0eb82fcb7930ae6219a7ecfd55b217f5f0893484b7a13022ebb2b2bf20b5283" +checksum = "bae1abb6806dc1ad9e560ed242107c0f6c84335f1749dd4e8ddb012ebd5e25a7" dependencies = [ "proc-macro2", "quote", @@ -2650,9 +2651,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.89" +version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ab9b36309365056cd639da3134bf87fa8f3d86008abf99e612384a6eecd459f" +checksum = "4d91413b1c31d7539ba5ef2451af3f0b833a005eb27a631cec32bc0635a8602b" [[package]] name = "wasm-bindgen-test" @@ -2695,9 +2696,9 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.66" +version = "0.3.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50c24a44ec86bb68fbecd1b3efed7e85ea5621b39b35ef2766b66cd984f8010f" +checksum = "58cd2333b6e0be7a39605f0e255892fd7418a682d8da8fe042fe25128794d2ed" dependencies = [ "js-sys", "wasm-bindgen", diff --git a/Cargo.toml b/Cargo.toml index bc1eb18..b7b93cc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -69,6 +69,7 @@ getrandom = { version = "0.2.12", features = ["js"] } ws_stream_wasm = "0.7.4" wasm-bindgen-futures = "0.4.39" wasmtimer = "0.2.0" +web-sys = "0.3.67" [dev-dependencies] lazy_static = "1.4.0" diff --git a/src/gateway/heartbeat.rs b/src/gateway/heartbeat.rs index 8e37697..e9805b9 100644 --- a/src/gateway/heartbeat.rs +++ b/src/gateway/heartbeat.rs @@ -73,6 +73,11 @@ impl HeartbeatHandler { let mut last_seq_number: Option = None; loop { + #[cfg(target_arch = "wasm32")] + web_sys::console::log_1(&String::from("Heartbeat works!").into()); + + println!("Heartbeat works!"); + if kill_receive.try_recv().is_ok() { trace!("GW: Closing heartbeat task"); break; diff --git a/tests/gateway.rs b/tests/gateway.rs index 5bf5865..5484c43 100644 --- a/tests/gateway.rs +++ b/tests/gateway.rs @@ -32,7 +32,9 @@ async fn test_gateway_authenticate() { identify.token = bundle.user.token.clone(); gateway.send_identify(identify).await; - common::teardown(bundle).await + common::teardown(bundle).await; + + assert!(false); } #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] From 8a2bc8287edb4b01e0c81390b347ffce16ba7238 Mon Sep 17 00:00:00 2001 From: kozabrada123 <59031733+kozabrada123@users.noreply.github.com> Date: Fri, 19 Jan 2024 16:05:34 +0100 Subject: [PATCH 15/15] Revert "Mess w/ the tests to see if it really works" This reverts commit 8243f103f90c878cd347edd631d80adf087ffabf. --- Cargo.lock | 29 ++++++++++++++--------------- Cargo.toml | 1 - src/gateway/heartbeat.rs | 5 ----- tests/gateway.rs | 4 +--- 4 files changed, 15 insertions(+), 24 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1bba5a2..9e4e135 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -235,7 +235,6 @@ dependencies = [ "wasm-bindgen-futures", "wasm-bindgen-test", "wasmtimer", - "web-sys", "ws_stream_wasm", ] @@ -956,9 +955,9 @@ checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" [[package]] name = "js-sys" -version = "0.3.67" +version = "0.3.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a1d36f1235bc969acba30b7f5990b864423a6068a10f7c90ae8f0112e3a59d1" +checksum = "cee9c64da59eae3b50095c18d3e74f8b73c0b86d2792824ff01bbce68ba229ca" dependencies = [ "wasm-bindgen", ] @@ -2591,9 +2590,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.90" +version = "0.2.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1223296a201415c7fad14792dbefaace9bd52b62d33453ade1c5b5f07555406" +checksum = "0ed0d4f68a3015cc185aff4db9506a015f4b96f95303897bfa23f846db54064e" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -2601,9 +2600,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.90" +version = "0.2.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcdc935b63408d58a32f8cc9738a0bffd8f05cc7c002086c6ef20b7312ad9dcd" +checksum = "1b56f625e64f3a1084ded111c4d5f477df9f8c92df113852fa5a374dbda78826" dependencies = [ "bumpalo", "log", @@ -2628,9 +2627,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.90" +version = "0.2.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e4c238561b2d428924c49815533a8b9121c664599558a5d9ec51f8a1740a999" +checksum = "0162dbf37223cd2afce98f3d0785506dcb8d266223983e4b5b525859e6e182b2" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -2638,9 +2637,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.90" +version = "0.2.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bae1abb6806dc1ad9e560ed242107c0f6c84335f1749dd4e8ddb012ebd5e25a7" +checksum = "f0eb82fcb7930ae6219a7ecfd55b217f5f0893484b7a13022ebb2b2bf20b5283" dependencies = [ "proc-macro2", "quote", @@ -2651,9 +2650,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.90" +version = "0.2.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d91413b1c31d7539ba5ef2451af3f0b833a005eb27a631cec32bc0635a8602b" +checksum = "7ab9b36309365056cd639da3134bf87fa8f3d86008abf99e612384a6eecd459f" [[package]] name = "wasm-bindgen-test" @@ -2696,9 +2695,9 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.67" +version = "0.3.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58cd2333b6e0be7a39605f0e255892fd7418a682d8da8fe042fe25128794d2ed" +checksum = "50c24a44ec86bb68fbecd1b3efed7e85ea5621b39b35ef2766b66cd984f8010f" dependencies = [ "js-sys", "wasm-bindgen", diff --git a/Cargo.toml b/Cargo.toml index b7b93cc..bc1eb18 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -69,7 +69,6 @@ getrandom = { version = "0.2.12", features = ["js"] } ws_stream_wasm = "0.7.4" wasm-bindgen-futures = "0.4.39" wasmtimer = "0.2.0" -web-sys = "0.3.67" [dev-dependencies] lazy_static = "1.4.0" diff --git a/src/gateway/heartbeat.rs b/src/gateway/heartbeat.rs index e9805b9..8e37697 100644 --- a/src/gateway/heartbeat.rs +++ b/src/gateway/heartbeat.rs @@ -73,11 +73,6 @@ impl HeartbeatHandler { let mut last_seq_number: Option = None; loop { - #[cfg(target_arch = "wasm32")] - web_sys::console::log_1(&String::from("Heartbeat works!").into()); - - println!("Heartbeat works!"); - if kill_receive.try_recv().is_ok() { trace!("GW: Closing heartbeat task"); break; diff --git a/tests/gateway.rs b/tests/gateway.rs index 5484c43..5bf5865 100644 --- a/tests/gateway.rs +++ b/tests/gateway.rs @@ -32,9 +32,7 @@ async fn test_gateway_authenticate() { identify.token = bundle.user.token.clone(); gateway.send_identify(identify).await; - common::teardown(bundle).await; - - assert!(false); + common::teardown(bundle).await } #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]