matrix-sdk: Fix our wasm command bot example

master
Damir Jelić 2021-01-22 18:14:08 +01:00
parent 9c98d0227b
commit d10b85a05d
2 changed files with 16 additions and 14 deletions

View File

@ -10,10 +10,15 @@ edition = "2018"
crate-type = ["cdylib"]
[dependencies]
matrix-sdk = { path = "../..", default-features = false, features = ["native-tls"] }
url = "2.1.1"
wasm-bindgen = { version = "0.2.62", features = ["serde-serialize"] }
wasm-bindgen-futures = "0.4.12"
console_error_panic_hook = "*"
web-sys = { version = "0.3.39", features = ["console"] }
[dependencies.matrix-sdk]
path = "../.."
default-features = false
features = ["native-tls"]
[workspace]

View File

@ -1,13 +1,11 @@
#![type_length_limit = "1702124"]
use matrix_sdk::{
api::r0::sync::sync_events::Response as SyncResponse,
deserialized_responses::SyncResponse,
events::{
room::message::{MessageEventContent, TextMessageEventContent},
AnyMessageEventContent, AnySyncMessageEvent, AnySyncRoomEvent, SyncMessageEvent,
},
identifiers::RoomId,
Client, ClientConfig, LoopCtrl, SyncSettings,
Client, LoopCtrl, SyncSettings,
};
use url::Url;
use wasm_bindgen::prelude::*;
@ -46,10 +44,8 @@ impl WasmBot {
for (room_id, room) in response.rooms.join {
for event in room.timeline.events {
if let Ok(event) = event.deserialize() {
if let AnySyncRoomEvent::Message(AnySyncMessageEvent::RoomMessage(ev)) = event {
self.on_room_message(&room_id, ev).await
}
if let AnySyncRoomEvent::Message(AnySyncMessageEvent::RoomMessage(ev)) = event {
self.on_room_message(&room_id, ev).await
}
}
}
@ -60,13 +56,14 @@ impl WasmBot {
#[wasm_bindgen]
pub async fn run() -> Result<JsValue, JsValue> {
let homeserver_url = "http://localhost:8008";
let username = "user";
let password = "password";
console_error_panic_hook::set_once();
let homeserver_url = "http://localhost:8008";
let username = "example";
let password = "wordpass";
let client_config = ClientConfig::new();
let homeserver_url = Url::parse(&homeserver_url).unwrap();
let client = Client::new_with_config(homeserver_url, client_config).unwrap();
let client = Client::new(homeserver_url).unwrap();
client
.login(username, password, None, Some("rust-sdk-wasm"))