Skip to content
Merged
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
12 changes: 10 additions & 2 deletions crates/sdk/examples/quickstart-chat/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
mod module_bindings;
use module_bindings::*;

use spacetimedb_client_api_messages::websocket::Compression;
use spacetimedb_sdk::{credentials, DbContext, Error, Event, Identity, Status, Table, TableWithPrimaryKey};

// ## Define the main function
Expand Down Expand Up @@ -36,12 +35,21 @@ const DB_NAME: &str = "quickstart-chat";
/// Load credentials from a file and connect to the database.
fn connect_to_db() -> DbConnection {
DbConnection::builder()
// Register our `on_connect` callback, which will save our auth token.
.on_connect(on_connected)
// Register our `on_connect_error` callback, which will print a message, then exit the process.
.on_connect_error(on_connect_error)
// Our `on_disconnect` callback, which will print a message, then exit the process.
.on_disconnect(on_disconnected)
// If the user has previously connected, we'll have saved a token in the `on_connect` callback.
// In that case, we'll load it and pass it to `with_token`,
// so we can re-authenticate as the same `Identity`.
.with_token(creds_store().load().expect("Error loading credentials"))
// Set the database name we chose when we called `spacetime publish`.
.with_module_name(DB_NAME)
// Set the URI of the SpacetimeDB host that's running our database.
.with_uri(HOST)
// Finalize configuration and connect!
.build()
.expect("Failed to connect")
}
Expand Down Expand Up @@ -197,7 +205,7 @@ fn on_sub_applied(ctx: &SubscriptionEventContext) {

/// Or `on_error` callback:
/// print the error, then exit the process.
fn on_sub_error(ctx: &ErrorContext, err: Error) {
fn on_sub_error(_ctx: &ErrorContext, err: Error) {
eprintln!("Subscription failed: {}", err);
std::process::exit(1);
}
Expand Down
Loading