Skip to content

Commit

Permalink
send message with plaintext
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanKung committed Apr 27, 2024
1 parent ab74421 commit b9e5b49
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions crates/node/src/provider/browser/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use rings_core::storage::idb::IdbStorage;
use rings_core::utils::js_utils;
use rings_core::utils::js_value;
use rings_derive::wasm_export;
use rings_rpc::method::Method;
use rings_rpc::protos::rings_node::*;
use wasm_bindgen;
use wasm_bindgen::prelude::*;
Expand Down Expand Up @@ -73,7 +74,7 @@ impl Provider {
/// Ice_servers should obey forrmat: "[turn|strun]://<Address>:<Port>;..."
/// Account is hex string
/// Account should format as same as account_type declared
/// Account_type is lowercase string, possible input are: `eip191`, `ed25519`, `bip137`, for more information,
/// Account_type is lowercase string, possible input are: `eip191`, `ed25519`, `bip137`, for more imformation,

Check warning on line 77 in crates/node/src/provider/browser/provider.rs

View workflow job for this annotation

GitHub Actions / Check rustfmt style && run clippy

"imformation" should be "information".
/// please check [rings_core::ecc]
/// Signer should be `async function (proof: string): Promise<Unit8Array>`
/// Signer should function as same as account_type declared, Eg: eip191 or secp256k1 or ed25519.
Expand Down Expand Up @@ -281,14 +282,19 @@ impl Provider {
}

/// send custom message to peer.
pub fn send_message(&self, destination: String, msg: js_sys::Uint8Array) -> js_sys::Promise {
let p = self.processor.clone();
pub fn send_message(&self, destination: String, msg: String) -> js_sys::Promise {
let ins = self.clone();
future_to_promise(async move {
let destination_did = get_did(destination.as_str(), AddressType::DEFAULT)?;
p.send_message(destination_did, &msg.to_vec())
.await
.map_err(JsError::from)?;
Ok(JsValue::from_bool(true))
let did = get_did(destination.as_str(), AddressType::DEFAULT)?;
let req: BackendMessage = BackendMessage::PlainText(msg);
let params = req.into_send_backend_message_request(did)?;
let ret = ins
.request_internal(
Method::SendBackendMessage.to_string(),
serde_json::to_value(params).map_err(JsError::from)?,
)
.await?;
Ok(js_value::serialize(&ret).map_err(JsError::from)?)
})
}

Expand Down

0 comments on commit b9e5b49

Please sign in to comment.