c50e9a9ed7
* Split text and binary client apis * Very initial attempt at new serialization * Defined ser+de for Recipient and ReplySURB * Response errors * builds with changes * Working WS API + moved to separate crate * updated python examples * Fixed parsing bug * Updated go examples * Updated rust examples * formatting * Removed unused imports * dependency updates * Further dependency changes * nymsphinx exposingn framing only if not in wasm32 * Cargo lock changes before develop merge * Pending work * Actually sending and receiving websocket from rust! * more WIP * Initial wasm client + establishing shared key with gateway! * Splitting and sending a message! * WIP * WIP * Initial wasm-ification of the gateway client * Passing reconstruction result to js callback! * Initial WASM cleaning pass * Dependency pruning * Moved processing loop to received_processor + at least ack unwrappingn * Post merge fix * Kinda updated react example * Old print statement removed * Removed yarn.lock * Fixed building issue for other clients * Fixed travis test command
63 lines
1.9 KiB
Rust
63 lines
1.9 KiB
Rust
// Copyright 2020 Nym Technologies SA
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
use js_sys::Promise;
|
|
use wasm_bindgen::prelude::*;
|
|
use wasm_bindgen::JsValue;
|
|
use wasm_bindgen_futures::JsFuture;
|
|
use web_sys::window;
|
|
|
|
pub mod websocket;
|
|
|
|
// will cause messages to be written as if console.log("...") was called
|
|
#[macro_export]
|
|
macro_rules! console_log {
|
|
($($t:tt)*) => ($crate::log(&format_args!($($t)*).to_string()))
|
|
}
|
|
|
|
// will cause messages to be written as if console.warm("...") was called
|
|
#[macro_export]
|
|
macro_rules! console_warn {
|
|
($($t:tt)*) => ($crate::warn(&format_args!($($t)*).to_string()))
|
|
}
|
|
|
|
// will cause messages to be written as if console.error("...") was called
|
|
#[macro_export]
|
|
macro_rules! console_error {
|
|
($($t:tt)*) => ($crate::error(&format_args!($($t)*).to_string()))
|
|
}
|
|
|
|
#[wasm_bindgen]
|
|
extern "C" {
|
|
#[wasm_bindgen(js_namespace = console)]
|
|
pub fn log(s: &str);
|
|
|
|
#[wasm_bindgen(js_namespace = console)]
|
|
pub fn warn(s: &str);
|
|
|
|
#[wasm_bindgen(js_namespace = console)]
|
|
pub fn error(s: &str);
|
|
}
|
|
|
|
pub async fn sleep(ms: i32) -> Result<(), JsValue> {
|
|
let promise = Promise::new(&mut |yes, _| {
|
|
let win = window().expect("no window available!");
|
|
win.set_timeout_with_callback_and_timeout_and_arguments_0(&yes, ms)
|
|
.unwrap();
|
|
});
|
|
let js_fut = JsFuture::from(promise);
|
|
js_fut.await?;
|
|
Ok(())
|
|
}
|