From a917f21ed6c5fd99f80af890502e845a5adf91ee Mon Sep 17 00:00:00 2001 From: TroyHernandez Date: Tue, 10 Nov 2026 09:02:40 -0600 Subject: [PATCH 1/8] Return the refreshed client from mx_set_displayname() (#18) --- R/profile.R | 11 +++++++---- R/session.R | 6 ++++++ inst/tinytest/test_relogin.R | 38 ++++++++++++++++++++++++++++++++++++ man/mx_set_displayname.Rd | 6 ++++-- man/mx_with_relogin.Rd | 8 ++++++++ 5 files changed, 63 insertions(+), 6 deletions(-) diff --git a/R/profile.R b/R/profile.R index e0e1b79..6f98c4e 100644 --- a/R/profile.R +++ b/R/profile.R @@ -14,12 +14,14 @@ #' @param name Character. New display name. #' @param save Logical. On a relogin, persist the refreshed token to the #' client's config path (see \code{\link{mx_client_relogin}}). -#' @return TRUE, invisibly. +#' @return The client config, invisibly. After a relogin this is the +#' refreshed client carrying the new token; keep it in place of the one +#' passed in. Without a relogin it is \code{client} unchanged. #' @examples #' \dontrun{ #' # A real rename needs a live homeserver session: #' client <- mx_client_load("myapp") -#' mx_set_displayname(client, "mybot (maintenance)") +#' client <- mx_set_displayname(client, "mybot (maintenance)") #' } #' @export mx_set_displayname <- function(client, name, save = TRUE) { @@ -27,8 +29,9 @@ mx_set_displayname <- function(client, name, save = TRUE) { !nzchar(name)) { stop("name must be a single non-empty string", call. = FALSE) } - mx_with_relogin(client, function(cl) { + refreshed <- mx_with_relogin(client, function(cl) { mx.api::mx_set_displayname(mx_client_session(cl), name) + cl }, save = save) - invisible(TRUE) + invisible(refreshed) } diff --git a/R/session.R b/R/session.R index d5faa9f..3b099df 100644 --- a/R/session.R +++ b/R/session.R @@ -117,6 +117,12 @@ mx_client_relogin <- function(client, save = TRUE) { #' mx.api >= 0.3.0), re-logs in via \code{\link{mx_client_relogin}} and #' retries once with the refreshed client. Any other error propagates. #' +#' With \code{save = TRUE} the refreshed config is written before the +#' retry. If the retry then fails, the new token is already on disk while +#' the caller still holds the rejected one; reload the config with +#' \code{\link{mx_client_load}} after such an error. To keep the refreshed +#' client on success, have \code{fn} return its argument. +#' #' @param client Matrix client config with \code{password}. #' @param fn Function taking a client config. #' @param save Logical. Persist the refreshed config on relogin. diff --git a/inst/tinytest/test_relogin.R b/inst/tinytest/test_relogin.R index 7c5a919..b778a44 100644 --- a/inst/tinytest/test_relogin.R +++ b/inst/tinytest/test_relogin.R @@ -42,3 +42,41 @@ expect_equal(names(formals(mx.client::mx_set_displayname)), expect_error(mx.client::mx_set_displayname(cl, ""), "non-empty") expect_error(mx.client::mx_set_displayname(cl, c("a", "b")), "single") expect_error(mx.client::mx_set_displayname(cl, NA_character_), "non-empty") + +# mx_set_displayname returns the client it ended up using (#18): the same +# client when the token holds, the refreshed one after a relogin. +local({ + old_name <- mx.api::mx_set_displayname + old_login <- mx.api::mx_login + on.exit({ + assignInNamespace("mx_set_displayname", old_name, ns = "mx.api") + assignInNamespace("mx_login", old_login, ns = "mx.api") + }) + tokens <- character() + assignInNamespace("mx_set_displayname", function(session, name) { + tokens <<- c(tokens, session$token) + if (identical(session$token, "t")) token_err(NULL) + invisible(TRUE) + }, ns = "mx.api") + assignInNamespace("mx_login", function(server, user, password, device_id = NULL) { + list(token = "fresh", user_id = "@bot:x", device_id = "DEV") + }, ns = "mx.api") + + good <- mx_client_from_config(list(server = "https://x", user = "bot", + token = "live", user_id = "@bot:x", + device_id = "DEV", room_id = "!r:x")) + out <- withVisible(mx.client::mx_set_displayname(good, "bot")) + expect_false(out$visible) + expect_equal(out$value$token, "live") + + stale <- mx_client_from_config(list(server = "https://x", user = "bot", + password = "pw", token = "t", + user_id = "@bot:x", device_id = "DEV", + room_id = "!r:x")) + expect_message( + refreshed <- mx.client::mx_set_displayname(stale, "bot", save = FALSE), + "re-logging in" + ) + expect_equal(refreshed$token, "fresh") + expect_equal(tokens, c("live", "t", "fresh")) +}) diff --git a/man/mx_set_displayname.Rd b/man/mx_set_displayname.Rd index 902a191..4e81619 100644 --- a/man/mx_set_displayname.Rd +++ b/man/mx_set_displayname.Rd @@ -14,7 +14,9 @@ mx_set_displayname(client, name, save = TRUE) client's config path (see \code{\link{mx_client_relogin}}).} } \value{ -TRUE, invisibly. +The client config, invisibly. After a relogin this is the + refreshed client carrying the new token; keep it in place of the one + passed in. Without a relogin it is \code{client} unchanged. } \description{ Client-level wrapper over \code{mx.api::mx_set_displayname()}: builds @@ -27,6 +29,6 @@ line of every message the account posts. \dontrun{ # A real rename needs a live homeserver session: client <- mx_client_load("myapp") -mx_set_displayname(client, "mybot (maintenance)") +client <- mx_set_displayname(client, "mybot (maintenance)") } } diff --git a/man/mx_with_relogin.Rd b/man/mx_with_relogin.Rd index b296c18..13940e8 100644 --- a/man/mx_with_relogin.Rd +++ b/man/mx_with_relogin.Rd @@ -20,6 +20,14 @@ Calls \code{fn(client)}; if it fails with the server's invalid-token error (\code{M_UNKNOWN_TOKEN}, signalled as a classed condition by mx.api >= 0.3.0), re-logs in via \code{\link{mx_client_relogin}} and retries once with the refreshed client. Any other error propagates. +} +\details{ +With \code{save = TRUE} the refreshed config is written before the +retry. If the retry then fails, the new token is already on disk while +the caller still holds the rejected one; reload the config with +\code{\link{mx_client_load}} after such an error. To keep the refreshed +client on success, have \code{fn} return its argument. + } \examples{ \dontrun{ From a076283dc57c05d697ea0e2c2a8cac454f374fb7 Mon Sep 17 00:00:00 2001 From: TroyHernandez Date: Tue, 10 Nov 2026 09:02:40 -0600 Subject: [PATCH 2/8] Require CRAN mx.api 0.4.0 and mx.crypto 0.3.0; declare the livekitr repository --- .github/workflows/ci.yaml | 4 ++-- DESCRIPTION | 5 +++-- R/call.R | 27 +++++++++++++++++++++++++++ R/media-encrypted.R | 15 ++++++++++++++- inst/tinytest/test_encrypted_media.R | 2 +- man/mx_call_connect.Rd | 8 ++++++++ man/mx_call_handle.Rd | 9 +++++++++ man/mx_call_leave.Rd | 6 ++++++ man/mx_call_poll.Rd | 8 ++++++++ man/mx_download_encrypted.Rd | 7 +++++++ man/mx_upload_encrypted.Rd | 8 ++++++++ 11 files changed, 93 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 5e2e594..4dea351 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -34,8 +34,8 @@ jobs: # older binary. The helper reads the floors from DESCRIPTION. - name: Install Matrix development dependencies env: - # mx.crypto 0.2.2.2, including Matrix v2 attachment primitives. - MX_CRYPTO_REF: "74980d6453b71bc6eac9639416e0ec96df971ba9" + # mx.crypto 0.3.0, the CRAN release with Matrix v2 attachment primitives. + MX_CRYPTO_REF: "2fc2d5e1c3716086a5f5a75342037882ed8e4440" run: | Rscript -e 'install.packages(c("curl", "jsonlite"))' Rscript .github/install-matrix-deps.R diff --git a/DESCRIPTION b/DESCRIPTION index 7f35146..aee419d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -22,14 +22,15 @@ Depends: R (>= 4.0) Imports: jsonlite, - mx.api (>= 0.3.1.1), + mx.api (>= 0.4.0), stats, tools, utils Suggests: livekitr, - mx.crypto (>= 0.2.2.2), + mx.crypto (>= 0.3.0), simplermarkdown, tinytest +Additional_repositories: https://cornball-ai.github.io/drat VignetteBuilder: simplermarkdown Encoding: UTF-8 diff --git a/R/call.R b/R/call.R index 6c24815..8cfac6c 100644 --- a/R/call.R +++ b/R/call.R @@ -521,6 +521,13 @@ mx_call_join <- function(client, account, sessions, room_id, #' @param ... Further arguments to \code{livekitr::lk_connect()}, such #' as \code{opts}. #' @return \code{call}, invisibly. +#' @examples +#' \dontrun{ +#' # Needs a live homeserver, a LiveKit service and the livekitr package: +#' call <- mx_call_join(client, acct, sessions, "!room:example.org", +#' connect = FALSE) +#' mx_call_connect(call) +#' } #' @export mx_call_connect <- function(call, ...) { mx_require_livekitr() @@ -572,6 +579,14 @@ mx_call_e2ee_options <- function() { #' @return A list of what changed: \code{keys}, the identities whose #' keys were received, and \code{members}, the current members when #' membership changed (NULL otherwise). +#' @examples +#' \dontrun{ +#' # Inside an application's own sync loop, during a live call: +#' res <- mx_sync_update(call$client, timeout = 0L) +#' call$client <- res$client +#' changed <- mx_call_handle(call, res$sync) +#' changed$keys +#' } #' @export mx_call_handle <- function(call, sync, processed = NULL) { if (is.null(processed)) { @@ -643,6 +658,13 @@ mx_call_handle <- function(call, sync, processed = NULL) { #' @param timeout Seconds to let the sync long poll wait. #' @return The LiveKit events from \code{livekitr::lk_poll()}, or an #' empty list when the call has no media session. +#' @examples +#' \dontrun{ +#' # Drive a live call for 30 seconds, then leave: +#' until <- Sys.time() + 30 +#' while (Sys.time() < until) mx_call_poll(call) +#' mx_call_leave(call) +#' } #' @export mx_call_poll <- function(call, media_timeout = 0.5, timeout = 0) { events <- if (is.null(call$session)) { @@ -663,6 +685,11 @@ mx_call_poll <- function(call, media_timeout = 0.5, timeout = 0) { #' #' @param call An \code{"mx_call"}. #' @return \code{NULL}, invisibly. +#' @examples +#' \dontrun{ +#' # Ends a call joined with mx_call_join() on a live homeserver: +#' mx_call_leave(call) +#' } #' @export mx_call_leave <- function(call) { if (!is.null(call$session)) { diff --git a/R/media-encrypted.R b/R/media-encrypted.R index ca800c7..9005291 100644 --- a/R/media-encrypted.R +++ b/R/media-encrypted.R @@ -13,6 +13,13 @@ #' @param max_bytes Maximum plaintext size in bytes, default 25 MiB. Encryption #' uses memory; larger files require an explicit higher limit. #' @return Matrix message content with \code{file} instead of \code{url}. +#' @examples +#' \dontrun{ +#' # Needs a live homeserver and an encrypted room: +#' content <- mx_upload_encrypted(client, file.path(tempdir(), "notes.pdf")) +#' mx_send_encrypted(client, acct, sessions, "!room:example.org", content, +#' store_dir = store) +#' } #' @export mx_upload_encrypted <- function(client, path, body = basename(path), msgtype = NULL, content_type = NULL, @@ -64,6 +71,12 @@ mx_upload_encrypted <- function(client, path, body = basename(path), #' @param max_bytes Maximum downloaded size to read into memory, default 25 #' MiB. This is checked on disk before decryption, not a network transfer cap. #' @return Destination path, invisibly. +#' @examples +#' \dontrun{ +#' # `content` is a decrypted m.room.message from a live encrypted room: +#' mx_download_encrypted(client, content$file, +#' file.path(tempdir(), content$body)) +#' } #' @export mx_download_encrypted <- function(client, file, dest, max_bytes = 25 * 1024^2) { @@ -97,7 +110,7 @@ mx_require_attachment_crypto <- function() { if (!requireNamespace("mx.crypto", quietly = TRUE) || !all(c("mxc_attachment_encrypt", "mxc_attachment_decrypt") %in% getNamespaceExports("mx.crypto"))) { - stop("mx.client: encrypted attachments require mx.crypto >= 0.2.2.2", + stop("mx.client: encrypted attachments require mx.crypto >= 0.3.0", call. = FALSE) } } diff --git a/inst/tinytest/test_encrypted_media.R b/inst/tinytest/test_encrypted_media.R index d59abb8..9580df4 100644 --- a/inst/tinytest/test_encrypted_media.R +++ b/inst/tinytest/test_encrypted_media.R @@ -1,7 +1,7 @@ library(mx.client) if (!requireNamespace("mx.crypto", quietly = TRUE) || !"mxc_attachment_encrypt" %in% getNamespaceExports("mx.crypto")) { - exit_file("encrypted attachments require mx.crypto >= 0.2.2.2") + exit_file("encrypted attachments require mx.crypto >= 0.3.0") } local({ root <- tempfile("media-test-") diff --git a/man/mx_call_connect.Rd b/man/mx_call_connect.Rd index a6b90dd..cc00d86 100644 --- a/man/mx_call_connect.Rd +++ b/man/mx_call_connect.Rd @@ -21,3 +21,11 @@ end-to-end encryption configured as Element Call and FluffyChat expect (per-participant HKDF keys, a 256-slot key ring), and sets our key and every peer key received so far. } +\examples{ +\dontrun{ +# Needs a live homeserver, a LiveKit service and the livekitr package: +call <- mx_call_join(client, acct, sessions, "!room:example.org", + connect = FALSE) +mx_call_connect(call) +} +} diff --git a/man/mx_call_handle.Rd b/man/mx_call_handle.Rd index 1a2a1a7..e7ed913 100644 --- a/man/mx_call_handle.Rd +++ b/man/mx_call_handle.Rd @@ -28,3 +28,12 @@ application already runs \code{\link{mx_crypto_process_sync}} on the response, pass its result as \code{processed} so to-device events are not decrypted twice. } +\examples{ +\dontrun{ +# Inside an application's own sync loop, during a live call: +res <- mx_sync_update(call$client, timeout = 0L) +call$client <- res$client +changed <- mx_call_handle(call, res$sync) +changed$keys +} +} diff --git a/man/mx_call_leave.Rd b/man/mx_call_leave.Rd index a6e732c..222d095 100644 --- a/man/mx_call_leave.Rd +++ b/man/mx_call_leave.Rd @@ -14,3 +14,9 @@ mx_call_leave(call) \description{ Leaves the LiveKit room and clears this device's membership event. } +\examples{ +\dontrun{ +# Ends a call joined with mx_call_join() on a live homeserver: +mx_call_leave(call) +} +} diff --git a/man/mx_call_poll.Rd b/man/mx_call_poll.Rd index fe4b622..e336286 100644 --- a/man/mx_call_poll.Rd +++ b/man/mx_call_poll.Rd @@ -35,3 +35,11 @@ but they reach the callback late. A program that needs prompt audio on such a server should sync from another process or thread. } +\examples{ +\dontrun{ +# Drive a live call for 30 seconds, then leave: +until <- Sys.time() + 30 +while (Sys.time() < until) mx_call_poll(call) +mx_call_leave(call) +} +} diff --git a/man/mx_download_encrypted.Rd b/man/mx_download_encrypted.Rd index 7c663c8..9122eb4 100644 --- a/man/mx_download_encrypted.Rd +++ b/man/mx_download_encrypted.Rd @@ -24,3 +24,10 @@ SHA-256 digest and decrypts it before replacing the destination. Failure leaves an existing destination unchanged. Metadata must come from an authenticated encrypted room event. Does not open a crypto store. } +\examples{ +\dontrun{ +# `content` is a decrypted m.room.message from a live encrypted room: +mx_download_encrypted(client, content$file, + file.path(tempdir(), content$body)) +} +} diff --git a/man/mx_upload_encrypted.Rd b/man/mx_upload_encrypted.Rd index bbb0f50..ea8488f 100644 --- a/man/mx_upload_encrypted.Rd +++ b/man/mx_upload_encrypted.Rd @@ -38,3 +38,11 @@ Returns content to pass to \code{mx_send_encrypted()} using the caller's existing account and sessions. The return value includes a secret key: never post it in an unencrypted event. Does not open a crypto store. } +\examples{ +\dontrun{ +# Needs a live homeserver and an encrypted room: +content <- mx_upload_encrypted(client, file.path(tempdir(), "notes.pdf")) +mx_send_encrypted(client, acct, sessions, "!room:example.org", content, + store_dir = store) +} +} From 9a638c7ae464a2b5d2e1fd98768517223b1fc50d Mon Sep 17 00:00:00 2001 From: TroyHernandez Date: Tue, 10 Nov 2026 09:02:40 -0600 Subject: [PATCH 3/8] Rewrite cran-comments for 0.3.0 --- cran-comments.md | 113 ++++++++++++++++++++++------------------------- 1 file changed, 54 insertions(+), 59 deletions(-) diff --git a/cran-comments.md b/cran-comments.md index b39b02f..7ada4b3 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -2,75 +2,70 @@ ## Submission -Update from CRAN version 0.2.0 to 0.2.1. +Update from CRAN version 0.2.1 to 0.3.0. -The Windows pre-flight candidate was numbered 0.3.0. It has been renumbered -to 0.2.1 for submission; its R code, examples, tests, and dependencies are unchanged. +This release adds MatrixRTC calls over LiveKit (`mx_call_join()` and +related functions), encrypted attachment upload and verified download +(`mx_upload_encrypted()`, `mx_download_encrypted()`), and Olm-encrypted +to-device events of any type. It fixes the loss of inbound Olm messages +sent on a session the peer had opened earlier, and `mx_set_displayname()` +now returns the client it used so a caller can keep a refreshed token. -This release adds interactive Matrix Short Authentication String (SAS) -verification, cross-signing bootstrap and pinned identity verification, -room-key requests and recovery, threaded messages, and richer sync-event -extraction. It fixes reception of Olm replies on locally initiated sessions, -rejects encrypted sends when no intended recipient can receive a key, and -validates crypto-store schema versions without changing the raw account -pickle format. Existing stores remain readable. +The mandatory mx.api floor is 0.4.0 and the optional mx.crypto floor is +0.3.0. Both versions are on CRAN. -The mandatory mx.api floor is 0.3.0.2; CRAN version 0.3.1 satisfies it. -The optional mx.crypto floor is 0.2.2, now on CRAN, for SAS primitives. -Unencrypted client operations still work without mx.crypto. +## Suggested package outside the mainstream repositories + +livekitr is in Suggests and is not on CRAN. It is available from the +repository declared in DESCRIPTION: + + Additional_repositories: https://cornball-ai.github.io/drat + +Expect the incoming NOTE "Suggests or Enhances not in mainstream +repositories: livekitr". The check reports it as available through the +Additional_repositories specification. + +livekitr carries only the media connection of a call. Every use is +conditional: `mx_call_connect()` calls `requireNamespace("livekitr")` +first and stops with an informative error when it is absent, and the +other call functions touch livekitr only on a session that +`mx_call_connect()` created. The Matrix side of a call +(`mx_call_join(connect = FALSE)`) works without it. No example, test, or +vignette needs livekitr; all checks below ran without it installed. ## API and compatibility -No exports were removed or renamed. Existing functions gain optional -arguments; newly added functions cover SAS, cross-signing, key-request -bookkeeping, identity trust, and event extraction. +No exports were removed or renamed. `mx_send_encrypted()` gains an +optional `event_type` argument. `mx_crypto_process_sync()` adds a +`to_device` element to its result and keeps each decrypted room event's +`type` and `content`. + +`mx_set_displayname()` returned `TRUE` invisibly and now returns the +client config invisibly. Neither reverse dependency uses the value. -Decryptable own encrypted messages are now returned with is_self = TRUE, -as cleartext own messages already were. Forwarded room keys never mark -the original event sender verified. Failed to-device decryption warns and -skips the event instead of aborting the batch. Session stores gain a version -field; legacy stores load, and account.pickle remains a raw encrypted pickle -so older clients can continue to read it. +Session stores written by 0.2.1 load unchanged: a single inbound Olm +session per peer becomes a one-element list. ## Test environments -* Ubuntu 24.04.5, R 4.6.1: R CMD check --as-cran, including PDF and HTML - manuals, examples with --run-donttest, tests, and rebuilt vignettes. - Status: OK, 0 errors, 0 warnings, 0 notes. -* Full source suite: 792 assertions passed with mx.crypto 0.2.2 and - mx.api 0.3.1. The 15 added or revised local examples also passed separately. -* GitHub Actions: Ubuntu and macOS passed on the merged 0.2.0.11 code. - Release preparation changes only documentation and metadata; parsed R - expressions are unchanged across all 24 source files. -* Windows R-devel (2026-09-10 r90519): Status OK, 682 test assertions. - Store-schema tests were skipped because the worker's mx.crypto version - was below 0.2.2. Report: https://win-builder.r-project.org/62jmaVSsW2vK/ -* Windows R-release 4.6.1: 1 error, 1 warning. The worker's mx.crypto lacked - the seven SAS exports, causing the dependency warning and SAS example - error. Only 466 test assertions ran; SAS and store-schema tests were - skipped. Report: https://win-builder.r-project.org/MvFXJ8kbX0Jp/ -* On 2026-09-11 CRAN listed mx.crypto 0.2.2 source but still 0.2.1 Windows - binaries. The Windows reports above used older dependencies and do not - establish full Windows coverage. The local check and full source suite - used the declared mx.crypto 0.2.2 dependency and passed. - -## Reverse dependency - -CRAN's corteza 0.7.1, a reverse Suggests dependency, was checked against -both CRAN mx.client 0.2.0 and the 0.2.0.11 candidate underlying this release. -Both runs passed installation, examples, tests, and vignette checks. -Both had the same incoming-feasibility warning because corteza 0.7.1 is -already on CRAN. There were no new errors or warnings from this update. +All local checks used a library built from CRAN source packages only, +with mx.api 0.4.0 and without livekitr. -## Examples +* Ubuntu 24.04.5, R 4.6.1: R CMD check --as-cran --run-donttest, + including PDF and HTML manuals, examples, tests, and rebuilt vignettes, + with mx.crypto 0.3.0 installed. Status: OK. +* The same check with mx.crypto also absent. Status: OK. +* Installed test suite with an empty HOME: 986 assertions passed and no + file was written under HOME. +* Windows, macOS, and R-oldrelease were not checked for this release. + +## Reverse dependencies -The new SAS examples use synthetic in-memory identities and exchanges. -They do not connect to Matrix, inspect a user's crypto store, or upload -trust. Explicit refusal examples demonstrate that cancelled or unconfirmed -exchanges cannot grant trust. Local encrypt/decrypt examples are runnable. +chat.api 0.1.0 and corteza 0.7.1, both reverse Suggests from CRAN, were +checked against the 0.3.0 tarball. Both: Status: OK. + +## Examples -The new cross-signing bootstrap example remains in \dontrun because it -requires account credentials, the existing device store, and a live Matrix -homeserver. Actual console verification additionally requires a human to -compare values on trusted displays. Other network examples remain guarded; -all executed example and test writes use temporary directories. +The call and encrypted-media examples are in \dontrun because they need +account credentials, a live Matrix homeserver, and for media a LiveKit +service. All executed example and test writes use temporary directories. From 11efe6821cb2f46c2aac92cc7e5b6d048ae0c7d2 Mon Sep 17 00:00:00 2001 From: TroyHernandez Date: Tue, 10 Nov 2026 09:02:40 -0600 Subject: [PATCH 4/8] Bump version to 0.3.0 --- DESCRIPTION | 4 +-- NEWS.md | 92 ++++++++++++++++++++++++++--------------------------- 2 files changed, 47 insertions(+), 49 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index aee419d..ea90a1c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: mx.client Type: Package Title: Stateful Matrix Client Helpers -Version: 0.2.1.4 -Date: 2026-10-26 +Version: 0.3.0 +Date: 2026-11-10 Authors@R: c( person("Troy", "Hernandez", role = c("aut", "cre"), email = "troy@cornball.ai", diff --git a/NEWS.md b/NEWS.md index 4956664..0d495bf 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,15 +1,46 @@ -# mx.client 0.2.1.4 +# mx.client 0.3.0 -- Add encrypted attachment upload and verified download helpers using - mx.crypto's Matrix v2 primitives. Uploads expose only ciphertext with a - generic filename; downloads verify integrity before replacing the destination. -- Refuse plaintext `mx_send_media()` uploads to encrypted rooms before - transferring any file. Callers retain ownership of their live crypto sessions - and send the returned attachment metadata through `mx_send_encrypted()`. - -# mx.client 0.2.1.3 +## MatrixRTC calls -* Fix: keep every inbound Olm session per peer, not just the latest. A +* New: `mx_call_join()`, `mx_call_handle()`, `mx_call_poll()`, + `mx_call_connect()` and `mx_call_leave()` run a MatrixRTC call over + LiveKit the way Element Call and FluffyChat do: a per-device + `org.matrix.msc3401.call.member` state event, a media token from the + LiveKit JWT service, and per-participant media keys exchanged as + `io.element.call.encryption_keys` events, with their key rotation + policy. `mx_call_members()`, `mx_call_service_url()`, + `mx_call_key_parse()` and `mx_call_key_plan()` expose the pieces. +* Media goes through the optional `livekitr` package (Suggests), available + from . The Matrix side of a call + (`mx_call_join(connect = FALSE)`) works without it. +* Call keys are read and sent both ways clients use: Olm-encrypted + to-device events (Element Call) and encrypted room events (FluffyChat / + matrix-dart-sdk). `keys` is handled as an array of `{index, key}`. +* New: `mx_send_to_device_encrypted()` and `mx_crypto_encrypt_to_device()` + send an Olm-encrypted to-device event of any type. +* `mx_crypto_process_sync()` returns decrypted Olm to-device events other + than room keys and verification messages in a new `to_device` element, + and keeps each decrypted room event's `type` and `content`. +* `mx_send_encrypted()` gains an `event_type` argument. + +## Encrypted media + +* New: `mx_upload_encrypted()` and `mx_download_encrypted()` use + mx.crypto's Matrix v2 attachment primitives. Uploads expose only + ciphertext with a generic filename; downloads verify integrity before + replacing the destination. +* `mx_send_media()` refuses a plaintext upload to an encrypted room before + transferring any file. Callers retain ownership of their live crypto + sessions and send the returned attachment metadata through + `mx_send_encrypted()`. + +## Fixes + +* `mx_set_displayname()` returns the client it used, invisibly, in place + of `TRUE`. After a relogin that is the refreshed client, so the caller + can keep the new token (#18). `?mx_with_relogin` now states that the + refreshed config is saved before the retry. +* Keep every inbound Olm session per peer, not just the latest. A peer can open several Olm sessions to us over its lifetime and reply on any of them; the single inbound slot per peer was overwritten by each new session, so a message sent on a session we had replaced could not be @@ -26,45 +57,12 @@ `create_inbound` error for a failed prekey, so a dropped message is diagnosable instead of silent. -# mx.client 0.2.1.2 - -* Fix: make MatrixRTC call encryption keys actually work, found during - the first live FluffyChat-to-bot call (the bot heard only undecryptable - silence). - - `keys` is an array of `{index, key}`, not a single object; - `mx_call_key_content()` and `mx_call_key_parse()` treated it as one, - so real key events (parsed off the wire with `simplifyVector = - FALSE`) were dropped. The parser now reads the array and returns one - entry per key. - - FluffyChat / matrix-dart-sdk sends the key as an encrypted ROOM - event (top-level `device_id`), not to-device. `mx_crypto_process_sync()` - now keeps each decrypted room event's `type` and `content`, - `mx_call_handle()` reads call keys from `processed$events` as well as - `to_device`, and `mx_call_key_parse()` accepts the room-event shape - (top-level `device_id`, room taken from the event). - - `mx_call_send_key()` also posts the key as an encrypted room event so - FluffyChat can decrypt the bot; `mx_send_encrypted()` gained an - `event_type` argument. - -# mx.client 0.2.1.1 +## Dependencies -## MatrixRTC calls - -* New: `mx_call_join()`, `mx_call_handle()`, `mx_call_poll()`, - `mx_call_connect()` and `mx_call_leave()` run a MatrixRTC call over - LiveKit the way Element Call and FluffyChat do: a per-device - `org.matrix.msc3401.call.member` state event, a media token from the - LiveKit JWT service, and per-participant media keys exchanged as - Olm-encrypted `io.element.call.encryption_keys` to-device events, with - their key rotation policy. Media goes through the `livekitr` package - (Suggests). `mx_call_members()`, `mx_call_service_url()`, - `mx_call_key_parse()` and `mx_call_key_plan()` expose the pieces. -* New: `mx_send_to_device_encrypted()` and `mx_crypto_encrypt_to_device()` - send an Olm-encrypted to-device event of any type. -* `mx_crypto_process_sync()` returns decrypted Olm to-device events other - than room keys and verification messages in a new `to_device` element. -* Requires mx.api 0.3.1.1 for the OpenID, RTC transport, LiveKit token and +* Requires mx.api 0.4.0 for the OpenID, RTC transport, LiveKit token and room-state endpoints. +* Raise the optional mx.crypto floor to 0.3.0, which adds the attachment + primitives. Unencrypted client operations still work without mx.crypto. # mx.client 0.2.1 From 5f49c6203c816a69b109a3ba5e32a11337f3c797 Mon Sep 17 00:00:00 2001 From: TroyHernandez Date: Tue, 10 Nov 2026 09:29:52 -0600 Subject: [PATCH 5/8] Add trailing slash to the drat URL in NEWS; record win-builder release result --- NEWS.md | 2 +- cran-comments.md | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/NEWS.md b/NEWS.md index 0d495bf..d519683 100644 --- a/NEWS.md +++ b/NEWS.md @@ -11,7 +11,7 @@ policy. `mx_call_members()`, `mx_call_service_url()`, `mx_call_key_parse()` and `mx_call_key_plan()` expose the pieces. * Media goes through the optional `livekitr` package (Suggests), available - from . The Matrix side of a call + from . The Matrix side of a call (`mx_call_join(connect = FALSE)`) works without it. * Call keys are read and sent both ways clients use: Olm-encrypted to-device events (Element Call) and encrypted room events (FluffyChat / diff --git a/cran-comments.md b/cran-comments.md index 7ada4b3..7878207 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -57,7 +57,11 @@ with mx.api 0.4.0 and without livekitr. * The same check with mx.crypto also absent. Status: OK. * Installed test suite with an empty HOME: 986 assertions passed and no file was written under HOME. -* Windows, macOS, and R-oldrelease were not checked for this release. +* win-builder, Windows Server 2022, R-release 4.6.2: Status: 1 NOTE, the + livekitr NOTE described above. That run also reported a redirect for + the drat URL in NEWS.md, which now has its trailing slash. +* GitHub Actions, ubuntu-latest and macos-latest, R 4.6: Status: OK. +* R-oldrelease was not checked for this release. ## Reverse dependencies From f256f6cb29cb27271a0db3745dc947c09d0190d4 Mon Sep 17 00:00:00 2001 From: TroyHernandez Date: Tue, 10 Nov 2026 09:41:25 -0600 Subject: [PATCH 6/8] Remove the MatrixRTC call surface and livekitr from the 0.3.0 release --- DESCRIPTION | 4 +- NAMESPACE | 10 - NEWS.md | 20 +- R/call.R | 715 ------------------------------------- inst/tinytest/test_call.R | 477 ------------------------- man/mx_call_connect.Rd | 31 -- man/mx_call_handle.Rd | 39 -- man/mx_call_join.Rd | 64 ---- man/mx_call_key_parse.Rd | 32 -- man/mx_call_key_plan.Rd | 38 -- man/mx_call_leave.Rd | 22 -- man/mx_call_members.Rd | 35 -- man/mx_call_poll.Rd | 45 --- man/mx_call_service_url.Rd | 27 -- 14 files changed, 3 insertions(+), 1556 deletions(-) delete mode 100644 R/call.R delete mode 100644 inst/tinytest/test_call.R delete mode 100644 man/mx_call_connect.Rd delete mode 100644 man/mx_call_handle.Rd delete mode 100644 man/mx_call_join.Rd delete mode 100644 man/mx_call_key_parse.Rd delete mode 100644 man/mx_call_key_plan.Rd delete mode 100644 man/mx_call_leave.Rd delete mode 100644 man/mx_call_members.Rd delete mode 100644 man/mx_call_poll.Rd delete mode 100644 man/mx_call_service_url.Rd diff --git a/DESCRIPTION b/DESCRIPTION index ea90a1c..6248e72 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -22,15 +22,13 @@ Depends: R (>= 4.0) Imports: jsonlite, - mx.api (>= 0.4.0), + mx.api (>= 0.3.0.2), stats, tools, utils Suggests: - livekitr, mx.crypto (>= 0.3.0), simplermarkdown, tinytest -Additional_repositories: https://cornball-ai.github.io/drat VignetteBuilder: simplermarkdown Encoding: UTF-8 diff --git a/NAMESPACE b/NAMESPACE index c4607e8..842421d 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,15 +1,6 @@ # tinyrox says don't edit this manually, but it can't stop you! export(mx_accept_invites) -export(mx_call_connect) -export(mx_call_handle) -export(mx_call_join) -export(mx_call_key_parse) -export(mx_call_key_plan) -export(mx_call_leave) -export(mx_call_members) -export(mx_call_poll) -export(mx_call_service_url) export(mx_client_config_path) export(mx_client_configure) export(mx_client_from_config) @@ -77,5 +68,4 @@ export(mx_upload_encrypted) export(mx_verify_console) export(mx_with_relogin) -S3method(print,mx_call) S3method(print,mx_client_config) diff --git a/NEWS.md b/NEWS.md index d519683..015534a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,21 +1,7 @@ # mx.client 0.3.0 -## MatrixRTC calls - -* New: `mx_call_join()`, `mx_call_handle()`, `mx_call_poll()`, - `mx_call_connect()` and `mx_call_leave()` run a MatrixRTC call over - LiveKit the way Element Call and FluffyChat do: a per-device - `org.matrix.msc3401.call.member` state event, a media token from the - LiveKit JWT service, and per-participant media keys exchanged as - `io.element.call.encryption_keys` events, with their key rotation - policy. `mx_call_members()`, `mx_call_service_url()`, - `mx_call_key_parse()` and `mx_call_key_plan()` expose the pieces. -* Media goes through the optional `livekitr` package (Suggests), available - from . The Matrix side of a call - (`mx_call_join(connect = FALSE)`) works without it. -* Call keys are read and sent both ways clients use: Olm-encrypted - to-device events (Element Call) and encrypted room events (FluffyChat / - matrix-dart-sdk). `keys` is handled as an array of `{index, key}`. +## Encrypted to-device events + * New: `mx_send_to_device_encrypted()` and `mx_crypto_encrypt_to_device()` send an Olm-encrypted to-device event of any type. * `mx_crypto_process_sync()` returns decrypted Olm to-device events other @@ -59,8 +45,6 @@ ## Dependencies -* Requires mx.api 0.4.0 for the OpenID, RTC transport, LiveKit token and - room-state endpoints. * Raise the optional mx.crypto floor to 0.3.0, which adds the attachment primitives. Unencrypted client operations still work without mx.crypto. diff --git a/R/call.R b/R/call.R deleted file mode 100644 index 8cfac6c..0000000 --- a/R/call.R +++ /dev/null @@ -1,715 +0,0 @@ -# MatrixRTC calls over LiveKit, as Element Call and FluffyChat run them: -# a per-device membership state event, a media token from the LiveKit -# JWT service, and per-participant media keys exchanged as Olm-encrypted -# to-device events. Media itself goes through the livekitr package. -# -# Wire format (both clients read, 2026-10): membership is a state event -# org.matrix.msc3401.call.member with state key "___m.call", -# keys are io.element.call.encryption_keys to-device events, and the -# LiveKit participant identity is ":". - -MX_CALL_MEMBER <- "org.matrix.msc3401.call.member" -MX_CALL_KEYS <- "io.element.call.encryption_keys" -MX_CALL_EXPIRES_MS <- 4 * 60 * 60 * 1000 -MX_CALL_REFRESH_S <- 60 * 60 -# A joiner inside this window gets the current key; later, the key rotates. -MX_CALL_KEY_GRACE_S <- 10 -# Key indexes cycle below 255: FluffyChat's key ring has 255 slots. -MX_CALL_KEY_INDEXES <- 255L - -mx_call_now_ms <- function(now = Sys.time()) { - floor(as.numeric(now) * 1000) -} - -mx_call_state_key <- function(user_id, device_id) { - paste0("_", user_id, "_", device_id, "_m.call") -} - -mx_call_identity <- function(user_id, device_id) { - paste(user_id, device_id, sep = ":") -} - -# Content of this device's membership event. created_ts is what Element -# reads, created_at what FluffyChat reads; both fall back to the event's -# origin_server_ts, so sending both only keeps the expiry exact. -mx_call_member_content <- function(user_id, device_id, service_url, room_id, - intent = "voice", now = Sys.time()) { - stopifnot(intent %in% c("voice", "video")) - ts <- mx_call_now_ms(now) - list( - application = "m.call", - call_id = "", - scope = "m.room", - device_id = device_id, - membershipID = mx_call_identity(user_id, device_id), - expires = MX_CALL_EXPIRES_MS, - `m.call.intent` = intent, - focus_active = list(type = "livekit", - focus_selection = "oldest_membership"), - foci_preferred = list(list(type = "livekit", - livekit_service_url = service_url, - livekit_alias = room_id)), - created_ts = ts, - created_at = ts - ) -} - -#' Active call memberships in a room's state -#' -#' Reads the \code{org.matrix.msc3401.call.member} state events out of a -#' room's full state (\code{mx.api::mx_room_state()}) and keeps the ones -#' that count as in the call: non-empty content, a LiveKit focus, and an -#' expiry (\code{created_ts}, or \code{created_at}, or the event's own -#' timestamp, plus \code{expires}, default 4 hours) still in the future. -#' -#' @param state List of state events. -#' @param now The current time. -#' @return A list of members, each \code{list(user_id, device_id, -#' identity, membership_id, service_urls, expires_at)}, where -#' \code{identity} is the member's LiveKit participant identity -#' \code{":"} and \code{service_urls} the LiveKit JWT -#' services it prefers. -#' @examples -#' state <- list(list(type = "org.matrix.msc3401.call.member", -#' sender = "@alice:example.org", origin_server_ts = 1e12, -#' content = list(application = "m.call", device_id = "PHONE", -#' focus_active = list(type = "livekit"), -#' foci_preferred = list(list(type = "livekit", -#' livekit_service_url = "https://jwt.example.org"))))) -#' mx_call_members(state, now = as.POSIXct(1e9, origin = "1970-01-01")) -#' @export -mx_call_members <- function(state, now = Sys.time()) { - now_ms <- mx_call_now_ms(now) - members <- list() - for (ev in state) { - if (!identical(ev$type, MX_CALL_MEMBER)) next - c <- ev$content - if (!is.list(c) || !length(c)) next - if (!identical(c$focus_active$type, "livekit")) next - if (!is.character(c$device_id) || !nzchar(c$device_id)) next - if (!is.character(ev$sender) || !nzchar(ev$sender)) next - created <- c$created_ts %||% c$created_at %||% ev$origin_server_ts - expires <- c$expires %||% MX_CALL_EXPIRES_MS - if (!is.numeric(created) || !is.numeric(expires)) next - expires_at <- created + expires - if (expires_at <= now_ms) next - urls <- character() - for (focus in c$foci_preferred %||% list()) { - if (identical(focus$type, "livekit") && - is.character(focus$livekit_service_url)) { - urls <- c(urls, focus$livekit_service_url) - } - } - members[[length(members) + 1L]] <- list( - user_id = ev$sender, - device_id = c$device_id, - identity = mx_call_identity(ev$sender, c$device_id), - membership_id = c$membershipID %||% - mx_call_identity(ev$sender, c$device_id), - service_urls = urls, - expires_at = expires_at) - } - members -} - -#' Find the LiveKit JWT service for a room's call -#' -#' Tries, in order, the services the current call members advertise in -#' their memberships, the homeserver's RTC transports -#' (\code{mx.api::mx_rtc_transports()}), and the -#' \code{org.matrix.msc4143.rtc_foci} entry of the server's client -#' well-known file. -#' -#' @param client Matrix client config. -#' @param members Current members from \code{\link{mx_call_members}}. -#' @return The service URL, a string. -#' @examples -#' \dontrun{ -#' mx_call_service_url(client, members) -#' } -#' @export -mx_call_service_url <- function(client, members = list()) { - for (member in members) { - if (length(member$service_urls)) { - return(member$service_urls[[1L]]) - } - } - s <- mx_client_session(client) - for (transport in mx.api::mx_rtc_transports(s)) { - if (identical(transport$type, "livekit") && - is.character(transport$livekit_service_url)) { - return(transport$livekit_service_url) - } - } - server_name <- sub("^@[^:]+:", "", client$user_id) - well_known <- mx.api::mx_well_known_client(server_name) - foci <- well_known[["org.matrix.msc4143.rtc_foci"]] - if (is.list(foci) && !is.null(foci$livekit_service_url)) { - foci <- list(foci) - } - for (focus in foci %||% list()) { - if (is.character(focus$livekit_service_url)) { - return(focus$livekit_service_url) - } - } - stop("no LiveKit JWT service found: nobody in the call advertises one, ", - "the homeserver lists no RTC transports, and ", server_name, - " has no rtc_foci in its well-known file", call. = FALSE) -} - -# ---- media keys ------------------------------------------------------- - -mx_call_b64 <- function(bytes) { - jsonlite::base64_enc(bytes) -} - -# Accepts standard or URL-safe alphabets, padded or not, as the Element -# decoder does. -mx_call_b64_decode <- function(x) { - x <- gsub("[\r\n= ]", "", chartr("-_", "+/", x)) - pad <- (4L - nchar(x) %% 4L) %% 4L - jsonlite::base64_dec(paste0(x, strrep("=", pad))) -} - -# Content of a key event: the key the receiver should use for this -# device's media. FluffyChat casts every field but sent_ts, so all of them -# are always present. -# A superset that both consumers accept: FluffyChat / matrix-dart-sdk -# reads top-level call_id + device_id + keys (it sends and expects the key -# as a room event); Element Call reads member + keys (to-device). Sending -# this one object by either transport reaches both. -mx_call_key_content <- function(key, index, user_id, device_id, room_id, - now = Sys.time()) { - list( - call_id = "", - device_id = device_id, - # keys is an array of {index, key}; the wrapping list makes JSON - # serialize it as an array even with a single entry. - keys = list(list(index = as.integer(index), key = mx_call_b64(key))), - member = list(id = mx_call_identity(user_id, device_id), - claimed_device_id = device_id), - room_id = room_id, - session = list(application = "m.call", call_id = "", scope = "m.room"), - sent_ts = mx_call_now_ms(now) - ) -} - -# Normalize the content's `keys` field to a list of {index, key}. The -# wire sends an array; depending on how the Olm plaintext was parsed it -# arrives as an unnamed list of objects (simplifyVector = FALSE), a data -# frame (simplifyVector = TRUE), and we also tolerate a single {index, -# key} object from a non-conformant sender. -mx_call_key_entries <- function(keys) { - if (is.null(keys)) { - return(list()) - } - if (is.data.frame(keys)) { - return(lapply(seq_len(nrow(keys)), function(i) { - list(index = keys$index[[i]], key = keys$key[[i]]) - })) - } - if (!is.null(names(keys)) && !is.null(keys$index)) { - return(list(list(index = keys$index, key = keys$key))) - } - if (is.list(keys)) { - return(Filter(function(e) is.list(e) && !is.null(e$index), keys)) - } - list() -} - -#' Read a call key event -#' -#' Parses a decrypted \code{io.element.call.encryption_keys} to-device -#' event (from the \code{to_device} list of -#' \code{\link{mx_crypto_process_sync}}) into the LiveKit identities and -#' keys to set. The event's \code{keys} field is an array, so one event -#' can carry several keys at different indices; each becomes one entry. -#' -#' @param event List with \code{type}, \code{content} and \code{sender}. -#' @param room_id The call's room; keys for other rooms are ignored. -#' @return A list of \code{list(identity, key, index)}, with \code{key} a -#' raw vector, one per usable key in the event; empty when the event is -#' not a usable key for this room. -#' @examples -#' ev <- list(type = "io.element.call.encryption_keys", -#' sender = "@alice:example.org", -#' content = list( -#' keys = list(list(index = 3, key = "AAECAwQFBgcICQoLDA0ODw==")), -#' member = list(claimed_device_id = "PHONE"), room_id = "!r:example.org")) -#' mx_call_key_parse(ev, "!r:example.org") -#' @export -mx_call_key_parse <- function(event, room_id) { - if (!identical(event$type, MX_CALL_KEYS)) return(list()) - c <- event$content - # A to-device event names its room in the content; a room event does - # not (its room is the event's own, matched by the caller). Enforce - # content$room_id only when it is present. - if (!is.null(c$room_id) && !identical(c$room_id, room_id)) return(list()) - # Element Call uses member$claimed_device_id; FluffyChat uses a - # top-level device_id. - device <- c$member$claimed_device_id %||% c$device_id - if (!is.character(event$sender) || !is.character(device) || - !nzchar(device)) { - return(list()) - } - identity <- mx_call_identity(event$sender, device) - out <- list() - for (k in mx_call_key_entries(c$keys)) { - index <- k$index - key <- k$key - if (!is.numeric(index) || length(index) != 1L || index < 0 || - index != floor(index) || !is.character(key) || length(key) != 1L) { - next - } - bytes <- tryCatch(mx_call_b64_decode(key), error = function(e) NULL) - if (is.null(bytes) || !length(bytes)) { - next - } - out[[length(out) + 1L]] <- list(identity = identity, key = bytes, - index = as.integer(index)) - } - out -} - -# The key state of one call: our key and index, when the key was made, -# whom it was sent to, and the peers' keys. -mx_call_keys_new <- function() { - keys <- new.env(parent = emptyenv()) - keys$key <- NULL - keys$index <- -1L - keys$created <- NULL - keys$shared_with <- character() - keys$peers <- list() - keys -} - -mx_call_keys_rotate <- function(keys, now = Sys.time()) { - keys$key <- mx_crypto_random_bytes(16L) - keys$index <- (keys$index + 1L) %% MX_CALL_KEY_INDEXES - keys$created <- now - keys$shared_with <- character() - invisible(keys) -} - -#' Decide what to do with the call key when membership changes -#' -#' Implements the rotation policy Element Call and FluffyChat follow: a -#' leaver forces a new key for everyone; a joiner within the grace period -#' after the key was made receives the current key; a joiner after it -#' gets a new key, as does everyone else. -#' -#' @param keys Key state from \code{mx_call_keys_new()} (an environment; -#' it is not modified). -#' @param identities LiveKit identities of the other members now in the -#' call. -#' @param now The current time. -#' @param grace Seconds after a key is made during which it is still -#' handed to joiners instead of rotated. -#' @return \code{list(rotate, targets)}: whether to make a new key, and -#' the identities to send the (new or current) key to. -#' @examples -#' keys <- mx.client:::mx_call_keys_new() -#' mx_call_key_plan(keys, c("@a:ex:D1", "@b:ex:D2")) -#' @export -mx_call_key_plan <- function(keys, identities, now = Sys.time(), - grace = MX_CALL_KEY_GRACE_S) { - identities <- unique(identities) - if (is.null(keys$key)) { - return(list(rotate = TRUE, targets = identities)) - } - left <- setdiff(keys$shared_with, identities) - joined <- setdiff(identities, keys$shared_with) - if (length(left)) { - return(list(rotate = TRUE, targets = identities)) - } - if (!length(joined)) { - return(list(rotate = FALSE, targets = character())) - } - age <- as.numeric(difftime(now, keys$created, units = "secs")) - if (age < grace) { - list(rotate = FALSE, targets = joined) - } else { - list(rotate = TRUE, targets = identities) - } -} - -# Devices of the given identities, with verified keys. -mx_call_devices <- function(client, identities) { - if (!length(identities)) return(list()) - parts <- regmatches(identities, regexec("^(.*):([^:]+)$", identities)) - user_ids <- unique(vapply(parts, `[`, "", 2L)) - known <- mx_crypto_known_devices(client, user_ids, strict = TRUE) - Filter(function(d) { - mx_call_identity(d$user_id, d$device_id) %in% identities - }, known) -} - -# ---- the call object -------------------------------------------------- - -mx_require_livekitr <- function() { - if (!requireNamespace("livekitr", quietly = TRUE)) { - stop("joining the media of a call needs the livekitr package", - call. = FALSE) - } - invisible(TRUE) -} - -# Apply a peer's key to the media session, remembering it for a session -# that is not connected yet. -mx_call_apply_peer_key <- function(call, parsed) { - call$keys$peers[[parsed$identity]] <- parsed[c("key", "index")] - if (!is.null(call$session)) { - livekitr::lk_set_e2ee_key(call$session, parsed$key, - identity = parsed$identity, - key_index = parsed$index) - } - invisible(NULL) -} - -# Send our current key to the given identities, then make sure our own -# media uses it. -mx_call_send_key <- function(call, targets) { - if (length(targets)) { - devices <- mx_call_devices(call$client, targets) - content <- mx_call_key_content(call$keys$key, call$keys$index, - call$client$user_id, - call$client$device_id, call$room_id) - res <- mx_send_to_device_encrypted(call$client, call$account, - call$sessions, MX_CALL_KEYS, content, - devices, call$store_dir) - call$sessions <- res$sessions - reached <- vapply(res$sent, function(p) { - mx_call_identity(p$user_id, p$device_id) - }, "") - call$keys$shared_with <- union(call$keys$shared_with, - intersect(targets, reached)) - # FluffyChat / matrix-dart-sdk reads the key from an encrypted - # ROOM event, not to-device, so also post it there. Guarded: a - # failure here must not break the to-device path or the call. - tryCatch({ - user_ids <- unique(sub(":[^:]+$", "", targets)) - room_res <- mx_send_encrypted(call$client, call$account, - call$sessions, call$room_id, content, call$store_dir, - member_ids = user_ids, event_type = MX_CALL_KEYS) - call$sessions <- room_res$sessions - }, error = function(e) { - warning("mx.client: could not post the call key as a room event: ", - conditionMessage(e), call. = FALSE) - }) - } - if (!is.null(call$session)) { - livekitr::lk_set_e2ee_key(call$session, call$keys$key, - identity = call$identity, - key_index = call$keys$index) - } - invisible(NULL) -} - -# Reconcile the key state with the current members. -mx_call_update_keys <- function(call, members, now = Sys.time()) { - others <- setdiff(vapply(members, `[[`, "", "identity"), call$identity) - plan <- mx_call_key_plan(call$keys, others, now) - if (plan$rotate) { - mx_call_keys_rotate(call$keys, now) - } - mx_call_send_key(call, plan$targets) - call$members <- members - invisible(NULL) -} - -mx_call_send_membership <- function(call, now = Sys.time()) { - content <- mx_call_member_content(call$client$user_id, - call$client$device_id, call$service_url, - call$room_id, call$intent, now) - tryCatch( - mx.api::mx_set_state(mx_client_session(call$client), call$room_id, - MX_CALL_MEMBER, content, - mx_call_state_key(call$client$user_id, - call$client$device_id)), - mx_error_M_FORBIDDEN = function(e) { - # Rooms default to power level 50 for state events. Element - # and FluffyChat set this event type to 0 when they create a - # room with calls; a room made another way needs the same. - stop(call$client$user_id, " may not send ", MX_CALL_MEMBER, - " in ", call$room_id, ": ", conditionMessage(e), - ". The room's m.room.power_levels needs events[\"", - MX_CALL_MEMBER, "\"] low enough for every participant ", - "(call clients set it to 0).", call. = FALSE) - }) - call$membership_sent <- now - invisible(NULL) -} - -#' Join a MatrixRTC call -#' -#' Joins the call of a room the way Element Call and FluffyChat do: -#' finds the LiveKit JWT service, trades an OpenID token for a media -#' token, announces this device's membership as a state event, makes a -#' media key and sends it Olm-encrypted to every device already in the -#' call, and, with \code{connect = TRUE}, joins the LiveKit room through -#' \pkg{livekitr} with end-to-end encryption on. The returned call must -#' then be driven with \code{\link{mx_call_handle}} (or -#' \code{\link{mx_call_poll}}) and ended with \code{\link{mx_call_leave}}. -#' -#' @param client Matrix client config. -#' @param account An mx.crypto account handle. -#' @param sessions A session set. -#' @param room_id The room whose call to join. -#' @param intent \code{"voice"} or \code{"video"}, what the membership -#' announces. -#' @param store_dir Character or NULL. Where the updated crypto sessions -#' are saved after each key send. -#' @param connect Join the LiveKit room now? \code{FALSE} does everything -#' on the Matrix side only. -#' @param service_url Character or NULL. The LiveKit JWT service to use -#' instead of discovering one. -#' @return An object of class \code{"mx_call"}: an environment holding -#' the \code{client} and \code{sessions} (both updated as the call -#' runs), the LiveKit \code{session} from \pkg{livekitr} (or NULL), this -#' device's LiveKit \code{identity}, the current \code{members}, and -#' the media \code{token}. -#' @examples -#' \dontrun{ -#' call <- mx_call_join(client, acct, sessions, "!room:example.org", -#' store_dir = store) -#' livekitr::lk_on_audio(call$session, function(pcm, info) { -#' cat(info$identity, "spoke\n") -#' }) -#' repeat mx_call_poll(call) -#' } -#' @export -mx_call_join <- function(client, account, sessions, room_id, - intent = "voice", store_dir = NULL, connect = TRUE, - service_url = NULL) { - mx_require_crypto() - call <- new.env(parent = emptyenv()) - call$client <- client - call$account <- account - call$sessions <- sessions - call$store_dir <- store_dir - call$room_id <- room_id - call$intent <- intent - call$identity <- mx_call_identity(client$user_id, client$device_id) - call$keys <- mx_call_keys_new() - call$session <- NULL - call$members <- list() - class(call) <- "mx_call" - - s <- mx_client_session(client) - members <- mx_call_members(mx.api::mx_room_state(s, room_id)) - call$service_url <- service_url %||% mx_call_service_url(client, members) - openid <- mx.api::mx_openid_token(s) - call$token <- mx.api::mx_rtc_livekit_token(call$service_url, room_id, - openid, client$device_id) - mx_call_send_membership(call) - mx_call_update_keys(call, members) - if (connect) { - mx_call_connect(call) - } - call -} - -#' Join the LiveKit room of a call -#' -#' Connects the media side of a call made with \code{mx_call_join(connect -#' = FALSE)}: joins the LiveKit room with the media token, with -#' end-to-end encryption configured as Element Call and FluffyChat -#' expect (per-participant HKDF keys, a 256-slot key ring), and sets our -#' key and every peer key received so far. -#' -#' @param call An \code{"mx_call"}. -#' @param ... Further arguments to \code{livekitr::lk_connect()}, such -#' as \code{opts}. -#' @return \code{call}, invisibly. -#' @examples -#' \dontrun{ -#' # Needs a live homeserver, a LiveKit service and the livekitr package: -#' call <- mx_call_join(client, acct, sessions, "!room:example.org", -#' connect = FALSE) -#' mx_call_connect(call) -#' } -#' @export -mx_call_connect <- function(call, ...) { - mx_require_livekitr() - if (!is.null(call$session)) { - return(invisible(call)) - } - call$session <- livekitr::lk_connect(call$token$url, call$token$jwt, - e2ee = mx_call_e2ee_options(), ...) - if (!identical(call$session$identity, call$identity)) { - warning("the LiveKit identity ", call$session$identity, - " differs from the Matrix identity ", call$identity, - "; other clients will not match this device's keys", - call. = FALSE) - } - livekitr::lk_set_e2ee_key(call$session, call$keys$key, - identity = call$identity, - key_index = call$keys$index) - for (identity in names(call$keys$peers)) { - peer <- call$keys$peers[[identity]] - livekitr::lk_set_e2ee_key(call$session, peer$key, identity = identity, - key_index = peer$index) - } - invisible(call) -} - -# How Element Call and FluffyChat configure the frame cryptor: keys are -# used as given (HKDF, not the shared-key PBKDF2 path), one slot per key -# index, and a few failed frames are tolerated while keys are in flight. -mx_call_e2ee_options <- function() { - list(kdf = "hkdf", key_ring_size = 256L, ratchet_window_size = 10L, - failure_tolerance = 10L) -} - -#' Feed a sync response to a call -#' -#' Applies what a \code{/sync} response means for the call: peers' media -#' keys from the decrypted to-device events, membership changes (which -#' may rotate and resend our key), and the hourly refresh of our own -#' membership. Call it with every sync while in the call. When the -#' application already runs \code{\link{mx_crypto_process_sync}} on the -#' response, pass its result as \code{processed} so to-device events -#' are not decrypted twice. -#' -#' @param call An \code{"mx_call"}. -#' @param sync A parsed \code{/sync} response. -#' @param processed The result of \code{mx_crypto_process_sync()} on -#' \code{sync}, or NULL to have it run here (its \code{sessions} are -#' then kept in \code{call$sessions}). -#' @return A list of what changed: \code{keys}, the identities whose -#' keys were received, and \code{members}, the current members when -#' membership changed (NULL otherwise). -#' @examples -#' \dontrun{ -#' # Inside an application's own sync loop, during a live call: -#' res <- mx_sync_update(call$client, timeout = 0L) -#' call$client <- res$client -#' changed <- mx_call_handle(call, res$sync) -#' changed$keys -#' } -#' @export -mx_call_handle <- function(call, sync, processed = NULL) { - if (is.null(processed)) { - identity <- mx.crypto::mxc_account_identity_keys(call$account) - processed <- mx_crypto_process_sync(call$account, call$sessions, - sync, identity$curve25519, self_id = call$client$user_id, - self_device_id = call$client$device_id) - call$sessions <- processed$sessions - } - received <- character() - # Call keys arrive two ways: Element Call sends them to-device, while - # FluffyChat / matrix-dart-sdk sends them as an encrypted ROOM event - # (surfaced in processed$events with its type and content). Read both. - key_events <- c(processed$to_device %||% list(), - Filter(function(ev) identical(ev$room_id, call$room_id), - processed$events %||% list())) - for (ev in key_events) { - for (parsed in mx_call_key_parse(ev, call$room_id)) { - # Our own key, posted as a room event, echoes back through our - # sync; it is not a peer key and must not be applied to our own - # participant slot. - if (identical(parsed$identity, call$identity)) { - next - } - mx_call_apply_peer_key(call, parsed) - received <- c(received, parsed$identity) - } - } - members <- NULL - room <- sync$rooms$join[[call$room_id]] - changed <- any(vapply(c(room$state$events %||% list(), - room$timeline$events %||% list()), - function(ev) identical(ev$type, MX_CALL_MEMBER), - logical(1))) - now <- Sys.time() - if (changed) { - members <- mx_call_members( - mx.api::mx_room_state(mx_client_session(call$client), - call$room_id), now) - mx_call_update_keys(call, members, now) - } - if (as.numeric(difftime(now, call$membership_sent, units = "secs")) >= - MX_CALL_REFRESH_S) { - mx_call_send_membership(call, now) - } - list(keys = received, members = members) -} - -#' Poll the media of a call, then sync once -#' -#' One iteration of a call loop for programs with no sync loop of their -#' own: polls the LiveKit session with \code{livekitr::lk_poll()}, which -#' is where audio callbacks run, for up to \code{media_timeout} seconds -#' (it returns as soon as media events arrive, so the wait is short while -#' someone speaks), then syncs with \code{\link{mx_sync_update}} and -#' applies the response with \code{\link{mx_call_handle}}. -#' -#' Audio callbacks only run while this process polls, so the sync must -#' not block for long: the default \code{timeout = 0} asks the homeserver -#' to answer at once. Not every homeserver complies: Tuwunel 1.9 holds an -#' incremental sync that has nothing new for 5 s whatever the timeout, -#' and returns at once only when something happened. Frames that arrive -#' meanwhile wait in \pkg{livekitr}'s native queue, so nothing is lost, -#' but they reach the callback late. A program that needs prompt audio -#' on such a server should sync from another process or thread. -#' -#' @param call An \code{"mx_call"}. -#' @param media_timeout Seconds to wait in the media poll. -#' @param timeout Seconds to let the sync long poll wait. -#' @return The LiveKit events from \code{livekitr::lk_poll()}, or an -#' empty list when the call has no media session. -#' @examples -#' \dontrun{ -#' # Drive a live call for 30 seconds, then leave: -#' until <- Sys.time() + 30 -#' while (Sys.time() < until) mx_call_poll(call) -#' mx_call_leave(call) -#' } -#' @export -mx_call_poll <- function(call, media_timeout = 0.5, timeout = 0) { - events <- if (is.null(call$session)) { - list() - } else { - livekitr::lk_poll(call$session, timeout = media_timeout) - } - res <- mx_sync_update(call$client, timeout = as.integer(timeout * 1000), - save = !is.null(attr(call$client, "path"))) - call$client <- res$client - mx_call_handle(call, res$sync) - events -} - -#' Leave a MatrixRTC call -#' -#' Leaves the LiveKit room and clears this device's membership event. -#' -#' @param call An \code{"mx_call"}. -#' @return \code{NULL}, invisibly. -#' @examples -#' \dontrun{ -#' # Ends a call joined with mx_call_join() on a live homeserver: -#' mx_call_leave(call) -#' } -#' @export -mx_call_leave <- function(call) { - if (!is.null(call$session)) { - livekitr::lk_disconnect(call$session) - call$session <- NULL - } - # An empty content object is how a device leaves; the state key stays. - mx.api::mx_set_state(mx_client_session(call$client), call$room_id, - MX_CALL_MEMBER, stats::setNames(list(), character()), - mx_call_state_key(call$client$user_id, call$client$device_id)) - invisible(NULL) -} - -#' @export -print.mx_call <- function(x, ...) { - cat(" room ", x$room_id, " as ", x$identity, - if (is.null(x$session)) " (media not connected)" else " (connected)", - "\n", sep = "") - cat(" JWT service: ", x$service_url, "\n", sep = "") - cat(" members in call: ", length(x$members), ", key index: ", - x$keys$index, ", peer keys: ", length(x$keys$peers), "\n", sep = "") - invisible(x) -} diff --git a/inst/tinytest/test_call.R b/inst/tinytest/test_call.R deleted file mode 100644 index 1cdca8c..0000000 --- a/inst/tinytest/test_call.R +++ /dev/null @@ -1,477 +0,0 @@ -# MatrixRTC call layer: membership events, key events, the rotation -# policy and service discovery. No homeserver and no LiveKit: HTTP is -# replaced below where a function reaches for it. - -library(tinytest) -library(mx.client) - -ns <- asNamespace("mx.client") -ROOM <- "!call:example.org" -T0 <- as.POSIXct(1.7e9, origin = "1970-01-01", tz = "UTC") - -with_api <- function(name, handler, code) { - api <- asNamespace("mx.api") - original <- get(name, envir = api, inherits = FALSE) - assignInNamespace(name, handler, ns = "mx.api") - on.exit(assignInNamespace(name, original, ns = "mx.api"), add = TRUE) - force(code) -} - -client <- list(server = "https://example.org", token = "t", - user_id = "@bot:example.org", device_id = "BOTDEV") - -# ---- identity and membership content --------------------------------- - -expect_identical(ns$mx_call_identity("@a:ex", "D"), "@a:ex:D") -expect_identical(ns$mx_call_state_key("@a:ex", "D"), "_@a:ex_D_m.call") - -content <- ns$mx_call_member_content("@bot:example.org", "BOTDEV", - "https://jwt.example.org", ROOM, now = T0) -expect_identical(content$application, "m.call") -expect_identical(content$call_id, "") -expect_identical(content$scope, "m.room") -expect_identical(content$device_id, "BOTDEV") -expect_identical(content$membershipID, "@bot:example.org:BOTDEV") -expect_equal(content$expires, 4 * 3600 * 1000) -expect_identical(content$`m.call.intent`, "voice") -expect_identical(content$focus_active$type, "livekit") -expect_identical(content$foci_preferred[[1]]$livekit_service_url, - "https://jwt.example.org") -expect_identical(content$foci_preferred[[1]]$livekit_alias, ROOM) -expect_equal(content$created_ts, 1.7e12) -expect_equal(content$created_at, 1.7e12) -expect_error(ns$mx_call_member_content("@a:ex", "D", "u", ROOM, intent = "x")) -# It survives JSON as the clients read it: expires and timestamps as numbers -js <- jsonlite::fromJSON(jsonlite::toJSON(content, auto_unbox = TRUE, - digits = NA), simplifyVector = FALSE) -expect_equal(js$created_ts, 1.7e12) -expect_equal(js$expires, 14400000) - -# ---- reading memberships from room state ----------------------------- - -member_event <- function(sender, device, created, expires = NULL, - focus = "livekit", content_extra = list(), - origin_ts = NULL) { - c <- list(application = "m.call", device_id = device, - focus_active = list(type = focus), - foci_preferred = list(list(type = "livekit", - livekit_service_url = "https://jwt.a"))) - if (!is.null(created)) c$created_ts <- created - if (!is.null(expires)) c$expires <- expires - c <- c(c, content_extra) - ev <- list(type = "org.matrix.msc3401.call.member", sender = sender, - state_key = ns$mx_call_state_key(sender, device), content = c) - if (!is.null(origin_ts)) ev$origin_server_ts <- origin_ts - ev -} -now_ms <- ns$mx_call_now_ms(T0) -state <- list( - member_event("@alice:example.org", "PHONE", now_ms - 1000), - member_event("@carol:example.org", "OLD", now_ms - 5 * 3600 * 1000), - member_event("@dave:example.org", "SHORT", now_ms - 2000, expires = 1000), - list(type = "org.matrix.msc3401.call.member", sender = "@erin:example.org", - state_key = "_@erin:example.org_GONE_m.call", - content = stats::setNames(list(), character())), - member_event("@frank:example.org", "JITSI", now_ms, focus = "jitsi"), - member_event("@bob:example.org", "LAPTOP", NULL, origin_ts = now_ms - 60000, - content_extra = list(membershipID = "custom")), - list(type = "m.room.member", sender = "@alice:example.org", - state_key = "@alice:example.org", content = list(membership = "join")) -) -members <- mx_call_members(state, now = T0) -expect_equal(length(members), 2L) -expect_identical(vapply(members, `[[`, "", "identity"), - c("@alice:example.org:PHONE", "@bob:example.org:LAPTOP")) -expect_identical(members[[1]]$service_urls, "https://jwt.a") -expect_identical(members[[1]]$membership_id, "@alice:example.org:PHONE") -expect_identical(members[[2]]$membership_id, "custom") -expect_equal(members[[2]]$expires_at, now_ms - 60000 + 4 * 3600 * 1000) -expect_equal(length(mx_call_members(list(), now = T0)), 0L) -# created_at (FluffyChat's name) is read too -fc <- member_event("@g:ex", "FC", NULL) -fc$content$created_at <- now_ms -expect_equal(length(mx_call_members(list(fc), now = T0)), 1L) - -# ---- service discovery ------------------------------------------------ - -expect_identical(mx_call_service_url(client, members), "https://jwt.a") -transports <- list(list(type = "livekit", - livekit_service_url = "https://jwt.transport")) -expect_identical( - with_api("mx_rtc_transports", function(session) transports, - mx_call_service_url(client, list())), - "https://jwt.transport") -expect_identical( - with_api("mx_rtc_transports", function(session) list(), - with_api("mx_well_known_client", function(server_name) { - expect_identical(server_name, "example.org") - list(`org.matrix.msc4143.rtc_foci` = list(list( - type = "livekit", - livekit_service_url = "https://jwt.wellknown"))) - }, mx_call_service_url(client, list()))), - "https://jwt.wellknown") -expect_error( - with_api("mx_rtc_transports", function(session) list(), - with_api("mx_well_known_client", function(server_name) NULL, - mx_call_service_url(client, list()))), - "no LiveKit JWT service found") - -# ---- key events ------------------------------------------------------- - -key <- as.raw(0:15) -kc <- ns$mx_call_key_content(key, 3L, "@bot:example.org", "BOTDEV", ROOM, - now = T0) -# keys is an ARRAY of {index, key} (MSC + Element/FluffyChat wire shape). -expect_true(is.null(names(kc$keys))) -expect_identical(length(kc$keys), 1L) -expect_identical(kc$keys[[1]]$index, 3L) -expect_identical(kc$keys[[1]]$key, "AAECAwQFBgcICQoLDA0ODw==") -# Superset content: FluffyChat's top-level device_id/call_id AND Element's -# member block, so one object serves both transports. -expect_identical(kc$device_id, "BOTDEV") -expect_identical(kc$call_id, "") -expect_identical(kc$member$id, "@bot:example.org:BOTDEV") -expect_identical(kc$member$claimed_device_id, "BOTDEV") -expect_identical(kc$room_id, ROOM) -expect_identical(kc$session$application, "m.call") -expect_equal(kc$sent_ts, 1.7e12) -# It must serialize with keys as a JSON array of objects. -kc_json <- jsonlite::toJSON(kc, auto_unbox = TRUE) -expect_true(grepl('"keys":\\[\\{"index":3,"key":', kc_json)) - -# A FluffyChat room-event key: top-level device_id, no member, no room_id -# in content (the room is the event's own). Parsed with simplifyVector -# = FALSE as off the wire. -room_ev <- jsonlite::fromJSON(paste0( - '{"type":"io.element.call.encryption_keys","sender":"@al:example.org",', - '"room_id":"', ROOM, '","content":{"call_id":"","device_id":"PHONE",', - '"keys":[{"index":2,"key":"AAECAwQFBgcICQoLDA0ODw"}],"sent_ts":1}}'), - simplifyVector = FALSE) -rp <- mx_call_key_parse(room_ev, ROOM) -expect_identical(length(rp), 1L) -expect_identical(rp[[1]]$identity, "@al:example.org:PHONE") -expect_identical(rp[[1]]$index, 2L) -expect_identical(rp[[1]]$key, key) - -# A spec-shaped event as it arrives off the wire: Olm plaintext is parsed -# with simplifyVector = FALSE, so keys is a list of lists. This is the -# exact shape that regressed in 0.2.1.1. -wire <- jsonlite::fromJSON(paste0( - '{"type":"io.element.call.encryption_keys","sender":"@bot:example.org",', - '"content":{"call_id":"","keys":[{"index":3,', - '"key":"AAECAwQFBgcICQoLDA0ODw"}],', - '"member":{"claimed_device_id":"BOTDEV","id":"@bot:example.org"},', - '"room_id":"', ROOM, '","sent_ts":1}}'), simplifyVector = FALSE) -parsed <- mx_call_key_parse(wire, ROOM) -expect_identical(length(parsed), 1L) -expect_identical(parsed[[1]]$identity, "@bot:example.org:BOTDEV") -expect_identical(parsed[[1]]$key, key) -expect_identical(parsed[[1]]$index, 3L) - -# Our own content round-trips through the parser. -rt <- mx_call_key_parse(list(type = "io.element.call.encryption_keys", - sender = "@bot:example.org", content = kc), ROOM) -expect_identical(length(rt), 1L) -expect_identical(rt[[1]]$key, key) -expect_identical(rt[[1]]$index, 3L) - -# Several keys in one event: each becomes an entry. -multi <- list(type = "io.element.call.encryption_keys", - sender = "@bot:example.org", - content = list(room_id = ROOM, - member = list(claimed_device_id = "BOTDEV"), - keys = list(list(index = 0, key = "AAA="), - list(index = 1, key = "AQE=")))) -pm <- mx_call_key_parse(multi, ROOM) -expect_identical(length(pm), 2L) -expect_identical(vapply(pm, `[[`, 0L, "index"), c(0L, 1L)) - -# Tolerate a non-conformant sender that puts keys as a single object. -obj <- list(type = "io.element.call.encryption_keys", - sender = "@bot:example.org", - content = list(room_id = ROOM, - member = list(claimed_device_id = "BOTDEV"), - keys = list(index = 3, key = "AAECAwQFBgcICQoLDA0ODw"))) -expect_identical(mx_call_key_parse(obj, ROOM)[[1]]$key, key) - -# Unpadded and URL-safe base64 decode too. -kc3 <- kc -kc3$keys[[1]]$key <- jsonlite::base64url_enc(as.raw(c(0xfb, 0xff, 0xfe, 1))) -expect_identical(mx_call_key_parse(list(type = "io.element.call.encryption_keys", - sender = "@bot:example.org", content = kc3), ROOM)[[1]]$key, - as.raw(c(0xfb, 0xff, 0xfe, 1))) - -# Rejections return an empty list: other room, other type, bad index, -# missing device. -expect_identical(mx_call_key_parse(list(type = "io.element.call.encryption_keys", - sender = "@bot:example.org", content = kc), "!other:example.org"), list()) -expect_identical(mx_call_key_parse(list(type = "m.room_key", sender = "@b:ex", - content = kc), ROOM), list()) -kc4 <- kc -kc4$keys[[1]]$index <- -1 -expect_identical(mx_call_key_parse(list(type = "io.element.call.encryption_keys", - sender = "@bot:example.org", content = kc4), ROOM), list()) -# No device at all (neither member$claimed_device_id nor top-level -# device_id): unparseable. -kc5 <- kc -kc5$member$claimed_device_id <- NULL -kc5$device_id <- NULL -expect_identical(mx_call_key_parse(list(type = "io.element.call.encryption_keys", - sender = "@bot:example.org", content = kc5), ROOM), list()) -# member alone still works when device_id is absent (Element Call shape). -kc6 <- kc -kc6$device_id <- NULL -expect_identical(mx_call_key_parse(list(type = "io.element.call.encryption_keys", - sender = "@bot:example.org", content = kc6), ROOM)[[1]]$identity, - "@bot:example.org:BOTDEV") - -# ---- rotation policy -------------------------------------------------- - -keys <- ns$mx_call_keys_new() -expect_identical(keys$index, -1L) -# No key yet: make one, send to everyone -plan <- mx_call_key_plan(keys, c("@a:ex:A", "@b:ex:B"), now = T0) -expect_true(plan$rotate) -expect_identical(plan$targets, c("@a:ex:A", "@b:ex:B")) -ns$mx_call_keys_rotate(keys, T0) -expect_identical(keys$index, 0L) -expect_equal(length(keys$key), 16L) -keys$shared_with <- c("@a:ex:A", "@b:ex:B") -# Same members: nothing to do -plan <- mx_call_key_plan(keys, c("@b:ex:B", "@a:ex:A"), now = T0 + 5) -expect_false(plan$rotate) -expect_identical(plan$targets, character()) -# Joiner inside the grace period: current key to the joiner only -plan <- mx_call_key_plan(keys, c("@a:ex:A", "@b:ex:B", "@c:ex:C"), now = T0 + 5) -expect_false(plan$rotate) -expect_identical(plan$targets, "@c:ex:C") -# Joiner after the grace period: rotate, send to all -plan <- mx_call_key_plan(keys, c("@a:ex:A", "@b:ex:B", "@c:ex:C"), now = T0 + 30) -expect_true(plan$rotate) -expect_identical(plan$targets, c("@a:ex:A", "@b:ex:B", "@c:ex:C")) -# Leaver: rotate for the rest, even inside the grace period -plan <- mx_call_key_plan(keys, "@a:ex:A", now = T0 + 1) -expect_true(plan$rotate) -expect_identical(plan$targets, "@a:ex:A") -# Everyone left: rotate, nobody to send to -plan <- mx_call_key_plan(keys, character(), now = T0 + 1) -expect_true(plan$rotate) -expect_identical(plan$targets, character()) -# Indexes wrap below 255 -keys$index <- 254L -ns$mx_call_keys_rotate(keys, T0) -expect_identical(keys$index, 0L) -expect_identical(keys$shared_with, character()) - -# ---- update_keys drives send_key with the plan ----------------------- - -local({ - sends <- list() - orig <- get("mx_call_send_key", envir = ns) - assignInNamespace("mx_call_send_key", function(call, targets) { - sends[[length(sends) + 1L]] <<- list(index = call$keys$index, - targets = targets) - call$keys$shared_with <- union(call$keys$shared_with, targets) - invisible(NULL) - }, ns = "mx.client") - on.exit(assignInNamespace("mx_call_send_key", orig, ns = "mx.client"), - add = TRUE) - call <- new.env() - call$identity <- "@bot:example.org:BOTDEV" - call$keys <- ns$mx_call_keys_new() - call$session <- NULL - me <- list(identity = "@bot:example.org:BOTDEV") - a <- list(identity = "@alice:example.org:PHONE") - b <- list(identity = "@bob:example.org:LAPTOP") - ns$mx_call_update_keys(call, list(me, a), now = T0) - expect_identical(sends[[1]], list(index = 0L, targets = a$identity)) - ns$mx_call_update_keys(call, list(me, a, b), now = T0 + 2) - expect_identical(sends[[2]], list(index = 0L, targets = b$identity)) - ns$mx_call_update_keys(call, list(me, b), now = T0 + 3) - expect_identical(sends[[3]], list(index = 1L, targets = b$identity)) - expect_equal(length(call$members), 2L) -}) - -# ---- mx_call_handle: keys from to_device, membership changes ---------- - -local({ - applied <- list() - orig_apply <- get("mx_call_apply_peer_key", envir = ns) - orig_update <- get("mx_call_update_keys", envir = ns) - assignInNamespace("mx_call_apply_peer_key", function(call, parsed) { - applied[[length(applied) + 1L]] <<- parsed$identity - call$keys$peers[[parsed$identity]] <- parsed[c("key", "index")] - }, ns = "mx.client") - assignInNamespace("mx_call_update_keys", function(call, members, now) { - call$members <- members - }, ns = "mx.client") - on.exit({ - assignInNamespace("mx_call_apply_peer_key", orig_apply, ns = "mx.client") - assignInNamespace("mx_call_update_keys", orig_update, ns = "mx.client") - }, add = TRUE) - - call <- new.env() - call$client <- client - call$room_id <- ROOM - call$identity <- "@bot:example.org:BOTDEV" - call$keys <- ns$mx_call_keys_new() - call$session <- NULL - call$members <- list() - call$membership_sent <- Sys.time() - - peer_key <- ns$mx_call_key_content(as.raw(1:16), 2L, "@alice:example.org", - "PHONE", ROOM) - other_room <- ns$mx_call_key_content(as.raw(1:16), 2L, "@alice:example.org", - "PHONE", "!other:example.org") - # A room-event key (FluffyChat): no content room_id, room is the - # record's room_id; a non-call room event and a wrong-room key event - # must be ignored. - room_key <- list(type = "io.element.call.encryption_keys", - sender = "@bob:example.org", room_id = ROOM, - content = list(call_id = "", device_id = "LAPTOP", - keys = list(list(index = 4, key = "AAECAwQFBgcICQoLDA0ODw")))) - processed <- list( - to_device = list( - list(type = "io.element.call.encryption_keys", - sender = "@alice:example.org", content = peer_key), - list(type = "io.element.call.encryption_keys", - sender = "@alice:example.org", content = other_room), - list(type = "org.example.other", sender = "@x:ex", content = list())), - events = list( - room_key, - list(type = "m.room.message", sender = "@c:ex", room_id = ROOM, - content = list(body = "hi")), - list(type = "io.element.call.encryption_keys", sender = "@d:ex", - room_id = "!elsewhere:example.org", - content = list(device_id = "X", - keys = list(list(index = 9, key = "AAA=")))), - # Our own key, echoed back through our sync: must be skipped. - list(type = "io.element.call.encryption_keys", - sender = "@bot:example.org", room_id = ROOM, - content = list(device_id = "BOTDEV", - keys = list(list(index = 7, key = "AAECAwQFBgcICQoLDA0ODw")))))) - quiet <- list(rooms = list(join = list())) - res <- mx_call_handle(call, quiet, processed) - expect_identical(sort(res$keys), - c("@alice:example.org:PHONE", "@bob:example.org:LAPTOP")) - expect_null(res$members) - expect_identical(sort(unlist(applied)), - c("@alice:example.org:PHONE", "@bob:example.org:LAPTOP")) - expect_identical(call$keys$peers[["@alice:example.org:PHONE"]]$index, 2L) - expect_identical(call$keys$peers[["@bob:example.org:LAPTOP"]]$index, 4L) - # Our own echoed key was not applied as a peer. - expect_false("@bot:example.org:BOTDEV" %in% res$keys) - expect_null(call$keys$peers[["@bot:example.org:BOTDEV"]]) - - # A membership event in the room's timeline triggers a state refresh - with_state <- list(rooms = list(join = stats::setNames(list(list( - timeline = list(events = list(list( - type = "org.matrix.msc3401.call.member", - sender = "@alice:example.org"))))), ROOM))) - res <- with_api("mx_room_state", function(session, room_id) { - expect_identical(room_id, ROOM) - list(member_event("@alice:example.org", "PHONE", - ns$mx_call_now_ms(Sys.time()))) - }, mx_call_handle(call, with_state, list(to_device = list()))) - expect_equal(length(res$members), 1L) - expect_identical(call$members[[1]]$identity, "@alice:example.org:PHONE") - - # Membership is re-sent once an hour - sent <- NULL - call$membership_sent <- Sys.time() - 3601 - call$service_url <- "https://jwt.a" - call$intent <- "voice" - with_api("mx_set_state", function(session, room_id, event_type, content, - state_key = "") { - sent <<- list(type = event_type, state_key = state_key, - content = content) - list(event_id = "$e") - }, mx_call_handle(call, quiet, list(to_device = list()))) - expect_identical(sent$type, "org.matrix.msc3401.call.member") - expect_identical(sent$state_key, "_@bot:example.org_BOTDEV_m.call") - expect_identical(sent$content$device_id, "BOTDEV") - expect_true(as.numeric(Sys.time()) - as.numeric(call$membership_sent) < 5) -}) - -# ---- mx_call_leave clears the membership ----------------------------- - -local({ - sent <- NULL - call <- new.env() - call$client <- client - call$room_id <- ROOM - call$session <- NULL - with_api("mx_set_state", function(session, room_id, event_type, content, - state_key = "") { - sent <<- list(room_id = room_id, type = event_type, content = content, - state_key = state_key) - list(event_id = "$e") - }, mx_call_leave(call)) - expect_identical(sent$room_id, ROOM) - expect_identical(sent$state_key, "_@bot:example.org_BOTDEV_m.call") - expect_equal(length(sent$content), 0L) - expect_identical(as.character(jsonlite::toJSON(sent$content, - auto_unbox = TRUE)), "{}") -}) - -# ---- mx_call_join on the Matrix side only ---------------------------- - -local({ - calls <- list() - record <- function(what) { - function(...) { - calls[[length(calls) + 1L]] <<- what - switch(what, - room_state = list(member_event("@alice:example.org", "PHONE", - ns$mx_call_now_ms(Sys.time()))), - openid = list(access_token = "oid", token_type = "Bearer", - matrix_server_name = "example.org", - expires_in = 3600L), - livekit_token = list(url = "wss://sfu.example.org", - jwt = "jwt"), - set_state = list(event_id = "$e")) - } - } - orig_send <- get("mx_call_send_key", envir = ns) - orig_req <- get("mx_require_crypto", envir = ns) - assignInNamespace("mx_call_send_key", function(call, targets) { - calls[[length(calls) + 1L]] <<- paste("send_key", paste(targets, - collapse = ",")) - call$keys$shared_with <- targets - }, ns = "mx.client") - assignInNamespace("mx_require_crypto", function() invisible(TRUE), - ns = "mx.client") - on.exit({ - assignInNamespace("mx_call_send_key", orig_send, ns = "mx.client") - assignInNamespace("mx_require_crypto", orig_req, ns = "mx.client") - }, add = TRUE) - call <- with_api("mx_room_state", record("room_state"), - with_api("mx_openid_token", record("openid"), - with_api("mx_rtc_livekit_token", record("livekit_token"), - with_api("mx_set_state", record("set_state"), - mx_call_join(client, NULL, mx_crypto_sessions_new(), ROOM, - connect = FALSE))))) - expect_inherits(call, "mx_call") - expect_identical(calls, list("room_state", "openid", "livekit_token", - "set_state", - "send_key @alice:example.org:PHONE")) - expect_identical(call$service_url, "https://jwt.a") - expect_identical(call$token$url, "wss://sfu.example.org") - expect_identical(call$identity, "@bot:example.org:BOTDEV") - expect_equal(length(call$members), 1L) - expect_identical(call$keys$index, 0L) - expect_null(call$session) - expect_stdout(print(call), "media not connected") - # An explicit service URL skips discovery - call2 <- with_api("mx_room_state", function(...) list(), - with_api("mx_openid_token", record("openid"), - with_api("mx_rtc_livekit_token", function(service_url, ...) { - expect_identical(service_url, "https://jwt.explicit") - list(url = "wss://x", jwt = "j") - }, - with_api("mx_set_state", record("set_state"), - mx_call_join(client, NULL, mx_crypto_sessions_new(), ROOM, - connect = FALSE, service_url = "https://jwt.explicit"))))) - expect_identical(call2$service_url, "https://jwt.explicit") - expect_equal(length(call2$members), 0L) -}) diff --git a/man/mx_call_connect.Rd b/man/mx_call_connect.Rd deleted file mode 100644 index cc00d86..0000000 --- a/man/mx_call_connect.Rd +++ /dev/null @@ -1,31 +0,0 @@ -% tinyrox says don't edit this manually, but it can't stop you! -\name{mx_call_connect} -\alias{mx_call_connect} -\title{Join the LiveKit room of a call} -\usage{ -mx_call_connect(call, ...) -} -\arguments{ -\item{call}{An \code{"mx_call"}.} - -\item{...}{Further arguments to \code{livekitr::lk_connect()}, such -as \code{opts}.} -} -\value{ -\code{call}, invisibly. -} -\description{ -Connects the media side of a call made with \code{mx_call_join(connect -= FALSE)}: joins the LiveKit room with the media token, with -end-to-end encryption configured as Element Call and FluffyChat -expect (per-participant HKDF keys, a 256-slot key ring), and sets our -key and every peer key received so far. -} -\examples{ -\dontrun{ -# Needs a live homeserver, a LiveKit service and the livekitr package: -call <- mx_call_join(client, acct, sessions, "!room:example.org", - connect = FALSE) -mx_call_connect(call) -} -} diff --git a/man/mx_call_handle.Rd b/man/mx_call_handle.Rd deleted file mode 100644 index e7ed913..0000000 --- a/man/mx_call_handle.Rd +++ /dev/null @@ -1,39 +0,0 @@ -% tinyrox says don't edit this manually, but it can't stop you! -\name{mx_call_handle} -\alias{mx_call_handle} -\title{Feed a sync response to a call} -\usage{ -mx_call_handle(call, sync, processed = NULL) -} -\arguments{ -\item{call}{An \code{"mx_call"}.} - -\item{sync}{A parsed \code{/sync} response.} - -\item{processed}{The result of \code{mx_crypto_process_sync()} on -\code{sync}, or NULL to have it run here (its \code{sessions} are -then kept in \code{call$sessions}).} -} -\value{ -A list of what changed: \code{keys}, the identities whose - keys were received, and \code{members}, the current members when - membership changed (NULL otherwise). -} -\description{ -Applies what a \code{/sync} response means for the call: peers' media -keys from the decrypted to-device events, membership changes (which -may rotate and resend our key), and the hourly refresh of our own -membership. Call it with every sync while in the call. When the -application already runs \code{\link{mx_crypto_process_sync}} on the -response, pass its result as \code{processed} so to-device events -are not decrypted twice. -} -\examples{ -\dontrun{ -# Inside an application's own sync loop, during a live call: -res <- mx_sync_update(call$client, timeout = 0L) -call$client <- res$client -changed <- mx_call_handle(call, res$sync) -changed$keys -} -} diff --git a/man/mx_call_join.Rd b/man/mx_call_join.Rd deleted file mode 100644 index cd98d0a..0000000 --- a/man/mx_call_join.Rd +++ /dev/null @@ -1,64 +0,0 @@ -% tinyrox says don't edit this manually, but it can't stop you! -\name{mx_call_join} -\alias{mx_call_join} -\title{Join a MatrixRTC call} -\usage{ -mx_call_join( - client, - account, - sessions, - room_id, - intent = "voice", - store_dir = NULL, - connect = TRUE, - service_url = NULL -) -} -\arguments{ -\item{client}{Matrix client config.} - -\item{account}{An mx.crypto account handle.} - -\item{sessions}{A session set.} - -\item{room_id}{The room whose call to join.} - -\item{intent}{\code{"voice"} or \code{"video"}, what the membership -announces.} - -\item{store_dir}{Character or NULL. Where the updated crypto sessions -are saved after each key send.} - -\item{connect}{Join the LiveKit room now? \code{FALSE} does everything -on the Matrix side only.} - -\item{service_url}{Character or NULL. The LiveKit JWT service to use -instead of discovering one.} -} -\value{ -An object of class \code{"mx_call"}: an environment holding - the \code{client} and \code{sessions} (both updated as the call - runs), the LiveKit \code{session} from \pkg{livekitr} (or NULL), this - device's LiveKit \code{identity}, the current \code{members}, and - the media \code{token}. -} -\description{ -Joins the call of a room the way Element Call and FluffyChat do: -finds the LiveKit JWT service, trades an OpenID token for a media -token, announces this device's membership as a state event, makes a -media key and sends it Olm-encrypted to every device already in the -call, and, with \code{connect = TRUE}, joins the LiveKit room through -\pkg{livekitr} with end-to-end encryption on. The returned call must -then be driven with \code{\link{mx_call_handle}} (or -\code{\link{mx_call_poll}}) and ended with \code{\link{mx_call_leave}}. -} -\examples{ -\dontrun{ -call <- mx_call_join(client, acct, sessions, "!room:example.org", - store_dir = store) -livekitr::lk_on_audio(call$session, function(pcm, info) { - cat(info$identity, "spoke\n") -}) -repeat mx_call_poll(call) -} -} diff --git a/man/mx_call_key_parse.Rd b/man/mx_call_key_parse.Rd deleted file mode 100644 index 22d3f04..0000000 --- a/man/mx_call_key_parse.Rd +++ /dev/null @@ -1,32 +0,0 @@ -% tinyrox says don't edit this manually, but it can't stop you! -\name{mx_call_key_parse} -\alias{mx_call_key_parse} -\title{Read a call key event} -\usage{ -mx_call_key_parse(event, room_id) -} -\arguments{ -\item{event}{List with \code{type}, \code{content} and \code{sender}.} - -\item{room_id}{The call's room; keys for other rooms are ignored.} -} -\value{ -A list of \code{list(identity, key, index)}, with \code{key} a - raw vector, one per usable key in the event; empty when the event is - not a usable key for this room. -} -\description{ -Parses a decrypted \code{io.element.call.encryption_keys} to-device -event (from the \code{to_device} list of -\code{\link{mx_crypto_process_sync}}) into the LiveKit identities and -keys to set. The event's \code{keys} field is an array, so one event -can carry several keys at different indices; each becomes one entry. -} -\examples{ -ev <- list(type = "io.element.call.encryption_keys", - sender = "@alice:example.org", - content = list( - keys = list(list(index = 3, key = "AAECAwQFBgcICQoLDA0ODw==")), - member = list(claimed_device_id = "PHONE"), room_id = "!r:example.org")) -mx_call_key_parse(ev, "!r:example.org") -} diff --git a/man/mx_call_key_plan.Rd b/man/mx_call_key_plan.Rd deleted file mode 100644 index 2c9c1cc..0000000 --- a/man/mx_call_key_plan.Rd +++ /dev/null @@ -1,38 +0,0 @@ -% tinyrox says don't edit this manually, but it can't stop you! -\name{mx_call_key_plan} -\alias{mx_call_key_plan} -\title{Decide what to do with the call key when membership changes} -\usage{ -mx_call_key_plan( - keys, - identities, - now = Sys.time(), - grace = MX_CALL_KEY_GRACE_S -) -} -\arguments{ -\item{keys}{Key state from \code{mx_call_keys_new()} (an environment; -it is not modified).} - -\item{identities}{LiveKit identities of the other members now in the -call.} - -\item{now}{The current time.} - -\item{grace}{Seconds after a key is made during which it is still -handed to joiners instead of rotated.} -} -\value{ -\code{list(rotate, targets)}: whether to make a new key, and - the identities to send the (new or current) key to. -} -\description{ -Implements the rotation policy Element Call and FluffyChat follow: a -leaver forces a new key for everyone; a joiner within the grace period -after the key was made receives the current key; a joiner after it -gets a new key, as does everyone else. -} -\examples{ -keys <- mx.client:::mx_call_keys_new() -mx_call_key_plan(keys, c("@a:ex:D1", "@b:ex:D2")) -} diff --git a/man/mx_call_leave.Rd b/man/mx_call_leave.Rd deleted file mode 100644 index 222d095..0000000 --- a/man/mx_call_leave.Rd +++ /dev/null @@ -1,22 +0,0 @@ -% tinyrox says don't edit this manually, but it can't stop you! -\name{mx_call_leave} -\alias{mx_call_leave} -\title{Leave a MatrixRTC call} -\usage{ -mx_call_leave(call) -} -\arguments{ -\item{call}{An \code{"mx_call"}.} -} -\value{ -\code{NULL}, invisibly. -} -\description{ -Leaves the LiveKit room and clears this device's membership event. -} -\examples{ -\dontrun{ -# Ends a call joined with mx_call_join() on a live homeserver: -mx_call_leave(call) -} -} diff --git a/man/mx_call_members.Rd b/man/mx_call_members.Rd deleted file mode 100644 index e89da82..0000000 --- a/man/mx_call_members.Rd +++ /dev/null @@ -1,35 +0,0 @@ -% tinyrox says don't edit this manually, but it can't stop you! -\name{mx_call_members} -\alias{mx_call_members} -\title{Active call memberships in a room's state} -\usage{ -mx_call_members(state, now = Sys.time()) -} -\arguments{ -\item{state}{List of state events.} - -\item{now}{The current time.} -} -\value{ -A list of members, each \code{list(user_id, device_id, - identity, membership_id, service_urls, expires_at)}, where - \code{identity} is the member's LiveKit participant identity - \code{":"} and \code{service_urls} the LiveKit JWT - services it prefers. -} -\description{ -Reads the \code{org.matrix.msc3401.call.member} state events out of a -room's full state (\code{mx.api::mx_room_state()}) and keeps the ones -that count as in the call: non-empty content, a LiveKit focus, and an -expiry (\code{created_ts}, or \code{created_at}, or the event's own -timestamp, plus \code{expires}, default 4 hours) still in the future. -} -\examples{ -state <- list(list(type = "org.matrix.msc3401.call.member", - sender = "@alice:example.org", origin_server_ts = 1e12, - content = list(application = "m.call", device_id = "PHONE", - focus_active = list(type = "livekit"), - foci_preferred = list(list(type = "livekit", - livekit_service_url = "https://jwt.example.org"))))) -mx_call_members(state, now = as.POSIXct(1e9, origin = "1970-01-01")) -} diff --git a/man/mx_call_poll.Rd b/man/mx_call_poll.Rd deleted file mode 100644 index e336286..0000000 --- a/man/mx_call_poll.Rd +++ /dev/null @@ -1,45 +0,0 @@ -% tinyrox says don't edit this manually, but it can't stop you! -\name{mx_call_poll} -\alias{mx_call_poll} -\title{Poll the media of a call, then sync once} -\usage{ -mx_call_poll(call, media_timeout = 0.5, timeout = 0) -} -\arguments{ -\item{call}{An \code{"mx_call"}.} - -\item{media_timeout}{Seconds to wait in the media poll.} - -\item{timeout}{Seconds to let the sync long poll wait.} -} -\value{ -The LiveKit events from \code{livekitr::lk_poll()}, or an - empty list when the call has no media session. -} -\description{ -One iteration of a call loop for programs with no sync loop of their -own: polls the LiveKit session with \code{livekitr::lk_poll()}, which -is where audio callbacks run, for up to \code{media_timeout} seconds -(it returns as soon as media events arrive, so the wait is short while -someone speaks), then syncs with \code{\link{mx_sync_update}} and -applies the response with \code{\link{mx_call_handle}}. -} -\details{ -Audio callbacks only run while this process polls, so the sync must -not block for long: the default \code{timeout = 0} asks the homeserver -to answer at once. Not every homeserver complies: Tuwunel 1.9 holds an -incremental sync that has nothing new for 5 s whatever the timeout, -and returns at once only when something happened. Frames that arrive -meanwhile wait in \pkg{livekitr}'s native queue, so nothing is lost, -but they reach the callback late. A program that needs prompt audio -on such a server should sync from another process or thread. - -} -\examples{ -\dontrun{ -# Drive a live call for 30 seconds, then leave: -until <- Sys.time() + 30 -while (Sys.time() < until) mx_call_poll(call) -mx_call_leave(call) -} -} diff --git a/man/mx_call_service_url.Rd b/man/mx_call_service_url.Rd deleted file mode 100644 index dfae8bc..0000000 --- a/man/mx_call_service_url.Rd +++ /dev/null @@ -1,27 +0,0 @@ -% tinyrox says don't edit this manually, but it can't stop you! -\name{mx_call_service_url} -\alias{mx_call_service_url} -\title{Find the LiveKit JWT service for a room's call} -\usage{ -mx_call_service_url(client, members = list()) -} -\arguments{ -\item{client}{Matrix client config.} - -\item{members}{Current members from \code{\link{mx_call_members}}.} -} -\value{ -The service URL, a string. -} -\description{ -Tries, in order, the services the current call members advertise in -their memberships, the homeserver's RTC transports -(\code{mx.api::mx_rtc_transports()}), and the -\code{org.matrix.msc4143.rtc_foci} entry of the server's client -well-known file. -} -\examples{ -\dontrun{ -mx_call_service_url(client, members) -} -} From fc7b4bf2cb22bbbfe8b3e9b115460d6e96ed77d4 Mon Sep 17 00:00:00 2001 From: TroyHernandez Date: Tue, 10 Nov 2026 09:41:25 -0600 Subject: [PATCH 7/8] Update cran-comments for the release without calls --- cran-comments.md | 59 ++++++++++++++++-------------------------------- 1 file changed, 20 insertions(+), 39 deletions(-) diff --git a/cran-comments.md b/cran-comments.md index 7878207..ee64f19 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -4,34 +4,18 @@ Update from CRAN version 0.2.1 to 0.3.0. -This release adds MatrixRTC calls over LiveKit (`mx_call_join()` and -related functions), encrypted attachment upload and verified download -(`mx_upload_encrypted()`, `mx_download_encrypted()`), and Olm-encrypted -to-device events of any type. It fixes the loss of inbound Olm messages -sent on a session the peer had opened earlier, and `mx_set_displayname()` -now returns the client it used so a caller can keep a refreshed token. - -The mandatory mx.api floor is 0.4.0 and the optional mx.crypto floor is -0.3.0. Both versions are on CRAN. - -## Suggested package outside the mainstream repositories - -livekitr is in Suggests and is not on CRAN. It is available from the -repository declared in DESCRIPTION: - - Additional_repositories: https://cornball-ai.github.io/drat - -Expect the incoming NOTE "Suggests or Enhances not in mainstream -repositories: livekitr". The check reports it as available through the -Additional_repositories specification. - -livekitr carries only the media connection of a call. Every use is -conditional: `mx_call_connect()` calls `requireNamespace("livekitr")` -first and stops with an informative error when it is absent, and the -other call functions touch livekitr only on a session that -`mx_call_connect()` created. The Matrix side of a call -(`mx_call_join(connect = FALSE)`) works without it. No example, test, or -vignette needs livekitr; all checks below ran without it installed. +This release adds encrypted attachment upload and verified download +(`mx_upload_encrypted()`, `mx_download_encrypted()`) and Olm-encrypted +to-device events of any type (`mx_send_to_device_encrypted()`, +`mx_crypto_encrypt_to_device()`). It fixes the loss of inbound Olm +messages sent on a session the peer had opened earlier, and +`mx_set_displayname()` now returns the client it used so a caller can +keep a refreshed token. + +The mandatory mx.api floor is unchanged at 0.3.0.2. The optional +mx.crypto floor rises to 0.3.0, now on CRAN, for the attachment +primitives. All dependencies are on CRAN. Unencrypted client operations +still work without mx.crypto. ## API and compatibility @@ -43,24 +27,21 @@ optional `event_type` argument. `mx_crypto_process_sync()` adds a `mx_set_displayname()` returned `TRUE` invisibly and now returns the client config invisibly. Neither reverse dependency uses the value. +`mx_send_media()` now refuses a plaintext upload to an encrypted room. + Session stores written by 0.2.1 load unchanged: a single inbound Olm session per peer becomes a one-element list. ## Test environments -All local checks used a library built from CRAN source packages only, -with mx.api 0.4.0 and without livekitr. +All local checks used a library built from CRAN source packages only. * Ubuntu 24.04.5, R 4.6.1: R CMD check --as-cran --run-donttest, including PDF and HTML manuals, examples, tests, and rebuilt vignettes, with mx.crypto 0.3.0 installed. Status: OK. -* The same check with mx.crypto also absent. Status: OK. -* Installed test suite with an empty HOME: 986 assertions passed and no +* The same check with mx.crypto absent. Status: OK. +* Installed test suite with an empty HOME: 873 assertions passed and no file was written under HOME. -* win-builder, Windows Server 2022, R-release 4.6.2: Status: 1 NOTE, the - livekitr NOTE described above. That run also reported a redirect for - the drat URL in NEWS.md, which now has its trailing slash. -* GitHub Actions, ubuntu-latest and macos-latest, R 4.6: Status: OK. * R-oldrelease was not checked for this release. ## Reverse dependencies @@ -70,6 +51,6 @@ checked against the 0.3.0 tarball. Both: Status: OK. ## Examples -The call and encrypted-media examples are in \dontrun because they need -account credentials, a live Matrix homeserver, and for media a LiveKit -service. All executed example and test writes use temporary directories. +The encrypted-media examples are in \dontrun because they need account +credentials and a live Matrix homeserver. All executed example and test +writes use temporary directories. From a70325d142aa977dd363451dd459af48bc3b8d16 Mon Sep 17 00:00:00 2001 From: TroyHernandez Date: Tue, 10 Nov 2026 10:17:05 -0600 Subject: [PATCH 8/8] Record win-builder and CI results in cran-comments --- cran-comments.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cran-comments.md b/cran-comments.md index ee64f19..dc581e0 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -42,6 +42,12 @@ All local checks used a library built from CRAN source packages only. * The same check with mx.crypto absent. Status: OK. * Installed test suite with an empty HOME: 873 assertions passed and no file was written under HOME. +* win-builder, Windows Server 2022, R-release 4.6.2: Status: OK, 872 + test assertions passed. +* win-builder R-devel (2026-11-07 r90850) installed the package and built + a binary, but its check log stopped at the incoming feasibility step + and reported no result. +* GitHub Actions, ubuntu-latest and macos-latest, R 4.6: Status: OK. * R-oldrelease was not checked for this release. ## Reverse dependencies