@classcad/client 0.0.0-stage → 3.0.0-beta.20261119100608
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/README.md +20 -2
- package/bin/buerli-classcad.cjs +23 -0
- package/build/cjs/BuerliCadFacade.js +718 -0
- package/build/cjs/cclass/utils/assembly.js +687 -0
- package/build/cjs/cclass/utils/base.js +136 -0
- package/build/cjs/cclass/utils/index.js +99 -0
- package/build/cjs/cclass/utils/part.js +153 -0
- package/build/cjs/classcadEngine.js +33 -0
- package/build/cjs/createApi.js +71 -0
- package/build/cjs/createUnwrappedApi.js +43 -0
- package/build/cjs/facade.js +103 -0
- package/build/cjs/globals.js +157 -0
- package/build/cjs/index.js +102 -0
- package/build/cjs/io/AwvNodeClient.js +290 -0
- package/build/cjs/io/SocketIOClient.js +339 -0
- package/build/cjs/io/Transaction.js +134 -0
- package/build/cjs/io/WASMClient.js +433 -0
- package/build/cjs/io/WSClient.js +646 -0
- package/build/cjs/io/engineKey.js +202 -0
- package/build/cjs/re-export.js +35 -0
- package/build/cjs/session/host.js +479 -0
- package/build/cjs/session/identity.js +38 -0
- package/build/cjs/session/selection.js +283 -0
- package/build/cjs/session/share.js +229 -0
- package/build/cjs/session/types.js +23 -0
- package/build/cjs/test/SocketIOClient.spec.js +178 -0
- package/build/cjs/types/ComClient.js +10 -0
- package/build/cjs/utils/createRecursiveBufferGeometry.js +55 -0
- package/build/cjs/utils/createRecursiveScene.js +140 -0
- package/build/cjs/utils/getDifferentColoredMeshesFromEntity.js +24 -0
- package/build/cjs/utils/index.js +20 -0
- package/build/cjs/utils/polyline.js +65 -0
- package/build/cjs/utils/waitForSelect.js +29 -0
- package/build/esm/BuerliCadFacade.js +714 -0
- package/build/esm/cclass/utils/assembly.js +665 -0
- package/build/esm/cclass/utils/base.js +127 -0
- package/build/esm/cclass/utils/index.js +62 -0
- package/build/esm/cclass/utils/part.js +144 -0
- package/build/esm/classcadEngine.js +30 -0
- package/build/esm/createApi.js +66 -0
- package/build/esm/createUnwrappedApi.js +39 -0
- package/build/esm/facade.js +98 -0
- package/build/esm/globals.js +150 -0
- package/build/esm/index.js +80 -0
- package/build/esm/io/AwvNodeClient.js +286 -0
- package/build/esm/io/SocketIOClient.js +332 -0
- package/build/esm/io/Transaction.js +130 -0
- package/build/esm/io/WASMClient.js +429 -0
- package/build/esm/io/WSClient.js +642 -0
- package/build/esm/io/engineKey.js +196 -0
- package/build/esm/re-export.js +3 -0
- package/build/esm/session/host.js +474 -0
- package/build/esm/session/identity.js +34 -0
- package/build/esm/session/selection.js +277 -0
- package/build/esm/session/share.js +221 -0
- package/build/esm/session/types.js +20 -0
- package/build/esm/test/SocketIOClient.spec.js +178 -0
- package/build/esm/types/ComClient.js +7 -0
- package/build/esm/utils/createRecursiveBufferGeometry.js +51 -0
- package/build/esm/utils/createRecursiveScene.js +136 -0
- package/build/esm/utils/getDifferentColoredMeshesFromEntity.js +20 -0
- package/build/esm/utils/index.js +4 -0
- package/build/esm/utils/polyline.js +60 -0
- package/build/esm/utils/waitForSelect.js +23 -0
- package/build/types/BuerliCadFacade.d.ts +410 -0
- package/build/types/cclass/utils/assembly.d.ts +180 -0
- package/build/types/cclass/utils/base.d.ts +55 -0
- package/build/types/cclass/utils/index.d.ts +46 -0
- package/build/types/cclass/utils/part.d.ts +46 -0
- package/build/types/classcadEngine.d.ts +40 -0
- package/build/types/createApi.d.ts +65 -0
- package/build/types/createUnwrappedApi.d.ts +36 -0
- package/build/types/facade.d.ts +9 -0
- package/build/types/globals.d.ts +79 -0
- package/build/types/index.d.ts +82 -0
- package/build/types/io/AwvNodeClient.d.ts +182 -0
- package/build/types/io/SocketIOClient.d.ts +84 -0
- package/build/types/io/Transaction.d.ts +56 -0
- package/build/types/io/WASMClient.d.ts +239 -0
- package/build/types/io/WSClient.d.ts +242 -0
- package/build/types/io/engineKey.d.ts +137 -0
- package/build/types/re-export.d.ts +6 -0
- package/build/types/session/host.d.ts +108 -0
- package/build/types/session/identity.d.ts +46 -0
- package/build/types/session/selection.d.ts +164 -0
- package/build/types/session/share.d.ts +131 -0
- package/build/types/session/types.d.ts +113 -0
- package/build/types/test/SocketIOClient.spec.d.ts +0 -0
- package/build/types/types/ComClient.d.ts +307 -0
- package/build/types/utils/createRecursiveBufferGeometry.d.ts +8 -0
- package/build/types/utils/createRecursiveScene.d.ts +24 -0
- package/build/types/utils/getDifferentColoredMeshesFromEntity.d.ts +14 -0
- package/build/types/utils/index.d.ts +4 -0
- package/build/types/utils/polyline.d.ts +43 -0
- package/build/types/utils/waitForSelect.d.ts +4 -0
- package/doc/api/advanced/connection.md +488 -0
- package/doc/api/clients.md +2045 -0
- package/doc/api/engine-keys.md +230 -0
- package/doc/api/index.md +58 -0
- package/doc/api/modeling.md +682 -0
- package/doc/api/other.md +33 -0
- package/doc/api/session-sharing.md +706 -0
- package/package.json +60 -4
- package/test/classcadEngine.test.cjs +44 -0
- package/test/connect.test.cjs +81 -0
- package/test/engineKey.test.cjs +80 -0
- package/test/onClient.test.cjs +82 -0
- package/typedoc.json +8 -0
|
@@ -0,0 +1,706 @@
|
|
|
1
|
+
# Session Sharing
|
|
2
|
+
|
|
3
|
+
Shares a drawing's session with other apps and AI agents: invites and share links, who is in the session, what
|
|
4
|
+
they publish, and what they have selected.
|
|
5
|
+
|
|
6
|
+
## Functions
|
|
7
|
+
|
|
8
|
+
### buildShareUrl() {#buildshareurl}
|
|
9
|
+
|
|
10
|
+
```ts
|
|
11
|
+
function buildShareUrl(invite, base?): string;
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Builds the link to hand to a guest: the current page with the invite token as query parameter.
|
|
15
|
+
|
|
16
|
+
A guest is another app window, or an MCP's `use_session`. `base` defaults to the page's origin + path.
|
|
17
|
+
|
|
18
|
+
#### Parameters
|
|
19
|
+
|
|
20
|
+
| Parameter | Type | Description |
|
|
21
|
+
| :------ | :------ | :------ |
|
|
22
|
+
| `invite` | `Pick`<[`SessionInvite`](#sessioninvite), `"invite"` \| `"kind"`> | The invite, as `createInvite` returns it. |
|
|
23
|
+
| `base?` | \{ `origin`: `string`; `pathname`: `string`; \} | The page the link opens; by default the current one. |
|
|
24
|
+
| `base.origin` | `string` | - |
|
|
25
|
+
| `base.pathname` | `string` | - |
|
|
26
|
+
|
|
27
|
+
#### Returns
|
|
28
|
+
|
|
29
|
+
`string`
|
|
30
|
+
|
|
31
|
+
#### Example
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
import { BuerliCadFacade, buildShareUrl, DEFAULT_SESSION_URL, getShareTokenFromUrl } from '@classcad/client'
|
|
35
|
+
import { init, WASMClient, WSClient } from '@classcad/client'
|
|
36
|
+
|
|
37
|
+
// One page, two roles: opened with a share link it joins as a guest, else it hosts the engine itself
|
|
38
|
+
const shared = getShareTokenFromUrl()
|
|
39
|
+
let client!: WASMClient | WSClient
|
|
40
|
+
init(drawingId =>
|
|
41
|
+
shared
|
|
42
|
+
? (client = new WSClient(DEFAULT_SESSION_URL, drawingId, { invite: shared.token }))
|
|
43
|
+
: (client = new WASMClient(drawingId, { token: 'ccpk_…' })),
|
|
44
|
+
)
|
|
45
|
+
await new BuerliCadFacade().connect()
|
|
46
|
+
|
|
47
|
+
// The host's button: a link to this page for a colleague
|
|
48
|
+
shareButton.hidden = Boolean(shared)
|
|
49
|
+
shareButton.onclick = async () => {
|
|
50
|
+
const invite = await client.createInvite('edit')
|
|
51
|
+
await navigator.clipboard.writeText(buildShareUrl(invite)) // https://my.app/editor?invite=…
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
***
|
|
56
|
+
|
|
57
|
+
### getShareTokenFromUrl() {#getsharetokenfromurl}
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
function getShareTokenFromUrl(search?):
|
|
61
|
+
| {
|
|
62
|
+
kind: "invite";
|
|
63
|
+
token: string;
|
|
64
|
+
}
|
|
65
|
+
| null;
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Reads a share token from a page URL (`?invite=…`).
|
|
69
|
+
|
|
70
|
+
Returns null when the page is a plain host. [buildShareUrl](#buildshareurl) has an example of both sides.
|
|
71
|
+
|
|
72
|
+
#### Parameters
|
|
73
|
+
|
|
74
|
+
| Parameter | Type | Description |
|
|
75
|
+
| :------ | :------ | :------ |
|
|
76
|
+
| `search?` | `string` | The query string to read; by default the page's (`window.location.search`). |
|
|
77
|
+
|
|
78
|
+
#### Returns
|
|
79
|
+
|
|
80
|
+
##### Type Literal
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
{
|
|
84
|
+
kind: "invite";
|
|
85
|
+
token: string;
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
| Name | Type | Description |
|
|
90
|
+
| :------ | :------ | :------ |
|
|
91
|
+
| `kind` | `"invite"` | How the token is honoured. |
|
|
92
|
+
| `token` | `string` | The token. |
|
|
93
|
+
|
|
94
|
+
***
|
|
95
|
+
|
|
96
|
+
`null`
|
|
97
|
+
|
|
98
|
+
***
|
|
99
|
+
|
|
100
|
+
### getSessionShareState() {#getsessionsharestate}
|
|
101
|
+
|
|
102
|
+
```ts
|
|
103
|
+
function getSessionShareState(drawingId): SessionShareState;
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Current sharing state of a drawing (stable object until something changes).
|
|
107
|
+
|
|
108
|
+
#### Parameters
|
|
109
|
+
|
|
110
|
+
| Parameter | Type | Description |
|
|
111
|
+
| :------ | :------ | :------ |
|
|
112
|
+
| `drawingId` | `DrawingID` | The drawing. |
|
|
113
|
+
|
|
114
|
+
#### Returns
|
|
115
|
+
|
|
116
|
+
[`SessionShareState`](#sessionsharestate)
|
|
117
|
+
|
|
118
|
+
#### Example
|
|
119
|
+
|
|
120
|
+
```ts
|
|
121
|
+
import { getSessionShareState, subscribeSessionShare } from '@classcad/client'
|
|
122
|
+
|
|
123
|
+
// A badge without a framework: who is in the session, kept up to date
|
|
124
|
+
const render = () => {
|
|
125
|
+
const share = getSessionShareState(drawingId)
|
|
126
|
+
const names = share.peers.map(peer => share.identities[peer.peerId]?.name ?? (peer.inviteName || 'Guest'))
|
|
127
|
+
badge.hidden = !share.supported
|
|
128
|
+
badge.textContent = share.isGuest ? `Guest (${share.role})` : `With you: ${names.join(', ') || 'nobody'}`
|
|
129
|
+
}
|
|
130
|
+
const unsubscribe = subscribeSessionShare(drawingId, render)
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
***
|
|
134
|
+
|
|
135
|
+
### syncSelection() {#syncselection}
|
|
136
|
+
|
|
137
|
+
```ts
|
|
138
|
+
function syncSelection(client): () => void;
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
Shares the selection of a client's drawing with its session: publishes it on change, selects what a peer asks for.
|
|
142
|
+
|
|
143
|
+
Call it when the client is created; it returns the function that stops it. On a client that
|
|
144
|
+
is in no shared session it does nothing.
|
|
145
|
+
|
|
146
|
+
#### Parameters
|
|
147
|
+
|
|
148
|
+
| Parameter | Type | Description |
|
|
149
|
+
| :------ | :------ | :------ |
|
|
150
|
+
| `client` | [`AwvNodeClient`](clients.md#abstract-awvnodeclient) | The drawing's client, e.g. from [onClient](clients.md#onclient). |
|
|
151
|
+
|
|
152
|
+
#### Returns
|
|
153
|
+
|
|
154
|
+
A function that stops sharing the selection.
|
|
155
|
+
|
|
156
|
+
() => `void`
|
|
157
|
+
|
|
158
|
+
#### Example
|
|
159
|
+
|
|
160
|
+
```ts
|
|
161
|
+
import { onClient, SELECTION_CHANNEL, syncSelection, WASMClient, WSClient } from '@classcad/client'
|
|
162
|
+
import type { PresenceMessage, SelectionFrame } from '@classcad/client'
|
|
163
|
+
|
|
164
|
+
// Every shared drawing shows its selection to the others, and selects what they ask for
|
|
165
|
+
let stop: (() => void) | undefined
|
|
166
|
+
onClient(client => {
|
|
167
|
+
if (!(client instanceof WSClient || client instanceof WASMClient)) return
|
|
168
|
+
stop?.()
|
|
169
|
+
stop = syncSelection(client)
|
|
170
|
+
// What the others have selected
|
|
171
|
+
client.on('presence', (_client, msg: PresenceMessage) => {
|
|
172
|
+
if (msg.channel === SELECTION_CHANNEL) highlightForPeer(msg.peerId, msg.data as SelectionFrame)
|
|
173
|
+
})
|
|
174
|
+
})
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
***
|
|
178
|
+
|
|
179
|
+
### subscribeSessionShare() {#subscribesessionshare}
|
|
180
|
+
|
|
181
|
+
```ts
|
|
182
|
+
function subscribeSessionShare(drawingId, callback): () => void;
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
Subscribes to sharing changes of a drawing: its client, connection, role, peers, invites and identities.
|
|
186
|
+
|
|
187
|
+
It fires when the client is (re)created, connects or loses its connection, joins a session (`session_joined`),
|
|
188
|
+
and when peers, invites or identities change. Returns the unsubscribe function.
|
|
189
|
+
|
|
190
|
+
With [getSessionShareState](#getsessionsharestate) it fits React's `useSyncExternalStore`.
|
|
191
|
+
|
|
192
|
+
#### Parameters
|
|
193
|
+
|
|
194
|
+
| Parameter | Type | Description |
|
|
195
|
+
| :------ | :------ | :------ |
|
|
196
|
+
| `drawingId` | `DrawingID` | The drawing. |
|
|
197
|
+
| `callback` | () => `void` | Called on every change; read the new state with [getSessionShareState](#getsessionsharestate). |
|
|
198
|
+
|
|
199
|
+
#### Returns
|
|
200
|
+
|
|
201
|
+
() => `void`
|
|
202
|
+
|
|
203
|
+
#### Example
|
|
204
|
+
|
|
205
|
+
```tsx
|
|
206
|
+
import { useSyncExternalStore } from 'react'
|
|
207
|
+
import { getSessionShareState, subscribeSessionShare } from '@classcad/client'
|
|
208
|
+
|
|
209
|
+
// A React hook for a drawing's sharing state
|
|
210
|
+
export function useSessionShare(drawingId: string) {
|
|
211
|
+
return useSyncExternalStore(
|
|
212
|
+
onChange => subscribeSessionShare(drawingId, onChange),
|
|
213
|
+
() => getSessionShareState(drawingId),
|
|
214
|
+
)
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export function Guests({ drawingId }: { drawingId: string }) {
|
|
218
|
+
const { peers, invites } = useSessionShare(drawingId)
|
|
219
|
+
return (
|
|
220
|
+
<span>
|
|
221
|
+
{peers.length} guests, {invites.length} invites
|
|
222
|
+
</span>
|
|
223
|
+
)
|
|
224
|
+
}
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
## Types
|
|
228
|
+
|
|
229
|
+
### ClientIdentity {#clientidentity}
|
|
230
|
+
|
|
231
|
+
```ts
|
|
232
|
+
type ClientIdentity = {
|
|
233
|
+
app: string;
|
|
234
|
+
kind?: "app" | "agent";
|
|
235
|
+
name?: string;
|
|
236
|
+
version?: string;
|
|
237
|
+
};
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
What a participant says about itself.
|
|
241
|
+
|
|
242
|
+
Give it to a [WSClient](clients.md#wsclient) or [WASMClient](clients.md#wasmclient) as `identity`; the others in the session find it in the
|
|
243
|
+
client's `identities`, by peer id.
|
|
244
|
+
|
|
245
|
+
#### Example
|
|
246
|
+
|
|
247
|
+
```ts
|
|
248
|
+
import { init, WASMClient } from '@classcad/client'
|
|
249
|
+
import type { ClientIdentity } from '@classcad/client'
|
|
250
|
+
|
|
251
|
+
// Says who this page is, and lists who else is in the session
|
|
252
|
+
const identity: ClientIdentity = { app: 'configurator', version: '2.1.0', name: 'Ada', kind: 'app' }
|
|
253
|
+
init(drawingId => {
|
|
254
|
+
const client = new WASMClient(drawingId, { token: 'ccpk_…', identity })
|
|
255
|
+
client.on('identities_changed', (_client, identities: Record<string, ClientIdentity>) =>
|
|
256
|
+
showParticipants(Object.values(identities).map(i => `${i.name ?? i.app}${i.kind === 'agent' ? ' (AI)' : ''}`)),
|
|
257
|
+
)
|
|
258
|
+
return client
|
|
259
|
+
})
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
#### Properties
|
|
263
|
+
|
|
264
|
+
| Property | Type | Description |
|
|
265
|
+
| :------ | :------ | :------ |
|
|
266
|
+
| <a id="property-app"></a> `app` | `string` | The program: 'buerligons', 'classcad-mcp', … |
|
|
267
|
+
| <a id="property-kind"></a> `kind?` | `"app"` \| `"agent"` | 'agent' for an AI agent's session, 'app' for a person at an app. |
|
|
268
|
+
| <a id="property-name"></a> `name?` | `string` | A name to show for this participant ("Claude Code", a person's name). |
|
|
269
|
+
| <a id="property-version"></a> `version?` | `string` | The program's version. |
|
|
270
|
+
|
|
271
|
+
***
|
|
272
|
+
|
|
273
|
+
### PresenceMessage {#presencemessage}
|
|
274
|
+
|
|
275
|
+
```ts
|
|
276
|
+
type PresenceMessage = {
|
|
277
|
+
channel: string;
|
|
278
|
+
data: Record<string, any>;
|
|
279
|
+
peerId: string;
|
|
280
|
+
};
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
An ephemeral presence message from a session sibling (e.g. its camera viewpoint).
|
|
284
|
+
|
|
285
|
+
Clients emit it as `presence` (client, message); the guest example of [WSClient](clients.md#wsclient) follows a camera with it.
|
|
286
|
+
|
|
287
|
+
#### Properties
|
|
288
|
+
|
|
289
|
+
| Property | Type | Description |
|
|
290
|
+
| :------ | :------ | :------ |
|
|
291
|
+
| <a id="property-channel"></a> `channel` | `string` | Application-defined channel, e.g. 'view' for shared camera viewpoints, 'leave' when a peer disconnects. |
|
|
292
|
+
| <a id="property-data"></a> `data` | `Record`<`string`, `any`> | Channel-specific payload, verbatim from the sender. |
|
|
293
|
+
| <a id="property-peerid"></a> `peerId` | `string` | Stable id of the sending connection (matches PeerJoined/PeerLeft peerIds). |
|
|
294
|
+
|
|
295
|
+
***
|
|
296
|
+
|
|
297
|
+
### SessionInvite {#sessioninvite}
|
|
298
|
+
|
|
299
|
+
```ts
|
|
300
|
+
type SessionInvite = {
|
|
301
|
+
invite: string;
|
|
302
|
+
kind: ShareKind;
|
|
303
|
+
name: string;
|
|
304
|
+
role: SessionRole;
|
|
305
|
+
};
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
An invite this client minted (the server keeps no queryable list, so the client tracks it).
|
|
309
|
+
|
|
310
|
+
[buildShareUrl](#buildshareurl) makes the link a guest opens.
|
|
311
|
+
|
|
312
|
+
#### Properties
|
|
313
|
+
|
|
314
|
+
| Property | Type | Description |
|
|
315
|
+
| :------ | :------ | :------ |
|
|
316
|
+
| <a id="property-invite"></a> `invite` | `string` | The token guests join with (`?invite=<token>`). |
|
|
317
|
+
| <a id="property-kind-2"></a> `kind` | [`ShareKind`](#sharekind) | How the invite is honoured. |
|
|
318
|
+
| <a id="property-name-2"></a> `name` | `string` | The name shown for the invite ('' for unnamed ones). |
|
|
319
|
+
| <a id="property-role"></a> `role` | [`SessionRole`](#sessionrole) | What guests with the invite may do. |
|
|
320
|
+
|
|
321
|
+
***
|
|
322
|
+
|
|
323
|
+
### SessionPeer {#sessionpeer}
|
|
324
|
+
|
|
325
|
+
```ts
|
|
326
|
+
type SessionPeer = {
|
|
327
|
+
invite: string;
|
|
328
|
+
inviteName: string;
|
|
329
|
+
peerId: string;
|
|
330
|
+
role: SessionRole;
|
|
331
|
+
};
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
A guest currently sharing the session, keyed by peerId.
|
|
335
|
+
|
|
336
|
+
Clients list them in `peers` and emit `peers_changed`; see the host example of [WSClient](clients.md#wsclient).
|
|
337
|
+
|
|
338
|
+
#### Properties
|
|
339
|
+
|
|
340
|
+
| Property | Type | Description |
|
|
341
|
+
| :------ | :------ | :------ |
|
|
342
|
+
| <a id="property-invite-1"></a> `invite` | `string` | The invite token the guest joined with. |
|
|
343
|
+
| <a id="property-invitename"></a> `inviteName` | `string` | Display name of that token ('' for unnamed tokens). |
|
|
344
|
+
| <a id="property-peerid-1"></a> `peerId` | `string` | Stable id of the guest's connection. |
|
|
345
|
+
| <a id="property-role-1"></a> `role` | [`SessionRole`](#sessionrole) | The role of that token. |
|
|
346
|
+
|
|
347
|
+
***
|
|
348
|
+
|
|
349
|
+
### SessionRole {#sessionrole}
|
|
350
|
+
|
|
351
|
+
```ts
|
|
352
|
+
type SessionRole = "edit" | "view";
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
Role attached to an invite. Advisory: enforced by the client, not the server (yet).
|
|
356
|
+
|
|
357
|
+
`'edit'` may change the model, `'view'` only look; an app suppresses changes for a `'view'` guest.
|
|
358
|
+
|
|
359
|
+
***
|
|
360
|
+
|
|
361
|
+
### SessionShareState {#sessionsharestate}
|
|
362
|
+
|
|
363
|
+
```ts
|
|
364
|
+
type SessionShareState = {
|
|
365
|
+
identities: Record<string, ClientIdentity>;
|
|
366
|
+
inviteName: string;
|
|
367
|
+
invites: SessionInvite[];
|
|
368
|
+
isGuest: boolean;
|
|
369
|
+
kind: ShareKind | null;
|
|
370
|
+
peers: SessionPeer[];
|
|
371
|
+
role: SessionRole;
|
|
372
|
+
supported: boolean;
|
|
373
|
+
};
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
Snapshot of a drawing's sharing state, as served to UI.
|
|
377
|
+
|
|
378
|
+
[getSessionShareState](#getsessionsharestate) returns it, [subscribeSessionShare](#subscribesessionshare) says when it changed.
|
|
379
|
+
|
|
380
|
+
#### Properties
|
|
381
|
+
|
|
382
|
+
| Property | Type | Description |
|
|
383
|
+
| :------ | :------ | :------ |
|
|
384
|
+
| <a id="property-identities"></a> `identities` | `Record`<`string`, [`ClientIdentity`](#clientidentity)> | What the other participants said about themselves, by peer id (see [ClientIdentity](#clientidentity)). |
|
|
385
|
+
| <a id="property-invitename-1"></a> `inviteName` | `string` | Name of the invite this page joined with ('' for the host). |
|
|
386
|
+
| <a id="property-invites"></a> `invites` | [`SessionInvite`](#sessioninvite)[] | The invites this client minted and has not revoked. |
|
|
387
|
+
| <a id="property-isguest"></a> `isGuest` | `boolean` | True when this page was opened with a share token (it is a guest, not the host). |
|
|
388
|
+
| <a id="property-kind-3"></a> `kind` | [`ShareKind`](#sharekind) \| `null` | How the client shares, or null when it cannot. |
|
|
389
|
+
| <a id="property-peers"></a> `peers` | [`SessionPeer`](#sessionpeer)[] | The guests in the session (host side). |
|
|
390
|
+
| <a id="property-role-2"></a> `role` | [`SessionRole`](#sessionrole) | This connection's own role ('edit' for hosts and non-sharing clients). |
|
|
391
|
+
| <a id="property-supported"></a> `supported` | `boolean` | A client exists for the drawing and can mint invites. |
|
|
392
|
+
|
|
393
|
+
## Constants
|
|
394
|
+
|
|
395
|
+
### DEFAULT\_SESSION\_URL {#default_session_url}
|
|
396
|
+
|
|
397
|
+
```ts
|
|
398
|
+
const DEFAULT_SESSION_URL: "ws://127.0.0.1:9098/session" = 'ws://127.0.0.1:9098/session';
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
Where a page that hosts its own engine is joined: the session address of a ClassCAD MCP on the same machine.
|
|
402
|
+
|
|
403
|
+
The default of the [WASMClient](clients.md#wasmclient) option `sessionUrl`. 127.0.0.1 on
|
|
404
|
+
purpose: `localhost` may be IPv6 in the browser and IPv4 in the MCP.
|
|
405
|
+
|
|
406
|
+
## Advanced
|
|
407
|
+
|
|
408
|
+
Most apps do not need these directly: types they meet through the exports above, and what is there for special cases or for building on the SDK itself.
|
|
409
|
+
|
|
410
|
+
### applySelection() {#applyselection}
|
|
411
|
+
|
|
412
|
+
```ts
|
|
413
|
+
function applySelection(
|
|
414
|
+
drawingId,
|
|
415
|
+
targets,
|
|
416
|
+
replace?
|
|
417
|
+
): number;
|
|
418
|
+
```
|
|
419
|
+
|
|
420
|
+
Selects `targets` in the drawing — what a peer asked for.
|
|
421
|
+
|
|
422
|
+
Returns how many of them were found. `replace: false` adds to the selection.
|
|
423
|
+
|
|
424
|
+
#### Parameters
|
|
425
|
+
|
|
426
|
+
| Parameter | Type | Default value | Description |
|
|
427
|
+
| :------ | :------ | :------ | :------ |
|
|
428
|
+
| `drawingId` | `DrawingID` | `undefined` | The drawing. |
|
|
429
|
+
| `targets` | [`SelectTarget`](#selecttarget)[] | `undefined` | What to select; targets that are not in the drawing (any more) are skipped. |
|
|
430
|
+
| `replace?` | `boolean` | `true` | `true` (default) replaces the selection, `false` adds to it. |
|
|
431
|
+
|
|
432
|
+
#### Returns
|
|
433
|
+
|
|
434
|
+
`number`
|
|
435
|
+
|
|
436
|
+
#### Example
|
|
437
|
+
|
|
438
|
+
```ts
|
|
439
|
+
import { applySelection } from '@classcad/client'
|
|
440
|
+
|
|
441
|
+
// Selects the faces a script found, adding them to what is selected
|
|
442
|
+
const found = applySelection(drawingId, faceIds.map(graphicId => ({ graphicId })), false)
|
|
443
|
+
if (found < faceIds.length) console.warn(`${faceIds.length - found} faces are not in the model any more`)
|
|
444
|
+
```
|
|
445
|
+
|
|
446
|
+
***
|
|
447
|
+
|
|
448
|
+
### CLIENT\_CHANNEL {#client_channel}
|
|
449
|
+
|
|
450
|
+
```ts
|
|
451
|
+
const CLIENT_CHANNEL: "client" = 'client';
|
|
452
|
+
```
|
|
453
|
+
|
|
454
|
+
The presence channel identities are published on.
|
|
455
|
+
|
|
456
|
+
***
|
|
457
|
+
|
|
458
|
+
### getSessionShareClient() {#getsessionshareclient}
|
|
459
|
+
|
|
460
|
+
```ts
|
|
461
|
+
function getSessionShareClient(drawingId): AwvNodeClient | null;
|
|
462
|
+
```
|
|
463
|
+
|
|
464
|
+
The client that serves `drawingId`, or null before the drawing is connected.
|
|
465
|
+
|
|
466
|
+
#### Parameters
|
|
467
|
+
|
|
468
|
+
| Parameter | Type | Description |
|
|
469
|
+
| :------ | :------ | :------ |
|
|
470
|
+
| `drawingId` | `DrawingID` | The drawing. |
|
|
471
|
+
|
|
472
|
+
#### Returns
|
|
473
|
+
|
|
474
|
+
[`AwvNodeClient`](clients.md#abstract-awvnodeclient) \| `null`
|
|
475
|
+
|
|
476
|
+
#### Example
|
|
477
|
+
|
|
478
|
+
```ts
|
|
479
|
+
import { getSessionShareClient } from '@classcad/client'
|
|
480
|
+
|
|
481
|
+
// Ends the sharing of a drawing: every invite taken back, every guest cut off
|
|
482
|
+
const client = getSessionShareClient(drawingId)
|
|
483
|
+
for (const invite of client?.invites ?? []) await client?.revokeInvite(invite.invite)
|
|
484
|
+
```
|
|
485
|
+
|
|
486
|
+
***
|
|
487
|
+
|
|
488
|
+
### OfferRefusal {#offerrefusal}
|
|
489
|
+
|
|
490
|
+
```ts
|
|
491
|
+
type OfferRefusal = {
|
|
492
|
+
code: number;
|
|
493
|
+
reason: string;
|
|
494
|
+
};
|
|
495
|
+
```
|
|
496
|
+
|
|
497
|
+
Why the share relay would not take a page's invite, for good: the code it closed the offer with, and its words.
|
|
498
|
+
|
|
499
|
+
The code is 4000 + the HTTP status: 4401 the sign-in, 4403 the plan, 4409 another account offers the invite.
|
|
500
|
+
A WASMClient emits it as 'invite_refused' (client, invite, refusal); [WASMClient.createInvite](clients.md#createinvite) has an
|
|
501
|
+
example.
|
|
502
|
+
|
|
503
|
+
#### Properties
|
|
504
|
+
|
|
505
|
+
| Property | Type | Description |
|
|
506
|
+
| :------ | :------ | :------ |
|
|
507
|
+
| <a id="property-code"></a> `code` | `number` | The close code: 4401 the sign-in, 4403 the plan, 4409 another account offers the invite. |
|
|
508
|
+
| <a id="property-reason"></a> `reason` | `string` | The relay's words. |
|
|
509
|
+
|
|
510
|
+
***
|
|
511
|
+
|
|
512
|
+
### readSelection() {#readselection}
|
|
513
|
+
|
|
514
|
+
```ts
|
|
515
|
+
function readSelection(drawingId): SelectionItem[];
|
|
516
|
+
```
|
|
517
|
+
|
|
518
|
+
The drawing's selection (interaction.selected), as session items.
|
|
519
|
+
|
|
520
|
+
#### Parameters
|
|
521
|
+
|
|
522
|
+
| Parameter | Type | Description |
|
|
523
|
+
| :------ | :------ | :------ |
|
|
524
|
+
| `drawingId` | `DrawingID` | The drawing. |
|
|
525
|
+
|
|
526
|
+
#### Returns
|
|
527
|
+
|
|
528
|
+
[`SelectionItem`](#selectionitem)[]
|
|
529
|
+
|
|
530
|
+
#### Example
|
|
531
|
+
|
|
532
|
+
```ts
|
|
533
|
+
import { readSelection } from '@classcad/client'
|
|
534
|
+
|
|
535
|
+
// Tells an assistant what "this" means: the selection, by the engine's ids
|
|
536
|
+
const faces = readSelection(drawingId).filter(item => item.kind === 'face')
|
|
537
|
+
const prompt = `Selected faces: ${faces.map(face => `${face.graphicId} (${face.type})`).join(', ')}`
|
|
538
|
+
```
|
|
539
|
+
|
|
540
|
+
***
|
|
541
|
+
|
|
542
|
+
### SELECT\_CHANNEL {#select_channel}
|
|
543
|
+
|
|
544
|
+
```ts
|
|
545
|
+
const SELECT_CHANNEL: "select" = 'select';
|
|
546
|
+
```
|
|
547
|
+
|
|
548
|
+
The presence channel requests to select something are sent on.
|
|
549
|
+
|
|
550
|
+
***
|
|
551
|
+
|
|
552
|
+
### SelectFrame {#selectframe}
|
|
553
|
+
|
|
554
|
+
```ts
|
|
555
|
+
type SelectFrame = {
|
|
556
|
+
done?: boolean;
|
|
557
|
+
id: string;
|
|
558
|
+
items?: SelectTarget[];
|
|
559
|
+
replace?: boolean;
|
|
560
|
+
};
|
|
561
|
+
```
|
|
562
|
+
|
|
563
|
+
The 'select' channel's payload: a request (`items`), or the note that the request `id` is over (`done`).
|
|
564
|
+
|
|
565
|
+
#### Example
|
|
566
|
+
|
|
567
|
+
```ts
|
|
568
|
+
import { SELECT_CHANNEL } from '@classcad/client'
|
|
569
|
+
import type { SelectFrame, WSClient } from '@classcad/client'
|
|
570
|
+
|
|
571
|
+
// Asks the others in the session to select an edge (they run syncSelection)
|
|
572
|
+
const id = crypto.randomUUID()
|
|
573
|
+
const request: SelectFrame = { id, items: [{ graphicId: edgeId }], replace: true }
|
|
574
|
+
client.sendPresence(SELECT_CHANNEL, request)
|
|
575
|
+
// Right after: the request is over, so the frame the server keeps asks for nothing
|
|
576
|
+
client.sendPresence(SELECT_CHANNEL, { id, done: true } satisfies SelectFrame)
|
|
577
|
+
```
|
|
578
|
+
|
|
579
|
+
#### Properties
|
|
580
|
+
|
|
581
|
+
| Property | Type | Description |
|
|
582
|
+
| :------ | :------ | :------ |
|
|
583
|
+
| <a id="property-done"></a> `done?` | `boolean` | The request `id` is over. |
|
|
584
|
+
| <a id="property-id"></a> `id` | `string` | The request's id; a peer follows each id once. |
|
|
585
|
+
| <a id="property-items"></a> `items?` | [`SelectTarget`](#selecttarget)[] | What to select. |
|
|
586
|
+
| <a id="property-replace"></a> `replace?` | `boolean` | `false` adds to the selection; by default it is replaced. |
|
|
587
|
+
|
|
588
|
+
***
|
|
589
|
+
|
|
590
|
+
### SELECTION\_CHANNEL {#selection_channel}
|
|
591
|
+
|
|
592
|
+
```ts
|
|
593
|
+
const SELECTION_CHANNEL: "selection" = 'selection';
|
|
594
|
+
```
|
|
595
|
+
|
|
596
|
+
The presence channel a participant's selection is published on.
|
|
597
|
+
|
|
598
|
+
***
|
|
599
|
+
|
|
600
|
+
### SelectionFrame {#selectionframe}
|
|
601
|
+
|
|
602
|
+
```ts
|
|
603
|
+
type SelectionFrame = {
|
|
604
|
+
items: SelectionItem[];
|
|
605
|
+
total: number;
|
|
606
|
+
};
|
|
607
|
+
```
|
|
608
|
+
|
|
609
|
+
The 'selection' channel's payload: what a participant has selected.
|
|
610
|
+
|
|
611
|
+
`total` counts the whole selection; `items` may be cut to fit a presence frame. The example of
|
|
612
|
+
[syncSelection](#syncselection) reads the frames of the others.
|
|
613
|
+
|
|
614
|
+
#### Properties
|
|
615
|
+
|
|
616
|
+
| Property | Type | Description |
|
|
617
|
+
| :------ | :------ | :------ |
|
|
618
|
+
| <a id="property-items-1"></a> `items` | [`SelectionItem`](#selectionitem)[] | The selected things; the first ones, when the selection does not fit a presence frame. |
|
|
619
|
+
| <a id="property-total"></a> `total` | `number` | How many things are selected. |
|
|
620
|
+
|
|
621
|
+
***
|
|
622
|
+
|
|
623
|
+
### SelectionItem {#selectionitem}
|
|
624
|
+
|
|
625
|
+
```ts
|
|
626
|
+
type SelectionItem = {
|
|
627
|
+
containerId?: number;
|
|
628
|
+
graphicId?: number;
|
|
629
|
+
kind: "face" | "edge" | "vertex" | "object";
|
|
630
|
+
name?: string;
|
|
631
|
+
objectId: number;
|
|
632
|
+
prodRefId?: number | null;
|
|
633
|
+
type?: string;
|
|
634
|
+
};
|
|
635
|
+
```
|
|
636
|
+
|
|
637
|
+
One selected thing: a face, edge or vertex of a body, or an object of the
|
|
638
|
+
model tree (a sketch entity, a dimension, a feature). [readSelection](#readselection) has an example.
|
|
639
|
+
|
|
640
|
+
#### Properties
|
|
641
|
+
|
|
642
|
+
| Property | Type | Description |
|
|
643
|
+
| :------ | :------ | :------ |
|
|
644
|
+
| <a id="property-containerid"></a> `containerId?` | `number` | Geometry: the body's graphic container. It is replaced whenever the body is rebuilt. |
|
|
645
|
+
| <a id="property-graphicid"></a> `graphicId?` | `number` | Geometry: the element in the container. This is the id API calls take for a face, an edge or a vertex. |
|
|
646
|
+
| <a id="property-kind-1"></a> `kind` | `"face"` \| `"edge"` \| `"vertex"` \| `"object"` | What was selected. |
|
|
647
|
+
| <a id="property-name-1"></a> `name?` | `string` | Objects: their name in the model tree. |
|
|
648
|
+
| <a id="property-objectid"></a> `objectId` | `number` | The model tree object: the picked object itself, or the owner of the picked geometry (a solid). |
|
|
649
|
+
| <a id="property-prodrefid"></a> `prodRefId?` | `number` \| `null` | The product or assembly instance the pick was made in. |
|
|
650
|
+
| <a id="property-type"></a> `type?` | `string` | Geometry: the element's type (plane, cylinder, line, arc, …). Objects: their class. |
|
|
651
|
+
|
|
652
|
+
***
|
|
653
|
+
|
|
654
|
+
### SelectTarget {#selecttarget}
|
|
655
|
+
|
|
656
|
+
```ts
|
|
657
|
+
type SelectTarget = {
|
|
658
|
+
containerId?: number;
|
|
659
|
+
graphicId?: number;
|
|
660
|
+
objectId?: number;
|
|
661
|
+
prodRefId?: number | null;
|
|
662
|
+
};
|
|
663
|
+
```
|
|
664
|
+
|
|
665
|
+
What a request names: a tree object by its id, or geometry by its element id (and container and product, when known).
|
|
666
|
+
|
|
667
|
+
[applySelection](#applyselection) and [SelectFrame](#selectframe) have examples.
|
|
668
|
+
|
|
669
|
+
#### Properties
|
|
670
|
+
|
|
671
|
+
| Property | Type | Description |
|
|
672
|
+
| :------ | :------ | :------ |
|
|
673
|
+
| <a id="property-containerid-1"></a> `containerId?` | `number` | Geometry: the body's graphic container. A body rebuilt since has another one; the element is looked up then. |
|
|
674
|
+
| <a id="property-graphicid-1"></a> `graphicId?` | `number` | Geometry: the face, edge or vertex. |
|
|
675
|
+
| <a id="property-objectid-1"></a> `objectId?` | `number` | A model tree object. |
|
|
676
|
+
| <a id="property-prodrefid-1"></a> `prodRefId?` | `number` \| `null` | The product or assembly instance to select the geometry in; by default the part, or its first instance. |
|
|
677
|
+
|
|
678
|
+
***
|
|
679
|
+
|
|
680
|
+
### SESSION\_SHARING\_UNSUPPORTED {#session_sharing_unsupported}
|
|
681
|
+
|
|
682
|
+
```ts
|
|
683
|
+
const SESSION_SHARING_UNSUPPORTED: "SessionSharingUnsupported" = 'SessionSharingUnsupported';
|
|
684
|
+
```
|
|
685
|
+
|
|
686
|
+
`Error.name` of the rejection when a client cannot share (no `shareKind`).
|
|
687
|
+
|
|
688
|
+
***
|
|
689
|
+
|
|
690
|
+
### SHARE\_PARAM {#share_param}
|
|
691
|
+
|
|
692
|
+
```ts
|
|
693
|
+
const SHARE_PARAM: Record<ShareKind, string>;
|
|
694
|
+
```
|
|
695
|
+
|
|
696
|
+
Query parameter carrying a share token, by [ShareKind](#sharekind): `invite`.
|
|
697
|
+
|
|
698
|
+
***
|
|
699
|
+
|
|
700
|
+
### ShareKind {#sharekind}
|
|
701
|
+
|
|
702
|
+
```ts
|
|
703
|
+
type ShareKind = "invite";
|
|
704
|
+
```
|
|
705
|
+
|
|
706
|
+
How a client's sessions are shared: by invite. `null` (on a client) = it cannot share.
|