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

Update library integration #165

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/vendor/magic-wormhole.rs
16 changes: 11 additions & 5 deletions client/wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::pin::Pin;
use std::task::{Context, Poll};
use thiserror::Error;

use magic_wormhole::{transfer, transit, AppID, Code, Wormhole, WormholeError};
use magic_wormhole::{transfer, transit, AppID, Code, Wormhole, WormholeError, MailboxConnection};
use wasm_bindgen::prelude::*;
use wasm_bindgen_futures::JsFuture;

Expand Down Expand Up @@ -120,10 +120,11 @@ pub async fn send(client: &Client, file: web_sys::File) -> Result<SendResult, Wa

let rendezvous = Box::new(client.rendezvous_url.as_str());
let config = transfer::APP_CONFIG.rendezvous_url(Cow::Owned(rendezvous.to_string()));
let (server_welcome, wormhole_future) = Wormhole::connect_without_code(config, 2).await?;
let connection = MailboxConnection::create(config, 2).await?;
let wormhole_future = Wormhole::connect(mailbox_connection);

Ok(SendResult {
code: server_welcome.code.0,
code: connection.code.0,
transit_server_url: client.transit_server_url.clone(),
f: Some(Box::pin(wormhole_future)),
file,
Expand Down Expand Up @@ -219,11 +220,16 @@ pub async fn receive(client: &Client, code: String) -> Result<ReceiveResult, Was
let rendezvous = Box::new(client.rendezvous_url.as_str());
let config = transfer::APP_CONFIG.rendezvous_url(Cow::Owned(rendezvous.to_string()));

let wormhole = match Wormhole::connect_with_code(config, Code(code), true).await {
Ok((_, x)) => x,
let connection = match MailboxConnection::connect(config, Code(code), false).await {
Ok(x) => x,
Err(e) => return Err(WasmWormholeError::BadCode(e)),
};

let wormhole = match Wormhole::connect(connection).await {
Ok(x) => x,
Err(e) => return Err(WasmWormholeError::WormholeConnectionFailed(e)),
};

let req = transfer::request_file(
wormhole,
vec![transit::RelayHint::new(
Expand Down