Skip to content

Commit

Permalink
refactor: rename option to property
Browse files Browse the repository at this point in the history
  • Loading branch information
TzuHuanTai committed Feb 21, 2025
1 parent 8a61d42 commit 57aed14
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 25 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ npm install picamera.js
conn.connect();
```

- ### Set camera options while streaming.
- ### Set camera properties while streaming.

This example only set auto-focus and auto white balance. Other options see `CameraOptionType`.
This example only set auto-focus and auto white balance. Other properties see `CameraPropertyType`.

```javascript
let videoRef = document.getElementById('videoElement');
Expand All @@ -96,12 +96,12 @@ npm install picamera.js

// click the button with onclick="setAwb()" when it's connected
setAwb = () => {
conn.setCameraOption(CameraOptionType.AWB_MODE, AwbModeEnum.AwbCloudy);
conn.setCameraProperty(CameraPropertyType.AWB_MODE, AwbModeEnum.AwbCloudy);
}

// click the button with onclick="setCameraOption()" when it's connected
// click the button with onclick="setAf()" when it's connected
setAf = () => {
conn.setCameraOption(CameraOptionType.AF_MODE, AfModeEnum.AfModeContinuous);
conn.setCameraProperty(CameraPropertynType.AF_MODE, AfModeEnum.AfModeContinuous);
}
```

Expand Down Expand Up @@ -303,11 +303,11 @@ Available flags for initialization.

Retrieves the current connection status.

- ### setCameraOption
- ### setCameraProperty

`.setCameraOption(key: CameraOptionType, value: CameraOptionValue)`
`.setCameraProperty(key: CameraPropertyType, value: CameraPropertyValue)`

Sets the camera option, such as 3A or so.
Sets camera properties, such as 3A or so.

- ### snapshot

Expand Down
4 changes: 2 additions & 2 deletions src/rtc/camera-options.ts → src/rtc/camera-property.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

export enum CameraOptionType {
export enum CameraPropertyType {
AE_ENABLE = 1,
AE_LOCKED = 2,
AE_METERING_MODE = 3,
Expand Down Expand Up @@ -146,4 +146,4 @@ export enum HdrChannelEnum {
HdrChannelLong = 3,
};

export type CameraOptionValue = HdrChannelEnum | HdrModeEnum | AfPauseStateEnum | AfStateEnum | AfPauseEnum | AfTriggerEnum | AfMeteringEnum | AfSpeedEnum | AfRangeEnum | AfModeEnum | AwbModeEnum | AeFlickerModeEnum | AeExposureModeEnum | AeConstraintModeEnum | AeMeteringModeEnum;
export type CameraPropertyValue = HdrChannelEnum | HdrModeEnum | AfPauseStateEnum | AfStateEnum | AfPauseEnum | AfTriggerEnum | AfMeteringEnum | AfSpeedEnum | AfRangeEnum | AfModeEnum | AwbModeEnum | AeFlickerModeEnum | AeExposureModeEnum | AeConstraintModeEnum | AeMeteringModeEnum;
10 changes: 5 additions & 5 deletions src/rtc/message.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CameraOptionType, CameraOptionValue } from "./camera-options";
import { CameraPropertyType, CameraPropertyValue } from "./camera-property";
import { CommandType, MetadataCommand } from "./command";

export class RtcMessage {
Expand Down Expand Up @@ -35,11 +35,11 @@ export type VideoMetadata = {
path: string;
}

export class CameraOptionMessage {
key: CameraOptionType;
value: CameraOptionValue;
export class CameraCtlMessage {
key: CameraPropertyType;
value: CameraPropertyValue;

constructor(key: CameraOptionType, value: CameraOptionValue) {
constructor(key: CameraPropertyType, value: CameraPropertyValue) {
this.key = key;
this.value = value;
}
Expand Down
10 changes: 5 additions & 5 deletions src/rtc/pi-camera.interface.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

import { CodecType } from '../utils/rtc-tools';
import { CameraOptionType, CameraOptionValue } from './camera-options';
import { CameraPropertyType, CameraPropertyValue } from './camera-property';
import { IMqttConnectionOptions } from '../mqtt/mqtt-client.interface';
import { VideoMetadata } from './message';

Expand Down Expand Up @@ -105,11 +105,11 @@ export interface IPiCamera {
fetchRecordedVideo(path: string): void;

/**
* Sets the camera option, such as 3A or so.
* @param key Camera Option Type
* @param value Value of the Camera Option
* Sets the camera property, such as 3A or so.
* @param key Camera property type
* @param value Value of the camera property
*/
setCameraOption(key: CameraOptionType, value: CameraOptionValue): void;
setCameraProperty(key: CameraPropertyType, value: CameraPropertyValue): void;

/**
* Requests a snapshot image from the server.
Expand Down
10 changes: 5 additions & 5 deletions src/rtc/pi-camera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import {
} from '../utils/rtc-tools';
import { CommandType, MetadataCommand } from './command';
import { DEFAULT_TIMEOUT, MQTT_ICE_TOPIC, MQTT_SDP_TOPIC } from '../constants';
import { CameraOptionMessage, MetaCmdMessage, RtcMessage, VideoMetadata } from './message';
import { CameraCtlMessage, MetaCmdMessage, RtcMessage, VideoMetadata } from './message';
import { IPiCamera, IPiCameraOptions } from './pi-camera.interface';
import { CameraOptionType, CameraOptionValue } from './camera-options';
import { CameraPropertyType, CameraPropertyValue } from './camera-property';
import { addWatermarkToImage, addWatermarkToStream } from '../utils/watermark';
import { DataChannelReceiver } from './datachannel-receiver';

Expand Down Expand Up @@ -148,10 +148,10 @@ export class PiCamera implements IPiCamera {
}
}

setCameraOption = (key: CameraOptionType, value: CameraOptionValue) => {
setCameraProperty = (key: CameraPropertyType, value: CameraPropertyValue) => {
if (this.dataChannel?.readyState === 'open') {
const option = new CameraOptionMessage(key, value);
const command = new RtcMessage(CommandType.CAMERA_CONTROL, JSON.stringify(option));
const ctl = new CameraCtlMessage(key, value);
const command = new RtcMessage(CommandType.CAMERA_CONTROL, JSON.stringify(ctl));
this.dataChannel.send(command.ToString());
}
}
Expand Down

0 comments on commit 57aed14

Please sign in to comment.