@protobase/cli 0.62.5 → 0.63.0

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.
@@ -1,4 +1,4 @@
1
1
  //#region package.json
2
- var version = "0.62.5";
2
+ var version = "0.63.0";
3
3
  //#endregion
4
4
  export { version };
@@ -1,6 +1,6 @@
1
1
  import { isAllowedHost } from "./allowed-host.js";
2
2
  //#region src/dev/api-websockets.ts
3
- const isApiWebSocket = (url) => /^\/api\/sb\/realtime\/v1\/websocket(\?|$)/.test(url) || /^\/api\/channels(\?|$)/.test(url) || /^\/api\/functions\/[^/?#]+(\/|\?|$)/.test(url);
3
+ const isApiWebSocket = (url) => /^\/api\/sb\/realtime\/v1\/websocket(\?|$)/.test(url) || /^\/api\/channels(\?|$)/.test(url) || /^\/api\/functions\/[^/?#]+(\/|\?|$)/.test(url) || /^\/api\/calls\/guests\/socket(\?|$)/.test(url);
4
4
  /**
5
5
  * The listener for Vite's `upgrade` event: an API socket goes to `forward` once its Host passes Vite's host check, as
6
6
  * every other dev request does, and is refused with 403 otherwise; any other upgrade is left to Vite.
@@ -53,7 +53,7 @@ const migrationParts = (project) => {
53
53
  }] : [],
54
54
  ...project.calls ? [{
55
55
  name: "calls",
56
- title: "The calls on records, who is in them, whom they ring, and the signals between the processes serving the app",
56
+ title: "The calls on records, who is in them, whom they ring, their guests, and the signals between the processes serving the app",
57
57
  sql: () => callsMigration(project.db, project.events)
58
58
  }] : [],
59
59
  ...relayed(project.realtime) ? [{
@@ -9,15 +9,17 @@ const npmWebSocketServer = () => {
9
9
  return require(path.join(path.dirname(require.resolve("ws/package.json")), "index.js")).WebSocketServer;
10
10
  };
11
11
  const functionsPrefix = "/api/functions/";
12
+ const guestSocketPath = "/api/calls/guests/socket";
12
13
  const functionMaxPayload = 104857600;
13
14
  /**
14
- * The frame cap of a socket upgraded at `url`: ws's default for an api function's socket, and realtime's
15
- * `maxFrameBytes` for any other, so a path this does not recognise as a function's, such as an encoded one, gets the
16
- * smaller cap.
15
+ * The frame cap of a socket upgraded at `url`: ws's default for an api function's socket and the guests' call socket,
16
+ * which lower it to their own, and realtime's `maxFrameBytes` for any other, so a path this does not recognise, such
17
+ * as an encoded one, gets the smaller cap.
17
18
  */
18
19
  const maxPayloadOf = (url) => {
19
20
  if (!URL.canParse(url, "http://localhost")) return realtimeLimits.maxFrameBytes;
20
- return new URL(url, "http://localhost").pathname.startsWith(functionsPrefix) ? functionMaxPayload : realtimeLimits.maxFrameBytes;
21
+ const { pathname } = new URL(url, "http://localhost");
22
+ return pathname.startsWith(functionsPrefix) || pathname === guestSocketPath ? functionMaxPayload : realtimeLimits.maxFrameBytes;
21
23
  };
22
24
  /**
23
25
  * The server of npm `ws` that upgrades the API's sockets, realtime's and the app's functions', on Node and Bun: a frame
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protobase/cli",
3
- "version": "0.62.5",
3
+ "version": "0.63.0",
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.62.5",
46
- "@protobase/layout": "0.62.5",
47
- "@protobase/query": "0.62.5",
48
- "@protobase/schema": "0.62.5",
49
- "@protobase/server": "0.62.5",
50
- "@protobase/ui": "0.62.5",
45
+ "@protobase/config": "0.63.0",
46
+ "@protobase/layout": "0.63.0",
47
+ "@protobase/query": "0.63.0",
48
+ "@protobase/schema": "0.63.0",
49
+ "@protobase/server": "0.63.0",
50
+ "@protobase/ui": "0.63.0",
51
51
  "@react-email/render": "^2.1.0",
52
52
  "@scalar/hono-api-reference": "^0.12.10",
53
53
  "@tailwindcss/vite": "^4.3.3",
@@ -4,7 +4,7 @@
4
4
 
5
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
6
 
7
- - [Calls](../reference/calls.md) (beta): Voice and video calls on any record, with screen sharing, a ready-made call view and ringing on any open page.
7
+ - [Calls](../reference/calls.md) (beta): Voice and video calls on any record, with screen sharing, a ready-made call view and ringing on any open page, and guest links that let someone from outside join one call.
8
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
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
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.
@@ -5,7 +5,7 @@
5
5
  Audio and video calls on any record of an app, through a LiveKit server or straight between browsers, with Protobase deciding who is in a call, who may send and who hears whom.
6
6
 
7
7
  :::caution[Beta]
8
- Calls live on records, with who is in them, removal and their end, a ready-made call view and ringing. The view is made for small peer-to-peer calls, and there are no host controls yet. A lobby, stage mode, recording and guests are not built yet, and calls have been tested in Chromium and Firefox only.
8
+ Calls live on records, with who is in them, removal and their end, a ready-made call view, ringing and guest links. The view is made for small peer-to-peer calls, and there are no host controls yet. Stage mode and recording are not built yet, and calls have been tested in Chromium and Firefox only.
9
9
  :::
10
10
 
11
11
  ## Turning them on
@@ -69,12 +69,14 @@ export default defineFunction(async (request, { session, records, acceptWebSocke
69
69
  | `publish` | `true` to send any source, a list of `'camera'`, `'microphone'`, `'screen'` and `'screen-audio'`, or `false` to only listen. |
70
70
  | `hears` | Optional: which of the others' tracks the member hears, as `(track) => boolean` of `{ member, kind, source }`; every track by default. |
71
71
  | `recheck` | Optional: the function's own checks, such as whether the caller is still invited, repeated every minute. Throw a 401, 403 or 404 problem to take the member out. |
72
+ | `name` | Optional: the name the others in the call see, such as the user's name. [Guests](#guests) see members by it alone. |
73
+ | `invites` | Optional: `true` lets the member share [guest links](#guests) to the call and let its guests in; `false` by default. |
72
74
 
73
75
  The socket is checked again every minute, like any function's, and so is the caller's read of the record, then `recheck`: a member who can no longer read the record, or whom `recheck` refuses, is out of the call within the minute, and so is one whose check fails or takes longer than a minute. Pass your own check as `recheck` to `calls.join`, not on the events it returns, which would replace the record's check. A member who joins the same call again, from another tab, takes the place of their first socket.
74
76
 
75
77
  ### Who is in it
76
78
 
77
- Each member's browser gets everyone in the call, themselves too, members who send nothing included, whenever that changes: `onMembers` of `joinCall`, and `call.members()`, as `[{ member, joined_at }]`. A change made on the process that serves a member reaches them at once; one made on another process, within a second.
79
+ Each member's browser gets everyone in the call, themselves too, members who send nothing included, whenever that changes: `onMembers` of `joinCall`, and `call.members()`, as `[{ member, joined_at, name? }]`, with `name` for a member your function named and for every guest. A change made on the process that serves a member reaches them at once; one made on another process, within a second.
78
80
 
79
81
  The record's readers get its calls, each with who is in it now, at `GET /api/{resource}/{key}:calls`, the one going on first, then the newest, 20 at most:
80
82
 
@@ -195,6 +197,58 @@ With [notifications](notifications.md), each person rung also gets the call in t
195
197
 
196
198
  `client.rings.list()` and `client.rings.decline(call)` of `@protobase/client` read and decline the calls ringing the signed-in user, for a ring of your own.
197
199
 
200
+ ## Guests
201
+
202
+ Share a link to one call with someone from outside, such as a candidate for a job interview: the guest gives a name, checks their microphone and camera, and waits in a lobby until someone in the call admits them. A guest has no account and reaches nothing but that call: not the record, its chat, its readers' list of calls, or anything else in the app.
203
+
204
+ ### Sharing a link
205
+
206
+ A member your function joins with `invites: true` gets Guests in the call view: a link to share, with what its guests may send (camera, microphone and screen; camera and microphone; or microphone only, never more than the member may send themselves), the links that are live, with Revoke, and who waits in the lobby, with Let in and Turn away. Someone who waits also shows above the call, to let in without opening Guests.
207
+
208
+ ```ts
209
+ // The name the others see, from the app's own records of its people.
210
+ const { record: me } = await records.get('people', String(session.user.id))
211
+ return acceptWebSocket(
212
+ await calls.join({
213
+ record: { resource: 'interviews', key: id },
214
+ member: String(session.user.id),
215
+ name: String(me.name),
216
+ publish: true,
217
+ invites: true,
218
+ }),
219
+ )
220
+ ```
221
+
222
+ A link opens `/-/call-guest` with its token after `#`, which the browser sends to no server. It lets guests in until the call ends, or for an hour when made so, or until the time `call.guests.link({ publish, expiresAt })` gives it, unless a member revokes it first. At most 10 wait on a link at once, and once its members turned away 3 guests, it lets nobody else wait: make a new link.
223
+
224
+ ### What a guest gets
225
+
226
+ The page a link opens asks the guest's name, then shows the call view's check of their microphone and camera, with Ask to join, then "Waiting for someone in the call to let you in" until a member lets them in or turns them away. Once in, the guest is `guest:<id>` in the call, shown by the name they gave with "(guest)", and sends only what their link allows. They see the members by the `name` your function gave, or as "Someone in the call".
227
+
228
+ The guest's token opens their lobby wait and the guest call socket, and nothing else: no other route takes it, it is no session, and no cookie is set. Members' functions never take a member of the form `guest:…`.
229
+
230
+ ### Taking a guest out
231
+
232
+ Revoking a link takes its guests out of the call, and Remove in Guests, or `calls.remove(call, 'guest:<id>')` in a function, takes out one. Their sockets close, and their joins and resumes are refused. Every guest's socket is checked again every minute too, and is closed once their link is revoked or past its time, they were removed, or guest links were turned off.
233
+
234
+ A call left with only guests in it ends 2 minutes after the last member left, and the guests see "The call ended". A member who comes back before then keeps it going.
235
+
236
+ ### Organizations
237
+
238
+ In an app with [organizations](auth.md#organizations), a link is for the organization of the call's record, and the organization's owner or an admin can turn guest links off on the organization's page, or with `PUT /api/calls/guests/organization` and `{ "allowed": false }`. That revokes every live link of its calls and takes their guests out at once, and no member can make a new link until it is on again. A call on a record of a resource without a tenant gets no guest links in an app with organizations, since no organization's switch could stop them.
239
+
240
+ ### Safety
241
+
242
+ The lobby is rate limited like the sign-in routes, by the address the sign-in routes use: 5 lobby entries a minute per address, and an address that sends 10 unknown or refused tokens in a minute is refused for the rest of that minute. <gap>The lobby's limits cannot hold across several processes because they are counted in each process's memory, as the sign-in routes' are.</gap>
243
+
244
+ In a peer-to-peer call, a guest and the members can see each other's network addresses, as their browsers connect to each other. A guest who waits, or was turned away, gets nothing of the call: no members, no tracks and no addresses. Protobase refuses what a guest may not send, but in a peer-to-peer call the media goes between the browsers, so a guest's browser that was changed to send more is only held back by the members' own browsers.
245
+
246
+ With `calls`, [`protobase migration`](cli.md#migration) adds the guests' tables to the `calls` schema, a calls schema made before them too.
247
+
248
+ ### From your own page
249
+
250
+ `guestLobby` from `@protobase/client/calls` is the guest's side, for a page of your own: `enter(link, name)` gives the guest's token, `wait(token)` says `waiting`, `admitted`, `denied` or `ended`, asked about once a second, and `leave(token)` leaves the lobby. Once admitted, `joinCall({ url: lobby.socketUrl, guest: token })` joins the call. A member's `call.guests` has `link({ publish, expiresAt })`, which resolves with the link and its token once, `revoke(link)`, `admit(guest)`, `deny(guest)` and `remove(guest)`, each rejecting with `GuestRefused` and its reason when the server did not; `onLobby` of `joinCall` gets who waits and the live links.
251
+
198
252
  ## Reconnecting
199
253
 
200
254
  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, through the function again, so a member who can no longer read the record, or was removed, is refused. 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.
@@ -207,7 +261,7 @@ When the socket to Protobase closes, such as during a deploy, media keeps flowin
207
261
 
208
262
  `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 the members of the same call only, and tells each member who else is in the call and which tracks they hear. `hears` decides which tracks a member is told of; the media itself goes between the browsers, which Protobase cannot stop.
209
263
 
210
- A peer-to-peer call holds a small group only: a browser uploads its media once per other member, so `maxMembers`, 8 by default, bounds it. Members of a peer-to-peer call can see each other's network addresses, as their browsers connect to each other; readers of the record who are not in the call cannot.
264
+ A peer-to-peer call holds a small group only: a browser uploads its media once per other member, so `maxMembers`, 8 by default, bounds it. Members of a peer-to-peer call, and its [guests](#guests), can see each other's network addresses, as their browsers connect to each other; readers of the record who are not in the call cannot.
211
265
 
212
266
  With `calls: { processes: 'many' }`, members that different processes serve meet in one call: a description or candidate for a member another process serves goes through the `calls` schema, which each process with a member in a call reads ten times a second.
213
267