Yeah had a few problems with the smart
Yeah had a few problems with the smart pointers a while ago as well. But I'll give it another go. My problem right now though is that I can't call self from within the event handler.
8 Replies
is "self" here the actual durable object?
Yup.
Here's the struct for self.
#[durable_object]
pub struct Server{
network: Network,
state: State,
env: Env,
}
ok, so what I ended up doing is basically keeping my equivalent of Network wrapped in Rc<RefCell<Network>>, and then passing a clone of that into my event handler
you can see my code here: https://github.com/radix/arpeggiorpg/blob/main/worker/src/durablegame.rs
GitHub
arpeggiorpg/worker/src/durablegame.rs at main · radix/arpeggiorpg
A tabletop role-playing game system. Contribute to radix/arpeggiorpg development by creating an account on GitHub.
(there's still a lot I need to do on how I maintain the websockets -- I'm not yet cleaning them up when they disconnect, but the general idea is there & works)
I created a separate struct in "wsrpi.rs" that is responsible for handling a single connection, and it has a clone of that Rc<RefCell<Network>>, and that's where my "broadcast" method lives: https://github.com/radix/arpeggiorpg/blob/main/worker/src/wsrpi.rs#L269
GitHub
arpeggiorpg/worker/src/wsrpi.rs at main · radix/arpeggiorpg
A tabletop role-playing game system. Contribute to radix/arpeggiorpg development by creating an account on GitHub.
Genius. Looking into it right now! Thanks.
@radix I'm finding that for some reason evokes this panic"called
Result::unwrap()
on an Err
value: JsValue(RangeError: Responses may only be constructed with status codes in the range 200 to 599, inclusive."
Any clue as to why?
I mean I get that it returns a 101 that's what it's supposed to return for websockets right?
Nevermind it works. Was a version issue.oh, interesting. I was going to say, that sounds really strange 🙂 glad you got it working.