AgentHostProxy is used to send data or security authentication requests from the AgentExtensionAbility server to the client.
sendData(data: string): void
Sends data from the AgentExtensionAbility server to the client.
Atomic service API: This API can be used in atomic services since API version 24.
System capability: SystemCapability.Ability.AgentRuntime.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| data | string | Yes | Data to be sent to the client of AgentExtensionAbility. |
Error codes
For details about the error codes, see Universal Error Codes and Ability Error Codes.
| ID | Error Message |
|---|---|
| 35600002 | Failed to send the IPC message. |
Example
import { common, AgentExtensionAbility } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
const TAG: string = '[AgentExtensionAbility] ';
export default class MyAgentExtensionAbility extends AgentExtensionAbility {
// Handle data sending.
onData(proxy: common.AgentHostProxy, data: string) {
console.info(TAG + `onData ${data}`);
try {
// Send data to the client of AgentExtensionAbility.
proxy.sendData('Hello Client');
} catch (err) {
let code = (err as BusinessError).code;
let msg = (err as BusinessError).message;
console.error(`${TAG} sendData failed, err code: ${code}, err msg: ${msg}.`);
}
}
} authorize(handshakeData: string): void
Sends a security authentication request from the AgentExtensionAbility server to the client.
Atomic service API: This API can be used in atomic services since API version 24.
System capability: SystemCapability.Ability.AgentRuntime.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| handshakeData | string | Yes | Security authentication data to be sent to the client. |
Error codes
For details about the error codes, see Universal Error Codes and Ability Error Codes.
| ID | Error Message |
|---|---|
| 35600002 | Failed to send the IPC message. |
Example
import { common, AgentExtensionAbility } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
const TAG: string = '[AgentExtensionAbility] ';
export default class MyAgentExtensionAbility extends AgentExtensionAbility {
// Handle security authentication.
onAuth(proxy: common.AgentHostProxy, handshakeData: string) {
console.info(TAG + `onAuth ${handshakeData}`);
try {
// Send the authentication data to the client of AgentExtensionAbility.
proxy.authorize('handshake_token');
} catch (err) {
let code = (err as BusinessError).code;
let msg = (err as BusinessError).message;
console.error(`${TAG} authorize failed, err code: ${code}, err msg: ${msg}.`);
}
}
}