Skip to content

Commit

Permalink
refactor: move WsId out from loaded settings
Browse files Browse the repository at this point in the history
  • Loading branch information
c-git committed Dec 13, 2024
1 parent 03b79e7 commit 770d767
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion crates/plugin-chat/src/server_only.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ mod plugin_impl;
mod server;

pub use connections::{chat_get_token, chat_ws_start_session};
pub use plugin_impl::{ChatPlugin, ChatSettings};
pub use plugin_impl::{ChatPlugin, ChatPluginConfig, ChatSettings};
15 changes: 12 additions & 3 deletions crates/plugin-chat/src/server_only/plugin_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@ use super::server::{ChatServer, ChatServerHandle};
#[derive(serde::Deserialize, Clone)]
pub struct ChatSettings {
pub heartbeat_interval_secs: u8,
}

pub struct ChatPluginConfig {
pub ws_id: WsId,
pub settings: ChatSettings,
}

pub struct ChatPlugin;

impl ServerPlugin for ChatPlugin {
type Config = ChatSettings;
type Config = ChatPluginConfig;

type Task = ChatServer;

Expand All @@ -28,8 +32,13 @@ impl ServerPlugin for ChatPlugin {
ws_config: &wykies_server::WebSocketSettings,
) -> anyhow::Result<wykies_server::plugin::ServerPluginArtifacts<Self::Task, Self::Handle>>
{
let (chat_server, chat_server_handle) =
ChatServer::new(config, ws_config, db_pool, cancellation_token);
let (chat_server, chat_server_handle) = ChatServer::new(
&config.settings,
config.ws_id,
ws_config,
db_pool,
cancellation_token,
);
Ok(ServerPluginArtifacts {
task: chat_server,
handle: Arc::new(chat_server_handle),
Expand Down
3 changes: 2 additions & 1 deletion crates/plugin-chat/src/server_only/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ pub struct ChatServerHandle {
impl ChatServer {
pub fn new(
config: &ChatSettings,
ws_id: WsId,
ws_config: &WebSocketSettings,
db_pool: DbPool,
cancellation_token: TrackedCancellationToken,
Expand Down Expand Up @@ -97,7 +98,7 @@ impl ChatServer {
ChatServerHandle {
cmd_tx,
heartbeat_config,
ws_id: config.ws_id,
ws_id,
},
)
}
Expand Down

0 comments on commit 770d767

Please sign in to comment.