diff --git a/src/utils/boxApi.ts b/src/utils/boxApi.ts index 6125df8..ed8dfa0 100644 --- a/src/utils/boxApi.ts +++ b/src/utils/boxApi.ts @@ -14,6 +14,8 @@ class BoxApi { private readonly apiAlgorithms: string = "/algorithms"; private readonly apiResetUser: string = "/auth/resetuser"; private readonly apiResetPassword: string = "/auth/reset_password"; + private readonly getMinCamerasApi: string = "/camera/cameras/get_all"; + private readonly getMinCamera: string = "/camera/cameras"; private readonly loginConfig: object = { headers: { @@ -210,6 +212,48 @@ class BoxApi { return await this.getCamerasByUrl(url, token); } + public async getMinCameras(token: string | null = null): Promise { + const url = `${this.getMinCamerasApi}`; + try { + const res = await this.axios.get(url, this._authHeader(token)); + if (res.data.err.ec === 0) { + return res.data.ret; + } else { + throw new Error(res.data.err.msg); + } + } catch (error) { + throw error; + } + } + + public async startCameraStream(token: string | null = null, cameraId: number): Promise { + const url = `${this.getMinCamera}/${cameraId}/start_stream`; + try { + const res = await this.axios.post(url, this._authHeader(token)); + if (res.data.err.ec === 0) { + return res.data.ret; + } else { + throw new Error(res.data.err.msg); + } + } catch (error) { + throw error; + } + } + + public async stopCameraStream(token: string | null = null, cameraId: number): Promise { + const url = `${this.getMinCamera}/${cameraId}/stop_stream`; + try { + const res = await this.axios.post(url, this._authHeader(token)); + if (res.data.err.ec === 0) { + return res.data.ret; + } else { + throw new Error(res.data.err.dm); + } + } catch (error) { + throw error; + } + } + public async getEventsByUrl(url: string, token: string | null = null): Promise { try { const res = await this.axios.get(url, this._authHeader(token));