yerpc question: sending updates from Rust to TypeScript (web)?
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. https://github.com/deltachat/yerpc/issues/56
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: https://github.com/deltachat/deltachat-core-rust/commit/514074de8bcd22c3181317e19238131d328ef3a1#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
}