IPC Cloud Storage

Last Updated on : 2026-02-10 02:48:08download

ThingCloudCamera is an interface for managing cloud-based functionalities of smart cameras. It provides features such as cloud-stored video playback, downloading, and timeline data retrieval.

API description

ThingCloudCamera module

bindXComponentContext

Functional description

Binds a YUV XComponent context instance, used for video rendering and display.

Function signature

bindXComponentContext(xComponentContext: XComponentContext|undefined): void;

Parameters

Parameter Type Description
xComponentContext XComponentContext The context object, used for video rendering. The value can be undefined.

You need to bind the context before playing the video. Otherwise, the video will not display correctly.

Example

const camera = new ThingCloudCamera("device_id");
camera.bindXComponentContext(xComponentContext);

registerCloudCameraListener

Functional description

Registers a cloud camera listener to receive callbacks for cloud storage-related events.

Function signature

registerCloudCameraListener(listener: ThingCameraCloudListener): void;

Parameters

Parameter Type Description
listener ThingCameraCloudListener The cloud camera listener object, implementing the ThingCameraCloudListener interface.

You can register multiple listeners, and all listeners will receive event notifications.

Example

const listener = {
  onSessionStatusChanged: (sessionId, status, camera) => {
    console.log("Session status changed:", status);  
  }};
camera.registerCloudCameraListener(listener);

unregisterCloudCameraListener

Functional description

Removes a registered cloud camera listener.

Function signature

unregisterCloudCameraListener(listener: ThingCameraCloudListener): void;

Parameters

Parameter Type Description
listener ThingCameraCloudListener The cloud camera listener object, implementing the ThingCameraCloudListener interface.

This will only remove the specified listener instance.

Example

camera.unregisterCloudCameraListener(listener);

getCloudDays

Functional description

Gets a list of cloud storage dates for the device, to show which dates have cloud storage data available.

Function signature

getCloudDays(devId: string): Promise<ThingCameraResponse<Array<ThingCameraCloudDay>> | null>

Parameters

Parameter Type Description
devId string The device ID.

Return value

Promise<ThingCameraResponse<Array<ThingCameraCloudDay>> | null>: A response object containing an array of cloud storage dates. null is returned on failure.

You need to call the getCloudState method first to load the cloud storage data.

Example

const cloudDays = await camera.getCloudDays("device_123");
if (cloudDays && cloudDays.data) {  console.log("Available cloud days:", cloudDays.data);}

getCloudSecret

Functional description

Gets the cloud storage encryption key, which is used for playing back and downloading cloud-stored video clips.

Function signature

getCloudSecret(devId: string): Promise<string | null>

Parameters

Parameter Type Description
devId string The device ID.

Return value

Promise<string | null>: The encryption key string in JSON format. null is returned on failure.

The encryption key is used to decrypt video clips stored in the cloud and must be kept securely.

Example

const secret = await camera.getCloudSecret("device_123");
if (secret) {  console.log("Cloud secret obtained");}

playCloudVideo

Functional description

Play cloud-stored video clips for a specified time period.

Function signature

playCloudVideo(devId: string, startTime: number, endTime: number, callback: ThingFinishableCallback): void;

Parameters

Parameter Type Description
devId string The device ID.
startTime number The start timestamp in milliseconds.
endTime number The end timestamp in milliseconds.
callback ThingFinishableCallback The callback for playback results.

Before playback, you need to get the cloud storage timeline data and encryption key.

Example

const callback = {  onSuccess: () => console.log("Play started"),  onError: (code, msg) => console.error("Play failed:", msg)};
camera.playCloudVideo("device_123", startTime, endTime, callback);

getCloudState

Functional description

Gets the device’s cloud storage status, including loading cloud storage dates and key information.

Function signature

getCloudState(devId: string, productId: string, instanceId: string): Promise<ThingCameraResponse<ThingCameraCloudStateBeans> | undefined>;

Parameters

Parameter Type Description
devId string The device ID.
productId string The product ID.
instanceId string The instance ID.

ThingCameraCloudStateBeans parameter structure

Parameter Type Description
savedSatus string The saved state.

Return value

Promise<ThingCameraResponse<ThingCameraCloudStateBeans> | undefined>: The response object for the cloud storage status.

This is an initialization method that must be called before using the cloud storage feature.

Example

const cloudState = await camera.getCloudState("device_123", "product_456", "instance_789");
if (cloudState) {  console.log("Cloud state loaded");}

getCloudTimeLineData

Functional description

Gets cloud storage timeline data for a specified time period, to show which time points have recorded video clips.

Function signature

getCloudTimeLineData(devId: string, startTime: number, endTime: number): Promise<ThingCameraResponse<Array<ThingCameraCloudTimeLineBean>> | undefined>

Parameters

Parameter Type Description
devId string The device ID.
startTime number The start timestamp in seconds.
endTime number The end timestamp in seconds.

ThingCameraCloudTimeLineBean parameter structure

Parameter Type Description
startTime number The start timestamp in seconds.
endTime number The end timestamp in seconds.
prefix number The classification identifier. Valid values:
  • 0: Regular recording (no event trigger).
  • 1: Alarm recording (for example, triggered by motion detection).
  • 2: AI event recording (used in conjunction with isAIStorage).
isAIStorage boolean Indicates whether the storage was triggered by an AI event.
aiDetectList Array The list of AI detection event details.

ThingCameraCloudaiDetectListBean parameter structure

Parameter Type Description
startTime number The start timestamp in seconds.
endTime number The end timestamp in seconds.
aiCode string The code of the specified type.
aiCodeIcon stirng The URL address of the icon.

Return value

Promise<ThingCameraResponse<Array<ThingCameraCloudTimeLineBean>> | undefined>: The timeline data array.

Calling this method will automatically configure the necessary authorization information for playback.

Example

const timeline = await camera.getCloudTimeLineData("device_123", startTime, endTime);
if (timeline && timeline.data) {  console.log("Timeline data:", timeline.data);}

isSupportCloudStorage

Functional description

Checks whether a device supports cloud storage.

Function signature

isSupportCloudStorage(devId: string): boolean

Parameters

devId: The device ID.

Return value

boolean: true indicates that cloud storage is supported, and false indicates that it is not supported.

Before using the cloud storage feature, it is recommended to check whether your device supports it.

Example

if (camera.isSupportCloudStorage("device_123")) {  console.log("Device supports cloud storage");}

enableMute

Functional description

Sets the mute status during playback.

Function signature

enableMute(mute: number): void;

Parameters

Parameter Type Description
mute number
  • 0: Unmute
  • 1: Mute

This parameter affects the audio output when playing cloud-stored video clips.

Example

camera.enableMute(1); // Enable mute
camera.enableMute(0); // Disable mute

pausePlayCloudVideo

Functional description

Pauses playback of cloud-stored video clips.

Function signature

pausePlayCloudVideo(): number | undefined

Return value

number | undefined: The operation result code. undefined indicates that the operation failed.

You can only pause cloud-stored video clips that are currently playing.

Example

const result = camera.pausePlayCloudVideo();
if (result === 0) {
  console.log("Video paused successfully")
;}

resumePlayCloudVideo

Functional description

Resumes playback of cloud-stored video clips.

Function signature

resumePlayCloudVideo(): number | undefined

Return value

number | undefined: The operation result code. undefined indicates that the operation failed.

You can only resume cloud-stored video clips that have been paused.

Example

const result = camera.resumePlayCloudVideo();
if (result === 0) {
  console.log("Video resumed successfully")
;}

stopPlayCloudData

Functional description

Stops playback of cloud-stored video clips.

Function signature

stopPlayCloudData(): number | undefined

Return value

number | undefined: The operation result code. undefined indicates that the operation failed.

After stop, you need to call playCloudVideo again to resume playback.

Example

const result = camera.stopPlayCloudData();
if (result === 0) {
  console.log("Video stopped successfully")
;}

getCloudEvents

Functional description

Gets a list of cloud storage events for a specified time period.

Function signature

getCloudEvents(devId: string, startTime: number, endTime: number): Promise<ThingCameraResponse<ThingCameraCloudEventBeans[]> | undefined>

Parameters

Parameter Type Description
devId string The device ID.
startTime number The start timestamp in milliseconds.
endTime number The end timestamp in milliseconds.

ThingCameraCloudEventBeans parameter description

Parameter Type Description
datas Array The data collection of events that stores a list of sub-events of the same type. For example, paginated data or multi-level event scenarios.
startTime number The start timestamp in milliseconds.
endTime number The end timestamp in milliseconds.
snapshotUrl string The URL address of a snapshot.
describe string The event description.
eventType string The event type.
encryption ThingCameraCloudEncryptionBeans The encryption information.

ThingCameraCloudEncryptionBeans parameter structure

Parameter Type Description
key string The encryption key.

Return value

Promise<ThingCameraResponse<ThingCameraCloudEventBeans> | undefined>: The cloud storage event data.

Events include recordings triggered by motion detection, sound detection, and similar triggers.

Example

const events = await camera.getCloudEvents("device_123", startTime, endTime);
if (events && events.data) {
  console.log("Cloud events:", events.data)
;}

downloadCloudVideo

Functional description

Downloads cloud-stored video clips for a specified time period to the local device.

Function signature

downloadCloudVideo(devId: string, startTime: number, endTime: number, filePath: string, fileName: string, thumbnailName: string): Promise<number>

Parameters

Parameter Type Description
devId string The device ID.
startTime number The start timestamp in milliseconds.
endTime number The end timestamp in milliseconds.
filePath string The local save path.
fileName string The video file name.
thumbnailName string The thumbnail file name.

Return value

Promise<number>: The download task ID, used to manage the download task.

The download progress is notified via listener callbacks.

Example

const taskId = await camera.downloadCloudVideo(
  "device_123",   startTime,   endTime,
  "/path/to/save",   "video.mp4",   "thumb.jpg"
);

cancelCloudVideoDownload

Functional description

Cancels download of cloud-stored video clips.

Function signature

cancelCloudVideoDownload(devId: string): number | undefined

Parameters

Parameter Type Description
devId string The device ID.

Return value

number | undefined: The operation result code. undefined indicates that the operation failed.

Only ongoing download tasks can be canceled.

Example

const result = camera.cancelCloudVideoDownload("device_123");
if (result === 0) {
  console.log("Download cancelled")
;}

pauseCloudVideoDownload

Functional description

Pauses download of cloud-stored video clips.

Function signature

pauseCloudVideoDownload(devId: string): number | undefined

Parameters

Parameter Type Description
devId string The device ID.

Return value

number | undefined: The operation result code. undefined indicates that the operation failed.

Paused downloads can be resumed using resumeCloudDataDownload.

Example

const result = camera.pauseCloudVideoDownload("device_123");
if (result === 0) {
  console.log("Download paused")
;}

resumeCloudDataDownload

Functional description

Resumes a download task of cloud-stored videos.

Function signature

resumeCloudDataDownload(devId: string): number | undefined

Parameters

Parameter Type Description
devId string The device ID.

Return value

number | undefined: The operation result code. undefined indicates that the operation failed.

Only paused download tasks can be resumed.

Example

const result = camera.resumeCloudDataDownload("device_123");
if (result === 0) {
  console.log("Download resumed")
;}

setPlayCloudDataSpeed

Functional description

Sets the playback speed for cloud-stored videos.

Function signature

setPlayCloudDataSpeed(speed: ThingCameraConstants.PlaySpeedLevel): number;

Parameters

Parameter Type Description
speed ThingCameraConstants.PlaySpeedLevel The enumeration values ​​for playback speed levels.

Return value

number: The operation result code. 0 indicates success, and other values ​​indicate failure.

You can only adjust the playback speed when playing videos stored in the cloud.

Example

const result = camera.setPlayCloudDataSpeed(ThingCameraConstants.PlaySpeedLevel.NORMAL);
if (result === 0) {
  console.log("Set the playback speed successfully");
}

startRecordLocalMp4

Functional description

Starts local recording of MP4 video clips, saving the current video stream to a local file.

Function signature

startRecordLocalMp4(folderPath: string, mp4FileName: string, thumbFileName: string, rotate: number): number;

Parameters

Parameter Type Description
folderPath string The path in which video files are stored.
mp4FileName string The MP4 video file name.
thumbFileName string The thumbnail file name.
rotate number The rotation angle of the video.

Return value

number: The operation result code. 0 indicates success, and other values ​​indicate failure.

Make sure you have write permissions to the folder path, and start playing the video before recording.

Example

const result = camera.startRecordLocalMp4(
  "/path/to/save",
  "record.mp4",
  "thumb.jpg",
  0);
if (result === 0) {
  console.log("Start to record videos");
}

stopRecordLocalMp4

Functional description

Stops local MP4 video recording.

Function signature

stopRecordLocalMp4(): number;

Return value

number: The operation result code. 0 indicates success, and other values ​​indicate failure.

Only ongoing recording operations can be stopped.

Example

const result = camera.stopRecordLocalMp4();
if (result === 0) {
  console.log("Stop video recording");
}

snapshot

Functional description

Captures the current video frame and saves it as an image file.

Function signature

snapshot(absoluteFilePath: string, rotation: ThingCameraConstants.Rotation): number

Parameters

Parameter Type Description
absoluteFilePath string The absolute path where the snapshot is saved, including the file name.
rotation ThingCameraConstants.Rotation The enumeration values ​​for image rotation parameters.

Return value

number: The operation result code. 0 indicates success, and other values ​​indicate failure.

Before taking a snapshot, make sure that the video is playing and that you have write permissions to the file path.

Example

const result = camera.snapshot(
  "/path/to/snapshot.jpg",
  ThingCameraConstants.Rotation.Rotation_0
);
if (result === 0) {
  console.log("Obtained a snapshot successfully");
}

setDeviceFeatures

Functional description

Sets device features and functional configurations.

Function signature

setDeviceFeatures(jsonFeatures: string): number;

Parameters

Parameter Type Description
jsonFeatures string The device feature configuration string in JSON format.

Return value

number: The operation result code. 0 indicates success, and other values ​​indicate failure.

The JSON configuration format must be provided according to device requirements. Configuration items may include video quality and encoding parameters.

Example

const features = {
  "videoQuality": "high",
  "encodeType": "h264"
};
const result = camera.setDeviceFeatures(JSON.stringify(features));
if (result === 0) {
  console.log("Set device features successfully");
}

Example

Get the cloud storage management class

if (this.cloudCameraManager === undefined) {
  this.cloudCameraManager = ThingIPCSdk.getCloudCamera(this.mDeviceId);
}

this.cloudCameraManager = ThingIPCSdk.getCloudCamera(this.mDeviceId);

Check support for cloud storage

if (this.cloudCameraManager === undefined) {
  this.cloudCameraManager = ThingIPCSdk.getCloudCamera(this.mDeviceId);
}

let support = this.cloudCameraManager?.isSupportCloudStorage(this.mDeviceId);

Query cloud storage status

if (this.cloudCameraManager === undefined) {
  this.cloudCameraManager = ThingIPCSdk.getCloudCamera(this.mDeviceId);
}

this.cloudCameraManager?.getCloudState(this.mDeviceId,(this.mDeviceBean?.productId ? this.mDeviceBean.productId : ''),(this.mDeviceBean?.uuid ? this.mDeviceBean.uuid : ''))
  .then((responres: ThingCameraResponse<ThingCameraCloudStateBeans> | undefined) => {
    if (responres !== undefined) {
      console.log('cloudState' + responres);
    }
  })
  .catch((e: TSmartAtopRequestError) => {
    IPCLog.d(this.logTag, "getCloudState = " + e);
  })

Get cloud storage time slices

if (this.cloudCameraManager === undefined) {
  this.cloudCameraManager = ThingIPCSdk.getCloudCamera(this.mDeviceId);
}
this.cloudCameraManager.getCloudTimeLineData(this.mDeviceId,1743091200,1743177599)
  .then((response: ThingCameraResponse<Array<ThingCameraCloudTimeLineBean>> | undefined) => {
    if (response) {
      // console.log('getCloudTimeLineData:' + response.result);
      let  prefix = '';
      response.data?.forEach((item: ThingCameraCloudTimeLineBean) => {
        prefix = prefix + item.prefix;
      })
      this.cloudDataTitle = 'Obtained cloud storage data successfully'
      this.canPlay = true;
    }
  }).catch((e: TSmartAtopRequestError) => {
  IPCLog.d(this.logTag, "getCloudState = " + e);
})

Get the number of days for cloud storage

if (this.cloudCameraManager === undefined) {
  this.cloudCameraManager = ThingIPCSdk.getCloudCamera(this.mDeviceId);
}
this.cloudCameraManager?.getCloudDays(this.mDeviceId).then((response: ThingCameraResponse<Array<ThingCameraCloudDay>> | null) => {
  response?.data?.forEach((item:ThingCameraCloudDay) => {
    console.log(item.uploadDay);
  })
});

Start playing cloud-stored clips

if (this.cloudCameraManager === undefined) {
  this.cloudCameraManager = ThingIPCSdk.getCloudCamera(this.mDeviceId);
}
let callback: ThingFinishableCallback = {
  onFinished: (data: string, errCode: number): void => {
    IPCLog.i(this.logTag, " onfinished message received.")
  },
  onEvent: (eventType: number, info1: number, info2: number, errInfo: string): void => {
    IPCLog.i(this.logTag, " onEvent message received.")
  },
  onResponse: (reason: string, errCode: number): number => {
    IPCLog.i(this.logTag, " onResponse reson:" + reason + " errCode:" + errCode);
    return 0;
  }
}
this.cloudCameraManager.playCloudVideo(this.mDeviceId,1743091201,1743104342,callback)

Bind cloud storage player

XComponent({
  id: 'xcomponentId0',
  type: XComponentType.SURFACE,
  libraryname: 'thingvideorenderersdk'
}).onLoad((xComponentContext) => {
  this.xComponentContext0 = xComponentContext as XComponentContext;
  if (this.cloudCameraManager === undefined) {
    this.cloudCameraManager = ThingIPCSdk.getCloudCamera(this.mDeviceId);
  }
  this.cloudCameraManager?.bindXComponentContext(this.xComponentContext0);
}).onDestroy(() => {
  console.log('onDestroy');
}).id("xcomponent")

Update cloud storage audio status

let callback: ThingFinishableCallback = {
  onFinished: (data: string, errCode: number): void => {
  IPCLog.i(this.logTag, " onfinished message received.")
  },
  onEvent: (eventType: number, info1: number, info2: number, errInfo: string): void => {
    IPCLog.i(this.logTag, " onEvent message received.")
  },
  onResponse: (reason: string, errCode: number): number => {
    IPCLog.i(this.logTag, " onResponse reson:" + reason + " errCode:" + errCode);
    return 0;
  }
}
this.cloudCameraManager?.enableMute(1,callback);