Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | 1x | import { Inject, Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { fromEventPattern, Observable, using } from 'rxjs';
import { SignalRBaseService } from './signalR.base.service';
import { LogService } from 'src/app/log/log.service';
import { CameraConfiguration, RecordingStateUpdate, TrackingConfigState } from '@reflex/shared-types';
@Injectable({
providedIn: 'root'
})
export class RecordingService extends SignalRBaseService<TrackingConfigState> {
private readonly baseRoute = 'api/Tracking/';
private readonly getRecordingsRoute = `${this.baseRoute}Recordings`;
private readonly startRecordingRoute = `${this.baseRoute}StartRecording`;
private readonly stopRecordingRoute = `${this.baseRoute}StopRecording`;
private readonly getRecordingStateRoute = `${this.baseRoute}RecordingState`;
private readonly getRecordingFrameCountRoute = `${this.baseRoute}RecordingFrameCount/`;
private readonly clearRecordingsRoute = `${this.baseRoute}ClearRecordings`;
private readonly deleteRecordingRoute = `${this.baseRoute}DeleteRecording`;
public constructor(
private readonly http: HttpClient,
// eslint-disable-next-line new-cap
@Inject('BASE_URL') private readonly baseUrl: string,
logService: LogService
) {
super(`${baseUrl}trkhub`, 'trackingState', logService);
}
public getRecordings(): Observable<Array<CameraConfiguration>> {
return this.http.get<Array<CameraConfiguration>>(
this.baseUrl + this.getRecordingsRoute
);
}
public startRecording(name: string): Observable<string> {
return this.http.put(
this.baseUrl + this.startRecordingRoute,
`"${name}"`,
{ headers: this.headers, responseType: 'text' }
);
}
public stopRecording(): Observable<CameraConfiguration> {
return this.http.get<CameraConfiguration>(
this.baseUrl + this.stopRecordingRoute
);
}
public queryRecordingState(): Observable<string> {
return this.http.get(this.baseUrl + this.getRecordingStateRoute, { responseType: 'text' });
}
public queryRecordingStateFrameCount(name: string): Observable<string> {
return this.http.get(
this.baseUrl + this.getRecordingFrameCountRoute + name,
{ responseType: 'text' }
);
}
public clearRecordings(): Observable<string> {
return this.http.get(this.baseUrl + this.clearRecordingsRoute, { responseType: 'text' });
}
public deleteRecording(name: string): Observable<string> {
return this.http.put(
this.baseUrl + this.deleteRecordingRoute,
`"${name}"`,
{ headers: this.headers, responseType: 'text' }
);
}
public getRecordingState(): Observable<RecordingStateUpdate> {
const recordingState$ = fromEventPattern<RecordingStateUpdate>(
(handler) => this.connection.on('recordingState', handler),
(handler) => this.connection.off('recordingState', handler)
);
return using(() => {
this.connection.send('StartRecordingState').catch((error) => {
console.error(error);
this.logService.sendErrorLog(`${error}`);
});
// eslint-disable-next-line @typescript-eslint/no-misused-promises
return { unsubscribe: async () => this.connection.send('StopRecordingState').catch((error) => {
console.error(error);
this.logService.sendErrorLog(`${error}`);
}) };
}, () => recordingState$);
}
}
|