Skip to content

Commit

Permalink
feat: Send pong
Browse files Browse the repository at this point in the history
  • Loading branch information
jcs090218 committed May 23, 2024
1 parent a2922f6 commit 511ce95
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
27 changes: 22 additions & 5 deletions src/handler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ pub async fn handle(connection: &mut server::Connection, json: &str) {
println!("{}: {:?}", "val", val["method"]);

match method {
"ping" => {
ping::handle(connection, &val).await;
}
"enter" => {
enter::handle(connection, &val).await;
}
Expand All @@ -30,15 +33,29 @@ pub async fn handle(connection: &mut server::Connection, json: &str) {
}
}

/// Ping pong
mod ping {
use crate::server;

pub async fn handle(connection: &mut server::Connection, json: &serde_json::Value) {
tracing::trace!("method: {:?}", json["method"]);
connection
.send(serde_json::json!({
"method": "pong",
}))
.await;
}
}

/// Enter session
mod enter {
use crate::server;

pub async fn handle(connection: &mut server::Connection, json: &serde_json::Value) {

Check failure on line 54 in src/handler/mod.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

unused variable: `json`

Check failure on line 54 in src/handler/mod.rs

View workflow job for this annotation

GitHub Actions / test (macos-latest)

unused variable: `json`

Check failure on line 54 in src/handler/mod.rs

View workflow job for this annotation

GitHub Actions / test (windows-latest)

unused variable: `json`
tracing::trace!("method: {:?}", json["method"]);
connection.send(serde_json::json!({
"jsonrpc": "2.0",
"method": "enter",
})).await;
connection
.send(serde_json::json!({
"method": "enter",
}))
.await;
}
}
3 changes: 2 additions & 1 deletion src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ impl Connection {
}

pub async fn send(&mut self, params: serde_json::Value) {
let data_str = params.to_string();
let json_str = params.to_string();
let data_str = format!("Content-Length: {}\r\n\r\n{}", json_str.len(), json_str);
let data = data_str.as_bytes();
self.write(&data).await;
}
Expand Down

0 comments on commit 511ce95

Please sign in to comment.