matrix-sdk: Fix our wasm command bot example
parent
9c98d0227b
commit
d10b85a05d
|
@ -10,10 +10,15 @@ edition = "2018"
|
||||||
crate-type = ["cdylib"]
|
crate-type = ["cdylib"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
matrix-sdk = { path = "../..", default-features = false, features = ["native-tls"] }
|
|
||||||
url = "2.1.1"
|
url = "2.1.1"
|
||||||
wasm-bindgen = { version = "0.2.62", features = ["serde-serialize"] }
|
wasm-bindgen = { version = "0.2.62", features = ["serde-serialize"] }
|
||||||
wasm-bindgen-futures = "0.4.12"
|
wasm-bindgen-futures = "0.4.12"
|
||||||
|
console_error_panic_hook = "*"
|
||||||
web-sys = { version = "0.3.39", features = ["console"] }
|
web-sys = { version = "0.3.39", features = ["console"] }
|
||||||
|
|
||||||
|
[dependencies.matrix-sdk]
|
||||||
|
path = "../.."
|
||||||
|
default-features = false
|
||||||
|
features = ["native-tls"]
|
||||||
|
|
||||||
[workspace]
|
[workspace]
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
#![type_length_limit = "1702124"]
|
|
||||||
|
|
||||||
use matrix_sdk::{
|
use matrix_sdk::{
|
||||||
api::r0::sync::sync_events::Response as SyncResponse,
|
deserialized_responses::SyncResponse,
|
||||||
events::{
|
events::{
|
||||||
room::message::{MessageEventContent, TextMessageEventContent},
|
room::message::{MessageEventContent, TextMessageEventContent},
|
||||||
AnyMessageEventContent, AnySyncMessageEvent, AnySyncRoomEvent, SyncMessageEvent,
|
AnyMessageEventContent, AnySyncMessageEvent, AnySyncRoomEvent, SyncMessageEvent,
|
||||||
},
|
},
|
||||||
identifiers::RoomId,
|
identifiers::RoomId,
|
||||||
Client, ClientConfig, LoopCtrl, SyncSettings,
|
Client, LoopCtrl, SyncSettings,
|
||||||
};
|
};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
use wasm_bindgen::prelude::*;
|
use wasm_bindgen::prelude::*;
|
||||||
|
@ -46,13 +44,11 @@ impl WasmBot {
|
||||||
|
|
||||||
for (room_id, room) in response.rooms.join {
|
for (room_id, room) in response.rooms.join {
|
||||||
for event in room.timeline.events {
|
for event in room.timeline.events {
|
||||||
if let Ok(event) = event.deserialize() {
|
|
||||||
if let AnySyncRoomEvent::Message(AnySyncMessageEvent::RoomMessage(ev)) = event {
|
if let AnySyncRoomEvent::Message(AnySyncMessageEvent::RoomMessage(ev)) = event {
|
||||||
self.on_room_message(&room_id, ev).await
|
self.on_room_message(&room_id, ev).await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
LoopCtrl::Continue
|
LoopCtrl::Continue
|
||||||
}
|
}
|
||||||
|
@ -60,13 +56,14 @@ impl WasmBot {
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub async fn run() -> Result<JsValue, JsValue> {
|
pub async fn run() -> Result<JsValue, JsValue> {
|
||||||
let homeserver_url = "http://localhost:8008";
|
console_error_panic_hook::set_once();
|
||||||
let username = "user";
|
|
||||||
let password = "password";
|
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 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
|
client
|
||||||
.login(username, password, None, Some("rust-sdk-wasm"))
|
.login(username, password, None, Some("rust-sdk-wasm"))
|
||||||
|
|
Loading…
Reference in New Issue