cf3fd00350
* - standardise versions for all nym-sdk workspace dependencies - prepend sqlx-pool-guard with 'nym-' * Test remove nym-api from deps * Add oneliner to client_pool doc comments * Add note to commented out docs.rs link in sdk * remove nym-api from script * add publishing file * bring non-binary / contract / tools into workspace version * added more info to publishing.md * make deps workspace version * remove uploaded sphinx-types crate from script * remove erroueously included ignore-defaults * add zeroise to feature * chore: Release * add topology to batch * more cargo versioning * more cargo versioning - wasm utils * more cargo versioning - wasm utils * Add publish=false to manifest for cargo workspaces / crates.io publishing exclusion * remove script now switched to manifest based exclusion * rename import based on rename of contracts-common dep * Making workspace versions for publication + removing unnecessary crates from publication * Remove OOD info from publishing sdk guide * rename contract imports + remove package * temp commit: continuing with removal of path from cargo manifest and replacing with workspace version import for publication * continuing with cargo.toml updates * dryrun only erroring on known version problem crates * remove old published-crates file * Minor comment change * remove default features warning * Additional info on workspace dep comment re publish list * Add missing description to cargo.toml * Fix missing feature flags * Add missing descriptions * Fix remaining path import * Add workspace repo / homepage / documentation links to cargo.toml files * remove workspace version from excluded crate * Remove todo descriptions * Minor comment change * add homepage etc * move from bls git import to nym_bls_fork crate * Modify rest of imports from path to workspace import, excluding binaries * add directory/homepage info * fix cargo fmt * add notes to gitignore * better solution to contracts/ experiment * wasm -> nym_wasm crate renaming * fix fatfinger * add metadata to ecash cargo.toml * stub publishing guide * fix misrevolved netlink- version * Fixes and block publication of rebase re: LP * first pass @ workflows
74 lines
2.5 KiB
Rust
74 lines
2.5 KiB
Rust
// Copyright 2022 - Nym Technologies SA <contact@nymtech.net>
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
use futures::channel::mpsc;
|
|
use futures::StreamExt;
|
|
use js_sys::Uint8Array;
|
|
use nym_wasm_client_core::client::base_client::ClientOutput;
|
|
use nym_wasm_client_core::client::received_buffer::{
|
|
ReceivedBufferMessage, ReceivedBufferRequestSender, ReconstructedMessagesReceiver,
|
|
};
|
|
use nym_wasm_utils::console_error;
|
|
use wasm_bindgen::JsValue;
|
|
use wasm_bindgen_futures::spawn_local;
|
|
|
|
pub(crate) struct ResponsePusher {
|
|
reconstructed_receiver: ReconstructedMessagesReceiver,
|
|
|
|
// we need to keep that channel alive as not to trigger the shutdown
|
|
_received_buffer_request_sender: ReceivedBufferRequestSender,
|
|
|
|
on_message: js_sys::Function,
|
|
}
|
|
|
|
impl ResponsePusher {
|
|
pub(crate) fn new(
|
|
client_output: ClientOutput,
|
|
on_message: js_sys::Function,
|
|
// on_mix_fetch_message: js_sys::Function,
|
|
) -> Self {
|
|
// register our output
|
|
let (reconstructed_sender, reconstructed_receiver) = mpsc::unbounded();
|
|
|
|
// tell the buffer to start sending stuff to us
|
|
client_output
|
|
.received_buffer_request_sender
|
|
.unbounded_send(ReceivedBufferMessage::ReceiverAnnounce(
|
|
reconstructed_sender,
|
|
))
|
|
.expect("the buffer request failed!");
|
|
|
|
ResponsePusher {
|
|
reconstructed_receiver,
|
|
_received_buffer_request_sender: client_output.received_buffer_request_sender,
|
|
on_message,
|
|
}
|
|
}
|
|
|
|
pub(crate) fn start(mut self) {
|
|
spawn_local(async move {
|
|
// for some reason if this channel is not explicitly moved into the block,
|
|
// it gets dropped when spawning the promise
|
|
let _request_sender = self._received_buffer_request_sender;
|
|
|
|
let this = JsValue::null();
|
|
|
|
while let Some(reconstructed) = self.reconstructed_receiver.next().await {
|
|
for reconstructed_msg in reconstructed {
|
|
let (msg, tag) = reconstructed_msg.into_inner();
|
|
|
|
let msg_slice: &[u8] = &msg;
|
|
let array = Uint8Array::from(msg_slice);
|
|
let arg1 = JsValue::from(array);
|
|
let arg2 = JsValue::from(tag);
|
|
self.on_message
|
|
.call2(&this, &arg1, &arg2)
|
|
.expect("on binary message failed!");
|
|
}
|
|
}
|
|
|
|
console_error!("we stopped receiving reconstructed messages!")
|
|
})
|
|
}
|
|
}
|