@netless/window-manager 0.4.54 → 0.4.56
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/CHANGELOG.md +10 -0
- package/README.zh-cn.md +1 -0
- package/dist/{index.cjs.js → index.js} +3 -3
- package/dist/index.js.map +1 -0
- package/dist/{index.es.js → index.mjs} +3 -3
- package/dist/index.mjs.map +1 -0
- package/docs/advanced.md +55 -55
- package/docs/api.md +116 -114
- package/docs/app-context.md +213 -213
- package/docs/basic.md +25 -26
- package/docs/camera.md +19 -20
- package/docs/cn/advanced.md +137 -0
- package/docs/cn/api.md +309 -0
- package/docs/cn/app-context.md +369 -0
- package/docs/cn/basic.md +64 -0
- package/docs/cn/camera.md +53 -0
- package/docs/cn/concept.md +9 -0
- package/docs/cn/custom-max-bar.md +31 -0
- package/docs/cn/develop-app.md +94 -0
- package/docs/cn/export-pdf.md +48 -0
- package/docs/cn/migrate.md +60 -0
- package/docs/cn/replay.md +40 -0
- package/docs/concept.md +6 -5
- package/docs/custom-max-bar.md +7 -7
- package/docs/develop-app.md +20 -20
- package/docs/export-pdf.md +20 -20
- package/docs/migrate.md +25 -27
- package/docs/quickstart.md +50 -0
- package/docs/replay.md +20 -20
- package/package.json +3 -3
- package/src/Helper.ts +1 -1
- package/vite.config.js +3 -1
- package/dist/index.cjs.js.map +0 -1
- package/dist/index.es.js.map +0 -1
- package/dist/index.umd.js +0 -60
- package/dist/index.umd.js.map +0 -1
- /package/docs/{qickstart.md → cn/quickstart.md} +0 -0
package/docs/app-context.md
CHANGED
@@ -1,369 +1,369 @@
|
|
1
1
|
## AppContext
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
- [
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
- [
|
11
|
-
- [
|
3
|
+
`AppContext` is the context passed in when the plugin runs.
|
4
|
+
You can operate the ui of the APP through this object, get the status of the current room, and subscribe to the status change.
|
5
|
+
|
6
|
+
- [API](#api)
|
7
|
+
- [View](#view)
|
8
|
+
- [Page](#page)
|
9
|
+
- [Storage](#storage)
|
10
|
+
- [UI (box)](#box)
|
11
|
+
- [Events](#events)
|
12
12
|
- [Advanced](#Advanced)
|
13
13
|
|
14
14
|
<h2 id="api">API</h2>
|
15
15
|
|
16
16
|
- **context.appId**
|
17
17
|
|
18
|
-
|
18
|
+
Unique ID generated when inserting `app`
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
```ts
|
21
|
+
const appId = context.appId;
|
22
|
+
```
|
23
23
|
|
24
24
|
- **context.isReplay**
|
25
25
|
|
26
|
-
|
26
|
+
Type: `boolean`
|
27
27
|
|
28
|
-
|
28
|
+
Whether the current playback mode
|
29
29
|
|
30
30
|
- **context.getDisplayer()**
|
31
31
|
|
32
|
-
|
32
|
+
By default `Displayer` is the `room` instance of the whiteboard
|
33
33
|
|
34
|
-
|
34
|
+
A `Player` instance during playback
|
35
35
|
|
36
|
-
|
37
|
-
|
36
|
+
```ts
|
37
|
+
const displayer = context.getDisplayer();
|
38
38
|
|
39
|
-
|
40
|
-
|
41
|
-
|
39
|
+
assert(displayer, room); // interactive room
|
40
|
+
assert(displayer, player); // playback room
|
41
|
+
```
|
42
42
|
|
43
43
|
|
44
44
|
- **context.getIsWritable()**
|
45
45
|
|
46
|
-
|
47
|
-
|
46
|
+
Get whether the current state is writable\
|
47
|
+
You can get the change of writable state by listening to `writableChange` event
|
48
48
|
|
49
|
-
|
50
|
-
|
51
|
-
|
49
|
+
```ts
|
50
|
+
const isWritable = context.getIsWritable();
|
51
|
+
```
|
52
52
|
|
53
53
|
- **context.getBox()**
|
54
54
|
|
55
|
-
|
55
|
+
Get the box of the current app
|
56
56
|
|
57
|
-
|
58
|
-
|
57
|
+
```ts
|
58
|
+
const box = context.getBox();
|
59
59
|
|
60
|
-
|
61
|
-
|
62
|
-
|
60
|
+
box.$content; // main element of the box
|
61
|
+
box.$footer;
|
62
|
+
```
|
63
63
|
|
64
|
-
<h3 id="view"
|
64
|
+
<h3 id="view">Mount whiteboard</h3>
|
65
65
|
|
66
|
-
|
66
|
+
When the application wants a whiteboard that can be drawn on, the following interface can be used
|
67
67
|
|
68
68
|
- **context.mountView()**
|
69
69
|
|
70
|
-
|
70
|
+
Mount the whiteboard to the specified dom
|
71
71
|
|
72
|
-
|
73
|
-
|
74
|
-
|
72
|
+
```ts
|
73
|
+
context.mountView(element);
|
74
|
+
```
|
75
75
|
|
76
|
-
|
76
|
+
**Note** When calling `addApp` of `manager`, you must fill in `scenePath` to use `view`
|
77
77
|
```ts
|
78
78
|
manager.addApp({
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
79
|
+
kind: "xxx",
|
80
|
+
options: { // optional configuration
|
81
|
+
scenePath: "/example-path"
|
82
|
+
}
|
83
83
|
})
|
84
84
|
```
|
85
85
|
|
86
86
|
<h3 id="page">Page</h3>
|
87
87
|
|
88
|
-
|
88
|
+
The whiteboard has the concept of multiple pages, which can be added, switched, and deleted through the following interfaces
|
89
89
|
|
90
90
|
- **context.addPage()**
|
91
91
|
|
92
|
-
|
92
|
+
Add a page to `view`
|
93
93
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
94
|
+
```ts
|
95
|
+
context.addPage() // add a page at the end by default
|
96
|
+
context.addPage({ after: true }) // add a page after the current page
|
97
|
+
context.addPage({ scene: { name: "page2" } }) // pass in page information
|
98
|
+
```
|
99
99
|
|
100
100
|
- **context.nextPage()**
|
101
101
|
|
102
|
-
|
102
|
+
previous page
|
103
103
|
|
104
|
-
|
105
|
-
|
106
|
-
|
104
|
+
```ts
|
105
|
+
context.nextPage();
|
106
|
+
```
|
107
107
|
|
108
108
|
- **context.prevPage()**
|
109
109
|
|
110
|
-
|
110
|
+
next page
|
111
111
|
|
112
|
-
|
113
|
-
|
114
|
-
|
112
|
+
```ts
|
113
|
+
context.prevPage();
|
114
|
+
```
|
115
115
|
- **context.removePage()**
|
116
116
|
|
117
|
-
|
117
|
+
delete a page
|
118
118
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
119
|
+
```ts
|
120
|
+
context.removePage() // delete the current page by default
|
121
|
+
context.removePage(1) // You can also specify index to delete
|
122
|
+
```
|
123
123
|
|
124
124
|
- **context.pageState**
|
125
125
|
|
126
|
-
|
127
|
-
|
126
|
+
Get the current `index` and how many pages there are\
|
127
|
+
When you want to monitor the change of `pageState`, you can listen to the `pageStateChange` event to get the latest `pageState`
|
128
128
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
129
|
+
```ts
|
130
|
+
context.pageState;
|
131
|
+
// {
|
132
|
+
// index: number,
|
133
|
+
// length: number,
|
134
|
+
// }
|
135
|
+
```
|
136
136
|
|
137
137
|
<h3 id="storage">storage</h3>
|
138
138
|
|
139
|
-
|
139
|
+
Store and synchronize state, and send a collection of events
|
140
140
|
|
141
141
|
- **context.storage**
|
142
142
|
|
143
|
-
|
143
|
+
Storage instance created by default
|
144
144
|
|
145
|
-
|
146
|
-
|
147
|
-
|
145
|
+
```ts
|
146
|
+
context.storage
|
147
|
+
```
|
148
148
|
|
149
149
|
- **context.createStorage(namespace)**
|
150
150
|
|
151
|
-
|
151
|
+
At the same time you can also create multiple `storage` instances
|
152
152
|
|
153
|
-
|
153
|
+
Returns: `Storage<State>`
|
154
154
|
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
155
|
+
```ts
|
156
|
+
type State = { count: number };
|
157
|
+
const defaultState = { count: 0 };
|
158
|
+
const storage = context.createStorage<State>("store1", defaultState);
|
159
|
+
```
|
160
160
|
|
161
161
|
- **storage.state**
|
162
162
|
|
163
|
-
|
164
|
-
|
163
|
+
Type: `State`\
|
164
|
+
Default: `defaultState`
|
165
165
|
|
166
|
-
|
166
|
+
State synchronized between all clients, call `storage.setState()` to change it.
|
167
167
|
|
168
168
|
- **storage.ensureState(partialState)**
|
169
169
|
|
170
|
-
|
170
|
+
Make sure `storage.state` contains some initial values, something like doing:
|
171
171
|
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
172
|
+
```js
|
173
|
+
// This code cannot be run directly because app.state is read-only
|
174
|
+
storage.state = { ...partialState, ...storage.state };
|
175
|
+
```
|
176
176
|
|
177
|
-
|
177
|
+
**partialState**
|
178
178
|
|
179
|
-
|
179
|
+
Type: `Partial<State>`
|
180
180
|
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
181
|
+
```js
|
182
|
+
storage.state; // { a: 1 }
|
183
|
+
storage.ensureState({ a: 0, b: 0 });
|
184
|
+
storage.state; // { a: 1, b: 0 }
|
185
|
+
```
|
186
186
|
|
187
187
|
- **storage.setState(partialState)**
|
188
188
|
|
189
|
-
|
189
|
+
Similar to React's `setState`, update `storage.state` and sync to all clients.
|
190
190
|
|
191
|
-
|
191
|
+
When setting a field to `undefined`, it will be removed from `storage.state`.
|
192
192
|
|
193
|
-
|
193
|
+
> The time required for state synchronization and the network state are related to the data size. It is recommended to only store necessary data in the state.
|
194
194
|
|
195
|
-
|
195
|
+
**partialState**
|
196
196
|
|
197
|
-
|
197
|
+
Type: `Partial<State>`
|
198
198
|
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
199
|
+
```js
|
200
|
+
storage.state; //=> { count: 0, a: 1 }
|
201
|
+
storage.setState({ count: storage.state.count + 1, b: 2 });
|
202
|
+
storage.state; //=> { count: 1, a: 1, b: 2 }
|
203
|
+
```
|
204
204
|
|
205
205
|
- **storage.addStateChangedListener(listener)**
|
206
206
|
|
207
|
-
|
207
|
+
It fires after someone calls `storage.setState()` (including the current `storage`)
|
208
208
|
|
209
|
-
|
209
|
+
return: `() => void`
|
210
210
|
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
211
|
+
```js
|
212
|
+
const disposer = storage.addStateChangedListener(diff => {
|
213
|
+
console.log("state changed", diff.oldValue, diff.newValue);
|
214
|
+
disposer(); // remove listener by calling disposer
|
215
|
+
});
|
216
|
+
```
|
217
217
|
|
218
218
|
- **context.dispatchMagixEvent(event, payload)**
|
219
219
|
|
220
|
-
|
220
|
+
Broadcast event messages to other clients
|
221
221
|
|
222
|
-
|
223
|
-
|
224
|
-
|
222
|
+
```js
|
223
|
+
context.dispatchMagixEvent("click", { data: "data" });
|
224
|
+
```
|
225
225
|
|
226
226
|
- **context.addMagixEventListener(event, listener)**
|
227
227
|
|
228
|
-
|
228
|
+
It is triggered when receiving messages from other clients (when other clients call `context.dispatchMagixEvent()`)
|
229
229
|
|
230
|
-
|
230
|
+
Returns: `() => void` a disposer function.
|
231
231
|
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
232
|
+
```js
|
233
|
+
const disposer = context.addMagixEventListener("click", ({ payload }) => {
|
234
|
+
console.log(payload.data);
|
235
|
+
disposer();
|
236
|
+
});
|
237
237
|
|
238
|
-
|
239
|
-
|
238
|
+
context.dispatchMagixEvent("click", { data: "data" });
|
239
|
+
```
|
240
240
|
|
241
241
|
<h2>UI (box)</h2>
|
242
242
|
|
243
|
-
|
244
|
-
|
243
|
+
Box is the default UI created by whiteboard for all apps.
|
244
|
+
All operable UI parts of the application are within the bounds of the box.
|
245
245
|
|
246
246
|
- **context.getBox()**
|
247
247
|
|
248
|
-
|
249
|
-
|
248
|
+
get box
|
249
|
+
Return type: `ReadonlyTeleBox`
|
250
250
|
|
251
251
|
- **box.mountStyles()**
|
252
252
|
|
253
|
-
|
254
|
-
|
253
|
+
Mount styles to `box`
|
254
|
+
Parameters: `string | HTMLStyleElement`
|
255
255
|
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
256
|
+
```js
|
257
|
+
const box = context. getBox();
|
258
|
+
box. mountStyles(`
|
259
|
+
.app-span {
|
260
|
+
color: red;
|
261
|
+
}
|
262
|
+
`)
|
263
|
+
```
|
264
264
|
|
265
265
|
- **box.mountContent()**
|
266
266
|
|
267
|
-
|
268
|
-
|
267
|
+
Mount element to `box`
|
268
|
+
Parameters: `HTMLElement`
|
269
269
|
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
270
|
+
```js
|
271
|
+
const box = context. getBox();
|
272
|
+
const content = document. createElement("div");
|
273
|
+
box. mountContent(context);
|
274
|
+
```
|
275
275
|
|
276
276
|
- **box.mountFooter()**
|
277
277
|
|
278
|
-
|
279
|
-
|
278
|
+
Mount element to `footer` of `box`
|
279
|
+
Parameters: `HTMLElement`
|
280
280
|
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
281
|
+
```js
|
282
|
+
const box = context. getBox();
|
283
|
+
const footer = document. createElement("div");
|
284
|
+
box. mountFooter(context);
|
285
|
+
```
|
286
286
|
|
287
287
|
<h2 id="events">events</h2>
|
288
288
|
|
289
289
|
- **destroy**
|
290
290
|
|
291
|
-
|
291
|
+
Sent when the app is closed
|
292
292
|
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
293
|
+
```ts
|
294
|
+
context.emitter.on("destroy", () => {
|
295
|
+
// release your listeners
|
296
|
+
});
|
297
|
+
```
|
298
298
|
|
299
299
|
- **writableChange**
|
300
300
|
|
301
|
-
|
301
|
+
Triggered when the whiteboard's writable state is switched
|
302
302
|
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
303
|
+
```ts
|
304
|
+
context.emitter.on("writableChange", isWritable => {
|
305
|
+
//
|
306
|
+
});
|
307
|
+
```
|
308
308
|
|
309
309
|
- **focus**
|
310
310
|
|
311
|
-
|
311
|
+
Triggered when the current app gains or loses focus
|
312
312
|
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
313
|
+
```ts
|
314
|
+
context.emitter.on("focus", focus => {
|
315
|
+
//
|
316
|
+
});
|
317
|
+
```
|
318
318
|
|
319
319
|
- **pageStateChange**
|
320
320
|
|
321
|
-
|
321
|
+
`PageState`
|
322
322
|
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
323
|
+
```ts
|
324
|
+
type PateState {
|
325
|
+
index: number;
|
326
|
+
length: number;
|
327
|
+
}
|
328
|
+
```
|
329
329
|
|
330
|
-
|
330
|
+
Triggered when the current page number and the total page number change
|
331
331
|
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
332
|
+
```ts
|
333
|
+
context.emitter.on("pageStateChange", pageState => {
|
334
|
+
// { index: 0, length: 1 }
|
335
|
+
});
|
336
|
+
```
|
337
337
|
- **roomStageChange**
|
338
338
|
|
339
|
-
|
340
|
-
|
339
|
+
Triggered when the state of the room changes\
|
340
|
+
For example, when teaching aids are switched
|
341
341
|
|
342
|
-
|
343
|
-
context.emitter.on("roomStageChange", stage => {
|
344
|
-
if (state.memberState) {
|
345
|
-
console.log("appliance change to", state.memberState.currentApplianceName);
|
346
|
-
}
|
347
|
-
});
|
348
|
-
```
|
349
|
-
|
350
|
-
或者是当前房间人数变化时
|
351
|
-
|
352
|
-
```js
|
342
|
+
```js
|
353
343
|
context.emitter.on("roomStageChange", stage => {
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
344
|
+
if (state. memberState) {
|
345
|
+
console.log("appliance change to", state.memberState.currentApplianceName);
|
346
|
+
}
|
347
|
+
});
|
348
|
+
```
|
349
|
+
|
350
|
+
or when the number of people in the current room changes
|
351
|
+
|
352
|
+
```js
|
353
|
+
context.emitter.on("roomStageChange", stage => {
|
354
|
+
if (state. roomMembers) {
|
355
|
+
console.log("current room members change", state.roomMembers);
|
356
|
+
}
|
357
|
+
});
|
358
|
+
```
|
359
|
+
For detailed status introduction, please refer to https://developer.netless.link/javascript-zh/home/business-state-management
|
360
360
|
|
361
361
|
<h2 id="Advanced">Advanced</h2>
|
362
362
|
|
363
363
|
- **context.getView()**
|
364
364
|
|
365
|
-
|
365
|
+
Get `view` instance
|
366
366
|
|
367
|
-
|
368
|
-
|
369
|
-
|
367
|
+
```ts
|
368
|
+
const view = context.getView();
|
369
|
+
```
|
package/docs/basic.md
CHANGED
@@ -1,64 +1,63 @@
|
|
1
|
-
#
|
2
|
-
`WindowManager`
|
1
|
+
# Basic Tutorial
|
2
|
+
`WindowManager` has built-in `DocsViewer` and `MediaPlayer` to play PPT and audio and video
|
3
3
|
|
4
|
-
##
|
4
|
+
## Open dynamic/static PPT
|
5
5
|
```typescript
|
6
6
|
import { BuiltinApps } from "@netless/window-manager";
|
7
7
|
|
8
8
|
const appId = await manager.addApp({
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
9
|
+
kind: BuiltinApps.DocsViewer,
|
10
|
+
options: {
|
11
|
+
scenePath: "/docs-viewer", // define the scenePath where the ppt is located
|
12
|
+
title: "docs1", // optional
|
13
|
+
scenes: [], // SceneDefinition[] static/dynamic Scene data
|
14
|
+
},
|
15
15
|
});
|
16
16
|
```
|
17
17
|
|
18
|
-
##
|
18
|
+
## Open audio and video
|
19
19
|
```typescript
|
20
20
|
import { BuiltinApps } from "@netless/window-manager";
|
21
21
|
|
22
22
|
const appId = await manager.addApp({
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
23
|
+
kind: BuiltinApps.MediaPlayer,
|
24
|
+
options: {
|
25
|
+
title: "test.mp3", // optional
|
26
|
+
},
|
27
|
+
attributes: {
|
28
|
+
src: "xxxx", // audio and video url
|
29
|
+
},
|
30
30
|
});
|
31
31
|
```
|
32
32
|
|
33
33
|
|
34
|
-
##
|
34
|
+
## Query all apps
|
35
35
|
```typescript
|
36
36
|
const apps = manager.queryAll();
|
37
37
|
```
|
38
38
|
|
39
|
-
##
|
39
|
+
## Query a single APP
|
40
40
|
```typescript
|
41
41
|
const app = manager.queryOne(appId);
|
42
|
-
```
|
42
|
+
```
|
43
43
|
|
44
|
-
##
|
44
|
+
## Close App
|
45
45
|
```typescript
|
46
46
|
manager.closeApp(appId);
|
47
47
|
```
|
48
48
|
|
49
49
|
## events
|
50
50
|
|
51
|
-
###
|
51
|
+
### Minimize and maximize the window
|
52
52
|
```typescript
|
53
53
|
manager.emitter.on("boxStateChange", state => {
|
54
|
-
|
54
|
+
// maximized | minimized | normal
|
55
55
|
});
|
56
56
|
```
|
57
57
|
|
58
|
-
###
|
58
|
+
### Camera follow mode
|
59
59
|
```typescript
|
60
60
|
manager.emitter.on("broadcastChange", state => {
|
61
|
-
|
61
|
+
// state: number | undefined
|
62
62
|
});
|
63
63
|
```
|
64
|
-
|