mirror of
https://github.com/koush/scrypted.git
synced 2026-02-10 01:02:18 +00:00
onvif: logging
This commit is contained in:
4
plugins/onvif/package-lock.json
generated
4
plugins/onvif/package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@scrypted/onvif",
|
||||
"version": "0.0.11",
|
||||
"version": "0.0.18",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@scrypted/onvif",
|
||||
"version": "0.0.11",
|
||||
"version": "0.0.18",
|
||||
"license": "Apache",
|
||||
"dependencies": {
|
||||
"@scrypted/sdk": "file:../../sdk",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@scrypted/onvif",
|
||||
"version": "0.0.11",
|
||||
"version": "0.0.18",
|
||||
"description": "ONVIF Camera Plugin for Scrypted",
|
||||
"author": "Scrypted",
|
||||
"license": "Apache",
|
||||
|
||||
@@ -9,6 +9,7 @@ const { mediaManager } = sdk;
|
||||
class OnvifCamera extends RtspSmartCamera {
|
||||
eventStream: Stream;
|
||||
client: OnvifCameraAPI;
|
||||
streamUrl;
|
||||
|
||||
listenEvents(): EventEmitter & Destroyable {
|
||||
(async () => {
|
||||
@@ -32,7 +33,7 @@ class OnvifCamera extends RtspSmartCamera {
|
||||
}
|
||||
|
||||
createClient() {
|
||||
return connectCameraAPI(this.storage.getItem('ip'), this.getUsername(), this.getPassword());
|
||||
return connectCameraAPI(this.storage.getItem('ip'), this.getUsername(), this.getPassword(), this.console);
|
||||
}
|
||||
|
||||
async takePicture(): Promise<MediaObject> {
|
||||
@@ -42,7 +43,17 @@ class OnvifCamera extends RtspSmartCamera {
|
||||
}
|
||||
|
||||
async getConstructedStreamUrl() {
|
||||
return `rtsp://${this.getRtspAddress()}/cam/realmonitor?channel=1&subtype=0`;
|
||||
try {
|
||||
if (!this.streamUrl) {
|
||||
if (!this.client)
|
||||
this.client = await this.createClient();
|
||||
this.streamUrl = await this.client.getStreamUrl();
|
||||
}
|
||||
return this.streamUrl;
|
||||
}
|
||||
catch (e) {
|
||||
return `rtsp://${this.getRtspAddress()}/cam/realmonitor?channel=1&subtype=0`;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,13 +34,18 @@ export class OnvifCameraAPI {
|
||||
digestAuth: DigestClient;
|
||||
mainProfileToken: Promise<string>;
|
||||
|
||||
constructor(public cam: any, username: string, password: string) {
|
||||
constructor(public cam: any, username: string, password: string, public console: Console) {
|
||||
this.digestAuth = new DigestClient(username, password);
|
||||
}
|
||||
|
||||
listenEvents() {
|
||||
const ret = new EventEmitter();
|
||||
this.cam.getEventProperties((err, results) => {
|
||||
this.console.log(results);
|
||||
})
|
||||
|
||||
this.cam.on('event', (event: any) => {
|
||||
this.console.log('onvif event', event);
|
||||
const eventTopic = stripNamespaces(event.topic._)
|
||||
|
||||
if (event.message.message.data && event.message.message.data.simpleItem) {
|
||||
@@ -75,7 +80,7 @@ export class OnvifCameraAPI {
|
||||
|
||||
async getStreamUrl(): Promise<string> {
|
||||
const token = await this.getMainProfileToken();
|
||||
return new Promise((resolve, reject) => this.cam.getStreamUri({ protocol: 'RTSP', profileToken: token }, (err: Error, uri: string) => err ? reject(err) : resolve(uri)));
|
||||
return new Promise((resolve, reject) => this.cam.getStreamUri({ protocol: 'RTSP', profileToken: token }, (err: Error, uri: any) => err ? reject(err) : resolve(uri.uri)));
|
||||
}
|
||||
|
||||
async jpegSnapshot(): Promise<Buffer> {
|
||||
@@ -89,15 +94,18 @@ export class OnvifCameraAPI {
|
||||
}
|
||||
}
|
||||
|
||||
export async function connectCameraAPI(hostname: string, username: string, password: string) {
|
||||
export async function connectCameraAPI(ipAndPort: string, username: string, password: string, console: Console) {
|
||||
const split = ipAndPort.split(':');
|
||||
const [hostname, port] = split;
|
||||
const cam = await new Promise((resolve, reject) => {
|
||||
const cam = new Cam({
|
||||
hostname,
|
||||
username,
|
||||
password,
|
||||
port,
|
||||
}, (err: Error) => err ? reject(err) : resolve(cam)
|
||||
)
|
||||
});
|
||||
|
||||
return new OnvifCameraAPI(cam, username, password);
|
||||
return new OnvifCameraAPI(cam, username, password, console);
|
||||
}
|
||||
Reference in New Issue
Block a user