@protobase/cli 0.58.5 → 0.58.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/package.js +1 -1
- package/dist/config/build-project.js +2 -1
- package/dist/project/project-admin.js +1 -0
- package/package.json +7 -7
- package/skills/protobase/SKILL.md +1 -0
- package/skills/protobase/references/features/calls.md +12 -0
- package/skills/protobase/references/features.md +1 -0
- package/skills/protobase/references/guides/api-functions.md +2 -1
- package/skills/protobase/references/reference/calls.md +103 -0
- package/skills/protobase/references/reference/config/api.md +13 -0
- package/skills/protobase/references/reference/config.md +1 -1
package/dist/cli/package.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { projectFiles, projectFunctions, projectJobs, projectNotifications, projectOptions, projectResources, projectWebhooks } from "./project-parts.js";
|
|
2
|
-
import { buildAppAuth, buildAuthenticator } from "@protobase/server/internal";
|
|
2
|
+
import { buildAppAuth, buildAuthenticator, checkCallsOptions } from "@protobase/server/internal";
|
|
3
3
|
//#region src/config/build-project.ts
|
|
4
4
|
/**
|
|
5
5
|
* The app's own mailer, the default export of its auth/mailer.ts: what sign-in and the jobs (`context.mail`) both send
|
|
@@ -70,6 +70,7 @@ const buildProject = async (config, database) => {
|
|
|
70
70
|
...webhooks && { webhooks },
|
|
71
71
|
...config.realtime && { realtime: config.realtime },
|
|
72
72
|
...notifications && { notifications },
|
|
73
|
+
...config.calls && { calls: checkCallsOptions(config.calls) },
|
|
73
74
|
...mailer && { mailer },
|
|
74
75
|
...config.mobile && { mobile: config.mobile },
|
|
75
76
|
...config.secret && { secret: config.secret },
|
|
@@ -28,6 +28,7 @@ const projectAdmin = (project, db, ui, reporter, upgradeWebSocket) => {
|
|
|
28
28
|
...project.webhooks && { webhooks: project.webhooks },
|
|
29
29
|
...project.realtime && { realtime: project.realtime },
|
|
30
30
|
...project.notifications && { notifications: project.notifications },
|
|
31
|
+
...project.calls && { calls: project.calls },
|
|
31
32
|
...project.mobile && { mobile: project.mobile },
|
|
32
33
|
...project.app && { app: project.app },
|
|
33
34
|
...ui?.icons && { icons: ui.icons },
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/cli",
|
|
3
|
-
"version": "0.58.
|
|
3
|
+
"version": "0.58.6",
|
|
4
4
|
"description": "The protobase command: scaffold, doctor, dev, build and serve a Protobase project.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -42,12 +42,12 @@
|
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"@better-auth/core": "^1.7.12",
|
|
44
44
|
"@hono/node-server": "^2.1.3",
|
|
45
|
-
"@protobase/config": "0.58.
|
|
46
|
-
"@protobase/layout": "0.58.
|
|
47
|
-
"@protobase/query": "0.58.
|
|
48
|
-
"@protobase/schema": "0.58.
|
|
49
|
-
"@protobase/server": "0.58.
|
|
50
|
-
"@protobase/ui": "0.58.
|
|
45
|
+
"@protobase/config": "0.58.6",
|
|
46
|
+
"@protobase/layout": "0.58.6",
|
|
47
|
+
"@protobase/query": "0.58.6",
|
|
48
|
+
"@protobase/schema": "0.58.6",
|
|
49
|
+
"@protobase/server": "0.58.6",
|
|
50
|
+
"@protobase/ui": "0.58.6",
|
|
51
51
|
"@react-email/render": "^2.1.0",
|
|
52
52
|
"@scalar/hono-api-reference": "^0.12.10",
|
|
53
53
|
"@tailwindcss/vite": "^4.3.3",
|
|
@@ -88,6 +88,7 @@ Reference:
|
|
|
88
88
|
- When running background jobs → read [Jobs](references/reference/jobs.md)
|
|
89
89
|
- When sending email → read [Email](references/reference/email.md)
|
|
90
90
|
- When registering users' devices for push notifications → read [Notifications](references/reference/notifications.md)
|
|
91
|
+
- When adding audio and video calls, through LiveKit or peer to peer → read [Calls](references/reference/calls.md)
|
|
91
92
|
- When setting roles, capabilities and row filters → read [Access](references/reference/access.md)
|
|
92
93
|
- When configuring sign-in, tokens and the auth schema → read [Login with Better Auth](references/reference/auth.md)
|
|
93
94
|
- When using the typed client and hooks → read [Client and live UI](references/reference/client.md)
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<!-- Generated by scripts/protobase-skill.ts from website/src/content/docs/features/calls.md: run `bun run docs:skill`, do not edit. -->
|
|
2
|
+
|
|
3
|
+
# Calls
|
|
4
|
+
|
|
5
|
+
Audio and video calls between an app's users, through LiveKit or peer to peer, with Protobase deciding who is in a call and who hears whom.
|
|
6
|
+
|
|
7
|
+
- [Calls](../reference/calls.md#turning-them-on) (in development): `calls: { backend }` in the config carries calls' audio and video through a media plugin inside the server, and an app without it loads none of it.
|
|
8
|
+
- [LiveKit](../reference/calls.md#livekit) (in development): The media goes through a LiveKit server, self-hosted or LiveKit Cloud, which Protobase speaks to for each member.
|
|
9
|
+
- [Peer to peer](../reference/calls.md#peer-to-peer) (in development): With no media server, the members' browsers send their media straight to each other, for small calls.
|
|
10
|
+
- [Admitting members](../reference/calls.md#admitting-members) (in development): A function of your own admits the caller to a call with what they may send and whose tracks they hear.
|
|
11
|
+
- [Joining from the browser](../reference/calls.md#joining-from-the-browser) (in development): `joinCall` from `@protobase/client/calls` sends the camera, microphone and screen in plain WebRTC, with no media library in the app.
|
|
12
|
+
- [Reconnecting](../reference/calls.md#reconnecting) (in development): A call keeps its media through a deploy or a dropped connection, and resumes on any process serving the app.
|
|
@@ -32,6 +32,7 @@ A feature without a mark is stable. The others say so after their name:
|
|
|
32
32
|
- [History, comments and live updates](features/history-comments-and-live-updates.md): The changes of each record, comments on it, and pages that refresh as records change.
|
|
33
33
|
- [Events, webhooks and jobs](features/events-webhooks-and-jobs.md): React to changes, deliver them to other systems, and run work in the background.
|
|
34
34
|
- [Notifications](features/notifications.md): A bell in the top bar and push to browsers and phones, for what your app tells its users.
|
|
35
|
+
- [Calls](features/calls.md): Audio and video calls between an app's users, with Protobase deciding who is in a call and who hears whom.
|
|
35
36
|
- [Email and public forms](features/email-and-public-forms.md): Mail the app sends, and forms for people without an account.
|
|
36
37
|
- [AI](features/ai.md): Fields and actions filled by a model, the assistant beside the admin, and MCP.
|
|
37
38
|
- [Compatibility and moving from other systems](features/compatibility.md): Apps written for other systems that keep working on Protobase, and moving their data and code over.
|
|
@@ -52,9 +52,10 @@ The second argument of a handler (`c.env` in a [Hono app](#hono-apps)):
|
|
|
52
52
|
| `caller()` | Resolves to `{ session, records }`. Public functions use it to ask for a caller when they need one. |
|
|
53
53
|
| `decryptField(resource, key, field)` | An [encrypted field](../reference/data-config.md#reading-in-jobs-and-functions)'s value, skipping access rules like `db`; each read is audited, naming the function and the caller. |
|
|
54
54
|
| `acceptWebSocket(events)` | Answers a WebSocket upgrade with a socket; return its response. See [WebSockets](#websockets). |
|
|
55
|
+
| `calls.join(member)` | The events of a member's socket in a call, for `acceptWebSocket`. See [Calls](../reference/calls.md). |
|
|
55
56
|
| `name` | The function's name. |
|
|
56
57
|
|
|
57
|
-
A [public function](#public-functions-and-webhooks) has only `db`, `caller()`, `acceptWebSocket` and `name`.
|
|
58
|
+
A [public function](#public-functions-and-webhooks) has only `db`, `caller()`, `acceptWebSocket`, `calls` and `name`.
|
|
58
59
|
|
|
59
60
|
## Reading and writing records as the caller
|
|
60
61
|
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
<!-- Generated by scripts/protobase-skill.ts from website/src/content/docs/reference/calls.md: run `bun run docs:skill`, do not edit. -->
|
|
2
|
+
|
|
3
|
+
# Calls
|
|
4
|
+
|
|
5
|
+
Audio and video calls between an app's users, through a LiveKit server or straight between browsers, with Protobase deciding who is in a call, who may send and who hears whom.
|
|
6
|
+
|
|
7
|
+
## Turning them on
|
|
8
|
+
|
|
9
|
+
:::caution[In development]
|
|
10
|
+
Members join through a function of your own and the browser client. Call rows, a lobby, stage mode, recording, guests and the call UI are not built yet, and only Chrome has been tested.
|
|
11
|
+
:::
|
|
12
|
+
|
|
13
|
+
Calls carry audio and video between an app's users. The browser runs plain WebRTC and talks only to Protobase, which relays its offers, answers and candidates to the call's media plugin, inside the Protobase server: [LiveKit](#livekit), whose server carries the media, or [peer to peer](#peer-to-peer), where the browsers send it to each other. Either way the media never passes through Protobase, which decides who is in a call, who may send and who hears whom, and apps load no media library.
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
// protobase.config.ts
|
|
17
|
+
import { defineConfig } from '@protobase/config'
|
|
18
|
+
|
|
19
|
+
export default defineConfig(({ env }) => ({
|
|
20
|
+
calls: {
|
|
21
|
+
backend: { kind: 'livekit', url: env.LIVEKIT_URL!, apiKey: env.LIVEKIT_API_KEY!, apiSecret: env.LIVEKIT_API_SECRET! },
|
|
22
|
+
},
|
|
23
|
+
}))
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
- `url`: the LiveKit server, self-hosted or LiveKit Cloud, such as `wss://livekit.example.com`.
|
|
27
|
+
- `apiKey`, `apiSecret`: the key Protobase signs each member's LiveKit token with.
|
|
28
|
+
|
|
29
|
+
Or, with no media server, `backend: { kind: 'peer' }`, with `iceServers` for the STUN and TURN servers browsers reach each other through: `[{ urls: ['stun:stun.example.com:3478'] }]`.
|
|
30
|
+
|
|
31
|
+
Without `calls`, an app has none of it: the server loads no calls code, and only a page that imports `@protobase/client/calls` bundles the browser side.
|
|
32
|
+
|
|
33
|
+
Running LiveKit on your own machine: `bun run calls:up` in the Protobase repository starts one from `docker-compose.yml`, at `ws://127.0.0.1:7880` with the key `devkey` and the secret `secretsecretsecretsecretsecretsecret`.
|
|
34
|
+
|
|
35
|
+
## Admitting members
|
|
36
|
+
|
|
37
|
+
A member joins a call through an [API function](../guides/api-functions.md) of your own, which decides whether the caller may join, then answers with `acceptWebSocket(await calls.join(member))`:
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
// functions/meeting.ts
|
|
41
|
+
import { defineFunction } from '@protobase/server'
|
|
42
|
+
|
|
43
|
+
export default defineFunction(async (request, { session, records, acceptWebSocket, calls }) => {
|
|
44
|
+
const id = new URL(request.url).searchParams.get('call')!
|
|
45
|
+
// The caller's access to the meeting record decides whether they may join; a refusal is a problem, as in any function.
|
|
46
|
+
const meeting = await records.get('meetings', id)
|
|
47
|
+
return acceptWebSocket(
|
|
48
|
+
await calls.join({ call: id, member: String(session.user.id), publish: meeting.host === session.user.id ? true : ['microphone'] }),
|
|
49
|
+
)
|
|
50
|
+
})
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
| | |
|
|
54
|
+
| --- | --- |
|
|
55
|
+
| `call` | The call: members with the same `call` meet. |
|
|
56
|
+
| `member` | Who joins, unique in the call, such as the user's id. LiveKit knows the member by nothing else: no name, no metadata. |
|
|
57
|
+
| `publish` | `true` to send any source, a list of `'camera'`, `'microphone'`, `'screen'` and `'screen-audio'`, or `false` to only listen. |
|
|
58
|
+
| `hears` | Optional: which of the others' tracks the member hears, as `(track) => boolean` of `{ member, kind, source }`; every track by default. |
|
|
59
|
+
|
|
60
|
+
The socket is checked again every minute like any function's: a caller who would now be refused is closed out of the socket and leaves the call. The function's own checks, such as access to the meeting, are repeated only when it passes them as `recheck`.
|
|
61
|
+
|
|
62
|
+
## Joining from the browser
|
|
63
|
+
|
|
64
|
+
`joinCall` from `@protobase/client/calls` opens the function's socket, with the browser's session cookie, and resolves once the member is in the call:
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
import { joinCall } from '@protobase/client/calls'
|
|
68
|
+
|
|
69
|
+
const call = await joinCall({
|
|
70
|
+
url: `/api/functions/meeting?call=${id}`,
|
|
71
|
+
onTracks: (tracks) => render(tracks), // [{ sid, member, kind, source, muted, track? }]
|
|
72
|
+
onState: (state) => showState(state), // connecting, joined, resuming, or left with its reason
|
|
73
|
+
})
|
|
74
|
+
const media = await navigator.mediaDevices.getUserMedia({ video: true, audio: true })
|
|
75
|
+
await call.publish({ camera: media.getVideoTracks()[0], microphone: media.getAudioTracks()[0] }, { simulcast: true })
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
| | |
|
|
79
|
+
| --- | --- |
|
|
80
|
+
| `publish(tracks, { simulcast })` | Sends tracks under their sources; rejects when the member may not. With `simulcast` and LiveKit, video goes in three sizes. |
|
|
81
|
+
| `unpublish(source)` | Stops sending the source; the track itself goes on until the page stops it. |
|
|
82
|
+
| `mute(source, muted)` | Mutes or unmutes a sent track; the others see `muted` on it. |
|
|
83
|
+
| `view(sids, { width, height })` | With LiveKit: how large the page shows remote video, so it receives the size that fits; `'hidden'` receives none. |
|
|
84
|
+
| `restartIce()` | New network paths, such as after a network change; a failed connection restarts by itself. |
|
|
85
|
+
| `leave()` | Leaves the call. |
|
|
86
|
+
|
|
87
|
+
`onSpeakers` gets who speaks how loudly, and `onUnpublished` a source the media server stopped, such as after the member lost the right to send.
|
|
88
|
+
|
|
89
|
+
## Reconnecting
|
|
90
|
+
|
|
91
|
+
When the socket to Protobase closes, such as during a deploy, media keeps flowing and the browser opens a new socket that resumes the member from its own state. With LiveKit any process serving the app can take it; when LiveKit no longer knows the member, the browser joins again and sends the same tracks. After `maxRetries` tries in a row, 8 by default, the call is left.
|
|
92
|
+
|
|
93
|
+
## LiveKit
|
|
94
|
+
|
|
95
|
+
`kind: 'livekit'`. Protobase speaks LiveKit's signal protocol, version 17, on each member's behalf, over its single peer connection endpoint (`/rtc/v1`, LiveKit 1.9.1 and later), so media goes straight between the browser and LiveKit. Each member is a LiveKit participant of their own, which subscribes to nothing until Protobase lets them hear a track. LiveKit's data messages are not used: chat and reactions go over Protobase.
|
|
96
|
+
|
|
97
|
+
## Peer to peer
|
|
98
|
+
|
|
99
|
+
`kind: 'peer'`. Each member's browser keeps a peer connection to every other member's and sends them its media directly; Protobase passes their descriptions and candidates between them and tells each member who else is in the call and which tracks they hear. It suits small calls: a browser uploads its media once per other member. Members meet only on the same process, which keeps who is in each call, and a member whose socket was lost stays in the call for 30 seconds while their browser resumes. `hears` decides which tracks a member is told of; the media itself goes between the browsers, which Protobase cannot stop.
|
|
100
|
+
|
|
101
|
+
## Contract test
|
|
102
|
+
|
|
103
|
+
The repository's contract test runs members in Chromium through both plugins, against a real LiveKit server: `bun run calls:up`, then `bun run test:calls`. `LIVEKIT_IMAGE` in the environment of `calls:up` tries another LiveKit version.
|
|
@@ -160,6 +160,19 @@ How [Supabase Realtime](../supabase-realtime.md) is served. With `'one'`, one pr
|
|
|
160
160
|
export default defineConfig({ realtime: { processes: 'many' } })
|
|
161
161
|
```
|
|
162
162
|
|
|
163
|
+
## calls
|
|
164
|
+
|
|
165
|
+
- **Type:** `{ backend: { kind: 'livekit', url: string, apiKey: string, apiSecret: string } | { kind: 'peer', iceServers?: { urls: string[], username?: string, credential?: string }[] } }`
|
|
166
|
+
- **Default:** none: no calls
|
|
167
|
+
|
|
168
|
+
The media plugin that carries the audio and video of the calls API functions admit members to with `calls.join`: a LiveKit server, or the members' browsers peer to peer. Without it, `calls.join` rejects and the app loads no calls code. See [Calls](../calls.md).
|
|
169
|
+
|
|
170
|
+
```ts
|
|
171
|
+
export default defineConfig(({ env }) => ({
|
|
172
|
+
calls: { backend: { kind: 'livekit', url: env.LIVEKIT_URL!, apiKey: env.LIVEKIT_API_KEY!, apiSecret: env.LIVEKIT_API_SECRET! } },
|
|
173
|
+
}))
|
|
174
|
+
```
|
|
175
|
+
|
|
163
176
|
## Code of the API
|
|
164
177
|
|
|
165
178
|
Two files of the project's own change what the API does, each its default export, with no key in the config:
|
|
@@ -28,7 +28,7 @@ Each key is described with its type and default in the option pages:
|
|
|
28
28
|
| --- | --- |
|
|
29
29
|
| [App options](config/app.md) | `name`, `url`, `secret`, `previousSecrets`, `locale`, `timezone`, `themeColor`, `backgroundColor`, `mobile` |
|
|
30
30
|
| [Sign-in options](config/sign-in.md) | `auth`, `authenticate`, `signingKeyDays`, `signingKeyGraceDays` |
|
|
31
|
-
| [API options](config/api.md) | `apiPath`, `apiKeys`, `cors`, `defaultAccess`, `rowPermissions`, `statementTimeoutMs`, `scanGuard`, `errorReporting`, `writeHooks`, `mcpEndpoint`, `remoteResources`, `runtimeUpdates`, `realtime` |
|
|
31
|
+
| [API options](config/api.md) | `apiPath`, `apiKeys`, `cors`, `defaultAccess`, `rowPermissions`, `statementTimeoutMs`, `scanGuard`, `errorReporting`, `writeHooks`, `mcpEndpoint`, `remoteResources`, `runtimeUpdates`, `realtime`, `calls` |
|
|
32
32
|
| [Admin app options](config/admin-app.md) | `assistant`, `maps`, `plugins` |
|
|
33
33
|
| [Jobs and events options](config/jobs-and-events.md) | `jobs`, `events`, `history`, `webhooks`, `notifications` |
|
|
34
34
|
| [Files options](config/files.md) | `files` |
|