-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
107 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
[build] | ||
target = "wasm32-unknown-unknown" | ||
|
||
[profile] | ||
|
||
[profile.dioxus-wasm] | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"rust-analyzer.cargo.target": "wasm32-unknown-unknown" | ||
"rust-analyzer.diagnostics.enable": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,31 @@ | ||
{ | ||
"version": "2.0.0", | ||
"tasks": [ | ||
{ | ||
"label": "dx build", | ||
"type": "shell", | ||
"command": "dx", | ||
"args": ["build", "--platform", "web"], | ||
"options": { | ||
"cwd": "${workspaceFolder}/ui" | ||
}, | ||
"group": { | ||
"kind": "build", | ||
"isDefault": true | ||
}, | ||
"problemMatcher": { | ||
"owner": "rust", | ||
"fileLocation": ["relative", "${workspaceFolder}"], | ||
"pattern": { | ||
"regexp": "^(.*):(\\d+):(\\d+):\\s(\\d+):\\s(.*)$", | ||
"file": 1, | ||
"line": 2, | ||
"column": 3, | ||
"message": 5 | ||
{ | ||
"label": "Build with dx in ui directory", | ||
"type": "shell", | ||
"command": "dx build --platform web", | ||
"options": { | ||
"cwd": "${workspaceFolder}/ui" | ||
}, | ||
"problemMatcher": { | ||
"owner": "rust", | ||
"fileLocation": ["relative", "${workspaceFolder}"], | ||
"pattern": [ | ||
{ | ||
"regexp": "^(.+):(\\d+):(\\d+):\\s+(error|warning):\\s+(.*)$", | ||
"file": 1, | ||
"line": 2, | ||
"column": 3, | ||
"severity": 4, | ||
"message": 5 | ||
} | ||
] | ||
}, | ||
"group": { | ||
"kind": "build", | ||
"isDefault": true | ||
} | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
use common::room_state::ChatRoomParametersV1; | ||
use ed25519_dalek::VerifyingKey; | ||
use freenet_stdlib::{client_api::{ClientError, ClientRequest, ContractRequest, HostResponse}, prelude::{ContractCode, ContractInstanceId, ContractKey, Parameters}}; | ||
use freenet_stdlib::client_api::WebApi; | ||
|
||
use crate::{constants::ROOM_CONTRACT_WASM, util::to_cbor_vec}; | ||
use futures::sink::SinkExt; | ||
|
||
pub struct FreenetApi<'a> { | ||
pub api: WebApi, | ||
pub requests: futures::channel::mpsc::UnboundedReceiver<ClientRequest<'a>>, | ||
pub host_responses: futures::channel::mpsc::UnboundedSender<HostResponse>, | ||
} | ||
|
||
impl FreenetApi<'_> { | ||
pub fn new() -> Self { | ||
let conn = web_sys::WebSocket::new( | ||
"ws://localhost:50509/contract/command?encodingProtocol=native", | ||
) | ||
.unwrap(); | ||
let (send_host_responses, host_responses) = futures::channel::mpsc::unbounded(); | ||
let (send_half, requests) = | ||
futures::channel::mpsc::unbounded::<freenet_stdlib::client_api::ClientRequest>(); | ||
let result_handler = move |result: Result<HostResponse, ClientError>| { | ||
let mut send_host_responses_clone = send_host_responses.clone(); | ||
let _ = wasm_bindgen_futures::future_to_promise(async move { | ||
send_host_responses_clone | ||
.send(result) | ||
.await | ||
.expect("channel open"); | ||
Ok(wasm_bindgen::JsValue::NULL) | ||
}); | ||
}; | ||
let (tx, rx) = futures::channel::oneshot::channel(); | ||
let onopen_handler = move || { | ||
let _ = tx.send(()); | ||
}; | ||
let mut api = WebApi::start( | ||
conn, | ||
result_handler, | ||
|err| { | ||
log::error!("host error: {}", err); | ||
}, | ||
onopen_handler, | ||
); | ||
todo!() | ||
//Self { | ||
// api, | ||
// requests: requests, | ||
// host_responses: host_responses, | ||
// } | ||
} | ||
|
||
pub fn subscribe(&mut self, room_owner: &VerifyingKey) { | ||
let parameters = ChatRoomParametersV1 { owner: *room_owner }; | ||
let parameters = to_cbor_vec(¶meters); | ||
let parameters: Parameters = parameters.into(); | ||
let contract_code = ContractCode::from(ROOM_CONTRACT_WASM); | ||
let contract_instance_id = | ||
ContractInstanceId::from_params_and_code(parameters, contract_code); | ||
let contract_key = ContractKey::from(contract_instance_id); | ||
let request = ContractRequest::Subscribe {key : contract_key, summary : None }; | ||
// self.api.send_request(request); | ||
} | ||
} |