🏑 index : quine-global/quple.git

# Quple

A tiny "call someone by username" desktop app built around
[Jitsi Meet](https://jitsi.org). Modeled on [quintodrome](../quintodrome), it
wraps a web app in a [Tauri](https://tauri.app) shell β€” but instead of hosting
a local sidecar server, it points at a hosted (or self-hosted) Jitsi Meet
deployment and uses a minimal central service to let two users find each
other and agree on a meeting room.

## How it works

1. **Sign in.** Everything is behind a Quine account at
   [login.quineglobal.com](https://login.quineglobal.com), Quine's Keycloak
   (the realm `public`, where anyone can sign up; Quple is its OIDC client
   `quple`). The app opens the sign-in page in the system browser. Your
   Quine username is what people call you by.
   **Contacts** are kept per person on the signaling server.
2. **Presence.** While the app is open, it polls the signaling server every
   few seconds, which doubles as "I'm online" and "did anyone call me?".
3. **Calling.** You call someone by username, on whichever Jitsi Meet
   server you like: meet.jit.si by default, or any other deployment (the
   app remembers the last one you used). Jitsi servers need no credentials
   from Quple, so nothing is set up on them. The signaling server mints a
   meeting ID and your app opens a window at `<jitsi>/<meeting-id>`.
4. **Receiving.** The callee's app sees the pending invite on its next poll,
   shows an "Incoming call from X on <server>" prompt, and β€” if accepted β€”
   opens the same meeting URL on the caller's chosen server. Jitsi Meet's
   own WebRTC signaling (XMPP + the videobridge) takes it from there;
   Quple's server never touches media or call content, it only introduces
   two clients to the same room name.
5. **Ringing.** The caller doesn't join the Jitsi room until
   the call is answered: it shows "Calling bob" and sends heartbeats
   (`/calls/{id}/heartbeat`). The callee's phone rings for 45 s, checking
   the call meanwhile (`GET /calls/{id}`, which isn't answering) and
   stopping if the caller cancels. Answering opens the callee's call screen,
   whose first heartbeat tells the caller's app, which joins the room then.
   Declining or ringing out hangs up, and the caller's app goes back to
   "bob didn't answer"; so it does after 60 s with no answer at all (the
   callee's app wasn't open). An invite for a call that's already been
   hung up isn't delivered.

   **Every device rings.** Each of the callee's devices (iPhone, Mac) gets
   the invite on its own `/poll?device=…`, once; one that opens within the
   invite's 2 minutes still rings. The first to answer has the call, and
   the others, checking `GET /calls/{id}?device=…` while they ring, see
   `answeredOn` ("Answered on your iPhone") and stop without hanging up.
   Declining on any of them declines the call.

   **Crossed calls.** If you call someone who is already ringing you (you
   both pressed call at once, or you call back instead of answering), the
   server doesn't open a second room: your `/call` answers their call on
   your device and returns its meeting and Jitsi server with
   `"joined": true`, and your app goes straight into it. Their ringing
   screen sees the answer as usual, and your other devices stop ringing
   ("Answered on your Mac"). A call that was hung up or has run out
   doesn't count: calling back then rings as a new call.

   **Calling yourself** (typing your own username), from your Mac to your
   iPhone or back: your other devices ring, not the one calling. The
   server tells the two sides apart by device rather than username (the
   caller's device is the caller's side; the other device that answers is
   the callee's), so apps send their device with `/call`, `/hangup` and
   `GET /calls/{id}`, and `peerEnded` says which side hung up (`endedBy`
   is you either way). Such a call can't be moved.
6. **Ending.** Jitsi doesn't end a call when the other side leaves, so the
   iPhone app's call screen does, on any Jitsi server
   ([`mobile/src/watchdog.ts`](mobile/src/watchdog.ts)). Every 3 s it sends
   a heartbeat to the signaling server, which answers whether the other
   side hung up (or declined) and when their call screen last sent one, and
   it watches who's in the Jitsi room. It ends the call when the other side
   hangs up, hasn't answered after 60 s, or is gone from both the room and
   the server (45 s), and rejoins (remounts the Jitsi SDK) when it never got
   into the room or the other side is in the call but not in its room.
   Quple's server being down never ends a call Jitsi is still carrying.
   Hanging up, declining or letting it ring out sends `/hangup`, so the
   other app ends too.

   The desktop app does the same with a copy of the watchdog
   (`desktop/src/watchdog.js`, tested with `node --test
   desktop/test/*.test.mjs`). Its meeting window is plain web content with
   no access to the app, so a script injected into it reports the room
   (joined, how many others, from Jitsi's `window.APP`) through the page
   title, which the app reads (`desktop/src-tauri/src/lib.rs`). Closing
   that window, or Jitsi's hang-up button, hangs up, and the window closes.
   Jitsi's red button is always a plain hang-up, on both apps: no "Leave /
   End meeting for all" menu, since hanging up already ends the call on
   both sides (desktop: the injected script; iPhone:
   `mobile/patches/@jitsi+react-native-sdk+*.patch`, applied by
   patch-package on `npm install`). Each call starts with the mic and
   camera on or off as they were at the end of the last one, on that
   device (Quple's own muting for a move, and iOS turning the camera off
   in the background, don't count).
7. **Calls while Quple is closed.** Without VoIP push (a paid Apple
   account), the iPhone app only rings while it's open. So when a call is
   placed to someone whose app hasn't polled in the last 10 s, the server
   also publishes "alice is calling. Open Quple to answer." to their own
   ntfy topic on ntfy.quineglobal.com (`quple_<random>`, made on first use,
   kept in `DATA_DIR`; petersweb-infra `docs/NTFY.md`), and "Missed call
   from alice" if alice gives up first. The ntfy app shows it even when
   Quple is closed; tapping it opens Quple (`com.quineglobal.quple://call`),
   which polls and rings as usual. The caller's app waits 100 s instead of
   60 for such a call (`/call` answers `"notified": true`). The ntfy iPhone
   app has no subscribe links, so at launch, until you've said you did it,
   the iPhone app walks you through subscribing (install ntfy, then its
   topic and server with copy buttons; **Notifications** on the home screen
   brings it back).
8. **Moving a call.** Each app has a device ID (kept for good: the iPhone's
   in AsyncStorage, the Mac's in its webview's localStorage), sent with
   every heartbeat. The first device to send one holds your side of the
   call. While it lasts, your other devices see it on their next poll
   (`/poll?device=…` lists it once answered): "In a call with bob on your
   iPhone β€” Move to this Mac". Moving (`POST /calls/{id}/move`) makes that
   device the holder and joins the same Jitsi room from it; the old one's
   next heartbeat answer says `movedTo`, so it mutes at once (the two may be
   side by side) and, once the new one reports it's in the room
   (`movedJoined`), leaves without hanging up. Bob sees you drop out and
   come back for a moment; his app keeps the call, since it goes by your
   username. It works both ways, but the device you move to has to have
   Quple open (no VoIP push).

Every request to the signaling server carries a Quine access token; the
server takes the caller's username (the token's `preferred_username`) from
it, never from the request, and only accepts access tokens issued to Quple
(`typ` Bearer, `azp` quple).

meet.jit.si only starts a meeting once a signed-in user joins, so when the
chosen server is meet.jit.si the app offers to sign you in to it (once; it's
remembered).

```
   Caller's Quple                Signaling server              Callee's Quple
   --------------                ----------------              --------------
   POST /call            ----->  mint meetingId,
   {to, jitsiUrl}
                                 queue invite for "to"
                         <-----  {meetingId, jitsiUrl}
   open window:
   <jitsiUrl>/<id>
                                                            GET /poll
                                                     <----- (polling every ~3s)
                                 return queued invite ----->
                                                            show "Incoming call
                                                            from X on <server>"
                                                            accept -> open window:
                                                            <jitsiUrl>/<id>
```

Both windows are now just two independent visitors to the same Jitsi Meet
room β€” the same as if they'd both manually opened
`https://meet.jit.si/quple-abc123` and shared the link.

## Layout

```
quple/
β”œβ”€β”€ server/       # Go: the minimal central signaling service
β”œβ”€β”€ desktop/      # Tauri desktop app (the thing each user runs); the UI is
β”‚                 # Preact + htm, vendored, so there's no frontend build
└── jitsi-meet/   # Upstream jitsi-meet source, as its own git clone (ignored
                  # here; reference only, not built as part of this app β€”
                  # see below)
```

### Why `jitsi-meet/` isn't built

Quple doesn't build or serve jitsi-meet's frontend itself. It just navigates
a window to a room URL on *some* Jitsi Meet deployment, the same way a
browser tab would. By default that's the public `meet.jit.si`, which requires
no infrastructure at all. Running your own deployment needs Prosody (XMPP),
Jicofo, and JVB in addition to the web frontend in this repo β€” that's a
separate, heavier project (see jitsi-meet's own `doc/quick-install.md` and
`docker-compose` setup). The source is vendored here so it's easy to build a
custom/branded frontend later; once one is running, just type its URL as the
server when calling (or make it the signaling server's `DEFAULT_JITSI`).

## Running it

Requires Go 1.25+.

### 1. Quine sign-in

Nothing to run: Quple uses login.quineglobal.com
(`https://login.quineglobal.com/realms/public`), where the `quple` client is
set up by petersweb-infra (`nixos/keycloak/public-realm.nix`, docs/LOGIN.md).
Self-hosting later means any OIDC provider with a public client `quple`
that allows PKCE and a `http://127.0.0.1/callback` redirect on any port,
issues `preferred_username` as a username like login.quineglobal.com's
(3-32 of a-z, 0-9, `.`, `_`, `-`), and offers
`offline_access`; Keycloak does all of that.

### 2. Signaling server

```sh
cd server
go run .              # listens on :8080; set ADDR to change it
```

`ISSUER` (default `https://login.quineglobal.com/realms/public`) is the
identity server whose access tokens it accepts and `CLIENT_ID` (default
`quple`) the app they must be issued to. Every endpoint needs `Authorization: Bearer <access token>`.
`DEFAULT_JITSI` (default `https://meet.jit.si`) hosts calls that don't name a
server, and `DATA_DIR` holds contacts and notification topics. `NTFY_URL` and
`NTFY_TOKEN` (one that may publish to `quple_*` topics) turn on call
notifications for closed apps; without them there are none.

**Deploying** (meet.quineglobal.com) works like our other services: a push
to `main` that touches `server/` runs `.forgejo/workflows/deploy.yml`, which
tests it, builds `server/Containerfile` as
`forge.in.quineglobal.com/quine-global/quple-server` and opens a
petersweb-infra PR bumping its pinned digest (`nixos/quple/default.nix`).
Merging the PR deploys it. Restarting clears presence and any in-flight
invites; contacts are kept in `DATA_DIR`.

### Local signaling server

```sh
(cd server && ADDR=127.0.0.1:8090 go run .)
```

Then in the app's **Advanced settings** set the signaling server to
`http://127.0.0.1:8090`. It still signs in at login.quineglobal.com.

### 3. Desktop app

Requires a Rust toolchain (pinned via `desktop/rust-toolchain.toml`,
installed automatically by `rustup`) and, on Linux, the system WebView
packages Tauri needs (`webkit2gtk-4.1`, `gtk3`, `libappindicator3`,
`librsvg2` β€” see [Tauri's Linux prerequisites](https://v2.tauri.app/start/prerequisites/)).
On this machine those aren't installed at the OS level (it's an immutable/
atomic distro), so build it the same way quintodrome does for Linux: inside
the `flatpak-builder` distrobox, or via `rpm-ostree install` + reboot if you
want it on the host directly. macOS and Windows need no extra system
packages beyond Xcode CLT / the MSVC Build Tools.

```sh
cd desktop/src-tauri
cargo run
```

On first launch you'll land on **Sign in with Quine**, which finishes in your
browser and comes back to the app (RFC 8252: a one-shot listener on
`127.0.0.1`). The refresh token is kept in the app's data dir, readable only
by you; the webview only ever sees short-lived access tokens. The identity
and signaling server URLs are under **Advanced settings**, and later the gear
icon. The Jitsi server for a call is picked on the main screen.

To build a standalone app bundle:

```sh
cd desktop/src-tauri
cargo tauri build
```

#### Updates and releases (macOS)

Like Quintodrome's, the Mac app updates itself with
[Sparkle](https://sparkle-project.org/) through
[tauri-plugin-sparkle-updater](https://crates.io/crates/tauri-plugin-sparkle-updater):
**Quple β€Ί Check for Updates…**, a background check at every launch, and
Sparkle's daily one. Sparkle shows its native "A new version is available"
window and installs the update itself (`desktop/src-tauri/src/updater.rs`).

- **Building locally:** `bash desktop/scripts/download-sparkle.sh
  desktop/src-tauri` once (Sparkle.framework and its tools, git-ignored),
  then `cd desktop && SPARKLE_FRAMEWORK_PATH=$PWD/src-tauri npx
  @tauri-apps/cli@2 build`. Sparkle only runs in the packaged `.app`, not
  `cargo run`.
- **Releasing:** `git tag -a v1.2.3 -m "What's new" && git push origin
  v1.2.3`. `.forgejo/workflows/desktop.yml` builds both architectures on the
  Mac runner, publishes the Forgejo release (downloadable through
  git.quineglobal.com), and writes the Homebrew cask (`brew install --cask
  quine-global/tap/quple`) and one Sparkle appcast per architecture
  (`appcasts/quple-<arch>.xml`) into quine-global/homebrew-tap. The tag's
  message is the release notes, shown in Sparkle's update window.
- **Signing:** each update zip is signed with an Ed25519 key; the public half
  is `SUPublicEDKey` in `desktop/src-tauri/Info.plist`, the private half the
  `SPARKLE_PRIVATE_KEY` Actions secret. It's Quintodrome's and Hyper's key
  (the login Keychain's `hyper` account, backed up in 1Password as "Hyper
  Sparkle update signing key"); the appcasts are separate, so no app is
  offered another's updates. Pushing to the tap needs the
  `HOMEBREW_TAP_SSH_KEY` secret, a key with write access to the tap.
- **Version:** release builds take the tag's version (what people see);
  Sparkle compares `CFBundleVersion`, which is the workflow's run number, as
  is the appcast's `sparkle:version`.
- The app is only ad-hoc signed: the cask strips the quarantine flag, and
  says `auto_updates true`, so `brew upgrade` leaves it to Sparkle.

#### Linux (Quine Linux)

A Flatpak, `com.quineglobal.Quple` (`desktop/flatpak/`), built for both
architectures by `.forgejo/workflows/flatpak.yml` on every push to `main`
that touches the desktop app, and uploaded as a bundle to the bucket's
`flatpak/incoming/`. quine-global/flatpak-repo publishes it from there to
Quine Linux's Flatpak repo (`flatpak.quineglobal.com`) within about 10
minutes. Quine Linux preinstalls it from that repo and updates it like its
other Flatpaks.

**Calls open in the browser**, not in a window of the app: Tauri draws with
WebKitGTK on Linux, and the GNOME runtime's WebKitGTK (the Flatpak's) is
built without WebRTC, so Jitsi Meet can't run in it (tested on GNOME 50
and 51: no `RTCPeerConnection`). Sign-in, contacts and ringing are in the
app as on the Mac; when a call starts, the meeting opens in the default
browser (`MEETING_IN_BROWSER` in `lib.rs`). The app can't see or close the
browser's tab, so:
- You hang up in Quple; when a call ends, it says to close the browser's
  tab too.
- The watchdog goes on Quple's server alone (`external` in
  `desktop/src/watchdog.js`): the other side hanging up or vanishing ends
  the call; the room-based rules (rejoining, alone in the room) don't
  apply.
- Hanging up only in the browser isn't seen: the other side ends the call
  after its own alone-in-the-room timeout.
- meet.jit.si's sign-in happens in the browser (its sign-in page comes first
  and goes straight on when the browser is signed in), so the app's own
  "Sign in to meet.jit.si" isn't shown.

The app id (the Tauri identifier, set by `TAURI_CONFIG` in the manifest) is
`com.quineglobal.Quple` here rather than the Mac's `com.quple.desktop`, so
the window matches its desktop file.

### 4. iPhone app (`mobile/`)

React Native 0.85 (the version the Jitsi Meet SDK, 13.3, supports), iOS
only. Same account, contacts and calling as the desktop app; calls happen in
the Jitsi Meet SDK, and incoming calls ring on iOS's own call screen
(CallKit).

- **Installed with AltStore**, re-signed with a free Apple ID, so no push
  notifications: a call only rings **while the app is open** (it polls the
  signaling server in the foreground, like the desktop app). Ringing when
  closed needs VoIP push, which needs the paid Apple Developer Program
  (then TestFlight); `src/callkit.ts` is where it would plug in.
- Sign-in: `com.quineglobal.quple:/oauth`, registered with the `quple`
  client (petersweb-infra docs/LOGIN.md). The refresh token is in the
  iOS Keychain.

**Installing:** in AltStore, Sources β†’ + β†’
`https://packages.quineglobal.com/altstore.json`,
then install Quple from it; new builds show up as updates. It's Quine's
source, for all our iPhone apps (Quple is the first). CI
(`.forgejo/workflows/ios.yml`, on the Mac runner) builds every push to
`main` that touches `mobile/`, uploads the build to this repo's `altstore`
release, and replaces Quple's entry in the source
(`.forgejo/altstore-source.py`; the listing is `mobile/altstore.json`),
leaving other apps' alone.

Building by hand (on a Mac with Xcode and CocoaPods; our Mac mini has both):

```sh
cd mobile && npm ci && cd ios && pod install
xcodebuild -workspace QupleMobile.xcworkspace -scheme QupleMobile \
  -configuration Release -sdk iphoneos -destination generic/platform=iOS \
  -derivedDataPath build CODE_SIGNING_ALLOWED=NO build
mkdir -p ipa/Payload && cp -R build/Build/Products/Release-iphoneos/QupleMobile.app ipa/Payload/
(cd ipa && zip -qry ../build/Quple.ipa Payload)
```

Unsigned on purpose: AltStore signs it with your Apple ID when it installs
it (and again every 7 days). TypeScript: `npx tsc --noEmit` (the Jitsi
SDK's own sources don't type-check, so `types/` declares its API).

## Verification status

- **`server/`**: `go vet`-clean, with HTTP-level tests for auth, calls on
  the default and a caller-chosen Jitsi server (and refusal of non-http(s)
  or otherwise odd server URLs), and contacts; the token check against a
  fake Keycloak-shaped issuer (ID, refresh and other apps' tokens, other
  issuers, expired tokens and other keys are refused).
- **`mobile/`**: type-checks, and builds for iPhone (Release, unsigned)
  with Xcode 27.2. Not yet run on a phone: sign-in, CallKit ringing and a
  Jitsi call need a device.
- **`desktop/`**: builds with `cargo build` on macOS and runs. The Preact UI
  (Quine sign-in, contacts, picking the server for a call, the meet.jit.si
  sign-in prompt, incoming calls showing their server) is checked headlessly
  against a mocked backend. The browser sign-in round trip in the real app
  hasn't been driven automatically.

## Server API

All endpoints require `Authorization: Bearer <Quine access token>`; the
caller's username is the token's `preferred_username`.

| Method & path                | Body                                   | Returns |
|-------------------------------|-----------------------------------------|---------|
| `GET /me`                     | β€”                                       | `{"username":"alice","defaultJitsiUrl":"https://meet.jit.si"}`, plus `"ntfyServer"` and `"ntfyTopic"` (yours, made on first use) when the server sends call notifications |
| `POST /register`              | β€”                                       | `{"ok":true}` β€” marks you online |
| `POST /call`                  | `{"to":"bob","jitsiUrl":"https://meet.jit.si","device":"…","name":"Mac"}` | `{"meetingId":…,"jitsiUrl":…,"notified":false}` β€” every device of `to` rings. `jitsiUrl` is optional (default `DEFAULT_JITSI`); `device` and `name` too, except to call yourself (`to` is you: your other devices ring; 400 without a device); `notified` when the callee's app was closed and they got a notification instead; `"joined": true` when `to` was already ringing you (a crossed call): that's their call, answered on your device, and nobody rings |
| `GET /poll[?device=…]`        | β€”                                       | `{"invites":[{"from":…,"meetingId":…,"jitsiUrl":…,"createdAt":…}]}` β€” also marks you online. Each invite comes once per device (apps without `device` share one), until it's answered, hung up or 2 minutes old. With `device`, also `"calls":[{"meetingId":…,"peer":…,"jitsiUrl":…,"device":"iPhone"}]`: your answered calls on your other devices, to move |
| `GET /calls/{meetingId}[?device=…]` | β€”                                 | the same as a heartbeat's answer, without counting as one: for a device that's ringing (has the caller given up?). With `device`, also `answeredOn` (a device name) once another of your devices has answered: stop ringing, don't hang up |
| `POST /calls/{meetingId}/heartbeat` | `{"device":"…","name":"iPhone","joined":true}` (optional) | `{"peer":"bob","peerSeenMsAgo":1200,"endedBy":"","peerEnded":false}` β€” sent every few seconds from a call screen; `peerSeenMsAgo` is `null` until the other side's call screen opens (not answered; the caller's call screen is up from the start), `endedBy` is who hung up and `peerEnded` whether it was the other side (what tells them apart in a call to yourself). With a device, also `movedTo`/`movedJoined` when the call is now on another of your devices (see "Moving a call"). Also marks you online. Only the call's two parties: 403 otherwise, 404 for unknown or long-idle calls |
| `POST /calls/{meetingId}/move`      | `{"device":"…","name":"Mac"}`     | `{"meetingId":…,"peer":"bob","jitsiUrl":…,"device":"Mac"}` β€” puts your side of the call on this device; your other one leaves once this one's heartbeat says `joined`. 409 if it's ended, or a call to yourself |
| `POST /calls/{meetingId}/hangup`    | `{"device":"…"}` (optional; needed in a call to yourself) | `{"ok":true}` β€” ends the call for both sides (hanging up, declining, or the ring running out) |
| `GET /contacts`               | β€”                                       | `{"contacts":[{"username":…,"online":true}]}` |
| `POST /contacts`              | `{"username":"bob"}`                    | the added contact |
| `DELETE /contacts/{username}` | β€”                                       | `{"ok":true}` |

Presence expires 90s after the last `/register` or `/poll`. Undelivered
invites expire after 2 minutes.