forked from ReolinkCameraAPI/reolinkapipy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from jaredcat/class-converstion-wip
some classes converted
- Loading branch information
Showing
25 changed files
with
1,032 additions
and
595 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
"eslint.enable": true, | ||
"files.eol": "\n", | ||
"cSpell.words": [ | ||
"bgcolor", | ||
"Rtsp" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,16 @@ | ||
import { Mixin } from 'ts-mixer'; | ||
import { AlarmAPIMixin } from '../mixins'; | ||
import DeviceAPIMixin from '../mixins/device'; | ||
import { | ||
AlarmAPIMixin, | ||
DeviceAPIMixin, | ||
DisplayAPIMixin, | ||
DownloadAPIMixin, | ||
ImageAPIMixin, | ||
} from '../mixins'; | ||
|
||
export default class APIHandler extends Mixin(AlarmAPIMixin, DeviceAPIMixin) {} | ||
export default class APIHandler extends Mixin( | ||
AlarmAPIMixin, | ||
DeviceAPIMixin, | ||
DisplayAPIMixin, | ||
DownloadAPIMixin, | ||
ImageAPIMixin, | ||
) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import { BaseAPIHandler } from '../handlers'; | ||
import CommandData, { OsdPos } from '../types/CommandData'; | ||
|
||
export interface SetOsdParams { | ||
Osd: { | ||
bgcolor: boolean; | ||
channel: number; | ||
osdChannel: { | ||
enable: boolean; | ||
name: string; | ||
pos: OsdPos; | ||
}; | ||
osdTime: { enable: boolean; pos: OsdPos }; | ||
watermark: boolean; | ||
}; | ||
} | ||
|
||
class DisplayAPIMixin extends BaseAPIHandler { | ||
/** | ||
* API calls related to the current image (osd, on screen display). | ||
*/ | ||
|
||
public async getOsd(): Promise<any> { | ||
/** | ||
* Get OSD information. | ||
* See examples/response/GetOsd.json for example response data. | ||
* @returns response json | ||
*/ | ||
const body: CommandData[] = [ | ||
{ cmd: 'GetOsd', action: 1, param: { channel: 0 } }, | ||
]; | ||
return this.executeCommand('GetOsd', body); | ||
} | ||
|
||
public async getMask(): Promise<any> { | ||
/** | ||
* Get the camera mask information. | ||
* See examples/response/GetMask.json for example response data. | ||
* @returns response json | ||
*/ | ||
const body: CommandData[] = [ | ||
{ cmd: 'GetMask', action: 1, param: { channel: 0 } }, | ||
]; | ||
return this.executeCommand('GetMask', body); | ||
} | ||
|
||
public async setOsd( | ||
bg_color: boolean = false, | ||
channel: number = 0, | ||
osd_channel_enabled: boolean = false, | ||
osd_channel_name: string = '', | ||
osd_channel_pos: OsdPos = OsdPos['Lower Right'], | ||
osd_time_enabled: boolean = false, | ||
osd_time_pos: OsdPos = OsdPos['Lower Right'], | ||
osd_watermark_enabled: boolean = false, | ||
): Promise<boolean> { | ||
/** | ||
* Set OSD | ||
* @returns whether the action was successful | ||
*/ | ||
const body: CommandData[] = [ | ||
{ | ||
cmd: 'SetOsd', | ||
action: 1, | ||
param: { | ||
Osd: { | ||
bgcolor: bg_color, | ||
channel: channel, | ||
osdChannel: { | ||
enable: osd_channel_enabled, | ||
name: osd_channel_name, | ||
pos: osd_channel_pos, | ||
}, | ||
osdTime: { enable: osd_time_enabled, pos: osd_time_pos }, | ||
watermark: osd_watermark_enabled, | ||
}, | ||
}, | ||
}, | ||
]; | ||
|
||
try { | ||
const response = await this.executeCommand('SetOsd', body); | ||
const r_data = response[0]; | ||
if (r_data?.value?.rspCode === 200) { | ||
return true; | ||
} | ||
console.log( | ||
'Could not set OSD. Camera responded with status:', | ||
r_data.error, | ||
); | ||
return false; | ||
} catch (error) { | ||
console.error('Error setting OSD:', error); | ||
return false; | ||
} | ||
} | ||
} | ||
|
||
export default DisplayAPIMixin; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { BaseAPIHandler } from '../handlers'; | ||
import CommandData from '../types/CommandData'; | ||
|
||
class DownloadAPIMixin extends BaseAPIHandler { | ||
/** | ||
* API calls for downloading video files. | ||
*/ | ||
|
||
public async getFile(filename: string, outputPath: string): Promise<boolean> { | ||
/** | ||
* Download the selected video file | ||
* @param filename The name of the file to download | ||
* @param outputPath The path where the file should be saved | ||
* @returns A boolean indicating whether the download was successful | ||
*/ | ||
const body: CommandData[] = [ | ||
{ | ||
cmd: 'Download', | ||
action: 0, // action is required in CommandData, but not used in the original Python code | ||
source: filename, | ||
output: filename, | ||
filepath: outputPath, | ||
}, | ||
]; | ||
|
||
try { | ||
const resp = await this.executeCommand('Download', body); | ||
return resp; | ||
} catch (error) { | ||
console.error('Error downloading file:', error); | ||
return false; | ||
} | ||
} | ||
} | ||
|
||
export default DownloadAPIMixin; |
Oops, something went wrong.