@kubohiroya/turbowarp-camera-source 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.ja.md +25 -2
- package/README.md +73 -2
- package/dist/camera-source.js +146 -9
- package/dist/extension-manifest.json +54 -0
- package/package.json +21 -18
package/README.ja.md
CHANGED
|
@@ -26,13 +26,13 @@ TurboWarp-Camera-Sourceは、MediaDevicesのカメラストリームを名前付
|
|
|
26
26
|
次のURLをunsandboxed custom extensionとして読み込みます。
|
|
27
27
|
|
|
28
28
|
```text
|
|
29
|
-
https://cdn.jsdelivr.net/npm/@kubohiroya/turbowarp-camera-source@0.
|
|
29
|
+
https://cdn.jsdelivr.net/npm/@kubohiroya/turbowarp-camera-source@0.5.0/dist/camera-source.js
|
|
30
30
|
```
|
|
31
31
|
|
|
32
32
|
npm hostでは次を使います。
|
|
33
33
|
|
|
34
34
|
```bash
|
|
35
|
-
pnpm add @kubohiroya/turbowarp-camera-source@0.
|
|
35
|
+
pnpm add @kubohiroya/turbowarp-camera-source@0.5.0
|
|
36
36
|
```
|
|
37
37
|
|
|
38
38
|
## Quick start
|
|
@@ -41,6 +41,10 @@ pnpm add @kubohiroya/turbowarp-camera-source@0.4.0
|
|
|
41
41
|
|
|
42
42
|
```text
|
|
43
43
|
start shared camera [pose] with device ID []
|
|
44
|
+
show shared camera [pose] preview mirrored [true]
|
|
45
|
+
shared camera [pose] frame width
|
|
46
|
+
shared camera [pose] frame rate
|
|
47
|
+
hide shared camera [pose] preview
|
|
44
48
|
start shared camera [qr] with device ID []
|
|
45
49
|
shared camera [pose] is running?
|
|
46
50
|
stop shared camera [pose]
|
|
@@ -52,6 +56,11 @@ stop shared camera [pose]
|
|
|
52
56
|
- `stop shared camera [CAMERA_ID]`: 名前付き共有カメラを停止し、MediaStreamTrackを解放します。
|
|
53
57
|
- `shared camera [CAMERA_ID] is running?`: 指定した共有カメラが起動中かを返します。
|
|
54
58
|
- `shared camera [CAMERA_ID] device ID`: 指定した共有カメラのdevice IDを返します。
|
|
59
|
+
- `show shared camera [CAMERA_ID] preview mirrored [MIRRORED]`: GPU-backed stage previewを表示します。
|
|
60
|
+
- `hide shared camera [CAMERA_ID] preview`: ブロックが所有するpreview leaseだけを解放して非表示にします。
|
|
61
|
+
- `shared camera [CAMERA_ID] frame width`: 実際のframe幅をpixel単位で返します。
|
|
62
|
+
- `shared camera [CAMERA_ID] frame height`: 実際のframe高さをpixel単位で返します。
|
|
63
|
+
- `shared camera [CAMERA_ID] frame rate`: 有効なvideo trackのframe rateを返します。
|
|
55
64
|
- `refresh camera devices`: カメラデバイス一覧を更新します。
|
|
56
65
|
- `camera device count`: 更新済みカメラデバイス数を返します。
|
|
57
66
|
- `camera device ID at [INDEX]`: 1始まりの位置でカメラdevice IDを返します。
|
|
@@ -91,6 +100,17 @@ await poseLease.release();
|
|
|
91
100
|
複数のpreview leaseが同じカメラを共有する場合、1つ以上の有効なleaseが`mirrored: true`を要求している間は
|
|
92
101
|
previewを左右反転します。
|
|
93
102
|
|
|
103
|
+
TurboWarp作品からは`show shared camera ... preview`と`hide shared camera ... preview`ブロックで同じ
|
|
104
|
+
表示経路を操作できます。showブロックが所有するpreview leaseはcamera IDごとに1つだけです。同じ設定で
|
|
105
|
+
繰り返し実行してもleaseやdrawableは増えず、`MIRRORED`を変更した場合は既存camera sessionを維持したまま
|
|
106
|
+
leaseを置換します。`MIRRORED`には`true`または`false`など、TurboWarpがbooleanとして解釈できる値を指定します。
|
|
107
|
+
hideはブロック所有の表示leaseだけを解放するため、ほかのブロックや拡張が所有する処理用leaseは継続します。
|
|
108
|
+
名前付きcameraの停止、作品の停止・再読込、runtime disposeではブロック所有resourceをすべて解放します。
|
|
109
|
+
|
|
110
|
+
frame widthとheightは、video elementが現在受信している寸法を優先し、最初のframeより前はvideo track設定を
|
|
111
|
+
fallbackとして使います。frame rateは有効なvideo track設定を返します。cameraが未起動の場合、またはブラウザが
|
|
112
|
+
値を提供しない場合、これら3つのreporterは`0`を返します。
|
|
113
|
+
|
|
94
114
|
`frame.element`はpreviewを左右反転した場合も未加工の`HTMLVideoElement`です。そのためWebGPUや
|
|
95
115
|
WebCodecsのconsumerは、CPU canvasやpreviewを経由せず、同じsourceを
|
|
96
116
|
`GPUQueue.copyExternalImageToTexture()`や短時間だけ保持する`VideoFrame`へ渡せます。consumerが生成した
|
|
@@ -104,6 +124,9 @@ Scratchのtouchingまたはcolor sensing用の画像sourceとしては扱いま
|
|
|
104
124
|
|
|
105
125
|
## 互換性
|
|
106
126
|
|
|
127
|
+
0.5.0ではGPU-backed previewの表示・非表示・mirror設定と、実際のframe width/height/rateを
|
|
128
|
+
TurboWarpブロックとして公開します。既定動作は変更しません。
|
|
129
|
+
|
|
107
130
|
0.4.0ではopt-inのGPU-backed video previewを追加します。Extension ID、ブロックopcode、camera lease
|
|
108
131
|
ownership、device selection、release semanticsは変更しません。`preview: true`を指定しないconsumerは、
|
|
109
132
|
従来のcamera-source動作を維持します。
|
package/README.md
CHANGED
|
@@ -30,13 +30,13 @@ or select separate cameras for separate roles.
|
|
|
30
30
|
Load this URL as an unsandboxed custom extension:
|
|
31
31
|
|
|
32
32
|
```text
|
|
33
|
-
https://cdn.jsdelivr.net/npm/@kubohiroya/turbowarp-camera-source@0.
|
|
33
|
+
https://cdn.jsdelivr.net/npm/@kubohiroya/turbowarp-camera-source@0.5.0/dist/camera-source.js
|
|
34
34
|
```
|
|
35
35
|
|
|
36
36
|
For npm hosts:
|
|
37
37
|
|
|
38
38
|
```bash
|
|
39
|
-
pnpm add @kubohiroya/turbowarp-camera-source@0.
|
|
39
|
+
pnpm add @kubohiroya/turbowarp-camera-source@0.5.0
|
|
40
40
|
```
|
|
41
41
|
|
|
42
42
|
## Quick Start
|
|
@@ -45,6 +45,10 @@ Use role names for camera streams. Consumers that use the same `cameraId` share
|
|
|
45
45
|
|
|
46
46
|
```text
|
|
47
47
|
start shared camera [pose] with device ID []
|
|
48
|
+
show shared camera [pose] preview mirrored [true]
|
|
49
|
+
shared camera [pose] frame width
|
|
50
|
+
shared camera [pose] frame rate
|
|
51
|
+
hide shared camera [pose] preview
|
|
48
52
|
start shared camera [qr] with device ID []
|
|
49
53
|
shared camera [pose] is running?
|
|
50
54
|
stop shared camera [pose]
|
|
@@ -95,6 +99,57 @@ Returns the active device ID for a named shared camera when available.
|
|
|
95
99
|
| Opcode | `cameraDeviceIdReporter` |
|
|
96
100
|
| `CAMERA_ID` | String, default: `default` |
|
|
97
101
|
|
|
102
|
+
### `show shared camera [CAMERA_ID] preview mirrored [MIRRORED]`
|
|
103
|
+
|
|
104
|
+
Shows the named shared camera with the GPU-backed stage preview.
|
|
105
|
+
|
|
106
|
+
| Property | Value |
|
|
107
|
+
|---|---|
|
|
108
|
+
| Type | Command |
|
|
109
|
+
| Opcode | `showCameraPreview` |
|
|
110
|
+
| `CAMERA_ID` | String, default: `default` |
|
|
111
|
+
| `MIRRORED` | String, default: `true` |
|
|
112
|
+
|
|
113
|
+
### `hide shared camera [CAMERA_ID] preview`
|
|
114
|
+
|
|
115
|
+
Hides the block-owned preview without stopping leases owned by other consumers.
|
|
116
|
+
|
|
117
|
+
| Property | Value |
|
|
118
|
+
|---|---|
|
|
119
|
+
| Type | Command |
|
|
120
|
+
| Opcode | `hideCameraPreview` |
|
|
121
|
+
| `CAMERA_ID` | String, default: `default` |
|
|
122
|
+
|
|
123
|
+
### `shared camera [CAMERA_ID] frame width`
|
|
124
|
+
|
|
125
|
+
Returns the active video frame width in pixels, or zero while the camera is not running.
|
|
126
|
+
|
|
127
|
+
| Property | Value |
|
|
128
|
+
|---|---|
|
|
129
|
+
| Type | Reporter |
|
|
130
|
+
| Opcode | `cameraFrameWidth` |
|
|
131
|
+
| `CAMERA_ID` | String, default: `default` |
|
|
132
|
+
|
|
133
|
+
### `shared camera [CAMERA_ID] frame height`
|
|
134
|
+
|
|
135
|
+
Returns the active video frame height in pixels, or zero while the camera is not running.
|
|
136
|
+
|
|
137
|
+
| Property | Value |
|
|
138
|
+
|---|---|
|
|
139
|
+
| Type | Reporter |
|
|
140
|
+
| Opcode | `cameraFrameHeight` |
|
|
141
|
+
| `CAMERA_ID` | String, default: `default` |
|
|
142
|
+
|
|
143
|
+
### `shared camera [CAMERA_ID] frame rate`
|
|
144
|
+
|
|
145
|
+
Returns the active video track frame rate, or zero when it is unavailable.
|
|
146
|
+
|
|
147
|
+
| Property | Value |
|
|
148
|
+
|---|---|
|
|
149
|
+
| Type | Reporter |
|
|
150
|
+
| Opcode | `cameraFrameRate` |
|
|
151
|
+
| `CAMERA_ID` | String, default: `default` |
|
|
152
|
+
|
|
98
153
|
### `refresh camera devices`
|
|
99
154
|
|
|
100
155
|
Refreshes the browser camera device list.
|
|
@@ -174,6 +229,19 @@ released.
|
|
|
174
229
|
If multiple preview leases share a camera, the preview is mirrored while any active preview lease
|
|
175
230
|
requests `mirrored: true`.
|
|
176
231
|
|
|
232
|
+
TurboWarp projects can manage the same display path with the `show shared camera ... preview`
|
|
233
|
+
and `hide shared camera ... preview` blocks. The show block owns exactly one preview lease per
|
|
234
|
+
camera ID. Calling it repeatedly with the same setting is idempotent; changing `MIRRORED` replaces
|
|
235
|
+
that lease without creating another drawable. `MIRRORED` accepts TurboWarp boolean text such as
|
|
236
|
+
`true` and `false`. Hiding the preview releases only the block-owned display lease, so processing
|
|
237
|
+
leases held by other blocks or extensions continue running. Stopping the named camera, stopping or
|
|
238
|
+
loading a project, and disposing the runtime release the block-owned camera and preview resources.
|
|
239
|
+
|
|
240
|
+
The frame width and height reporters prefer the dimensions currently delivered by the video
|
|
241
|
+
element and fall back to the active track settings before its first frame. The frame-rate reporter
|
|
242
|
+
uses the active track setting. All three reporters return `0` when the camera is not running or the
|
|
243
|
+
browser does not provide the value.
|
|
244
|
+
|
|
177
245
|
`frame.element` is the original, unmodified `HTMLVideoElement`, even when the preview is mirrored.
|
|
178
246
|
WebGPU and WebCodecs consumers can therefore use that same source without going through the preview
|
|
179
247
|
or a CPU canvas, for example with `GPUQueue.copyExternalImageToTexture()` or a short-lived
|
|
@@ -185,6 +253,9 @@ noninteractive; it is intended for display, not Scratch touching or color-sensin
|
|
|
185
253
|
|
|
186
254
|
## Compatibility
|
|
187
255
|
|
|
256
|
+
Version 0.5.0 exposes GPU-backed preview visibility, mirroring, and actual frame width, height,
|
|
257
|
+
and rate as TurboWarp blocks. The default behavior remains unchanged.
|
|
258
|
+
|
|
188
259
|
Version 0.4.0 adds the opt-in GPU-backed video preview without changing the extension ID,
|
|
189
260
|
block opcodes, camera lease ownership, device selection, or release semantics. Consumers that do
|
|
190
261
|
not request `preview: true` retain the existing camera-source behavior.
|
package/dist/camera-source.js
CHANGED
|
@@ -66,6 +66,62 @@
|
|
|
66
66
|
"defaultValue": "default"
|
|
67
67
|
} }
|
|
68
68
|
},
|
|
69
|
+
{
|
|
70
|
+
"opcode": "showCameraPreview",
|
|
71
|
+
"blockType": "COMMAND",
|
|
72
|
+
"text": "show shared camera [CAMERA_ID] preview mirrored [MIRRORED]",
|
|
73
|
+
"description": "Shows the named shared camera with the GPU-backed stage preview.",
|
|
74
|
+
"arguments": {
|
|
75
|
+
"CAMERA_ID": {
|
|
76
|
+
"type": "STRING",
|
|
77
|
+
"defaultValue": "default"
|
|
78
|
+
},
|
|
79
|
+
"MIRRORED": {
|
|
80
|
+
"type": "STRING",
|
|
81
|
+
"defaultValue": "true"
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
"opcode": "hideCameraPreview",
|
|
87
|
+
"blockType": "COMMAND",
|
|
88
|
+
"text": "hide shared camera [CAMERA_ID] preview",
|
|
89
|
+
"description": "Hides the block-owned preview without stopping leases owned by other consumers.",
|
|
90
|
+
"arguments": { "CAMERA_ID": {
|
|
91
|
+
"type": "STRING",
|
|
92
|
+
"defaultValue": "default"
|
|
93
|
+
} }
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
"opcode": "cameraFrameWidth",
|
|
97
|
+
"blockType": "REPORTER",
|
|
98
|
+
"text": "shared camera [CAMERA_ID] frame width",
|
|
99
|
+
"description": "Returns the active video frame width in pixels, or zero while the camera is not running.",
|
|
100
|
+
"arguments": { "CAMERA_ID": {
|
|
101
|
+
"type": "STRING",
|
|
102
|
+
"defaultValue": "default"
|
|
103
|
+
} }
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
"opcode": "cameraFrameHeight",
|
|
107
|
+
"blockType": "REPORTER",
|
|
108
|
+
"text": "shared camera [CAMERA_ID] frame height",
|
|
109
|
+
"description": "Returns the active video frame height in pixels, or zero while the camera is not running.",
|
|
110
|
+
"arguments": { "CAMERA_ID": {
|
|
111
|
+
"type": "STRING",
|
|
112
|
+
"defaultValue": "default"
|
|
113
|
+
} }
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
"opcode": "cameraFrameRate",
|
|
117
|
+
"blockType": "REPORTER",
|
|
118
|
+
"text": "shared camera [CAMERA_ID] frame rate",
|
|
119
|
+
"description": "Returns the active video track frame rate, or zero when it is unavailable.",
|
|
120
|
+
"arguments": { "CAMERA_ID": {
|
|
121
|
+
"type": "STRING",
|
|
122
|
+
"defaultValue": "default"
|
|
123
|
+
} }
|
|
124
|
+
},
|
|
69
125
|
{
|
|
70
126
|
"opcode": "refreshCameraDevices",
|
|
71
127
|
"blockType": "COMMAND",
|
|
@@ -302,8 +358,22 @@
|
|
|
302
358
|
constructor() {
|
|
303
359
|
this.sessions = /* @__PURE__ */ new Map();
|
|
304
360
|
this.blockLeases = /* @__PURE__ */ new Map();
|
|
361
|
+
this.blockPreviewLeases = /* @__PURE__ */ new Map();
|
|
362
|
+
this.blockPreviewRevisions = /* @__PURE__ */ new Map();
|
|
305
363
|
this.devices = [];
|
|
364
|
+
this.dispose = () => {
|
|
365
|
+
this.stopAllCameras();
|
|
366
|
+
Scratch.vm.runtime.off?.("PROJECT_STOP_ALL", this.handleProjectBoundary);
|
|
367
|
+
Scratch.vm.runtime.off?.("PROJECT_LOADED", this.handleProjectBoundary);
|
|
368
|
+
Scratch.vm.runtime.off?.("RUNTIME_DISPOSED", this.dispose);
|
|
369
|
+
};
|
|
370
|
+
this.handleProjectBoundary = () => {
|
|
371
|
+
this.stopAllCameras();
|
|
372
|
+
};
|
|
306
373
|
Scratch.vm.runtime.ext_kubohiroyacamerasource = this;
|
|
374
|
+
Scratch.vm.runtime.on?.("PROJECT_STOP_ALL", this.handleProjectBoundary);
|
|
375
|
+
Scratch.vm.runtime.on?.("PROJECT_LOADED", this.handleProjectBoundary);
|
|
376
|
+
Scratch.vm.runtime.on?.("RUNTIME_DISPOSED", this.dispose);
|
|
307
377
|
}
|
|
308
378
|
getInfo() {
|
|
309
379
|
return {
|
|
@@ -319,6 +389,20 @@
|
|
|
319
389
|
cameraDeviceIdReporter(args = {}) {
|
|
320
390
|
return this.sessions.get(normalizeId(args.CAMERA_ID))?.activeDeviceId ?? "";
|
|
321
391
|
}
|
|
392
|
+
cameraFrameWidth(args = {}) {
|
|
393
|
+
const session = this.sessions.get(normalizeId(args.CAMERA_ID));
|
|
394
|
+
if (!session?.stream) return 0;
|
|
395
|
+
return session.video?.videoWidth || this.trackSetting(session, "width");
|
|
396
|
+
}
|
|
397
|
+
cameraFrameHeight(args = {}) {
|
|
398
|
+
const session = this.sessions.get(normalizeId(args.CAMERA_ID));
|
|
399
|
+
if (!session?.stream) return 0;
|
|
400
|
+
return session.video?.videoHeight || this.trackSetting(session, "height");
|
|
401
|
+
}
|
|
402
|
+
cameraFrameRate(args = {}) {
|
|
403
|
+
const session = this.sessions.get(normalizeId(args.CAMERA_ID));
|
|
404
|
+
return session?.stream ? this.trackSetting(session, "frameRate") : 0;
|
|
405
|
+
}
|
|
322
406
|
async startSharedCamera(args = {}) {
|
|
323
407
|
const cameraId = normalizeId(args.CAMERA_ID);
|
|
324
408
|
if (this.blockLeases.has(cameraId)) return;
|
|
@@ -366,6 +450,36 @@
|
|
|
366
450
|
}
|
|
367
451
|
});
|
|
368
452
|
}
|
|
453
|
+
async showCameraPreview(args = {}) {
|
|
454
|
+
const cameraId = normalizeId(args.CAMERA_ID);
|
|
455
|
+
const mirrored = Scratch.Cast.toBoolean(args.MIRRORED ?? true);
|
|
456
|
+
if (this.blockPreviewLeases.get(cameraId)?.mirrored === mirrored) return;
|
|
457
|
+
const revision = this.nextPreviewBlockRevision(cameraId);
|
|
458
|
+
const lease = await this.acquireCamera({
|
|
459
|
+
owner: "camera-source-preview-block",
|
|
460
|
+
cameraId,
|
|
461
|
+
preview: true,
|
|
462
|
+
mirrored
|
|
463
|
+
});
|
|
464
|
+
if (this.blockPreviewRevisions.get(cameraId) !== revision) {
|
|
465
|
+
await lease.release();
|
|
466
|
+
return;
|
|
467
|
+
}
|
|
468
|
+
const current = this.blockPreviewLeases.get(cameraId);
|
|
469
|
+
this.blockPreviewLeases.set(cameraId, {
|
|
470
|
+
lease,
|
|
471
|
+
mirrored
|
|
472
|
+
});
|
|
473
|
+
await current?.lease.release();
|
|
474
|
+
}
|
|
475
|
+
async hideCameraPreview(args = {}) {
|
|
476
|
+
const cameraId = normalizeId(args.CAMERA_ID);
|
|
477
|
+
this.nextPreviewBlockRevision(cameraId);
|
|
478
|
+
const existing = this.blockPreviewLeases.get(cameraId);
|
|
479
|
+
if (!existing) return;
|
|
480
|
+
this.blockPreviewLeases.delete(cameraId);
|
|
481
|
+
await existing.lease.release();
|
|
482
|
+
}
|
|
369
483
|
stopSharedCamera(args = {}) {
|
|
370
484
|
this.stopCameraSession(normalizeId(args.CAMERA_ID));
|
|
371
485
|
}
|
|
@@ -384,6 +498,7 @@
|
|
|
384
498
|
stopAllCameras() {
|
|
385
499
|
for (const cameraId of [...this.sessions.keys()]) this.stopCameraSession(cameraId);
|
|
386
500
|
this.blockLeases.clear();
|
|
501
|
+
this.blockPreviewLeases.clear();
|
|
387
502
|
}
|
|
388
503
|
session(cameraId) {
|
|
389
504
|
const existing = this.sessions.get(cameraId);
|
|
@@ -392,6 +507,7 @@
|
|
|
392
507
|
cameraId,
|
|
393
508
|
leases: /* @__PURE__ */ new Set(),
|
|
394
509
|
previewLeases: /* @__PURE__ */ new Map(),
|
|
510
|
+
active: true,
|
|
395
511
|
stream: null,
|
|
396
512
|
video: null,
|
|
397
513
|
preview: null,
|
|
@@ -406,26 +522,44 @@
|
|
|
406
522
|
session.mirrored = options.mirrored === true;
|
|
407
523
|
session.startPromise = (async () => {
|
|
408
524
|
const stream = await mediaDevices().getUserMedia(videoConstraints(options));
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
525
|
+
let video = null;
|
|
526
|
+
try {
|
|
527
|
+
if (!session.active) throw new Error("Camera acquisition was cancelled.");
|
|
528
|
+
video = document.createElement("video");
|
|
529
|
+
video.muted = true;
|
|
530
|
+
video.playsInline = true;
|
|
531
|
+
video.srcObject = stream;
|
|
532
|
+
await video.play();
|
|
533
|
+
if (!session.active) throw new Error("Camera acquisition was cancelled.");
|
|
534
|
+
session.stream = stream;
|
|
535
|
+
session.video = video;
|
|
536
|
+
this.updateActiveDevice(session);
|
|
537
|
+
} catch (error) {
|
|
538
|
+
stream.getTracks().forEach((track) => track.stop());
|
|
539
|
+
if (video) video.srcObject = null;
|
|
540
|
+
throw error;
|
|
541
|
+
}
|
|
417
542
|
})();
|
|
418
543
|
try {
|
|
419
544
|
await session.startPromise;
|
|
420
545
|
} catch (error) {
|
|
421
|
-
this.stopCameraSession(session.cameraId);
|
|
546
|
+
if (this.sessions.get(session.cameraId) === session) this.stopCameraSession(session.cameraId);
|
|
422
547
|
throw error;
|
|
423
548
|
}
|
|
424
549
|
}
|
|
550
|
+
nextPreviewBlockRevision(cameraId) {
|
|
551
|
+
const revision = (this.blockPreviewRevisions.get(cameraId) ?? 0) + 1;
|
|
552
|
+
this.blockPreviewRevisions.set(cameraId, revision);
|
|
553
|
+
return revision;
|
|
554
|
+
}
|
|
425
555
|
updateActiveDevice(session) {
|
|
426
556
|
const settings = (session.stream?.getVideoTracks()[0] ?? null)?.getSettings();
|
|
427
557
|
session.activeDeviceId = typeof settings?.deviceId === "string" ? settings.deviceId : "";
|
|
428
558
|
}
|
|
559
|
+
trackSetting(session, name) {
|
|
560
|
+
const value = session.stream?.getVideoTracks()[0]?.getSettings()[name];
|
|
561
|
+
return typeof value === "number" && Number.isFinite(value) ? value : 0;
|
|
562
|
+
}
|
|
429
563
|
ensurePreview(session) {
|
|
430
564
|
if (session.preview || !session.video) return;
|
|
431
565
|
const runtime = Scratch.vm.runtime;
|
|
@@ -448,6 +582,8 @@
|
|
|
448
582
|
stopCameraSession(cameraId) {
|
|
449
583
|
const session = this.sessions.get(cameraId);
|
|
450
584
|
if (!session) return;
|
|
585
|
+
session.active = false;
|
|
586
|
+
this.nextPreviewBlockRevision(cameraId);
|
|
451
587
|
session.preview?.dispose();
|
|
452
588
|
session.stream?.getTracks().forEach((track) => track.stop());
|
|
453
589
|
if (session.video) session.video.srcObject = null;
|
|
@@ -460,6 +596,7 @@
|
|
|
460
596
|
session.previewLeases.clear();
|
|
461
597
|
this.sessions.delete(cameraId);
|
|
462
598
|
this.blockLeases.delete(cameraId);
|
|
599
|
+
this.blockPreviewLeases.delete(cameraId);
|
|
463
600
|
}
|
|
464
601
|
toScratchBlock(block) {
|
|
465
602
|
return {
|
|
@@ -37,6 +37,46 @@
|
|
|
37
37
|
}
|
|
38
38
|
]
|
|
39
39
|
},
|
|
40
|
+
{
|
|
41
|
+
"opcode": "cameraFrameHeight",
|
|
42
|
+
"blockType": "REPORTER",
|
|
43
|
+
"arguments": [
|
|
44
|
+
{
|
|
45
|
+
"id": "CAMERA_ID",
|
|
46
|
+
"type": "STRING"
|
|
47
|
+
}
|
|
48
|
+
]
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"opcode": "cameraFrameRate",
|
|
52
|
+
"blockType": "REPORTER",
|
|
53
|
+
"arguments": [
|
|
54
|
+
{
|
|
55
|
+
"id": "CAMERA_ID",
|
|
56
|
+
"type": "STRING"
|
|
57
|
+
}
|
|
58
|
+
]
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
"opcode": "cameraFrameWidth",
|
|
62
|
+
"blockType": "REPORTER",
|
|
63
|
+
"arguments": [
|
|
64
|
+
{
|
|
65
|
+
"id": "CAMERA_ID",
|
|
66
|
+
"type": "STRING"
|
|
67
|
+
}
|
|
68
|
+
]
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
"opcode": "hideCameraPreview",
|
|
72
|
+
"blockType": "COMMAND",
|
|
73
|
+
"arguments": [
|
|
74
|
+
{
|
|
75
|
+
"id": "CAMERA_ID",
|
|
76
|
+
"type": "STRING"
|
|
77
|
+
}
|
|
78
|
+
]
|
|
79
|
+
},
|
|
40
80
|
{
|
|
41
81
|
"opcode": "isCameraRunning",
|
|
42
82
|
"blockType": "BOOLEAN",
|
|
@@ -52,6 +92,20 @@
|
|
|
52
92
|
"blockType": "COMMAND",
|
|
53
93
|
"arguments": []
|
|
54
94
|
},
|
|
95
|
+
{
|
|
96
|
+
"opcode": "showCameraPreview",
|
|
97
|
+
"blockType": "COMMAND",
|
|
98
|
+
"arguments": [
|
|
99
|
+
{
|
|
100
|
+
"id": "CAMERA_ID",
|
|
101
|
+
"type": "STRING"
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
"id": "MIRRORED",
|
|
105
|
+
"type": "STRING"
|
|
106
|
+
}
|
|
107
|
+
]
|
|
108
|
+
},
|
|
55
109
|
{
|
|
56
110
|
"opcode": "startSharedCamera",
|
|
57
111
|
"blockType": "COMMAND",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubohiroya/turbowarp-camera-source",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"author": "Hiroya Kubo <hiroya@cuc.ac.jp>",
|
|
5
5
|
"description": "A TurboWarp capability extension for sharing one MediaDevices camera stream across extensions.",
|
|
6
6
|
"type": "module",
|
|
@@ -29,9 +29,27 @@
|
|
|
29
29
|
"access": "public",
|
|
30
30
|
"registry": "https://registry.npmjs.org/"
|
|
31
31
|
},
|
|
32
|
+
"packageManager": "pnpm@11.18.0",
|
|
32
33
|
"engines": {
|
|
33
34
|
"node": ">=22.18.0"
|
|
34
35
|
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"dev": "vite build --watch",
|
|
38
|
+
"typecheck": "tsc --noEmit",
|
|
39
|
+
"build": "vite build",
|
|
40
|
+
"lint": "eslint src tests vite.config.ts",
|
|
41
|
+
"format": "eslint src tests vite.config.ts --fix",
|
|
42
|
+
"test": "vitest run",
|
|
43
|
+
"docs": "node scripts/generate-readme.ts",
|
|
44
|
+
"docs:check": "pnpm run docs && git diff --exit-code -- README.md",
|
|
45
|
+
"docs:pages:check": "node scripts/check-pages.ts",
|
|
46
|
+
"repo:check": "node scripts/check-repo.ts",
|
|
47
|
+
"pack:check": "npm pack --dry-run --ignore-scripts",
|
|
48
|
+
"release:check": "pnpm publish --dry-run --access public --no-git-checks",
|
|
49
|
+
"check": "pnpm run typecheck && pnpm run lint && pnpm run test && pnpm run docs:check && pnpm run docs:pages:check && pnpm run check:dist && pnpm run repo:check && pnpm run pack:check",
|
|
50
|
+
"check:dist": "pnpm run build && node scripts/check-dist.ts",
|
|
51
|
+
"prepack": "pnpm run check"
|
|
52
|
+
},
|
|
35
53
|
"devDependencies": {
|
|
36
54
|
"@eslint/js": "^9.39.5",
|
|
37
55
|
"@kubohiroya/vite-plugin-turbowarp-extension": "0.4.0",
|
|
@@ -49,20 +67,5 @@
|
|
|
49
67
|
"camera",
|
|
50
68
|
"media-devices",
|
|
51
69
|
"getusermedia"
|
|
52
|
-
]
|
|
53
|
-
|
|
54
|
-
"dev": "vite build --watch",
|
|
55
|
-
"typecheck": "tsc --noEmit",
|
|
56
|
-
"build": "vite build",
|
|
57
|
-
"lint": "eslint src tests vite.config.ts",
|
|
58
|
-
"test": "vitest run",
|
|
59
|
-
"docs": "node scripts/generate-readme.ts",
|
|
60
|
-
"docs:check": "pnpm run docs && git diff --exit-code -- README.md",
|
|
61
|
-
"docs:pages:check": "node scripts/check-pages.ts",
|
|
62
|
-
"repo:check": "node scripts/check-repo.ts",
|
|
63
|
-
"pack:check": "npm pack --dry-run --ignore-scripts",
|
|
64
|
-
"release:check": "pnpm publish --dry-run --access public --no-git-checks",
|
|
65
|
-
"check": "pnpm run typecheck && pnpm run lint && pnpm run test && pnpm run docs:check && pnpm run docs:pages:check && pnpm run check:dist && pnpm run repo:check && pnpm run pack:check",
|
|
66
|
-
"check:dist": "pnpm run build && node scripts/check-dist.ts"
|
|
67
|
-
}
|
|
68
|
-
}
|
|
70
|
+
]
|
|
71
|
+
}
|