@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.
Files changed (108) hide show
  1. package/README.md +20 -2
  2. package/bin/buerli-classcad.cjs +23 -0
  3. package/build/cjs/BuerliCadFacade.js +718 -0
  4. package/build/cjs/cclass/utils/assembly.js +687 -0
  5. package/build/cjs/cclass/utils/base.js +136 -0
  6. package/build/cjs/cclass/utils/index.js +99 -0
  7. package/build/cjs/cclass/utils/part.js +153 -0
  8. package/build/cjs/classcadEngine.js +33 -0
  9. package/build/cjs/createApi.js +71 -0
  10. package/build/cjs/createUnwrappedApi.js +43 -0
  11. package/build/cjs/facade.js +103 -0
  12. package/build/cjs/globals.js +157 -0
  13. package/build/cjs/index.js +102 -0
  14. package/build/cjs/io/AwvNodeClient.js +290 -0
  15. package/build/cjs/io/SocketIOClient.js +339 -0
  16. package/build/cjs/io/Transaction.js +134 -0
  17. package/build/cjs/io/WASMClient.js +433 -0
  18. package/build/cjs/io/WSClient.js +646 -0
  19. package/build/cjs/io/engineKey.js +202 -0
  20. package/build/cjs/re-export.js +35 -0
  21. package/build/cjs/session/host.js +479 -0
  22. package/build/cjs/session/identity.js +38 -0
  23. package/build/cjs/session/selection.js +283 -0
  24. package/build/cjs/session/share.js +229 -0
  25. package/build/cjs/session/types.js +23 -0
  26. package/build/cjs/test/SocketIOClient.spec.js +178 -0
  27. package/build/cjs/types/ComClient.js +10 -0
  28. package/build/cjs/utils/createRecursiveBufferGeometry.js +55 -0
  29. package/build/cjs/utils/createRecursiveScene.js +140 -0
  30. package/build/cjs/utils/getDifferentColoredMeshesFromEntity.js +24 -0
  31. package/build/cjs/utils/index.js +20 -0
  32. package/build/cjs/utils/polyline.js +65 -0
  33. package/build/cjs/utils/waitForSelect.js +29 -0
  34. package/build/esm/BuerliCadFacade.js +714 -0
  35. package/build/esm/cclass/utils/assembly.js +665 -0
  36. package/build/esm/cclass/utils/base.js +127 -0
  37. package/build/esm/cclass/utils/index.js +62 -0
  38. package/build/esm/cclass/utils/part.js +144 -0
  39. package/build/esm/classcadEngine.js +30 -0
  40. package/build/esm/createApi.js +66 -0
  41. package/build/esm/createUnwrappedApi.js +39 -0
  42. package/build/esm/facade.js +98 -0
  43. package/build/esm/globals.js +150 -0
  44. package/build/esm/index.js +80 -0
  45. package/build/esm/io/AwvNodeClient.js +286 -0
  46. package/build/esm/io/SocketIOClient.js +332 -0
  47. package/build/esm/io/Transaction.js +130 -0
  48. package/build/esm/io/WASMClient.js +429 -0
  49. package/build/esm/io/WSClient.js +642 -0
  50. package/build/esm/io/engineKey.js +196 -0
  51. package/build/esm/re-export.js +3 -0
  52. package/build/esm/session/host.js +474 -0
  53. package/build/esm/session/identity.js +34 -0
  54. package/build/esm/session/selection.js +277 -0
  55. package/build/esm/session/share.js +221 -0
  56. package/build/esm/session/types.js +20 -0
  57. package/build/esm/test/SocketIOClient.spec.js +178 -0
  58. package/build/esm/types/ComClient.js +7 -0
  59. package/build/esm/utils/createRecursiveBufferGeometry.js +51 -0
  60. package/build/esm/utils/createRecursiveScene.js +136 -0
  61. package/build/esm/utils/getDifferentColoredMeshesFromEntity.js +20 -0
  62. package/build/esm/utils/index.js +4 -0
  63. package/build/esm/utils/polyline.js +60 -0
  64. package/build/esm/utils/waitForSelect.js +23 -0
  65. package/build/types/BuerliCadFacade.d.ts +410 -0
  66. package/build/types/cclass/utils/assembly.d.ts +180 -0
  67. package/build/types/cclass/utils/base.d.ts +55 -0
  68. package/build/types/cclass/utils/index.d.ts +46 -0
  69. package/build/types/cclass/utils/part.d.ts +46 -0
  70. package/build/types/classcadEngine.d.ts +40 -0
  71. package/build/types/createApi.d.ts +65 -0
  72. package/build/types/createUnwrappedApi.d.ts +36 -0
  73. package/build/types/facade.d.ts +9 -0
  74. package/build/types/globals.d.ts +79 -0
  75. package/build/types/index.d.ts +82 -0
  76. package/build/types/io/AwvNodeClient.d.ts +182 -0
  77. package/build/types/io/SocketIOClient.d.ts +84 -0
  78. package/build/types/io/Transaction.d.ts +56 -0
  79. package/build/types/io/WASMClient.d.ts +239 -0
  80. package/build/types/io/WSClient.d.ts +242 -0
  81. package/build/types/io/engineKey.d.ts +137 -0
  82. package/build/types/re-export.d.ts +6 -0
  83. package/build/types/session/host.d.ts +108 -0
  84. package/build/types/session/identity.d.ts +46 -0
  85. package/build/types/session/selection.d.ts +164 -0
  86. package/build/types/session/share.d.ts +131 -0
  87. package/build/types/session/types.d.ts +113 -0
  88. package/build/types/test/SocketIOClient.spec.d.ts +0 -0
  89. package/build/types/types/ComClient.d.ts +307 -0
  90. package/build/types/utils/createRecursiveBufferGeometry.d.ts +8 -0
  91. package/build/types/utils/createRecursiveScene.d.ts +24 -0
  92. package/build/types/utils/getDifferentColoredMeshesFromEntity.d.ts +14 -0
  93. package/build/types/utils/index.d.ts +4 -0
  94. package/build/types/utils/polyline.d.ts +43 -0
  95. package/build/types/utils/waitForSelect.d.ts +4 -0
  96. package/doc/api/advanced/connection.md +488 -0
  97. package/doc/api/clients.md +2045 -0
  98. package/doc/api/engine-keys.md +230 -0
  99. package/doc/api/index.md +58 -0
  100. package/doc/api/modeling.md +682 -0
  101. package/doc/api/other.md +33 -0
  102. package/doc/api/session-sharing.md +706 -0
  103. package/package.json +60 -4
  104. package/test/classcadEngine.test.cjs +44 -0
  105. package/test/connect.test.cjs +81 -0
  106. package/test/engineKey.test.cjs +80 -0
  107. package/test/onClient.test.cjs +82 -0
  108. package/typedoc.json +8 -0
@@ -0,0 +1,2045 @@
1
+ # Clients
2
+
3
+ Start here: `init` takes a factory that makes the client of each drawing, which connects it to ClassCAD: the engine
4
+ in the page (`WASMClient`), a native engine (`WSClient`) or the ClassCAD server (`SocketIOClient`).
5
+
6
+ ## Functions
7
+
8
+ ### init() {#init}
9
+
10
+ ```ts
11
+ function init(source, options?): void;
12
+ ```
13
+
14
+ Sets up the SDK: tells it how to reach ClassCAD, with a factory that makes the client for each drawing.
15
+
16
+ Call it once, before the first drawing connects. Every drawing that connects afterwards
17
+ ([BuerliCadFacade.connect](modeling.md#connect), `BuerliCadFacade.utils.connect`, react-cad, Buerligons) gets its client from
18
+ `source`; the client connects right after it is made. Calling `init` again replaces the factory for the drawings
19
+ that connect from then on. `options` go to the SDK's store (`init` of `@classcad/sdkjs`).
20
+
21
+ #### Parameters
22
+
23
+ | Parameter | Type | Description |
24
+ | :------ | :------ | :------ |
25
+ | `source` | (`drawingId`) => [`AwvNodeClient`](#abstract-awvnodeclient) | Makes the client for a drawing: called with the new drawing's id, returns a client that is not connected yet. |
26
+ | `options?` | `Partial`<\{ `config`: \{ `geometry`: `GeometryConfig`; \}; `elements`: `any`; `globalPlugins`: (`Plugin` \| `Promise`<`Plugin`>)[]; `plugins`: `Record`<`string`, `PluginImpl`>; `theme`: \{ `dark`: `string`; `highlightedGeom`: `string`; `hoveredGeom`: `string`; `primary`: `string`; `secondary`: `string`; \}; \}> | Options of the SDK's store: theme colors, how geometry is shown (`config.geometry`), plugins. |
27
+
28
+ #### Returns
29
+
30
+ `void`
31
+
32
+ #### Examples
33
+
34
+ ```ts
35
+ import { init, WASMClient } from '@classcad/client'
36
+
37
+ // The engine in the browser, with a public access token from classcad.ch/account
38
+ init(drawingId => new WASMClient(drawingId, { token: 'ccpk_…' }))
39
+ ```
40
+
41
+ ```ts
42
+ import { init, SocketIOClient, WSClient } from '@classcad/client'
43
+
44
+ // A ClassCAD server (classcad-socketio)
45
+ init(drawingId => new SocketIOClient('ws://localhost:9091', drawingId))
46
+ // Or the native engine's own WebSocket server (classcad-cli worker)
47
+ init(drawingId => new WSClient('ws://localhost:9094', drawingId))
48
+ ```
49
+
50
+ ***
51
+
52
+ ### onClient() {#onclient}
53
+
54
+ ```ts
55
+ function onClient(callback): () => void;
56
+ ```
57
+
58
+ Calls back with every drawing's client: the ones there are, and each new one before it connects.
59
+
60
+ A new client is passed as soon as the factory has made it. An app that prepares the clients a host makes
61
+ (session sharing, engine settings) registers here instead of wrapping the host's factory. Returns a function
62
+ that unregisters.
63
+
64
+ A callback that throws is logged; the drawing connects all the same.
65
+
66
+ #### Parameters
67
+
68
+ | Parameter | Type | Description |
69
+ | :------ | :------ | :------ |
70
+ | `callback` | (`client`, `drawingId`) => `void` | Called with each client and the id of its drawing. |
71
+
72
+ #### Returns
73
+
74
+ A function that unregisters `callback`.
75
+
76
+ () => `void`
77
+
78
+ #### Example
79
+
80
+ ```ts
81
+ import { onClient, syncSelection, WASMClient, WSClient } from '@classcad/client'
82
+
83
+ // Prepares every client a host makes (react-cad, Buerligons, a facade), before it connects
84
+ const unregister = onClient((client, drawingId) => {
85
+ // Shares the selection where the session can be shared
86
+ if (client instanceof WSClient || client instanceof WASMClient) syncSelection(client)
87
+ // Hidden objects are not needed in this app
88
+ client.on('connected', () => client.setEmissionConfig({ sendGraphic_Invisible: false }).catch(console.warn))
89
+ client.on('conn_error', (_client, reason) => console.error(`Drawing ${drawingId} lost ClassCAD:`, reason))
90
+ })
91
+ ```
92
+
93
+ ## Classes
94
+
95
+ ### WASMClient {#wasmclient}
96
+
97
+ Runs the ClassCAD engine in the browser, as WebAssembly in a web worker, and hosts its session for guests.
98
+
99
+ `connect` gets the engine's key first: from `token` (fetched from ClassCAD, cached in `localStorage` and renewed),
100
+ `getKey` or `classcadKey` (see [resolveEngineKey](engine-keys.md#resolveenginekey)). Then it loads the engine from `url`, by default from
101
+ ClassCAD's CDN in the version this package is made for, and starts it in a worker. A public access token
102
+ (`ccpk_…`, from classcad.ch/account) may sit in a web page; it yields keys for the account's registered domains
103
+ and for localhost.
104
+
105
+ Nobody can connect to a page, so the page hosts its session itself. With the first invite
106
+ ([WASMClient.createInvite](#createinvite)) it offers its invites at `sessionUrl`, a ClassCAD MCP on the same machine or the
107
+ ClassCAD share relay, where guests join with `?invite=<token>` as they would join a server. Undo and redo are not
108
+ supported by this client.
109
+
110
+ #### Examples
111
+
112
+ ```ts
113
+ import { init, WASMClient } from '@classcad/client'
114
+
115
+ // A public access token from classcad.ch/account; it works on the account's domains and on localhost
116
+ init(drawingId => new WASMClient(drawingId, { token: 'ccpk_…' }))
117
+ ```
118
+ Its events (`connected`, `conn_error`, …) and the members all clients share are on [AwvNodeClient](#abstract-awvnodeclient).
119
+
120
+ ```ts
121
+ import { init, WASMClient } from '@classcad/client'
122
+ import type { EngineKey } from '@classcad/client'
123
+
124
+ // The app's own sign-in: its server hands signed-in users a key (see requestEngineKey)
125
+ init(
126
+ drawingId =>
127
+ new WASMClient(drawingId, {
128
+ getKey: async () => {
129
+ const res = await fetch('/api/engine-key', { headers: { authorization: `Bearer ${await idToken()}` } })
130
+ if (!res.ok) throw new Error(`No engine key: ${res.status}`)
131
+ return (await res.json()) as EngineKey
132
+ },
133
+ }),
134
+ )
135
+ ```
136
+
137
+ #### Extends
138
+
139
+ - [`AwvNodeClient`](#abstract-awvnodeclient)
140
+
141
+ #### Accessors
142
+
143
+ ##### drawingId {#drawingid}
144
+
145
+ ###### Get Signature
146
+
147
+ ```ts
148
+ get drawingId(): DrawingID;
149
+ ```
150
+
151
+ The drawing this client serves.
152
+
153
+ ###### Returns
154
+
155
+ `DrawingID`
156
+
157
+ ###### Inherited from
158
+
159
+ [`AwvNodeClient`](#abstract-awvnodeclient).[`drawingId`](#drawingid-3)
160
+
161
+ ##### identities {#identities}
162
+
163
+ ###### Get Signature
164
+
165
+ ```ts
166
+ get identities(): Record<string, ClientIdentity>;
167
+ ```
168
+
169
+ What the other participants said about themselves ([ClientIdentity](session-sharing.md#clientidentity)), by peer id.
170
+
171
+ ###### Returns
172
+
173
+ `Record`&lt;`string`, [`ClientIdentity`](session-sharing.md#clientidentity)&gt;
174
+
175
+ ###### Inherited from
176
+
177
+ [`AwvNodeClient`](#abstract-awvnodeclient).[`identities`](#identities-3)
178
+
179
+ ##### invites {#invites}
180
+
181
+ ###### Get Signature
182
+
183
+ ```ts
184
+ get invites(): SessionInvite[];
185
+ ```
186
+
187
+ The invites this client minted and has not revoked.
188
+
189
+ ###### Returns
190
+
191
+ [`SessionInvite`](session-sharing.md#sessioninvite)[]
192
+
193
+ ###### Inherited from
194
+
195
+ [`AwvNodeClient`](#abstract-awvnodeclient).[`invites`](#invites-3)
196
+
197
+ ##### peers {#peers}
198
+
199
+ ###### Get Signature
200
+
201
+ ```ts
202
+ get peers(): SessionPeer[];
203
+ ```
204
+
205
+ The guests in this page's session.
206
+
207
+ ###### Returns
208
+
209
+ [`SessionPeer`](session-sharing.md#sessionpeer)[]
210
+
211
+ ###### Overrides
212
+
213
+ [`AwvNodeClient`](#abstract-awvnodeclient).[`peers`](#peers-3)
214
+
215
+ #### Constructors
216
+
217
+ ##### Constructor
218
+
219
+ ```ts
220
+ new WASMClient(drawingId, config): WASMClient;
221
+ ```
222
+
223
+ ###### Parameters
224
+
225
+ | Parameter | Type | Description |
226
+ | :------ | :------ | :------ |
227
+ | `drawingId` | `DrawingID` | The drawing the client serves (the factory given to [init](#init) is called with it). |
228
+ | `config` | \{ `classcadKey?`: `string`; `getKey?`: () => `Promise`&lt;`string` \| [`EngineKey`](engine-keys.md#enginekey)&gt;; `identity?`: [`ClientIdentity`](session-sharing.md#clientidentity); `keyUrl?`: `string`; `logToConsole?`: `boolean`; `sessionAuth?`: (`refresh`) => `Promise`&lt;`string` \| `null` \| `undefined`&gt;; `sessionUrl?`: `string`; `token?`: `string`; `url?`: `string`; \} | The engine's key (`token`, `getKey` or `classcadKey`), where the engine is loaded from, and the session's settings. |
229
+ | `config.classcadKey?` | `string` | An engine key itself; when given, nothing is fetched. |
230
+ | `config.getKey?` | () => `Promise`&lt;`string` \| [`EngineKey`](engine-keys.md#enginekey)&gt; | Or the app supplies the key itself, for example from its own sign-in. |
231
+ | `config.identity?` | [`ClientIdentity`](session-sharing.md#clientidentity) | Who this client is, for the guests of its session. |
232
+ | `config.keyUrl?` | `string` | The token exchange, if not ClassCAD's (see [DEFAULT\_KEY\_URL](engine-keys.md#default_key_url)). |
233
+ | `config.logToConsole?` | `boolean` | Lets the engine log to the browser console. Default `false`. |
234
+ | `config.sessionAuth?` | (`refresh`) => `Promise`&lt;`string` \| `null` \| `undefined`&gt; | The sign-in the relay takes an invite with: a Firebase ID token of the reader's ClassCAD account, a fresh one when `refresh` is set. |
235
+ | `config.sessionUrl?` | `string` | Where guests of this page's session join: the session address of a local ClassCAD MCP (default [DEFAULT\_SESSION\_URL](session-sharing.md#default_session_url)), or of the ClassCAD share relay (`wss://<relay>/session`), which wants `sessionAuth`. |
236
+ | `config.token?` | `string` | A ClassCAD access token (`ccpk_…`, from classcad.ch/account): the engine's key is fetched, cached and renewed with it. |
237
+ | `config.url?` | `string` | Where the engine's files are (`ClassCADWasmWorker.js` and the engine), when they are hosted elsewhere. A path is taken on the page's origin. By default ClassCAD's CDN, in the engine version this package is made for. |
238
+
239
+ ###### Returns
240
+
241
+ [`WASMClient`](#wasmclient)
242
+
243
+ ###### Overrides
244
+
245
+ [`AwvNodeClient`](#abstract-awvnodeclient).[`constructor`](#constructor-3)
246
+
247
+ #### Methods
248
+
249
+ ##### connect() {#connect}
250
+
251
+ ```ts
252
+ connect(): Promise<WASMClient>;
253
+ ```
254
+
255
+ Gets the engine's key, loads the engine's worker from `url` and starts the engine. Rejects with an
256
+ [EngineKeyError](engine-keys.md#enginekeyerror) when there is no key, and when the engine cannot be loaded.
257
+
258
+ ###### Returns
259
+
260
+ `Promise`&lt;[`WASMClient`](#wasmclient)&gt;
261
+
262
+ ###### Overrides
263
+
264
+ [`AwvNodeClient`](#abstract-awvnodeclient).[`connect`](#connect-3)
265
+
266
+ ##### createInvite() {#createinvite}
267
+
268
+ ```ts
269
+ createInvite(role?, name?): Promise<SessionInvite>;
270
+ ```
271
+
272
+ Mints an invite for this page's session. Guests join with it at the
273
+ session address (`sessionUrl`: a local ClassCAD MCP, or the share relay),
274
+ which introduces them to this page; the invite stays joinable until it is
275
+ revoked or the client disconnects.
276
+
277
+ When the share relay will not take the invite (no sign-in, a plan that does not share), it is dropped and the
278
+ client emits `invite_refused`.
279
+
280
+ ###### Parameters
281
+
282
+ | Parameter | Type | Default value | Description |
283
+ | :------ | :------ | :------ | :------ |
284
+ | `role?` | [`SessionRole`](session-sharing.md#sessionrole) | `'edit'` | What guests with the invite may do: `'edit'` (default) or `'view'`. |
285
+ | `name?` | `string` | `''` | A name to show for the invite. |
286
+
287
+ ###### Returns
288
+
289
+ `Promise`&lt;[`SessionInvite`](session-sharing.md#sessioninvite)&gt;
290
+
291
+ ###### Example
292
+
293
+ ```ts
294
+ import { BuerliCadFacade, buildShareUrl, init, WASMClient } from '@classcad/client'
295
+ import type { OfferRefusal, SessionInvite } from '@classcad/client'
296
+
297
+ // The engine in the page; guests join from anywhere through the share relay
298
+ let client!: WASMClient
299
+ init(
300
+ drawingId =>
301
+ (client = new WASMClient(drawingId, {
302
+ token: 'ccpk_…',
303
+ sessionUrl: 'wss://<relay>/session',
304
+ // The relay takes invites from signed-in ClassCAD accounts
305
+ sessionAuth: refresh => classcadIdToken(refresh),
306
+ })),
307
+ )
308
+ await new BuerliCadFacade().connect()
309
+
310
+ client.on('invite_refused', (_client, invite: SessionInvite, refusal: OfferRefusal) =>
311
+ showError(refusal.code === 4403 ? 'Your plan does not share sessions' : `${invite.name}: ${refusal.reason}`),
312
+ )
313
+ const invite = await client.createInvite('edit', 'team')
314
+ const link = buildShareUrl(invite)
315
+ ```
316
+
317
+ ###### Overrides
318
+
319
+ [`AwvNodeClient`](#abstract-awvnodeclient).[`createInvite`](#createinvite-3)
320
+
321
+ ##### disconnect() {#disconnect}
322
+
323
+ ```ts
324
+ disconnect(): Promise<AwvNodeClient>;
325
+ ```
326
+
327
+ Ends the session (guests are closed, invites taken back) and terminates the engine's worker.
328
+
329
+ ###### Returns
330
+
331
+ `Promise`&lt;[`AwvNodeClient`](#abstract-awvnodeclient)&gt;
332
+
333
+ ###### Overrides
334
+
335
+ [`AwvNodeClient`](#abstract-awvnodeclient).[`disconnect`](#disconnect-3)
336
+
337
+ ##### executeMiddleware() {#executemiddleware}
338
+
339
+ ```ts
340
+ executeMiddleware(command, data): Promise<ServerResponse>;
341
+ ```
342
+
343
+ Sends a command of the server's own (a middleware command), with the fields of `data`.
344
+
345
+ ###### Parameters
346
+
347
+ | Parameter | Type | Description |
348
+ | :------ | :------ | :------ |
349
+ | `command` | `string` | The command's name. |
350
+ | `data` | `any` | Fields sent along with the command. |
351
+
352
+ ###### Returns
353
+
354
+ `Promise`&lt;[`ServerResponse`](advanced/connection.md#serverresponse)&gt;
355
+
356
+ ###### Inherited from
357
+
358
+ [`AwvNodeClient`](#abstract-awvnodeclient).[`executeMiddleware`](#executemiddleware-3)
359
+
360
+ ##### executeRequest() {#executerequest}
361
+
362
+ ```ts
363
+ executeRequest(
364
+ task,
365
+ streamMap?,
366
+ options?
367
+ ): Promise<ServerResponse>;
368
+ ```
369
+
370
+ Runs `task` (API calls) on the engine with an `Execute` request. Rejects with the reply when it carries an error.
371
+
372
+ The drawing's API ([createApi](modeling.md#createapi)) calls through here; the streams of `streamMap` are deflated and sent as
373
+ base64.
374
+
375
+ ###### Parameters
376
+
377
+ | Parameter | Type | Description |
378
+ | :------ | :------ | :------ |
379
+ | `task` | [`Task`](advanced/connection.md#task) | The API calls to run, e.g. `[{ 'v1.part.create': [{ name: 'Part' }] }]`. |
380
+ | `streamMap?` | [`StreamMap`](advanced/connection.md#streammap) | Data the calls read, by stream key (a file to import, for example). |
381
+ | `options?` | [`RequestOptions`](advanced/connection.md#requestoptions) | Options of the request, such as `undoable`. |
382
+
383
+ ###### Returns
384
+
385
+ `Promise`&lt;[`ServerResponse`](advanced/connection.md#serverresponse)&gt;
386
+
387
+ ###### Inherited from
388
+
389
+ [`AwvNodeClient`](#abstract-awvnodeclient).[`executeRequest`](#executerequest-3)
390
+
391
+ ##### getEmissionConfig() {#getemissionconfig}
392
+
393
+ ```ts
394
+ getEmissionConfig(): Promise<EmissionConfig>;
395
+ ```
396
+
397
+ The effective emission config of this connection ([EmissionConfig](advanced/connection.md#emissionconfig)): what the engine sends back after a
398
+ command.
399
+
400
+ Rejects with an Error named [EMISSION\_CONFIG\_UNSUPPORTED](advanced/connection.md#emission_config_unsupported) on engines that predate the command.
401
+
402
+ ###### Returns
403
+
404
+ `Promise`&lt;[`EmissionConfig`](advanced/connection.md#emissionconfig)&gt;
405
+
406
+ ###### Inherited from
407
+
408
+ [`AwvNodeClient`](#abstract-awvnodeclient).[`getEmissionConfig`](#getemissionconfig-3)
409
+
410
+ ##### redo() {#redo}
411
+
412
+ ```ts
413
+ redo(options?): Promise<ServerResponse>;
414
+ ```
415
+
416
+ Goes forward to the state after the current one, or to `options.state` (see undo).
417
+
418
+ ###### Parameters
419
+
420
+ | Parameter | Type |
421
+ | :------ | :------ |
422
+ | `options?` | [`RedoOptions`](advanced/connection.md#redooptions) |
423
+
424
+ ###### Returns
425
+
426
+ `Promise`&lt;[`ServerResponse`](advanced/connection.md#serverresponse)&gt;
427
+
428
+ ###### Overrides
429
+
430
+ [`AwvNodeClient`](#abstract-awvnodeclient).[`redo`](#redo-3)
431
+
432
+ ##### requestByName() {#requestbyname}
433
+
434
+ ```ts
435
+ requestByName(name, command?): Promise<ServerResponse>;
436
+ ```
437
+
438
+ Runs `command` on the engine and resolves to its reply. What the command changed (structure, graphic) goes into
439
+ the drawing, and to the session's guests. Rejects with the reply when it carries an error.
440
+
441
+ ###### Parameters
442
+
443
+ | Parameter | Type | Description |
444
+ | :------ | :------ | :------ |
445
+ | `name` | `string` | Not used by this client. |
446
+ | `command?` | [`ServerRequest`](advanced/connection.md#serverrequest) | The request. |
447
+
448
+ ###### Returns
449
+
450
+ `Promise`&lt;[`ServerResponse`](advanced/connection.md#serverresponse)&gt;
451
+
452
+ ###### Overrides
453
+
454
+ [`AwvNodeClient`](#abstract-awvnodeclient).[`requestByName`](#requestbyname-3)
455
+
456
+ ##### requestTree() {#requesttree}
457
+
458
+ ```ts
459
+ requestTree(): Promise<ServerResponse>;
460
+ ```
461
+
462
+ Loads the drawing's structure tree from the engine and sets it in the SDK's store.
463
+
464
+ ###### Returns
465
+
466
+ `Promise`&lt;[`ServerResponse`](advanced/connection.md#serverresponse)&gt;
467
+
468
+ ###### Inherited from
469
+
470
+ [`AwvNodeClient`](#abstract-awvnodeclient).[`requestTree`](#requesttree-3)
471
+
472
+ ##### revokeInvite() {#revokeinvite}
473
+
474
+ ```ts
475
+ revokeInvite(invite): Promise<{
476
+ invite: string;
477
+ kicked: number;
478
+ revoked: boolean;
479
+ }>;
480
+ ```
481
+
482
+ Takes an invite back; guests that joined with it are cut off.
483
+
484
+ ###### Parameters
485
+
486
+ | Parameter | Type | Description |
487
+ | :------ | :------ | :------ |
488
+ | `invite` | `string` | The invite token. |
489
+
490
+ ###### Returns
491
+
492
+ `Promise`&lt;\{
493
+ `invite`: `string`;
494
+ `kicked`: `number`;
495
+ `revoked`: `boolean`;
496
+ \}&gt;
497
+
498
+ The token, whether this client had made it, and how many guests were cut off.
499
+
500
+ ###### Overrides
501
+
502
+ [`AwvNodeClient`](#abstract-awvnodeclient).[`revokeInvite`](#revokeinvite-3)
503
+
504
+ ##### sendPresence() {#sendpresence}
505
+
506
+ ```ts
507
+ sendPresence(channel, data): void;
508
+ ```
509
+
510
+ Presence to the guests of this page's session (see WSClient.sendPresence). Nothing happens while nobody was invited.
511
+
512
+ ###### Parameters
513
+
514
+ | Parameter | Type | Description |
515
+ | :------ | :------ | :------ |
516
+ | `channel` | `string` | The channel, e.g. `'view'` for a camera viewpoint. |
517
+ | `data` | `Record`&lt;`string`, `any`&gt; | The payload, sent as it is; the last one per channel is kept for guests who join later. |
518
+
519
+ ###### Returns
520
+
521
+ `void`
522
+
523
+ ###### Overrides
524
+
525
+ [`AwvNodeClient`](#abstract-awvnodeclient).[`sendPresence`](#sendpresence-3)
526
+
527
+ ##### setEmissionConfig() {#setemissionconfig}
528
+
529
+ ```ts
530
+ setEmissionConfig(partial): Promise<EmissionConfig>;
531
+ ```
532
+
533
+ Merges `partial` into the emission config of this connection and resolves to the effective flags.
534
+
535
+ The engine keeps the config for every command that follows, until it is changed again. Rejects with an Error
536
+ named [EMISSION\_CONFIG\_UNSUPPORTED](advanced/connection.md#emission_config_unsupported) on engines that predate the command. [EmissionConfig](advanced/connection.md#emissionconfig) has an
537
+ example, and [onClient](#onclient) sets flags as every client connects.
538
+
539
+ ###### Parameters
540
+
541
+ | Parameter | Type | Description |
542
+ | :------ | :------ | :------ |
543
+ | `partial` | `Partial`&lt;[`EmissionConfig`](advanced/connection.md#emissionconfig)&gt; | The flags to change; the others stay as they are. |
544
+
545
+ ###### Returns
546
+
547
+ `Promise`&lt;[`EmissionConfig`](advanced/connection.md#emissionconfig)&gt;
548
+
549
+ ###### Inherited from
550
+
551
+ [`AwvNodeClient`](#abstract-awvnodeclient).[`setEmissionConfig`](#setemissionconfig-3)
552
+
553
+ ##### undo() {#undo}
554
+
555
+ ```ts
556
+ undo(options?): Promise<ServerResponse>;
557
+ ```
558
+
559
+ Goes back to the state before the current one of the engine's undo history, or to
560
+ `options.state`. The engine records a state after every command sent with
561
+ `options.undoable` (api-js marks the modelling calls) and reports the history in an
562
+ UndoStack message, which updates `cad.states`. The result is the history afterwards:
563
+ `{ stack, current }`. An engine from before undo answers without one; nothing happens then.
564
+
565
+ ###### Parameters
566
+
567
+ | Parameter | Type |
568
+ | :------ | :------ |
569
+ | `options?` | [`UndoOptions`](advanced/connection.md#undooptions) |
570
+
571
+ ###### Returns
572
+
573
+ `Promise`&lt;[`ServerResponse`](advanced/connection.md#serverresponse)&gt;
574
+
575
+ ###### Overrides
576
+
577
+ [`AwvNodeClient`](#abstract-awvnodeclient).[`undo`](#undo-3)
578
+
579
+ #### Properties
580
+
581
+ | Property | Modifier | Type | Default value | Description | Overrides | Inherited from |
582
+ | :------ | :------ | :------ | :------ | :------ | :------ | :------ |
583
+ | <a id="property-invitename"></a> `inviteName` | `public` | `string` | `''` | Name of the invite this connection joined with ('' for the host or unnamed tokens). | - | [`AwvNodeClient`](#abstract-awvnodeclient).[`inviteName`](#property-invitename-3) |
584
+ | <a id="property-role"></a> `role` | `public` | [`SessionRole`](session-sharing.md#sessionrole) | `'edit'` | This connection's role within a shared session ('edit' unless a guest with a view invite). | - | [`AwvNodeClient`](#abstract-awvnodeclient).[`role`](#property-role-3) |
585
+ | <a id="property-sharekind"></a> `shareKind` | `public readonly` | `"invite"` | `'invite'` | Invites are honoured: guests join at `sessionUrl` with `?invite=<token>`. | [`AwvNodeClient`](#abstract-awvnodeclient).[`shareKind`](#property-sharekind-3) | - |
586
+
587
+ ***
588
+
589
+ ### WSClient {#wsclient}
590
+
591
+ Connects the SDK to a native ClassCAD engine through the engine's own WebSocket server (`classcad-cli worker`).
592
+
593
+ The server owns the session. Without an invite it creates one for this connection, which lasts as long as the
594
+ connection; others join it with an invite from [WSClient.createInvite](#createinvite-1), passed as `config.invite`. A URL
595
+ without a scheme (`/session`) is on the server the page came from.
596
+
597
+ Connection flow:
598
+ 1. WebSocket handshake (server auto-creates session)
599
+ 2. SetEmissionConfig command stores this connection's emission flags on the server
600
+ 3. `fetchTree()` retrieves initial object tree
601
+ 4. Connection promise resolves
602
+
603
+ Undo and redo: `undo()` / `redo()` send the engine's `Undo` / `Redo` commands, and the `UndoStack` frames the
604
+ server sends after every undoable command and every undo / redo fill `cad.states` (see [WSClient.undo](#undo-1)).
605
+
606
+ #### Examples
607
+
608
+ ```ts
609
+ import { init, WSClient } from '@classcad/client'
610
+
611
+ // The native engine's own WebSocket server (classcad-cli worker)
612
+ init(drawingId => new WSClient('ws://localhost:9094', drawingId))
613
+ ```
614
+
615
+ ```ts
616
+ import { BuerliCadFacade, buildShareUrl, init, WSClient } from '@classcad/client'
617
+ import type { SessionPeer } from '@classcad/client'
618
+
619
+ // The host: a session of its own on the engine, and an invite to it
620
+ let host!: WSClient
621
+ init(drawingId => (host = new WSClient('ws://localhost:9094', drawingId, { identity: { app: 'my-app' } })))
622
+ await new BuerliCadFacade().connect()
623
+
624
+ host.on('peers_changed', (_client, peers: SessionPeer[]) => {
625
+ console.log(peers.map(peer => `${peer.inviteName}: ${peer.role}`))
626
+ })
627
+ const invite = await host.createInvite('view', 'review')
628
+ console.log('Join at', buildShareUrl(invite))
629
+ // Later: the token stops working, its guests are cut off
630
+ await host.revokeInvite(invite.invite)
631
+ ```
632
+ Its events (`connected`, `conn_error`, …) and the members all clients share are on [AwvNodeClient](#abstract-awvnodeclient).
633
+
634
+ ```ts
635
+ import { BuerliCadFacade, init, WSClient } from '@classcad/client'
636
+ import type { PresenceMessage } from '@classcad/client'
637
+
638
+ // A guest: joins the host's session with its token
639
+ let guest!: WSClient
640
+ init(drawingId => (guest = new WSClient('ws://localhost:9094', drawingId, { invite: token })))
641
+ await new BuerliCadFacade().connect()
642
+ // With a 'view' invite the app keeps the guest from changing the model
643
+ setReadOnly(guest.role === 'view')
644
+
645
+ // The cameras follow each other
646
+ guest.on('presence', (_client, msg: PresenceMessage) => {
647
+ if (msg.channel === 'view') moveCamera(msg.data)
648
+ })
649
+ guest.sendPresence('view', myCamera())
650
+ ```
651
+
652
+ #### Extends
653
+
654
+ - [`AwvNodeClient`](#abstract-awvnodeclient)
655
+
656
+ #### Accessors
657
+
658
+ ##### drawingId {#drawingid-1}
659
+
660
+ ###### Get Signature
661
+
662
+ ```ts
663
+ get drawingId(): DrawingID;
664
+ ```
665
+
666
+ The drawing this client serves.
667
+
668
+ ###### Returns
669
+
670
+ `DrawingID`
671
+
672
+ ###### Inherited from
673
+
674
+ [`AwvNodeClient`](#abstract-awvnodeclient).[`drawingId`](#drawingid-3)
675
+
676
+ ##### identities {#identities-1}
677
+
678
+ ###### Get Signature
679
+
680
+ ```ts
681
+ get identities(): Record<string, ClientIdentity>;
682
+ ```
683
+
684
+ What the other participants said about themselves ([ClientIdentity](session-sharing.md#clientidentity)), by peer id.
685
+
686
+ ###### Returns
687
+
688
+ `Record`&lt;`string`, [`ClientIdentity`](session-sharing.md#clientidentity)&gt;
689
+
690
+ ###### Inherited from
691
+
692
+ [`AwvNodeClient`](#abstract-awvnodeclient).[`identities`](#identities-3)
693
+
694
+ ##### invites {#invites-1}
695
+
696
+ ###### Get Signature
697
+
698
+ ```ts
699
+ get invites(): SessionInvite[];
700
+ ```
701
+
702
+ The invites this client minted and has not revoked.
703
+
704
+ ###### Returns
705
+
706
+ [`SessionInvite`](session-sharing.md#sessioninvite)[]
707
+
708
+ ###### Inherited from
709
+
710
+ [`AwvNodeClient`](#abstract-awvnodeclient).[`invites`](#invites-3)
711
+
712
+ ##### peers {#peers-1}
713
+
714
+ ###### Get Signature
715
+
716
+ ```ts
717
+ get peers(): SessionPeer[];
718
+ ```
719
+
720
+ Snapshot of the guests currently sharing this session (main connection only).
721
+
722
+ ###### Returns
723
+
724
+ [`SessionPeer`](session-sharing.md#sessionpeer)[]
725
+
726
+ ###### Overrides
727
+
728
+ [`AwvNodeClient`](#abstract-awvnodeclient).[`peers`](#peers-3)
729
+
730
+ ##### url {#url}
731
+
732
+ ###### Get Signature
733
+
734
+ ```ts
735
+ get url(): string;
736
+ ```
737
+
738
+ The address the client was given; one without a scheme (`/session`) is on the server the page came from.
739
+
740
+ ###### Returns
741
+
742
+ `string`
743
+
744
+ #### Constructors
745
+
746
+ ##### Constructor
747
+
748
+ ```ts
749
+ new WSClient(
750
+ _url,
751
+ drawingId,
752
+ config?
753
+ ): WSClient;
754
+ ```
755
+
756
+ ###### Parameters
757
+
758
+ | Parameter | Type | Description |
759
+ | :------ | :------ | :------ |
760
+ | `_url` | `string` | The server's WebSocket address, e.g. `ws://localhost:9094`, or a path on the page's own server. |
761
+ | `drawingId` | `DrawingID` | The drawing the client serves (the factory given to [init](#init) is called with it). |
762
+ | `config?` | [`WSClientConfig`](#wsclientconfig) | Sub-path, invite, identity and emission config ([WSClientConfig](#wsclientconfig)). |
763
+
764
+ ###### Returns
765
+
766
+ [`WSClient`](#wsclient)
767
+
768
+ ###### Overrides
769
+
770
+ [`AwvNodeClient`](#abstract-awvnodeclient).[`constructor`](#constructor-3)
771
+
772
+ #### Methods
773
+
774
+ ##### connect() {#connect-1}
775
+
776
+ ```ts
777
+ connect(): Promise<WSClient>;
778
+ ```
779
+
780
+ Opens the WebSocket, sets the connection's emission config, loads the structure tree and publishes `identity`.
781
+ Rejects when the socket fails before that, or when the engine predates SetEmissionConfig.
782
+
783
+ ###### Returns
784
+
785
+ `Promise`&lt;[`WSClient`](#wsclient)&gt;
786
+
787
+ ###### Overrides
788
+
789
+ [`AwvNodeClient`](#abstract-awvnodeclient).[`connect`](#connect-3)
790
+
791
+ ##### createInvite() {#createinvite-1}
792
+
793
+ ```ts
794
+ createInvite(role?, name?): Promise<SessionInvite>;
795
+ ```
796
+
797
+ Mints an invite token for this connection's session (multi-client invite
798
+ model). The returned token can be handed to other clients, which join via
799
+ `new WSClient(url, id, { invite })`. Server-side this is a controller-level
800
+ meta command; it is rejected when this connection itself joined via invite.
801
+
802
+ `name` is optional and purely for display (e.g. "workgroup"); it has no
803
+ effect on behavior. Multiple tokens can be minted (e.g. a named group token
804
+ plus an unnamed one-off token). The examples of [WSClient](#wsclient) show the host and a guest.
805
+
806
+ ###### Parameters
807
+
808
+ | Parameter | Type | Default value | Description |
809
+ | :------ | :------ | :------ | :------ |
810
+ | `role?` | [`SessionRole`](session-sharing.md#sessionrole) | `'edit'` | What guests with the invite may do: `'edit'` (default) or `'view'`. |
811
+ | `name?` | `string` | `''` | A name to show for the invite. |
812
+
813
+ ###### Returns
814
+
815
+ `Promise`&lt;[`SessionInvite`](session-sharing.md#sessioninvite)&gt;
816
+
817
+ ###### Overrides
818
+
819
+ [`AwvNodeClient`](#abstract-awvnodeclient).[`createInvite`](#createinvite-3)
820
+
821
+ ##### disconnect() {#disconnect-1}
822
+
823
+ ```ts
824
+ disconnect(): Promise<AwvNodeClient>;
825
+ ```
826
+
827
+ Closes the WebSocket; the server ends the session if this connection made it. No `conn_error` is emitted.
828
+
829
+ ###### Returns
830
+
831
+ `Promise`&lt;[`AwvNodeClient`](#abstract-awvnodeclient)&gt;
832
+
833
+ ###### Overrides
834
+
835
+ [`AwvNodeClient`](#abstract-awvnodeclient).[`disconnect`](#disconnect-3)
836
+
837
+ ##### executeMiddleware() {#executemiddleware-1}
838
+
839
+ ```ts
840
+ executeMiddleware(command, data): Promise<ServerResponse>;
841
+ ```
842
+
843
+ Sends a command of the server's own (a middleware command), with the fields of `data`.
844
+
845
+ ###### Parameters
846
+
847
+ | Parameter | Type | Description |
848
+ | :------ | :------ | :------ |
849
+ | `command` | `string` | The command's name. |
850
+ | `data` | `any` | Fields sent along with the command. |
851
+
852
+ ###### Returns
853
+
854
+ `Promise`&lt;[`ServerResponse`](advanced/connection.md#serverresponse)&gt;
855
+
856
+ ###### Inherited from
857
+
858
+ [`AwvNodeClient`](#abstract-awvnodeclient).[`executeMiddleware`](#executemiddleware-3)
859
+
860
+ ##### executeRequest() {#executerequest-1}
861
+
862
+ ```ts
863
+ executeRequest(
864
+ task,
865
+ streamMap?,
866
+ options?
867
+ ): Promise<ServerResponse>;
868
+ ```
869
+
870
+ Runs `task` (API calls) on the engine with an `Execute` request. Rejects with the reply when it carries an error.
871
+
872
+ The drawing's API ([createApi](modeling.md#createapi)) calls through here; the streams of `streamMap` are deflated and sent as
873
+ base64.
874
+
875
+ ###### Parameters
876
+
877
+ | Parameter | Type | Description |
878
+ | :------ | :------ | :------ |
879
+ | `task` | [`Task`](advanced/connection.md#task) | The API calls to run, e.g. `[{ 'v1.part.create': [{ name: 'Part' }] }]`. |
880
+ | `streamMap?` | [`StreamMap`](advanced/connection.md#streammap) | Data the calls read, by stream key (a file to import, for example). |
881
+ | `options?` | [`RequestOptions`](advanced/connection.md#requestoptions) | Options of the request, such as `undoable`. |
882
+
883
+ ###### Returns
884
+
885
+ `Promise`&lt;[`ServerResponse`](advanced/connection.md#serverresponse)&gt;
886
+
887
+ ###### Inherited from
888
+
889
+ [`AwvNodeClient`](#abstract-awvnodeclient).[`executeRequest`](#executerequest-3)
890
+
891
+ ##### getEmissionConfig() {#getemissionconfig-1}
892
+
893
+ ```ts
894
+ getEmissionConfig(): Promise<EmissionConfig>;
895
+ ```
896
+
897
+ The effective emission config of this connection ([EmissionConfig](advanced/connection.md#emissionconfig)): what the engine sends back after a
898
+ command.
899
+
900
+ Rejects with an Error named [EMISSION\_CONFIG\_UNSUPPORTED](advanced/connection.md#emission_config_unsupported) on engines that predate the command.
901
+
902
+ ###### Returns
903
+
904
+ `Promise`&lt;[`EmissionConfig`](advanced/connection.md#emissionconfig)&gt;
905
+
906
+ ###### Inherited from
907
+
908
+ [`AwvNodeClient`](#abstract-awvnodeclient).[`getEmissionConfig`](#getemissionconfig-3)
909
+
910
+ ##### redo() {#redo-1}
911
+
912
+ ```ts
913
+ redo(options?): Promise<ServerResponse>;
914
+ ```
915
+
916
+ Goes forward to the state after the current one, or to `options.state` (see undo).
917
+
918
+ ###### Parameters
919
+
920
+ | Parameter | Type |
921
+ | :------ | :------ |
922
+ | `options?` | [`RedoOptions`](advanced/connection.md#redooptions) |
923
+
924
+ ###### Returns
925
+
926
+ `Promise`&lt;[`ServerResponse`](advanced/connection.md#serverresponse)&gt;
927
+
928
+ ###### Overrides
929
+
930
+ [`AwvNodeClient`](#abstract-awvnodeclient).[`redo`](#redo-3)
931
+
932
+ ##### requestByName() {#requestbyname-1}
933
+
934
+ ```ts
935
+ requestByName(_name, command?): Promise<ServerResponse>;
936
+ ```
937
+
938
+ Sends `command` to the server and resolves to its reply, once the server's `Result` frame arrives. Structure,
939
+ graphic and messages that come before it go into the drawing on the way. Rejects with the reply when it carries
940
+ an error, and when the socket closes first.
941
+
942
+ ###### Parameters
943
+
944
+ | Parameter | Type | Description |
945
+ | :------ | :------ | :------ |
946
+ | `_name` | `string` | Not used by this client. |
947
+ | `command?` | [`ServerRequest`](advanced/connection.md#serverrequest) | The request. |
948
+
949
+ ###### Returns
950
+
951
+ `Promise`&lt;[`ServerResponse`](advanced/connection.md#serverresponse)&gt;
952
+
953
+ ###### Overrides
954
+
955
+ [`AwvNodeClient`](#abstract-awvnodeclient).[`requestByName`](#requestbyname-3)
956
+
957
+ ##### requestTree() {#requesttree-1}
958
+
959
+ ```ts
960
+ requestTree(): Promise<ServerResponse>;
961
+ ```
962
+
963
+ Loads the drawing's structure tree from the engine and sets it in the SDK's store.
964
+
965
+ ###### Returns
966
+
967
+ `Promise`&lt;[`ServerResponse`](advanced/connection.md#serverresponse)&gt;
968
+
969
+ ###### Inherited from
970
+
971
+ [`AwvNodeClient`](#abstract-awvnodeclient).[`requestTree`](#requesttree-3)
972
+
973
+ ##### revokeInvite() {#revokeinvite-1}
974
+
975
+ ```ts
976
+ revokeInvite(invite): Promise<{
977
+ invite: string;
978
+ kicked: number;
979
+ revoked: boolean;
980
+ }>;
981
+ ```
982
+
983
+ Revokes a previously minted invite token. Any guests currently connected
984
+ with that token are immediately disconnected, and the token can no longer
985
+ be used to join. Owner-only; rejected on connections that joined via invite.
986
+
987
+ ###### Parameters
988
+
989
+ | Parameter | Type | Description |
990
+ | :------ | :------ | :------ |
991
+ | `invite` | `string` | The invite token. |
992
+
993
+ ###### Returns
994
+
995
+ `Promise`&lt;\{
996
+ `invite`: `string`;
997
+ `kicked`: `number`;
998
+ `revoked`: `boolean`;
999
+ \}&gt;
1000
+
1001
+ The token, whether it was revoked, and how many guests were cut off.
1002
+
1003
+ ###### Overrides
1004
+
1005
+ [`AwvNodeClient`](#abstract-awvnodeclient).[`revokeInvite`](#revokeinvite-3)
1006
+
1007
+ ##### sendPresence() {#sendpresence-1}
1008
+
1009
+ ```ts
1010
+ sendPresence(channel, data): void;
1011
+ ```
1012
+
1013
+ Fire-and-forget ephemeral presence broadcast to the session's siblings
1014
+ (e.g. this client's camera viewpoint on the 'view' channel). Handled by a
1015
+ server fast-path that bypasses the command queue entirely; the server
1016
+ stamps the sender's peerId and fans the frame out. Siblings receive it via
1017
+ the `presence` event; late joiners get the last frame per channel as a
1018
+ snapshot. NOTE: the server matches on the exact serialized prefix
1019
+ `{"command":"Presence"`, so `command` must stay the first key here.
1020
+
1021
+ The guest example of [WSClient](#wsclient) shares the camera this way.
1022
+
1023
+ ###### Parameters
1024
+
1025
+ | Parameter | Type | Description |
1026
+ | :------ | :------ | :------ |
1027
+ | `channel` | `string` | The channel, e.g. `'view'` for a camera viewpoint. |
1028
+ | `data` | `Record`&lt;`string`, `any`&gt; | The payload, sent as it is. The server drops a frame larger than 8 KB. |
1029
+
1030
+ ###### Returns
1031
+
1032
+ `void`
1033
+
1034
+ ###### Overrides
1035
+
1036
+ [`AwvNodeClient`](#abstract-awvnodeclient).[`sendPresence`](#sendpresence-3)
1037
+
1038
+ ##### setEmissionConfig() {#setemissionconfig-1}
1039
+
1040
+ ```ts
1041
+ setEmissionConfig(partial): Promise<EmissionConfig>;
1042
+ ```
1043
+
1044
+ Merges `partial` into the emission config of this connection and resolves to the effective flags.
1045
+
1046
+ The engine keeps the config for every command that follows, until it is changed again. Rejects with an Error
1047
+ named [EMISSION\_CONFIG\_UNSUPPORTED](advanced/connection.md#emission_config_unsupported) on engines that predate the command. [EmissionConfig](advanced/connection.md#emissionconfig) has an
1048
+ example, and [onClient](#onclient) sets flags as every client connects.
1049
+
1050
+ ###### Parameters
1051
+
1052
+ | Parameter | Type | Description |
1053
+ | :------ | :------ | :------ |
1054
+ | `partial` | `Partial`&lt;[`EmissionConfig`](advanced/connection.md#emissionconfig)&gt; | The flags to change; the others stay as they are. |
1055
+
1056
+ ###### Returns
1057
+
1058
+ `Promise`&lt;[`EmissionConfig`](advanced/connection.md#emissionconfig)&gt;
1059
+
1060
+ ###### Inherited from
1061
+
1062
+ [`AwvNodeClient`](#abstract-awvnodeclient).[`setEmissionConfig`](#setemissionconfig-3)
1063
+
1064
+ ##### undo() {#undo-1}
1065
+
1066
+ ```ts
1067
+ undo(options?): Promise<ServerResponse>;
1068
+ ```
1069
+
1070
+ Goes back to the state before the current one of the session's undo history, or to
1071
+ `options.state`. The server records a state after every command sent with
1072
+ `options.undoable` (api-js marks the modelling calls) and answers with the frames of the
1073
+ change and an UndoStack frame, which updates `cad.states` of every client in the session.
1074
+ The result is the history afterwards: `{ stack, current }`.
1075
+
1076
+ ###### Parameters
1077
+
1078
+ | Parameter | Type |
1079
+ | :------ | :------ |
1080
+ | `options?` | [`UndoOptions`](advanced/connection.md#undooptions) |
1081
+
1082
+ ###### Returns
1083
+
1084
+ `Promise`&lt;[`ServerResponse`](advanced/connection.md#serverresponse)&gt;
1085
+
1086
+ ###### Overrides
1087
+
1088
+ [`AwvNodeClient`](#abstract-awvnodeclient).[`undo`](#undo-3)
1089
+
1090
+ #### Properties
1091
+
1092
+ | Property | Modifier | Type | Default value | Description | Overrides | Inherited from |
1093
+ | :------ | :------ | :------ | :------ | :------ | :------ | :------ |
1094
+ | <a id="property-invitename-1"></a> `inviteName` | `public` | `string` | `''` | Name of the invite this connection joined with ('' for the host or unnamed tokens). | - | [`AwvNodeClient`](#abstract-awvnodeclient).[`inviteName`](#property-invitename-3) |
1095
+ | <a id="property-role-1"></a> `role` | `public` | [`SessionRole`](session-sharing.md#sessionrole) | `'edit'` | This connection's role within a shared session ('edit' unless a guest with a view invite). | - | [`AwvNodeClient`](#abstract-awvnodeclient).[`role`](#property-role-3) |
1096
+ | <a id="property-sharekind-1"></a> `shareKind` | `public readonly` | `"invite"` | `'invite'` | The server owns the session: invites are honoured by joining with `?invite=` on the server URL. | [`AwvNodeClient`](#abstract-awvnodeclient).[`shareKind`](#property-sharekind-3) | - |
1097
+
1098
+ ***
1099
+
1100
+ ### SocketIOClient {#socketioclient}
1101
+
1102
+ Connects the SDK to a ClassCAD server (`classcad-socketio`) over Socket.IO.
1103
+
1104
+ The server runs the engine and keeps the drawing's undo history, so `undo`, `redo` and `undoable` requests work
1105
+ with this client. It cannot share its session (`shareKind` is null). When the connection drops and comes back, the
1106
+ client reconnects the drawing, recalculates it and emits `reconnect`.
1107
+
1108
+ Its events (`connected`, `conn_error`, …) and the members all clients share are on [AwvNodeClient](#abstract-awvnodeclient).
1109
+
1110
+ #### Example
1111
+
1112
+ ```ts
1113
+ import { init, SocketIOClient } from '@classcad/client'
1114
+
1115
+ // The ClassCAD server (classcad-socketio); a connection that drops is picked up again
1116
+ init(drawingId => {
1117
+ const client = new SocketIOClient('ws://localhost:9091', drawingId)
1118
+ client.on('conn_error', () => notify('The connection to ClassCAD is lost'))
1119
+ client.on('reconnect', () => notify('Connected again; the model was recalculated'))
1120
+ return client
1121
+ })
1122
+ ```
1123
+
1124
+ #### Extends
1125
+
1126
+ - [`AwvNodeClient`](#abstract-awvnodeclient)
1127
+
1128
+ #### Accessors
1129
+
1130
+ ##### drawingId {#drawingid-2}
1131
+
1132
+ ###### Get Signature
1133
+
1134
+ ```ts
1135
+ get drawingId(): DrawingID;
1136
+ ```
1137
+
1138
+ The drawing this client serves.
1139
+
1140
+ ###### Returns
1141
+
1142
+ `DrawingID`
1143
+
1144
+ ###### Inherited from
1145
+
1146
+ [`AwvNodeClient`](#abstract-awvnodeclient).[`drawingId`](#drawingid-3)
1147
+
1148
+ ##### identities {#identities-2}
1149
+
1150
+ ###### Get Signature
1151
+
1152
+ ```ts
1153
+ get identities(): Record<string, ClientIdentity>;
1154
+ ```
1155
+
1156
+ What the other participants said about themselves ([ClientIdentity](session-sharing.md#clientidentity)), by peer id.
1157
+
1158
+ ###### Returns
1159
+
1160
+ `Record`&lt;`string`, [`ClientIdentity`](session-sharing.md#clientidentity)&gt;
1161
+
1162
+ ###### Inherited from
1163
+
1164
+ [`AwvNodeClient`](#abstract-awvnodeclient).[`identities`](#identities-3)
1165
+
1166
+ ##### invites {#invites-2}
1167
+
1168
+ ###### Get Signature
1169
+
1170
+ ```ts
1171
+ get invites(): SessionInvite[];
1172
+ ```
1173
+
1174
+ The invites this client minted and has not revoked.
1175
+
1176
+ ###### Returns
1177
+
1178
+ [`SessionInvite`](session-sharing.md#sessioninvite)[]
1179
+
1180
+ ###### Inherited from
1181
+
1182
+ [`AwvNodeClient`](#abstract-awvnodeclient).[`invites`](#invites-3)
1183
+
1184
+ ##### peers {#peers-2}
1185
+
1186
+ ###### Get Signature
1187
+
1188
+ ```ts
1189
+ get peers(): SessionPeer[];
1190
+ ```
1191
+
1192
+ Guests currently sharing this session (host side).
1193
+
1194
+ ###### Returns
1195
+
1196
+ [`SessionPeer`](session-sharing.md#sessionpeer)[]
1197
+
1198
+ ###### Inherited from
1199
+
1200
+ [`AwvNodeClient`](#abstract-awvnodeclient).[`peers`](#peers-3)
1201
+
1202
+ #### Constructors
1203
+
1204
+ ##### Constructor
1205
+
1206
+ ```ts
1207
+ new SocketIOClient(url, drawingId): SocketIOClient;
1208
+ ```
1209
+
1210
+ ###### Parameters
1211
+
1212
+ | Parameter | Type | Description |
1213
+ | :------ | :------ | :------ |
1214
+ | `url` | `string` | The server's address, e.g. `ws://localhost:9091`. |
1215
+ | `drawingId` | `DrawingID` | The drawing the client serves (the factory given to [init](#init) is called with it). |
1216
+
1217
+ ###### Returns
1218
+
1219
+ [`SocketIOClient`](#socketioclient)
1220
+
1221
+ ###### Overrides
1222
+
1223
+ [`AwvNodeClient`](#abstract-awvnodeclient).[`constructor`](#constructor-3)
1224
+
1225
+ #### Methods
1226
+
1227
+ ##### connect() {#connect-2}
1228
+
1229
+ ```ts
1230
+ connect(): Promise<SocketIOClient>;
1231
+ ```
1232
+
1233
+ Opens the connection, registers the drawing with the server and loads its structure tree. Rejects on a
1234
+ connection error or timeout.
1235
+
1236
+ ###### Returns
1237
+
1238
+ `Promise`&lt;[`SocketIOClient`](#socketioclient)&gt;
1239
+
1240
+ ###### Overrides
1241
+
1242
+ [`AwvNodeClient`](#abstract-awvnodeclient).[`connect`](#connect-3)
1243
+
1244
+ ##### createInvite() {#createinvite-2}
1245
+
1246
+ ```ts
1247
+ createInvite(role?, name?): Promise<SessionInvite>;
1248
+ ```
1249
+
1250
+ Mints an invite token guests (apps, an MCP) can join with. Rejects with SESSION_SHARING_UNSUPPORTED on non-sharing transports.
1251
+
1252
+ ###### Parameters
1253
+
1254
+ | Parameter | Type | Default value | Description |
1255
+ | :------ | :------ | :------ | :------ |
1256
+ | `role?` | [`SessionRole`](session-sharing.md#sessionrole) | `'edit'` | What guests with the invite may do: `'edit'` (default) or `'view'`. |
1257
+ | `name?` | `string` | `''` | A name to show for the invite, e.g. "workgroup"; it has no effect. |
1258
+
1259
+ ###### Returns
1260
+
1261
+ `Promise`&lt;[`SessionInvite`](session-sharing.md#sessioninvite)&gt;
1262
+
1263
+ ###### Inherited from
1264
+
1265
+ [`AwvNodeClient`](#abstract-awvnodeclient).[`createInvite`](#createinvite-3)
1266
+
1267
+ ##### disconnect() {#disconnect-2}
1268
+
1269
+ ```ts
1270
+ disconnect(): Promise<AwvNodeClient>;
1271
+ ```
1272
+
1273
+ Closes the connection to the server.
1274
+
1275
+ ###### Returns
1276
+
1277
+ `Promise`&lt;[`AwvNodeClient`](#abstract-awvnodeclient)&gt;
1278
+
1279
+ ###### Overrides
1280
+
1281
+ [`AwvNodeClient`](#abstract-awvnodeclient).[`disconnect`](#disconnect-3)
1282
+
1283
+ ##### executeMiddleware() {#executemiddleware-2}
1284
+
1285
+ ```ts
1286
+ executeMiddleware(command, data): Promise<ServerResponse>;
1287
+ ```
1288
+
1289
+ Sends a command of the server's own (a middleware command), with the fields of `data`.
1290
+
1291
+ ###### Parameters
1292
+
1293
+ | Parameter | Type | Description |
1294
+ | :------ | :------ | :------ |
1295
+ | `command` | `string` | The command's name. |
1296
+ | `data` | `any` | Fields sent along with the command. |
1297
+
1298
+ ###### Returns
1299
+
1300
+ `Promise`&lt;[`ServerResponse`](advanced/connection.md#serverresponse)&gt;
1301
+
1302
+ ###### Inherited from
1303
+
1304
+ [`AwvNodeClient`](#abstract-awvnodeclient).[`executeMiddleware`](#executemiddleware-3)
1305
+
1306
+ ##### executeRequest() {#executerequest-2}
1307
+
1308
+ ```ts
1309
+ executeRequest(
1310
+ task,
1311
+ streamMap?,
1312
+ options?
1313
+ ): Promise<ServerResponse>;
1314
+ ```
1315
+
1316
+ Runs `task` (API calls) on the engine with an `Execute` request. Rejects with the reply when it carries an error.
1317
+
1318
+ The drawing's API ([createApi](modeling.md#createapi)) calls through here; the streams of `streamMap` are deflated and sent as
1319
+ base64.
1320
+
1321
+ ###### Parameters
1322
+
1323
+ | Parameter | Type | Description |
1324
+ | :------ | :------ | :------ |
1325
+ | `task` | [`Task`](advanced/connection.md#task) | The API calls to run, e.g. `[{ 'v1.part.create': [{ name: 'Part' }] }]`. |
1326
+ | `streamMap?` | [`StreamMap`](advanced/connection.md#streammap) | Data the calls read, by stream key (a file to import, for example). |
1327
+ | `options?` | [`RequestOptions`](advanced/connection.md#requestoptions) | Options of the request, such as `undoable`. |
1328
+
1329
+ ###### Returns
1330
+
1331
+ `Promise`&lt;[`ServerResponse`](advanced/connection.md#serverresponse)&gt;
1332
+
1333
+ ###### Inherited from
1334
+
1335
+ [`AwvNodeClient`](#abstract-awvnodeclient).[`executeRequest`](#executerequest-3)
1336
+
1337
+ ##### getEmissionConfig() {#getemissionconfig-2}
1338
+
1339
+ ```ts
1340
+ getEmissionConfig(): Promise<EmissionConfig>;
1341
+ ```
1342
+
1343
+ The effective emission config of this connection ([EmissionConfig](advanced/connection.md#emissionconfig)): what the engine sends back after a
1344
+ command.
1345
+
1346
+ Rejects with an Error named [EMISSION\_CONFIG\_UNSUPPORTED](advanced/connection.md#emission_config_unsupported) on engines that predate the command.
1347
+
1348
+ ###### Returns
1349
+
1350
+ `Promise`&lt;[`EmissionConfig`](advanced/connection.md#emissionconfig)&gt;
1351
+
1352
+ ###### Inherited from
1353
+
1354
+ [`AwvNodeClient`](#abstract-awvnodeclient).[`getEmissionConfig`](#getemissionconfig-3)
1355
+
1356
+ ##### redo() {#redo-2}
1357
+
1358
+ ```ts
1359
+ redo(options?): Promise<ServerResponse>;
1360
+ ```
1361
+
1362
+ Steps forward in the drawing's undo history on the server: to `options.state` when given.
1363
+
1364
+ ###### Parameters
1365
+
1366
+ | Parameter | Type | Description |
1367
+ | :------ | :------ | :------ |
1368
+ | `options?` | [`RedoOptions`](advanced/connection.md#redooptions) | The state to go forward to, and options for the server. |
1369
+
1370
+ ###### Returns
1371
+
1372
+ `Promise`&lt;[`ServerResponse`](advanced/connection.md#serverresponse)&gt;
1373
+
1374
+ ###### Overrides
1375
+
1376
+ [`AwvNodeClient`](#abstract-awvnodeclient).[`redo`](#redo-3)
1377
+
1378
+ ##### requestByName() {#requestbyname-2}
1379
+
1380
+ ```ts
1381
+ requestByName(name, command?): Promise<ServerResponse>;
1382
+ ```
1383
+
1384
+ Sends `command` to the server as the event `name` and resolves to the reply once all its frames have arrived.
1385
+ Structure patches and graphic go into the drawing on the way. Rejects with the reply when it carries an error.
1386
+
1387
+ ###### Parameters
1388
+
1389
+ | Parameter | Type | Description |
1390
+ | :------ | :------ | :------ |
1391
+ | `name` | `string` | The server's event: `send` for requests, `undo`, `redo`. |
1392
+ | `command?` | [`ServerRequest`](advanced/connection.md#serverrequest) | The request. |
1393
+
1394
+ ###### Returns
1395
+
1396
+ `Promise`&lt;[`ServerResponse`](advanced/connection.md#serverresponse)&gt;
1397
+
1398
+ ###### Overrides
1399
+
1400
+ [`AwvNodeClient`](#abstract-awvnodeclient).[`requestByName`](#requestbyname-3)
1401
+
1402
+ ##### requestTree() {#requesttree-2}
1403
+
1404
+ ```ts
1405
+ requestTree(): Promise<ServerResponse>;
1406
+ ```
1407
+
1408
+ Loads the drawing's structure tree from the engine and sets it in the SDK's store.
1409
+
1410
+ ###### Returns
1411
+
1412
+ `Promise`&lt;[`ServerResponse`](advanced/connection.md#serverresponse)&gt;
1413
+
1414
+ ###### Inherited from
1415
+
1416
+ [`AwvNodeClient`](#abstract-awvnodeclient).[`requestTree`](#requesttree-3)
1417
+
1418
+ ##### revokeInvite() {#revokeinvite-2}
1419
+
1420
+ ```ts
1421
+ revokeInvite(invite): Promise<{
1422
+ invite: string;
1423
+ kicked: number;
1424
+ revoked: boolean;
1425
+ }>;
1426
+ ```
1427
+
1428
+ Revokes a token and kicks the guests using it.
1429
+
1430
+ ###### Parameters
1431
+
1432
+ | Parameter | Type | Description |
1433
+ | :------ | :------ | :------ |
1434
+ | `invite` | `string` | The invite token. |
1435
+
1436
+ ###### Returns
1437
+
1438
+ `Promise`&lt;\{
1439
+ `invite`: `string`;
1440
+ `kicked`: `number`;
1441
+ `revoked`: `boolean`;
1442
+ \}&gt;
1443
+
1444
+ The token, whether it was revoked, and how many guests were cut off.
1445
+
1446
+ ###### Inherited from
1447
+
1448
+ [`AwvNodeClient`](#abstract-awvnodeclient).[`revokeInvite`](#revokeinvite-3)
1449
+
1450
+ ##### sendPresence() {#sendpresence-2}
1451
+
1452
+ ```ts
1453
+ sendPresence(channel, data): void;
1454
+ ```
1455
+
1456
+ Fire-and-forget presence broadcast to session siblings (camera, cursor …). No-op on non-sharing transports.
1457
+
1458
+ ###### Parameters
1459
+
1460
+ | Parameter | Type | Description |
1461
+ | :------ | :------ | :------ |
1462
+ | `channel` | `string` | The channel, e.g. `'view'` for a camera viewpoint; others get it in their `presence` event. |
1463
+ | `data` | `Record`&lt;`string`, `any`&gt; | The payload, sent as it is. A frame larger than 8 KB is dropped. |
1464
+
1465
+ ###### Returns
1466
+
1467
+ `void`
1468
+
1469
+ ###### Inherited from
1470
+
1471
+ [`AwvNodeClient`](#abstract-awvnodeclient).[`sendPresence`](#sendpresence-3)
1472
+
1473
+ ##### setEmissionConfig() {#setemissionconfig-2}
1474
+
1475
+ ```ts
1476
+ setEmissionConfig(partial): Promise<EmissionConfig>;
1477
+ ```
1478
+
1479
+ Merges `partial` into the emission config of this connection and resolves to the effective flags.
1480
+
1481
+ The engine keeps the config for every command that follows, until it is changed again. Rejects with an Error
1482
+ named [EMISSION\_CONFIG\_UNSUPPORTED](advanced/connection.md#emission_config_unsupported) on engines that predate the command. [EmissionConfig](advanced/connection.md#emissionconfig) has an
1483
+ example, and [onClient](#onclient) sets flags as every client connects.
1484
+
1485
+ ###### Parameters
1486
+
1487
+ | Parameter | Type | Description |
1488
+ | :------ | :------ | :------ |
1489
+ | `partial` | `Partial`&lt;[`EmissionConfig`](advanced/connection.md#emissionconfig)&gt; | The flags to change; the others stay as they are. |
1490
+
1491
+ ###### Returns
1492
+
1493
+ `Promise`&lt;[`EmissionConfig`](advanced/connection.md#emissionconfig)&gt;
1494
+
1495
+ ###### Inherited from
1496
+
1497
+ [`AwvNodeClient`](#abstract-awvnodeclient).[`setEmissionConfig`](#setemissionconfig-3)
1498
+
1499
+ ##### undo() {#undo-2}
1500
+
1501
+ ```ts
1502
+ undo(options?): Promise<ServerResponse>;
1503
+ ```
1504
+
1505
+ Steps back in the drawing's undo history on the server: to `options.state` when given.
1506
+
1507
+ ###### Parameters
1508
+
1509
+ | Parameter | Type | Description |
1510
+ | :------ | :------ | :------ |
1511
+ | `options?` | [`UndoOptions`](advanced/connection.md#undooptions) | The state to go back to, and options for the server. |
1512
+
1513
+ ###### Returns
1514
+
1515
+ `Promise`&lt;[`ServerResponse`](advanced/connection.md#serverresponse)&gt;
1516
+
1517
+ ###### Overrides
1518
+
1519
+ [`AwvNodeClient`](#abstract-awvnodeclient).[`undo`](#undo-3)
1520
+
1521
+ #### Properties
1522
+
1523
+ | Property | Modifier | Type | Default value | Description | Inherited from |
1524
+ | :------ | :------ | :------ | :------ | :------ | :------ |
1525
+ | <a id="property-invitename-2"></a> `inviteName` | `public` | `string` | `''` | Name of the invite this connection joined with ('' for the host or unnamed tokens). | [`AwvNodeClient`](#abstract-awvnodeclient).[`inviteName`](#property-invitename-3) |
1526
+ | <a id="property-role-2"></a> `role` | `public` | [`SessionRole`](session-sharing.md#sessionrole) | `'edit'` | This connection's role within a shared session ('edit' unless a guest with a view invite). | [`AwvNodeClient`](#abstract-awvnodeclient).[`role`](#property-role-3) |
1527
+ | <a id="property-sharekind-2"></a> `shareKind` | `public readonly` | `"invite"` \| `null` | `null` | How this client's invites are honoured; null = this client cannot share. | [`AwvNodeClient`](#abstract-awvnodeclient).[`shareKind`](#property-sharekind-3) |
1528
+
1529
+ ## Objects
1530
+
1531
+ ### classcadEngine {#classcadengine}
1532
+
1533
+ ```ts
1534
+ const classcadEngine: ClassCadEngine;
1535
+ ```
1536
+
1537
+ The ClassCAD engine this package is built against: its version, its quality, and where its bundle is.
1538
+
1539
+ `@classcad/api-js`, the ClassCAD API this package calls, is generated by the ClassCAD engine, and carries the
1540
+ version and the quality of the bundle it belongs to. That bundle is the engine this version of the SDK is made
1541
+ for: [WASMClient](#wasmclient) loads its WebAssembly from `wasmUrl`, and a host that runs the engine behind a server
1542
+ ([WSClient](#wsclient), [SocketIOClient](#socketioclient)) installs the same version, from `url`. A beta of the SDK is built
1543
+ against an `alpha` build, a stable release against a `release`.
1544
+
1545
+ `npx @classcad/client info` prints the same (`--json` for the object).
1546
+
1547
+ #### Example
1548
+
1549
+ ```ts
1550
+ import { classcadEngine } from '@classcad/client'
1551
+
1552
+ console.log(`Built against ClassCAD ${classcadEngine.version} (${classcadEngine.quality}): ${classcadEngine.url}`)
1553
+ ```
1554
+
1555
+ ## Types
1556
+
1557
+ ### ClassCadEngine {#classcadengine-1}
1558
+
1559
+ ```ts
1560
+ type ClassCadEngine = {
1561
+ apiUrl: string;
1562
+ metadataUrl: string;
1563
+ quality: string;
1564
+ url: string;
1565
+ version: string;
1566
+ wasmUrl: string;
1567
+ };
1568
+ ```
1569
+
1570
+ The ClassCAD engine a version of `@classcad/client` is built against: see [classcadEngine](#classcadengine).
1571
+
1572
+ #### Properties
1573
+
1574
+ | Property | Modifier | Type | Description |
1575
+ | :------ | :------ | :------ | :------ |
1576
+ | <a id="property-apiurl"></a> `apiUrl` | `readonly` | `string` | The `@classcad/api-js` package this package is built with, as a tarball. |
1577
+ | <a id="property-metadataurl"></a> `metadataUrl` | `readonly` | `string` | The bundle's `metadata.json`: its files, with their URLs and checksums. |
1578
+ | <a id="property-quality"></a> `quality` | `readonly` | `string` | `release`, `alpha` (what a beta of the SDK is built against) or `dev` (a feature branch). |
1579
+ | <a id="property-url"></a> `url` | `readonly` | `string` | The bundle on awvstatic.com: the engine for every platform, the server, the API packages. |
1580
+ | <a id="property-version"></a> `version` | `readonly` | `string` | The ClassCAD version: `21.2.0`, or `21.2.1-alpha.169`. |
1581
+ | <a id="property-wasmurl"></a> `wasmUrl` | `readonly` | `string` | The WebAssembly engine [WASMClient](#wasmclient) loads when it is given no `url`. |
1582
+
1583
+ ***
1584
+
1585
+ ### WSClientConfig {#wsclientconfig}
1586
+
1587
+ ```ts
1588
+ type WSClientConfig = {
1589
+ commandConfig?: Partial<EmissionConfig>;
1590
+ identity?: ClientIdentity;
1591
+ invite?: string;
1592
+ path?: string;
1593
+ };
1594
+ ```
1595
+
1596
+ Options of a [WSClient](#wsclient): sub-path, an invite to join a shared session, identity and emission config.
1597
+
1598
+ #### Example
1599
+
1600
+ ```ts
1601
+ import { getShareTokenFromUrl, init, WSClient } from '@classcad/client'
1602
+ import type { WSClientConfig } from '@classcad/client'
1603
+
1604
+ const config: WSClientConfig = {
1605
+ // Joins a shared session when the page was opened with a share link
1606
+ invite: getShareTokenFromUrl()?.token,
1607
+ identity: { app: 'configurator', version: '2.1.0', name: 'Ada', kind: 'app' },
1608
+ // This app shows no hidden objects
1609
+ commandConfig: { sendGraphic_Invisible: false },
1610
+ }
1611
+ init(drawingId => new WSClient('ws://localhost:9094', drawingId, config))
1612
+ ```
1613
+
1614
+ #### Properties
1615
+
1616
+ | Property | Type | Description |
1617
+ | :------ | :------ | :------ |
1618
+ | <a id="property-commandconfig"></a> `commandConfig?` | `Partial`&lt;[`EmissionConfig`](advanced/connection.md#emissionconfig)&gt; | Startup emission config of this connection, merged on top of the client's defaults and sent once with SetEmissionConfig on connect. Set individual flags to false to disable them; change them later with `setEmissionConfig()`. Not to be confused with v1.common.setDatabaseSettings, which decides what the engine TESSELLATES - this decides what it SENDS. The defaults turn on the structure, every graphic category and messages, and stream them: structure patches, graphic as compressed binary frames, one package per object, messages as they come. |
1619
+ | <a id="property-identity"></a> `identity?` | [`ClientIdentity`](session-sharing.md#clientidentity) | Who this client is, for the others in the session: published once after connecting on the 'client' presence channel (see [ClientIdentity](session-sharing.md#clientidentity)). |
1620
+ | <a id="property-invite"></a> `invite?` | `string` | Invite token for joining a shared session as a guest (sent as query param). Without it the server creates a fresh main session that lives for the duration of this connection; use `createInvite()` to let others join it. The server confirms an invite join with a `SessionJoined` frame carrying the invite's role — see the `session_joined` event and the `role` property. |
1621
+ | <a id="property-path"></a> `path?` | `string` | WebSocket sub-path: '/', '/command', or '/api'. Defaults to '/'. |
1622
+
1623
+ ## Advanced
1624
+
1625
+ 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.
1626
+
1627
+ ### `abstract` AwvNodeClient {#abstract-awvnodeclient}
1628
+
1629
+ The base of every client: what the SDK asks of a connection to ClassCAD, and the session-sharing surface.
1630
+
1631
+ An app makes a [WASMClient](#wasmclient), [WSClient](#wsclient) or [SocketIOClient](#socketioclient) in the factory it gives [init](#init);
1632
+ The SDK connects it and sends the drawing's API calls through it. A client that cannot share its session (the base
1633
+ class, [SocketIOClient](#socketioclient)) has `shareKind` null and rejects `createInvite` with
1634
+ [SESSION\_SHARING\_UNSUPPORTED](session-sharing.md#session_sharing_unsupported).
1635
+
1636
+ A client is an `EventEmitter`; every event passes the client first:
1637
+
1638
+ - `connected` (client, true): the client has connected.
1639
+ - `conn_error` (client, reason): the connection failed or broke off.
1640
+ - `conn_timeout` (client, reason): connecting timed out ([SocketIOClient](#socketioclient)).
1641
+ - `reconnect` (client): the connection is back, and the drawing reconnected ([SocketIOClient](#socketioclient)).
1642
+ - `session_joined` (client, role, inviteName): the client joined a shared session with an invite ([WSClient](#wsclient)).
1643
+ - `peer_joined` / `peer_left` (client, [SessionPeer](session-sharing.md#sessionpeer)): a guest joined or left this client's session.
1644
+ - `peers_changed` (client, [SessionPeer](session-sharing.md#sessionpeer)[]): the guests in the session changed.
1645
+ - `invites_changed` (client, [SessionInvite](session-sharing.md#sessioninvite)[]): an invite was made or taken back.
1646
+ - `identities_changed` (client, identities): a participant said who it is, or left.
1647
+ - `presence` (client, [PresenceMessage](session-sharing.md#presencemessage)): another participant published something.
1648
+ - `invite_refused` (client, [SessionInvite](session-sharing.md#sessioninvite), [OfferRefusal](session-sharing.md#offerrefusal)): the share relay would not take an invite
1649
+ ([WASMClient](#wasmclient)).
1650
+
1651
+ #### Example
1652
+
1653
+ ```ts
1654
+ import { onClient } from '@classcad/client'
1655
+ import type { PresenceMessage, SessionPeer } from '@classcad/client'
1656
+
1657
+ // A status line (an element of the app's page) for every drawing's connection and session
1658
+ onClient(client => {
1659
+ client.on('connected', () => (statusLine.textContent = 'Connected'))
1660
+ client.on('conn_error', (_client, reason) => (statusLine.textContent = `No connection: ${reason}`))
1661
+ client.on('peers_changed', (_client, peers: SessionPeer[]) => (statusLine.textContent = `${peers.length} guests`))
1662
+ client.on('presence', (_client, msg: PresenceMessage) => {
1663
+ if (msg.channel === 'leave') console.log(`${client.identities[msg.peerId]?.name ?? msg.peerId} left`)
1664
+ })
1665
+ })
1666
+ ```
1667
+
1668
+ #### Extends
1669
+
1670
+ - `EventEmitter`
1671
+
1672
+ #### Extended by
1673
+
1674
+ - [`SocketIOClient`](#socketioclient)
1675
+ - [`WASMClient`](#wasmclient)
1676
+ - [`WSClient`](#wsclient)
1677
+
1678
+ #### Implements
1679
+
1680
+ - [`IComClient`](advanced/connection.md#icomclient)
1681
+
1682
+ #### Accessors
1683
+
1684
+ ##### drawingId {#drawingid-3}
1685
+
1686
+ ###### Get Signature
1687
+
1688
+ ```ts
1689
+ get drawingId(): DrawingID;
1690
+ ```
1691
+
1692
+ The drawing this client serves.
1693
+
1694
+ ###### Returns
1695
+
1696
+ `DrawingID`
1697
+
1698
+ ##### identities {#identities-3}
1699
+
1700
+ ###### Get Signature
1701
+
1702
+ ```ts
1703
+ get identities(): Record<string, ClientIdentity>;
1704
+ ```
1705
+
1706
+ What the other participants said about themselves ([ClientIdentity](session-sharing.md#clientidentity)), by peer id.
1707
+
1708
+ ###### Returns
1709
+
1710
+ `Record`&lt;`string`, [`ClientIdentity`](session-sharing.md#clientidentity)&gt;
1711
+
1712
+ ##### invites {#invites-3}
1713
+
1714
+ ###### Get Signature
1715
+
1716
+ ```ts
1717
+ get invites(): SessionInvite[];
1718
+ ```
1719
+
1720
+ The invites this client minted and has not revoked.
1721
+
1722
+ ###### Returns
1723
+
1724
+ [`SessionInvite`](session-sharing.md#sessioninvite)[]
1725
+
1726
+ ##### peers {#peers-3}
1727
+
1728
+ ###### Get Signature
1729
+
1730
+ ```ts
1731
+ get peers(): SessionPeer[];
1732
+ ```
1733
+
1734
+ Guests currently sharing this session (host side).
1735
+
1736
+ ###### Returns
1737
+
1738
+ [`SessionPeer`](session-sharing.md#sessionpeer)[]
1739
+
1740
+ #### Constructors
1741
+
1742
+ ##### Constructor
1743
+
1744
+ ```ts
1745
+ new AwvNodeClient(): AwvNodeClient;
1746
+ ```
1747
+
1748
+ ###### Returns
1749
+
1750
+ [`AwvNodeClient`](#abstract-awvnodeclient)
1751
+
1752
+ ###### Overrides
1753
+
1754
+ ```ts
1755
+ EventEmitter.constructor
1756
+ ```
1757
+
1758
+ #### Methods
1759
+
1760
+ ##### connect() {#connect-3}
1761
+
1762
+ ```ts
1763
+ abstract connect(): Promise<AwvNodeClient>;
1764
+ ```
1765
+
1766
+ Connects to the engine. The SDK calls it when the drawing connects; it resolves once the drawing's structure tree
1767
+ is loaded and API calls can be made.
1768
+
1769
+ ###### Returns
1770
+
1771
+ `Promise`&lt;[`AwvNodeClient`](#abstract-awvnodeclient)&gt;
1772
+
1773
+ ###### Implementation of
1774
+
1775
+ [`IComClient`](advanced/connection.md#icomclient).[`connect`](advanced/connection.md#connect)
1776
+
1777
+ ##### createInvite() {#createinvite-3}
1778
+
1779
+ ```ts
1780
+ createInvite(role?, name?): Promise<SessionInvite>;
1781
+ ```
1782
+
1783
+ Mints an invite token guests (apps, an MCP) can join with. Rejects with SESSION_SHARING_UNSUPPORTED on non-sharing transports.
1784
+
1785
+ ###### Parameters
1786
+
1787
+ | Parameter | Type | Default value | Description |
1788
+ | :------ | :------ | :------ | :------ |
1789
+ | `role?` | [`SessionRole`](session-sharing.md#sessionrole) | `'edit'` | What guests with the invite may do: `'edit'` (default) or `'view'`. |
1790
+ | `name?` | `string` | `''` | A name to show for the invite, e.g. "workgroup"; it has no effect. |
1791
+
1792
+ ###### Returns
1793
+
1794
+ `Promise`&lt;[`SessionInvite`](session-sharing.md#sessioninvite)&gt;
1795
+
1796
+ ##### disconnect() {#disconnect-3}
1797
+
1798
+ ```ts
1799
+ abstract disconnect(): Promise<AwvNodeClient>;
1800
+ ```
1801
+
1802
+ Closes the connection to the engine.
1803
+
1804
+ ###### Returns
1805
+
1806
+ `Promise`&lt;[`AwvNodeClient`](#abstract-awvnodeclient)&gt;
1807
+
1808
+ ###### Implementation of
1809
+
1810
+ [`IComClient`](advanced/connection.md#icomclient).[`disconnect`](advanced/connection.md#disconnect)
1811
+
1812
+ ##### executeMiddleware() {#executemiddleware-3}
1813
+
1814
+ ```ts
1815
+ executeMiddleware(command, data): Promise<ServerResponse>;
1816
+ ```
1817
+
1818
+ Sends a command of the server's own (a middleware command), with the fields of `data`.
1819
+
1820
+ ###### Parameters
1821
+
1822
+ | Parameter | Type | Description |
1823
+ | :------ | :------ | :------ |
1824
+ | `command` | `string` | The command's name. |
1825
+ | `data` | `any` | Fields sent along with the command. |
1826
+
1827
+ ###### Returns
1828
+
1829
+ `Promise`&lt;[`ServerResponse`](advanced/connection.md#serverresponse)&gt;
1830
+
1831
+ ###### Implementation of
1832
+
1833
+ [`IComClient`](advanced/connection.md#icomclient).[`executeMiddleware`](advanced/connection.md#executemiddleware)
1834
+
1835
+ ##### executeRequest() {#executerequest-3}
1836
+
1837
+ ```ts
1838
+ executeRequest(
1839
+ task,
1840
+ streamMap?,
1841
+ options?
1842
+ ): Promise<ServerResponse>;
1843
+ ```
1844
+
1845
+ Runs `task` (API calls) on the engine with an `Execute` request. Rejects with the reply when it carries an error.
1846
+
1847
+ The drawing's API ([createApi](modeling.md#createapi)) calls through here; the streams of `streamMap` are deflated and sent as
1848
+ base64.
1849
+
1850
+ ###### Parameters
1851
+
1852
+ | Parameter | Type | Description |
1853
+ | :------ | :------ | :------ |
1854
+ | `task` | [`Task`](advanced/connection.md#task) | The API calls to run, e.g. `[{ 'v1.part.create': [{ name: 'Part' }] }]`. |
1855
+ | `streamMap?` | [`StreamMap`](advanced/connection.md#streammap) | Data the calls read, by stream key (a file to import, for example). |
1856
+ | `options?` | [`RequestOptions`](advanced/connection.md#requestoptions) | Options of the request, such as `undoable`. |
1857
+
1858
+ ###### Returns
1859
+
1860
+ `Promise`&lt;[`ServerResponse`](advanced/connection.md#serverresponse)&gt;
1861
+
1862
+ ###### Implementation of
1863
+
1864
+ [`IComClient`](advanced/connection.md#icomclient).[`executeRequest`](advanced/connection.md#executerequest)
1865
+
1866
+ ##### getEmissionConfig() {#getemissionconfig-3}
1867
+
1868
+ ```ts
1869
+ getEmissionConfig(): Promise<EmissionConfig>;
1870
+ ```
1871
+
1872
+ The effective emission config of this connection ([EmissionConfig](advanced/connection.md#emissionconfig)): what the engine sends back after a
1873
+ command.
1874
+
1875
+ Rejects with an Error named [EMISSION\_CONFIG\_UNSUPPORTED](advanced/connection.md#emission_config_unsupported) on engines that predate the command.
1876
+
1877
+ ###### Returns
1878
+
1879
+ `Promise`&lt;[`EmissionConfig`](advanced/connection.md#emissionconfig)&gt;
1880
+
1881
+ ###### Implementation of
1882
+
1883
+ [`IComClient`](advanced/connection.md#icomclient).[`getEmissionConfig`](advanced/connection.md#getemissionconfig)
1884
+
1885
+ ##### redo() {#redo-3}
1886
+
1887
+ ```ts
1888
+ abstract redo(options?): Promise<ServerResponse>;
1889
+ ```
1890
+
1891
+ Steps forward in the drawing's undo history: to `options.state` when given. The ClassCAD server
1892
+ ([SocketIOClient](#socketioclient)) keeps that history.
1893
+
1894
+ ###### Parameters
1895
+
1896
+ | Parameter | Type | Description |
1897
+ | :------ | :------ | :------ |
1898
+ | `options?` | [`RedoOptions`](advanced/connection.md#redooptions) | The state to go forward to, and options for the engine. |
1899
+
1900
+ ###### Returns
1901
+
1902
+ `Promise`&lt;[`ServerResponse`](advanced/connection.md#serverresponse)&gt;
1903
+
1904
+ ###### Implementation of
1905
+
1906
+ [`IComClient`](advanced/connection.md#icomclient).[`redo`](advanced/connection.md#redo)
1907
+
1908
+ ##### requestByName() {#requestbyname-3}
1909
+
1910
+ ```ts
1911
+ abstract requestByName(name, command?): Promise<ServerResponse>;
1912
+ ```
1913
+
1914
+ Sends a raw request to the engine and resolves to its reply. Rejects with the reply when it carries an error.
1915
+
1916
+ ###### Parameters
1917
+
1918
+ | Parameter | Type | Description |
1919
+ | :------ | :------ | :------ |
1920
+ | `name` | `string` | Names the request on the transport: the event of the ClassCAD server ([SocketIOClient](#socketioclient)); the other clients ignore it. |
1921
+ | `command?` | [`ServerRequest`](advanced/connection.md#serverrequest) | The request. |
1922
+
1923
+ ###### Returns
1924
+
1925
+ `Promise`&lt;[`ServerResponse`](advanced/connection.md#serverresponse)&gt;
1926
+
1927
+ ##### requestTree() {#requesttree-3}
1928
+
1929
+ ```ts
1930
+ requestTree(): Promise<ServerResponse>;
1931
+ ```
1932
+
1933
+ Loads the drawing's structure tree from the engine and sets it in the SDK's store.
1934
+
1935
+ ###### Returns
1936
+
1937
+ `Promise`&lt;[`ServerResponse`](advanced/connection.md#serverresponse)&gt;
1938
+
1939
+ ###### Implementation of
1940
+
1941
+ [`IComClient`](advanced/connection.md#icomclient).[`requestTree`](advanced/connection.md#requesttree)
1942
+
1943
+ ##### revokeInvite() {#revokeinvite-3}
1944
+
1945
+ ```ts
1946
+ revokeInvite(invite): Promise<{
1947
+ invite: string;
1948
+ kicked: number;
1949
+ revoked: boolean;
1950
+ }>;
1951
+ ```
1952
+
1953
+ Revokes a token and kicks the guests using it.
1954
+
1955
+ ###### Parameters
1956
+
1957
+ | Parameter | Type | Description |
1958
+ | :------ | :------ | :------ |
1959
+ | `invite` | `string` | The invite token. |
1960
+
1961
+ ###### Returns
1962
+
1963
+ `Promise`&lt;\{
1964
+ `invite`: `string`;
1965
+ `kicked`: `number`;
1966
+ `revoked`: `boolean`;
1967
+ \}&gt;
1968
+
1969
+ The token, whether it was revoked, and how many guests were cut off.
1970
+
1971
+ ##### sendPresence() {#sendpresence-3}
1972
+
1973
+ ```ts
1974
+ sendPresence(channel, data): void;
1975
+ ```
1976
+
1977
+ Fire-and-forget presence broadcast to session siblings (camera, cursor …). No-op on non-sharing transports.
1978
+
1979
+ ###### Parameters
1980
+
1981
+ | Parameter | Type | Description |
1982
+ | :------ | :------ | :------ |
1983
+ | `channel` | `string` | The channel, e.g. `'view'` for a camera viewpoint; others get it in their `presence` event. |
1984
+ | `data` | `Record`&lt;`string`, `any`&gt; | The payload, sent as it is. A frame larger than 8 KB is dropped. |
1985
+
1986
+ ###### Returns
1987
+
1988
+ `void`
1989
+
1990
+ ##### setEmissionConfig() {#setemissionconfig-3}
1991
+
1992
+ ```ts
1993
+ setEmissionConfig(partial): Promise<EmissionConfig>;
1994
+ ```
1995
+
1996
+ Merges `partial` into the emission config of this connection and resolves to the effective flags.
1997
+
1998
+ The engine keeps the config for every command that follows, until it is changed again. Rejects with an Error
1999
+ named [EMISSION\_CONFIG\_UNSUPPORTED](advanced/connection.md#emission_config_unsupported) on engines that predate the command. [EmissionConfig](advanced/connection.md#emissionconfig) has an
2000
+ example, and [onClient](#onclient) sets flags as every client connects.
2001
+
2002
+ ###### Parameters
2003
+
2004
+ | Parameter | Type | Description |
2005
+ | :------ | :------ | :------ |
2006
+ | `partial` | `Partial`&lt;[`EmissionConfig`](advanced/connection.md#emissionconfig)&gt; | The flags to change; the others stay as they are. |
2007
+
2008
+ ###### Returns
2009
+
2010
+ `Promise`&lt;[`EmissionConfig`](advanced/connection.md#emissionconfig)&gt;
2011
+
2012
+ ###### Implementation of
2013
+
2014
+ [`IComClient`](advanced/connection.md#icomclient).[`setEmissionConfig`](advanced/connection.md#setemissionconfig)
2015
+
2016
+ ##### undo() {#undo-3}
2017
+
2018
+ ```ts
2019
+ abstract undo(options?): Promise<ServerResponse>;
2020
+ ```
2021
+
2022
+ Steps back in the drawing's undo history: to `options.state` when given. The ClassCAD server
2023
+ ([SocketIOClient](#socketioclient)) keeps that history.
2024
+
2025
+ ###### Parameters
2026
+
2027
+ | Parameter | Type | Description |
2028
+ | :------ | :------ | :------ |
2029
+ | `options?` | [`UndoOptions`](advanced/connection.md#undooptions) | The state to go back to, and options for the engine. |
2030
+
2031
+ ###### Returns
2032
+
2033
+ `Promise`&lt;[`ServerResponse`](advanced/connection.md#serverresponse)&gt;
2034
+
2035
+ ###### Implementation of
2036
+
2037
+ [`IComClient`](advanced/connection.md#icomclient).[`undo`](advanced/connection.md#undo)
2038
+
2039
+ #### Properties
2040
+
2041
+ | Property | Modifier | Type | Default value | Description |
2042
+ | :------ | :------ | :------ | :------ | :------ |
2043
+ | <a id="property-invitename-3"></a> `inviteName` | `public` | `string` | `''` | Name of the invite this connection joined with ('' for the host or unnamed tokens). |
2044
+ | <a id="property-role-3"></a> `role` | `public` | [`SessionRole`](session-sharing.md#sessionrole) | `'edit'` | This connection's role within a shared session ('edit' unless a guest with a view invite). |
2045
+ | <a id="property-sharekind-3"></a> `shareKind` | `public readonly` | `"invite"` \| `null` | `null` | How this client's invites are honoured; null = this client cannot share. |