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

yerpc question: sending updates from Rust to TypeScript (web)? #59

Closed
greatcat19 opened this issue Nov 19, 2023 · 1 comment
Closed

Comments

@greatcat19
Copy link

If there's new data update from Rust, is there any way to send it from Rust to TypeScript?

I also found Notification, but it seems to be Notifications from TypeScript to Rust.
#56

@Simon-Laux
Copy link
Member

Simon-Laux commented Feb 3, 2024

In deltachat we switched to a fetch next event loop (long polling) on the client:

while (true) {
  let event = await rpc.getNextEvent()
}

Our actual implementation:

https://github.com/deltachat/deltachat-core-rust/blob/bce5203eebc95357d293ee948f78f1c96a057db9/deltachat-jsonrpc/typescript/src/client.ts#L45-L61

If you do your own transport for jsonrpc you can also inject your own notification messages, we did this previously in deltachat. (the commit that changed it from notifications to long polling: deltachat/deltachat-core-rust@514074d#diff-7151c7c6805a166dc5109686642fbd1c6e9a667279da9fa5d365f997cb9874b8)

Basically looked like this:

async fn handler(ws: WebSocketUpgrade, Extension(api): Extension<CommandApi>) -> Response {
     let (client, out_receiver) = RpcClient::new();
     let session = RpcSession::new(client.clone(), api.clone());
     tokio::spawn(async move {
         let events = api.accounts.read().await.get_event_emitter();
         while let Some(event) = events.recv().await {
             let event = event_to_json_rpc_notification(event);
             client.send_notification("event", Some(event)).await.ok();
         }
     });
     handle_ws_rpc(ws, out_receiver, session).await
 }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants