@flighthq/webcam 0.4.0-next.1903.50bfa67 → 0.4.0-next.1908.751021c
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/package.json +3 -3
- package/src/webcam.test.ts +81 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flighthq/webcam",
|
|
3
|
-
"version": "0.4.0-next.
|
|
3
|
+
"version": "0.4.0-next.1908.751021c",
|
|
4
4
|
"author": "Joshua Granick and other contributors",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
"clean:dist": "tsx ../../scripts/clean-package-dist.ts"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@flighthq/entity": "0.4.0-next.
|
|
42
|
-
"@flighthq/types": "0.4.0-next.
|
|
41
|
+
"@flighthq/entity": "0.4.0-next.1908.751021c",
|
|
42
|
+
"@flighthq/types": "0.4.0-next.1908.751021c"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"typescript": "^5.3.0"
|
package/src/webcam.test.ts
CHANGED
|
@@ -8,6 +8,10 @@ import {
|
|
|
8
8
|
selectWebcamImage,
|
|
9
9
|
setWebcamBackend,
|
|
10
10
|
takeWebcamPhoto,
|
|
11
|
+
explainWebcamBackend,
|
|
12
|
+
installWebcamHostBackend,
|
|
13
|
+
observeWebcamHostResult,
|
|
14
|
+
resetWebcamBackendForTest,
|
|
11
15
|
} from './webcam';
|
|
12
16
|
|
|
13
17
|
function fakeBackend(): WebcamBackend & { lastOptions: WebcamCaptureOptions | null } {
|
|
@@ -36,6 +40,34 @@ describe('createWebWebcamBackend', () => {
|
|
|
36
40
|
});
|
|
37
41
|
});
|
|
38
42
|
|
|
43
|
+
describe('explainWebcamBackend', () => {
|
|
44
|
+
afterEach(() => resetWebcamBackendForTest());
|
|
45
|
+
|
|
46
|
+
it('reports host-not-enabled when no backend is installed', () => {
|
|
47
|
+
resetWebcamBackendForTest();
|
|
48
|
+
const explanation = explainWebcamBackend();
|
|
49
|
+
expect(explanation.layer).toBe('host-not-enabled');
|
|
50
|
+
expect(explanation.conflict).toBe(false);
|
|
51
|
+
expect(explanation.viability).toBe('unobserved');
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('reports custom layer when a custom backend is set', () => {
|
|
55
|
+
setWebcamBackend(fakeBackend());
|
|
56
|
+
expect(explainWebcamBackend().layer).toBe('custom');
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('reports host layer when a host backend is installed', () => {
|
|
60
|
+
installWebcamHostBackend(fakeBackend());
|
|
61
|
+
expect(explainWebcamBackend().layer).toBe('host');
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('reports conflict when two different host backends are installed', () => {
|
|
65
|
+
installWebcamHostBackend(fakeBackend());
|
|
66
|
+
installWebcamHostBackend(fakeBackend());
|
|
67
|
+
expect(explainWebcamBackend().conflict).toBe(true);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
|
|
39
71
|
describe('getWebcamBackend', () => {
|
|
40
72
|
it('falls back to a web backend', () => {
|
|
41
73
|
expect(getWebcamBackend()).not.toBeNull();
|
|
@@ -48,6 +80,43 @@ describe('getWebcamBackend', () => {
|
|
|
48
80
|
});
|
|
49
81
|
});
|
|
50
82
|
|
|
83
|
+
describe('installWebcamHostBackend', () => {
|
|
84
|
+
afterEach(() => resetWebcamBackendForTest());
|
|
85
|
+
|
|
86
|
+
it('installs a host backend that getWebcamBackend returns', () => {
|
|
87
|
+
const backend = fakeBackend();
|
|
88
|
+
installWebcamHostBackend(backend);
|
|
89
|
+
expect(getWebcamBackend()).toBe(backend);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('is first-host-wins: a second different backend sets conflict', () => {
|
|
93
|
+
const first = fakeBackend();
|
|
94
|
+
const second = fakeBackend();
|
|
95
|
+
installWebcamHostBackend(first);
|
|
96
|
+
installWebcamHostBackend(second);
|
|
97
|
+
expect(getWebcamBackend()).toBe(first);
|
|
98
|
+
expect(explainWebcamBackend().conflict).toBe(true);
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
describe('observeWebcamHostResult', () => {
|
|
103
|
+
afterEach(() => resetWebcamBackendForTest());
|
|
104
|
+
|
|
105
|
+
it('records a successful observation', () => {
|
|
106
|
+
installWebcamHostBackend(fakeBackend());
|
|
107
|
+
observeWebcamHostResult('capture', true);
|
|
108
|
+
const explanation = explainWebcamBackend();
|
|
109
|
+
expect(explanation.operation).toBe('capture');
|
|
110
|
+
expect(explanation.viability).toBe('available');
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('records a failed observation', () => {
|
|
114
|
+
installWebcamHostBackend(fakeBackend());
|
|
115
|
+
observeWebcamHostResult('capture', false);
|
|
116
|
+
expect(explainWebcamBackend().viability).toBe('runtime-api-unavailable');
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
|
|
51
120
|
describe('recordWebcamVideo', () => {
|
|
52
121
|
it('captures video with the camera source', async () => {
|
|
53
122
|
const backend = fakeBackend();
|
|
@@ -74,6 +143,18 @@ describe('requestWebcamPermission', () => {
|
|
|
74
143
|
});
|
|
75
144
|
});
|
|
76
145
|
|
|
146
|
+
describe('resetWebcamBackendForTest', () => {
|
|
147
|
+
it('clears all backend slots', () => {
|
|
148
|
+
setWebcamBackend(fakeBackend());
|
|
149
|
+
installWebcamHostBackend(fakeBackend());
|
|
150
|
+
observeWebcamHostResult('capture', true);
|
|
151
|
+
resetWebcamBackendForTest();
|
|
152
|
+
expect(explainWebcamBackend().layer).toBe('host-not-enabled');
|
|
153
|
+
expect(explainWebcamBackend().conflict).toBe(false);
|
|
154
|
+
expect(explainWebcamBackend().viability).toBe('unobserved');
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
|
|
77
158
|
describe('selectWebcamImage', () => {
|
|
78
159
|
it('captures with the photos source', async () => {
|
|
79
160
|
const backend = fakeBackend();
|