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

Version updates #41

Merged
merged 11 commits into from
May 5, 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
1,985 changes: 1,101 additions & 884 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[workspace]
resolver = "2"

exclude = [
"./examples"
Expand Down
5 changes: 3 additions & 2 deletions aper-serve/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ publish = false
[dependencies]
aper = { path = "../aper" }
aper-stateroom = {path = "../aper-stateroom"}
env_logger = "0.9.0"
stateroom-server = { version="0.2.5" }
env_logger = "0.11.3"
stateroom-server = { version="0.4.0" }
log = "0.4.17"
stateroom = "0.4.2"
9 changes: 5 additions & 4 deletions aper-serve/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
use aper_stateroom::{AperStateroomServiceBuilder, StateProgram};
use aper_stateroom::{AperStateroomService, StateProgram};
use env_logger::Builder;
use stateroom_server::{Server, ServiceActorContext};
use stateroom::DefaultStateroomFactory;
use stateroom_server::Server;

pub fn serve<F: StateProgram + Send + Sync + Default + Unpin>() -> std::io::Result<()> {
let mut builder = Builder::new();
builder.filter(Some("stateroom_server"), log::LevelFilter::Info);
builder.filter(Some("stateroom_wasm_host"), log::LevelFilter::Info);
builder.init();

let host_factory: AperStateroomServiceBuilder<F, ServiceActorContext> =
AperStateroomServiceBuilder::default();
let host_factory: DefaultStateroomFactory<AperStateroomService<F>> =
DefaultStateroomFactory::default();

let server = Server::new();

Expand Down
2 changes: 1 addition & 1 deletion aper-stateroom/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ repository = "https://github.com/drifting-in-space/aper"
publish = false

[dependencies]
stateroom = { version="0.2.5", features=["serde"] }
stateroom = { version="0.4.0", features=["serde"] }
aper = { version="0.2.1", path = "../aper" }
serde = "1.0.143"
serde_json = "1.0.75"
Expand Down
85 changes: 29 additions & 56 deletions aper-stateroom/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@ use serde::{Deserialize, Serialize};
pub use state_program::{StateMachineContainerProgram, StateProgram};
pub use state_program_client::StateProgramClient;
pub use stateroom::ClientId;
use stateroom::{
MessageRecipient, SimpleStateroomService, StateroomContext, StateroomServiceFactory,
WrappedStateroomService,
};
use std::convert::Infallible;
use std::marker::PhantomData;
use stateroom::{MessagePayload, MessageRecipient, StateroomContext, StateroomService};

mod state_program;
mod state_program_client;
Expand All @@ -39,12 +34,21 @@ where
},
}

pub struct AperStateroomService<P: StateProgram> {
pub struct AperStateroomService<P: StateProgram + Default> {
state: StateServer<P>,
suspended_event: Option<TransitionEvent<P::T>>,
}

impl<P: StateProgram> AperStateroomService<P> {
impl<P: StateProgram + Default> Default for AperStateroomService<P> {
fn default() -> Self {
AperStateroomService {
state: StateServer::default(),
suspended_event: None,
}
}
}

impl<P: StateProgram + Default> AperStateroomService<P> {
fn update_suspended_event(&mut self, ctx: &impl StateroomContext) {
let susp = self.state.state().suspended_event();
if susp == self.suspended_event {
Expand Down Expand Up @@ -117,21 +121,10 @@ impl<P: StateProgram> AperStateroomService<P> {
}
}

impl<P: StateProgram + Default> SimpleStateroomService for AperStateroomService<P>
impl<P: StateProgram + Default> StateroomService for AperStateroomService<P>
where
P::T: Unpin + Send + Sync + 'static,
{
fn new(_name: &str, ctx: &impl StateroomContext) -> Self {
let state: StateServer<P> = StateServer::default();
let mut serv = AperStateroomService {
state,
suspended_event: None,
};
serv.update_suspended_event(ctx);

serv
}

fn connect(&mut self, client_id: ClientId, ctx: &impl StateroomContext) {
let response = StateProgramMessage::InitialState {
timestamp: Utc::now(),
Expand All @@ -148,14 +141,22 @@ where

fn disconnect(&mut self, _user: ClientId, _ctx: &impl StateroomContext) {}

fn message(&mut self, client_id: ClientId, message: &str, ctx: &impl StateroomContext) {
let message: MessageToServer<P> = serde_json::from_str(message).unwrap();
self.process_message(message, Some(client_id), ctx);
}

fn binary(&mut self, client_id: ClientId, message: &[u8], ctx: &impl StateroomContext) {
let message: MessageToServer<P> = bincode::deserialize(message).unwrap();
self.process_message(message, Some(client_id), ctx);
fn message(
&mut self,
client_id: ClientId,
message: MessagePayload,
ctx: &impl StateroomContext,
) {
match message {
MessagePayload::Text(txt) => {
let message: MessageToServer<P> = serde_json::from_str(&txt).unwrap();
self.process_message(message, Some(client_id), ctx);
}
MessagePayload::Bytes(bytes) => {
let message: MessageToServer<P> = bincode::deserialize(&bytes).unwrap();
self.process_message(message, Some(client_id), ctx);
}
}
}

fn timer(&mut self, ctx: &impl StateroomContext) {
Expand All @@ -172,34 +173,6 @@ where
}
}

pub struct AperStateroomServiceBuilder<K: StateProgram, C: StateroomContext> {
ph_k: PhantomData<K>,
ph_c: PhantomData<C>,
}

impl<K: StateProgram, C: StateroomContext> Default for AperStateroomServiceBuilder<K, C> {
fn default() -> Self {
AperStateroomServiceBuilder {
ph_k: Default::default(),
ph_c: Default::default(),
}
}
}

impl<K: StateProgram + Default, C: StateroomContext> StateroomServiceFactory<C>
for AperStateroomServiceBuilder<K, C>
where
K::T: Unpin + Send + Sync + 'static,
{
type Service = WrappedStateroomService<AperStateroomService<K>, C>;
type Error = Infallible;

fn build(&self, room_id: &str, context: C) -> Result<Self::Service, Infallible> {
let service = AperStateroomService::new(room_id, &context);
Ok(WrappedStateroomService::new(service, context))
}
}

pub type Timestamp = DateTime<Utc>;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
Expand Down
6 changes: 4 additions & 2 deletions aper-stateroom/src/state_program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ use std::fmt::Debug;
/// This trait can be added to a [StateMachine] which takes a [TransitionEvent] as
/// its transition. Only state machines with this trait can be used directly with
/// the aper client/server infrastructure.
pub trait StateProgram: StateMachine<Transition = TransitionEvent<Self::T>>
pub trait StateProgram:
StateMachine<Transition = TransitionEvent<Self::T>> + Send + Sync + 'static
where
<Self as StateProgram>::T: Unpin + Send + Sync,
{
Expand Down Expand Up @@ -61,7 +62,8 @@ where
}
}

impl<SM: StateMachine + Default> StateProgram for StateMachineContainerProgram<SM>
impl<SM: StateMachine + Default + Send + Sync + 'static> StateProgram
for StateMachineContainerProgram<SM>
where
<SM as StateMachine>::Transition: Send + Unpin + Sync,
{
Expand Down
2 changes: 1 addition & 1 deletion aper-websocket-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ js-sys = "0.3.59"
serde = "1.0.143"
serde_json = "1.0.74"
wasm-bindgen = "0.2.82"
web-sys = { version = "0.3.59", features = ["BinaryType", "WebSocket"] }
web-sys = { version = "0.3.59", features = ["BinaryType", "WebSocket", "MessageEvent"] }
6 changes: 3 additions & 3 deletions aper-yew/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ aper-websocket-client = { path="../aper-websocket-client" }
bincode = "1.3.3"
chrono = { version = "0.4.22", features = ["serde", "wasmbind"] }
console_error_panic_hook = "0.1.7"
gloo-storage = "0.2.2"
gloo-timers = "0.2.4"
gloo-storage = "0.3.0"
gloo-timers = "0.3.0"
js-sys = "0.3.59"
rand = "0.8.5"
serde = "1.0.143"
serde_json = "1.0.74"
wasm-bindgen = "0.2.82"
web-sys = { version = "0.3.59", features = ["BinaryType", "WebSocket"] }
yew = "0.19.3"
yew = "0.21.0"
15 changes: 6 additions & 9 deletions aper-yew/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ pub use aper_stateroom::{ClientId, StateMachineContainerProgram, StateProgram, T
use aper_websocket_client::AperWebSocketStateProgramClient;
use chrono::Duration;
use gloo_storage::{SessionStorage, Storage};
use rand::Rng;
use rand::distributions::Alphanumeric;
use rand::Rng;
use std::marker::PhantomData;
use std::{fmt::Debug, rc::Rc};
pub use update_interval::UpdateInterval;
Expand Down Expand Up @@ -81,7 +81,7 @@ impl<V: StateProgramViewComponent> StateProgramComponent<V> {
/// Initiate a connection to the remote server.
fn do_connect(&mut self, context: &yew::Context<Self>) {
let link = context.link().clone();

let token = if let Ok(token) = SessionStorage::get::<String>(CONNECTION_TOKEN_KEY) {
token
} else {
Expand All @@ -90,19 +90,16 @@ impl<V: StateProgramViewComponent> StateProgramComponent<V> {
.take(24)
.map(char::from)
.collect();

SessionStorage::set(CONNECTION_TOKEN_KEY, &token).expect("Couldn't set session state.");
token
};

let url = format!("{}?token={}", context.props().websocket_url, token);

let client = AperWebSocketStateProgramClient::new(
&url,
move |state, offset, client_id| {
link.send_message(Msg::SetState(state, offset, client_id))
},
)
let client = AperWebSocketStateProgramClient::new(&url, move |state, offset, client_id| {
link.send_message(Msg::SetState(state, offset, client_id))
})
.unwrap();
self.client = Some(client);
}
Expand Down
2 changes: 1 addition & 1 deletion aper/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ categories = ["data-structures", "web-programming::websocket", "wasm"]
serde = { version = "1.0.143", features = ["derive"] }
uuid = { version = "1.1.2", features = ["serde", "v4", "js"] }
aper_derive = { version="0.2.1", path="./aper_derive" }
fractional_index = "1.0.0"
fractional_index = "2.0.1"
im-rc = { version = "15.1.0", features = ["serde"] }

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion aper/aper_derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ proc-macro = true
inflections = "1.1.1"
proc-macro2 = "1.0.43"
quote = "1.0.21"
syn = { version = "1.0.99", features = ["full"] }
syn = "2.0.1"
1 change: 1 addition & 0 deletions aper/src/data_structures/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ mod atom;
mod atom_rc;
mod constant;
mod counter;
#[allow(deprecated)] // ZenoIndex is deprecated in fractional_index 2.0.0.
mod list;
mod map;

Expand Down
Loading
Loading