@camera.ui/sdk 0.0.1

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 (43) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/CONTRIBUTING.md +1 -0
  3. package/LICENSE.md +22 -0
  4. package/README.md +5 -0
  5. package/dist/camera/config.js +1 -0
  6. package/dist/camera/detection.js +1 -0
  7. package/dist/camera/device.js +1 -0
  8. package/dist/camera/index.js +5 -0
  9. package/dist/camera/streaming.js +1 -0
  10. package/dist/camera/types.js +1 -0
  11. package/dist/external.js +1 -0
  12. package/dist/index.d.ts +5042 -0
  13. package/dist/index.js +16 -0
  14. package/dist/manager/index.js +1 -0
  15. package/dist/manager/types.js +1 -0
  16. package/dist/plugin/contract.js +120 -0
  17. package/dist/plugin/index.js +3 -0
  18. package/dist/plugin/interfaces.js +1 -0
  19. package/dist/plugin/types.js +1 -0
  20. package/dist/sensor/audio.js +118 -0
  21. package/dist/sensor/base.js +460 -0
  22. package/dist/sensor/battery.js +101 -0
  23. package/dist/sensor/contact.js +33 -0
  24. package/dist/sensor/doorbell.js +63 -0
  25. package/dist/sensor/face.js +124 -0
  26. package/dist/sensor/guards.js +133 -0
  27. package/dist/sensor/index.js +19 -0
  28. package/dist/sensor/licensePlate.js +116 -0
  29. package/dist/sensor/light.js +66 -0
  30. package/dist/sensor/motion.js +103 -0
  31. package/dist/sensor/object.js +137 -0
  32. package/dist/sensor/ptz.js +159 -0
  33. package/dist/sensor/siren.js +73 -0
  34. package/dist/sensor/types.js +46 -0
  35. package/dist/service/base.js +96 -0
  36. package/dist/service/index.js +3 -0
  37. package/dist/service/services.js +1 -0
  38. package/dist/service/types.js +1 -0
  39. package/dist/storage/index.js +2 -0
  40. package/dist/storage/schema.js +1 -0
  41. package/dist/storage/storages.js +1 -0
  42. package/package.json +61 -0
  43. package/tsconfig.node.json +30 -0
package/dist/index.js ADDED
@@ -0,0 +1,16 @@
1
+ // External library re-exports
2
+ export * from './external.js';
3
+ // Schema definitions
4
+ export * from './storage/schema.js';
5
+ // Camera system
6
+ export * from './camera/index.js';
7
+ // Manager interfaces
8
+ export * from './manager/index.js';
9
+ // Plugin system
10
+ export * from './plugin/index.js';
11
+ // Sensor system
12
+ export * from './sensor/index.js';
13
+ // Service system
14
+ export * from './service/index.js';
15
+ // Storage system
16
+ export * from './storage/index.js';
@@ -0,0 +1 @@
1
+ export * from './types.js';
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,120 @@
1
+ import { SensorType } from '../sensor/types.js';
2
+ /**
3
+ * Validate a plugin contract
4
+ *
5
+ * @param contract - The contract to validate
6
+ *
7
+ * @returns Whether the contract is valid
8
+ */
9
+ export function validateContract(contract) {
10
+ if (!contract || typeof contract !== 'object') {
11
+ return false;
12
+ }
13
+ const c = contract;
14
+ // Required fields
15
+ if (!Array.isArray(c.provides))
16
+ return false;
17
+ if (!Array.isArray(c.consumes))
18
+ return false;
19
+ if (typeof c.name !== 'string' || c.name.length === 0)
20
+ return false;
21
+ // Validate sensor types
22
+ const validSensorTypes = Object.values(SensorType);
23
+ for (const type of c.provides) {
24
+ if (!validSensorTypes.includes(type)) {
25
+ return false;
26
+ }
27
+ }
28
+ for (const type of c.consumes) {
29
+ if (!validSensorTypes.includes(type)) {
30
+ return false;
31
+ }
32
+ }
33
+ // Optional fields validation
34
+ if (c.pythonVersion !== undefined) {
35
+ if (!['3.10', '3.11', '3.12'].includes(c.pythonVersion)) {
36
+ return false;
37
+ }
38
+ }
39
+ if (c.dependencies !== undefined && !Array.isArray(c.dependencies)) {
40
+ return false;
41
+ }
42
+ if (c.cameraController !== undefined && typeof c.cameraController !== 'boolean') {
43
+ return false;
44
+ }
45
+ return true;
46
+ }
47
+ /**
48
+ * Check if a plugin is a provider (provides any sensors)
49
+ *
50
+ * @param contract - The plugin contract to check
51
+ *
52
+ * @returns Whether the plugin is a provider
53
+ */
54
+ export function isProvider(contract) {
55
+ return contract.provides.length > 0;
56
+ }
57
+ /**
58
+ * Check if a plugin is a consumer (consumes any sensors)
59
+ *
60
+ * @param contract - The plugin contract to check
61
+ *
62
+ * @returns Whether the plugin is a consumer
63
+ */
64
+ export function isConsumer(contract) {
65
+ return contract.consumes.length > 0;
66
+ }
67
+ /**
68
+ * Check if a plugin is a pure hub (only consumes, doesn't provide)
69
+ *
70
+ * @param contract - The plugin contract to check
71
+ *
72
+ * @returns Whether the plugin is a pure hub
73
+ */
74
+ export function isHub(contract) {
75
+ return contract.provides.length === 0 && contract.consumes.length > 0;
76
+ }
77
+ /**
78
+ * Check if a plugin provides a specific sensor type
79
+ *
80
+ * @param contract - The plugin contract to check
81
+ *
82
+ * @param type - The sensor type to check
83
+ *
84
+ * @returns Whether the plugin provides the sensor type
85
+ */
86
+ export function providesSensor(contract, type) {
87
+ return contract.provides.includes(type);
88
+ }
89
+ /**
90
+ * Check if a plugin consumes a specific sensor type
91
+ *
92
+ * @param contract - The plugin contract to check
93
+ *
94
+ * @param type - The sensor type to check
95
+ *
96
+ * @returns Whether the plugin consumes the sensor type
97
+ */
98
+ export function consumesSensor(contract, type) {
99
+ return contract.consumes.includes(type);
100
+ }
101
+ /**
102
+ * Check if a plugin is a camera controller (can create/manage cameras)
103
+ *
104
+ * @param contract - The plugin contract to check
105
+ *
106
+ * @returns Whether the plugin is a camera controller
107
+ */
108
+ export function isCameraController(contract) {
109
+ return contract.cameraController === true;
110
+ }
111
+ /**
112
+ * Check if a plugin is qualified (provides, consumes, or is camera controller)
113
+ *
114
+ * @param contract - The plugin contract to check
115
+ *
116
+ * @returns Whether the plugin is qualified
117
+ */
118
+ export function isQualifiedContract(contract) {
119
+ return contract.provides.length > 0 || contract.consumes.length > 0 || contract.cameraController === true;
120
+ }
@@ -0,0 +1,3 @@
1
+ export * from './contract.js';
2
+ export * from './interfaces.js';
3
+ export * from './types.js';
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,118 @@
1
+ import { Sensor } from './base.js';
2
+ import { SensorCategory, SensorType } from './types.js';
3
+ /**
4
+ * Audio sensor property keys
5
+ */
6
+ export var AudioProperty;
7
+ (function (AudioProperty) {
8
+ AudioProperty["Detected"] = "detected";
9
+ AudioProperty["Detections"] = "detections";
10
+ AudioProperty["Decibels"] = "decibels";
11
+ })(AudioProperty || (AudioProperty = {}));
12
+ /**
13
+ * Audio Sensor
14
+ *
15
+ * Base class for external audio detection (Ring, ONVIF events, etc.)
16
+ * Properties can be set directly: `sensor.detected = true`
17
+ *
18
+ * For audio-stream-based detection, use `AudioDetectorSensor` instead.
19
+ */
20
+ export class AudioSensor extends Sensor {
21
+ type = SensorType.Audio;
22
+ category = SensorCategory.Sensor;
23
+ name;
24
+ /**
25
+ * External audio sensors don't require audio frames.
26
+ * They receive detection events from external sources (APIs, ONVIF, etc.)
27
+ */
28
+ _requiresFrames = false;
29
+ constructor(name = 'Audio Sensor') {
30
+ super();
31
+ this.name = name;
32
+ // Initialize defaults
33
+ this.props.detected = false;
34
+ this.props.detections = [];
35
+ this.props.decibels = 0;
36
+ }
37
+ /** Whether audio event is currently detected */
38
+ get detected() {
39
+ return this.rawProps.detected;
40
+ }
41
+ /** Set audio detected state */
42
+ set detected(value) {
43
+ this.props.detected = value;
44
+ }
45
+ /** Current audio detections */
46
+ get detections() {
47
+ return this.rawProps.detections;
48
+ }
49
+ /** Set audio detections */
50
+ set detections(value) {
51
+ this.props.detections = value;
52
+ }
53
+ /** Current decibel level */
54
+ get decibels() {
55
+ return this.rawProps.decibels;
56
+ }
57
+ /** Set decibel level */
58
+ set decibels(value) {
59
+ this.props.decibels = value;
60
+ }
61
+ /**
62
+ * Update audio detection state
63
+ *
64
+ * @param detected - Whether audio event is currently detected
65
+ *
66
+ * @param detections - Array of detection events
67
+ *
68
+ * @param decibels - Current decibel level
69
+ */
70
+ setAudio(detected, detections = [], decibels) {
71
+ this.props.detected = detected;
72
+ this.props.detections = detections;
73
+ if (decibels !== undefined) {
74
+ this.props.decibels = decibels;
75
+ }
76
+ }
77
+ /** Clear audio detection state */
78
+ clearAudio() {
79
+ this.props.detected = false;
80
+ this.props.detections = [];
81
+ this.props.decibels = 0;
82
+ }
83
+ }
84
+ /**
85
+ * Audio Detector Sensor (Active Detection)
86
+ *
87
+ * Use this class for audio-based event detection (glass break, screams, etc.)
88
+ * The `inputProperties` getter specifies the required audio input format.
89
+ *
90
+ * @example
91
+ * ```typescript
92
+ * class GlassBreakDetector extends AudioDetectorSensor {
93
+ * get inputProperties(): AudioInputProperties {
94
+ * return { sampleRate: 16000, channels: 1, format: 'pcm16' };
95
+ * }
96
+ *
97
+ * async detectAudio(audio: AudioData): Promise<AudioResult> {
98
+ * const events = await this.classifier.classify(audio.data);
99
+ * return {
100
+ * detected: events.some(e => e.label === 'glass_break'),
101
+ * detections: events.map(e => ({
102
+ * label: e.label,
103
+ * confidence: e.score,
104
+ * box: { x: 0, y: 0, width: 1, height: 1 },
105
+ * })),
106
+ * decibels: audio.decibels,
107
+ * };
108
+ * }
109
+ * }
110
+ * ```
111
+ */
112
+ export class AudioDetectorSensor extends AudioSensor {
113
+ /**
114
+ * Indicates this sensor requires audio frames for detection.
115
+ * Used by the backend to determine streaming requirements.
116
+ */
117
+ _requiresFrames = true;
118
+ }