Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade edn to fix #12

Merged
merged 2 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "calcit_wss"
version = "0.2.1"
version = "0.2.3"
authors = ["jiyinyiyong <jiyinyiyong@gmail.com>"]
edition = "2021"

Expand All @@ -13,7 +13,6 @@ crate-type = ["dylib"] # Creates dynamic lib
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
cirru_edn = "0.5.4"
cirru_edn = "0.6.3"
lazy_static = "1.4.0"
simple-websockets = "0.1.6"

8 changes: 5 additions & 3 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

rm -rfv dylibs/
cargo build --release
mkdir -p dylibs/ && ls target/release/ && cp -v target/release/*.* dylibs/
rm -rfv dylibs/ && \
cargo build --release && \
mkdir -p dylibs/ && \
ls target/release/ && \
cp -v target/release/*.* dylibs/
2 changes: 1 addition & 1 deletion calcit.cirru

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 18 additions & 15 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use cirru_edn::Edn;
use cirru_edn::{Edn, EdnTupleView};
use lazy_static::lazy_static;
use simple_websockets::{Event, Message, Responder};
use std::collections::HashMap;
Expand All @@ -21,7 +21,7 @@ pub fn wss_serve(
_finish: Box<dyn FnOnce()>,
) -> Result<Edn, String> {
let port = match args.first() {
Some(Edn::Map(m)) => match m.get(&Edn::tag("port")) {
Some(Edn::Map(m)) => match m.tag_get("port") {
Some(Edn::Number(n)) => n.floor().round() as u16,
Some(a) => return Err(format!("Unknown port: {}", a)),
None => 9001,
Expand All @@ -44,7 +44,10 @@ pub fn wss_serve(
let mut clients = CLIENTS.write().unwrap();
clients.insert(client_id, responder);
}
if let Err(e) = handler(vec![Edn::Tuple(Arc::new(Edn::tag("connect")), vec![Edn::Number(client_id as f64)])]) {
if let Err(e) = handler(vec![Edn::Tuple(EdnTupleView {
tag: Arc::new(Edn::tag("connect")),
extra: vec![Edn::Number(client_id as f64)],
})]) {
println!("Failed to handle connect: {}", e)
}
}
Expand All @@ -54,27 +57,27 @@ pub fn wss_serve(
let mut clients = CLIENTS.write().unwrap();
clients.remove(&client_id);
}
if let Err(e) = handler(vec![Edn::Tuple(
Arc::new(Edn::tag("disconnect")),
vec![Edn::Number(client_id as f64)],
)]) {
if let Err(e) = handler(vec![Edn::Tuple(EdnTupleView {
tag: Arc::new(Edn::tag("disconnect")),
extra: vec![Edn::Number(client_id as f64)],
})]) {
println!("Failed to handle disconnect: {}", e)
}
}
Event::Message(client_id, message) => match message {
Message::Text(s) => {
if let Err(e) = handler(vec![Edn::Tuple(
Arc::new(Edn::tag("message")),
vec![Edn::Number(client_id as f64), Edn::Str(s.into())],
)]) {
if let Err(e) = handler(vec![Edn::Tuple(EdnTupleView {
tag: Arc::new(Edn::tag("message")),
extra: vec![Edn::Number(client_id as f64), Edn::Str(s.into())],
})]) {
println!("Failed to handle text message: {}", e)
}
}
Message::Binary(buf) => {
if let Err(e) = handler(vec![Edn::Tuple(
Arc::new(Edn::tag("blob")),
vec![Edn::Number(client_id as f64), Edn::Buffer(buf)],
)]) {
if let Err(e) = handler(vec![Edn::Tuple(EdnTupleView {
tag: Arc::new(Edn::tag("blob")),
extra: vec![Edn::Number(client_id as f64), Edn::Buffer(buf)],
})]) {
println!("Failed to handle binary message: {}", e)
}
}
Expand Down
Loading