### Start HTTP Server Source: https://www.alibabacloud.com/help/en/agentbay/web-sdk-of-agentbay Command to start a local HTTP server for serving the demo HTML file. ```bash python3 -m http.server ``` -------------------------------- ### Install Project Dependencies Source: https://www.alibabacloud.com/help/en/agentbay/web-sdk-of-agentbay Command to install required dependencies for the Vue project. ```bash npm i ``` -------------------------------- ### Start Development Server Source: https://www.alibabacloud.com/help/en/agentbay/web-sdk-of-agentbay Command to launch the development server for the Vue project. ```bash npm run dev ``` -------------------------------- ### Create ActionTrail Trail with Python SDK Source: https://www.alibabacloud.com/help/en/actiontrail Use the Alibaba Cloud SDK for Python to create a new ActionTrail trail. Ensure you have the SDK installed and configured with your credentials. ```python from alibabacloud_actiontrail20200706.client import Client as ActionTrailClient from alibabacloud_tea_openapi import models as open_api_models def create_trail(region_id, trail_name, oss_bucket_name, oss_key_prefix): config = open_api_models.Config( access_key_id='YOUR_ACCESS_KEY_ID', access_key_secret='YOUR_ACCESS_KEY_SECRET', endpoint='actiontrail.' + region_id + '.aliyuncs.com', region_id=region_id ) client = ActionTrailClient(config) request = open_api_models.CreateTrailRequest( name=trail_name, oss_bucket_name=oss_bucket_name, oss_key_prefix=oss_key_prefix ) try: response = client.create_trail_with_map(request.to_map()) print(f"Trail created successfully: {response}") except Exception as e: print(f"Error creating trail: {e}") # Example usage: # create_trail('cn-hangzhou', 'my-trail', 'my-oss-bucket', 'actiontrail-logs/') ``` -------------------------------- ### Start Session Connection Source: https://www.alibabacloud.com/help/en/agentbay/web-sdk-of-agentbay Initiates a session connection. Ensure the session object is properly initialized before calling this method. ```javascript session.start(); ``` -------------------------------- ### Node.js Environment Check Source: https://www.alibabacloud.com/help/en/agentbay/web-sdk-of-agentbay Command to verify if Node.js is installed in the local environment. ```bash node ``` -------------------------------- ### Application Information Structure Source: https://www.alibabacloud.com/help/en/agentbay/web-sdk-of-agentbay Defines the parameters for starting a cloud phone application. ```APIDOC ## AppInfo ### Description The parameters for starting a cloud phone. ### Parameters #### Request Body - **osType** (string) - Required - The constant value is Android. - **appId** (string) - Required - Enter the PersistentAppInstanceId. - **appVersion** (string) - Optional - The version of the application to start. - **loginRegionId** (string) - Required - The region where the cloud phone resource is located. - **connConfig** (ConnConfig) - Optional - Connection configuration parameters. - **appInstanceGroupId** (string) - Optional - The delivery group ID. - **appInstanceId** (string) - Optional - The instance ID. - **taskId** (string) - Optional - The application startup task ID. - **bizRegionId** (string) - Optional - The region where the application resource is located. - **productType** (string) - Optional - The delivery group type. ``` -------------------------------- ### Session Management APIs Source: https://www.alibabacloud.com/help/en/agentbay/web-sdk-of-agentbay Methods for starting and stopping cloud phone sessions. ```APIDOC ## session.start() ### Description Establishes a connection to the cloud phone instance. ## session.stop() ### Description Terminates the active connection to the cloud phone instance. ``` -------------------------------- ### Handle Session Events Source: https://www.alibabacloud.com/help/en/agentbay/web-sdk-of-agentbay Adds event listeners for various session events. Use this to react to connection status changes, receive data, or get ticket information. ```javascript session.addHandle('getConnectionTicketInfo', (data) => { console.log(data); }); ``` ```javascript session.addHandle('onConnected', (data) => { console.log('connected', data); }); ``` ```javascript session.addHandle('onDisConnected', (data) => { console.log('disconnect', data); }); ``` ```javascript session.addHandle('onRuntimeMsg', (data) => { document.getElementById('GuestMsgContext').value = JSON.stringify(data); }); ``` -------------------------------- ### Navigate to Project Directory Source: https://www.alibabacloud.com/help/en/agentbay/web-sdk-of-agentbay Command to change the current working directory to the project root. ```bash cd ``` -------------------------------- ### Project Directory Structure Source: https://www.alibabacloud.com/help/en/agentbay/web-sdk-of-agentbay The standard file layout for the Web SDK demo project. ```text ├── WuyingWebDemo.html // SDK sample. ├── WuyingWebSDK.js // The SDK API file. Reference this file on the frontend page. └── sdk // iframe embedded resource file └── ASP └── container.html ``` -------------------------------- ### Configure and Listen on Data Channel Source: https://www.alibabacloud.com/help/en/agentbay/web-sdk-of-agentbay Sets up a custom data channel for client-cloud communication and listens for incoming messages. The dataChannelName must match the configuration. ```javascript // Configure dataChannelConfig in sessionParam. dataChannelConfig: [{ dataChannelName: 'wy_vdagent_default_dc', }] // Listen for tunnel messages. /** The meaning of value: 0 specifies 0 degrees, 1 specifies 90 degrees, 2 specifies 180 degrees, and 3 specifies 270 degrees. * The format of the landscape mode message is {"action":"rotation","value":"0"}. */ session.addDataChannelListener('wy_vdagent_default_dc', 'data', data => console.log('data from wy_vdagent_default_dc', data)); ``` -------------------------------- ### Navigate to HTML Directory Source: https://www.alibabacloud.com/help/en/agentbay/web-sdk-of-agentbay Command to change the directory to the location of the HTML file. ```bash cd ``` -------------------------------- ### Create Session with Ticket Source: https://www.alibabacloud.com/help/en/agentbay/web-sdk-of-agentbay Initializes a session using a ticket authentication method. ```javascript // Create a session using a ticket. var userInfo = { ticket: 'xxx', }; var appInfo = { osType: 'Android', // Required appId: "android", appInstanceId: "ai-xxxxxx", // The appInstanceId starts with ai-. productType: "AndroidCloud", connectionProperties: JSON.stringify({ authMode: "Session" }) , }; var sessionParam = { openType: openType, iframeId: 'sessionIframe', resourceType: "local", connectType: 'app', userInfo: userInfo, appInfo: appInfo, }; var wuyingSdk = Wuying.WebSDK; session = wuyingSdk.createSession('appstream', sessionParam); ``` -------------------------------- ### Send ADB Commands and Listen for Responses Source: https://www.alibabacloud.com/help/en/agentbay/web-sdk-of-agentbay Use session.sendLyncMessage to execute commands and session.addLyncListener to handle incoming data from the channel. ```javascript session.sendLyncMessage( "lync_adb_shell", JSON. stringify({ id: crypto. randomUUID(), cmd: 'input keyevent KEYCODE_VOLUME_UP', }) ); ``` ```javascript session.addLyncListener('lync_adb_shell', 'onReceivedLyncData', data => console.log('data from lync_adb_shell', data)); ``` -------------------------------- ### Connection Configuration Source: https://www.alibabacloud.com/help/en/agentbay/web-sdk-of-agentbay Parameters for establishing and managing connections. ```APIDOC ## ConnConfig ### Description Connection configuration parameters. ### Parameters #### Query Parameters - **decodeType** (ConnDecodeType) - No - The coding configuration. - **playSoundBackground** (bool) - No - Specifies whether to continue playing sound after switching to the background. ``` -------------------------------- ### Create Session with AuthCode Source: https://www.alibabacloud.com/help/en/agentbay/web-sdk-of-agentbay Initializes a session using an authCode authentication method. ```javascript // Create a session using an authCode. var userInfo = { sessionId: sessionId, authCode: authCode, }; var appInfo = { osType: 'Android', // Required appId: "android", resourceId: "p-xxxxxx", // The resourceId starts with p-. productType: "AndroidCloud", connectionProperties: JSON.stringify({ authMode: "Session" }) , }; var sessionParam = { openType: openType, iframeId: 'sessionIframe', resourceType: "local", connectType: 'app', userInfo: userInfo, appInfo: appInfo, }; var wuyingSdk = Wuying.WebSDK; session = wuyingSdk.createSession('appstream', sessionParam); ``` -------------------------------- ### Create Session with LoginToken or STS Token Source: https://www.alibabacloud.com/help/en/agentbay/web-sdk-of-agentbay Initializes a session using a loginToken or stsToken authentication method. ```javascript // Create a session using a loginToken or stsToken. var userInfo = { sessionId: sessionId, loginToken: loginToken, }; var appInfo = { osType: 'Android', // Required appId: "android", resourceId: "p-xxxxxx", // The resourceId starts with p-. productType: "AndroidCloud", connectionProperties: JSON.stringify({ authMode: "Session" }) , }; var sessionParam = { openType: openType, iframeId: 'sessionIframe', resourceType: "local", connectType: 'app', userInfo: userInfo, appInfo: appInfo, }; var wuyingSdk = Wuying.WebSDK; session = wuyingSdk.createSession('appstream', sessionParam); ``` -------------------------------- ### UI Configuration Structure Source: https://www.alibabacloud.com/help/en/agentbay/web-sdk-of-agentbay Defines the UI settings for the connection page. ```APIDOC ## UiConfig ### Description The UI settings for the connection page. ### Parameters #### Request Body - **toolbar** (ToolBarConfig) - Optional - The display settings for the toolbar on the connection page. - **exitCheck** (bool) - Optional - Specifies whether to enable secondary confirmation in the browser when you exit the current page. - **rotateDegree** (number) - Optional - Specifies whether to force landscape mode. - **vconsoleVisiable** (bool) - Optional - Specifies whether to display the vconsole debug box. - **debugPanelVisiable** (bool) - Optional - Specifies whether to display the information box for bitstream, frame rate, and other information. - **reconnectType** (ReconnectType) - Optional - The style of the reconnection prompt box. - **defaultResolution** (ResolutionType) - Optional - The default resolution for the first connection. - **language** (Language) - Optional - The language of internal pop-up prompts. - **allowErrorDialog** (bool) - Optional - Specifies whether to display an error pop-up window. - **backgroundColor** (string) - Optional - A custom background for the loading process. - **backgroundImg** (string) - Optional - A custom image for the loading process. ``` -------------------------------- ### Configure UI Parameters Source: https://www.alibabacloud.com/help/en/agentbay/web-sdk-of-agentbay Actively sets UI configurations after a session is established, such as toolbar visibility or rotation. Ensure UiConfig is defined according to the SDK's specifications. ```javascript var uiConfig = { toolbar: { visible: false, }, rotateDegree: 90, }; session.setUiParams(uiConfig); ``` -------------------------------- ### Initialize ADB Channel via lyncChannelConfig Source: https://www.alibabacloud.com/help/en/agentbay/web-sdk-of-agentbay Configure the lyncChannelConfig during session creation to enable the ADB shell channel. ```javascript lyncChannelConfig: [ { lyncChannelName: "lync_adb_shell", }, ], ``` -------------------------------- ### Toolbar Configuration Source: https://www.alibabacloud.com/help/en/agentbay/web-sdk-of-agentbay Settings to control the display and behavior of the toolbar. ```APIDOC ## ToolbarConfig ### Description The display settings for the toolbar. ### Parameters #### Query Parameters - **visible** (bool) - No - Specifies whether to display the toolbar. - **noMenu** (bool) - No - Specifies whether the DesktopAssistant supports opening the context menu. Default value: `false`. This feature is supported in versions 1.4.20 and later. ``` -------------------------------- ### Session Configuration Parameters Source: https://www.alibabacloud.com/help/en/agentbay/web-sdk-of-agentbay Defines the structure and required parameters for creating a session, including connection types and user authentication. ```APIDOC ## SessionParam ### Description The parameters for creating a session. ### Parameters #### Request Body - **openType** (OpenType) - Required - Specifies whether to open the page in an embedded iframe or a new tab. - **iframeId** (string) - Optional - If you open the page in an iframe, you must specify the iframeId. - **sdkPath** (string) - Optional - The path of the SDK file. - **resourceType** (ResourceType) - Required - Only opening the local connection page is supported. - **connectType** (ConnectType) - Required - Specifies whether to start a cloud phone or a cloud computer. - **isOverseas** (boolean) - Optional - Specifies whether the access is from outside the Chinese mainland. Default value: false. - **userInfo** (UserInfo) - Required - The logon status information of the user. - **regionId** (string) - Required - Required when you start a cloud phone. - **appInfo** (AppInfo) - Optional - Information about the cloud phone. - **fileInfo** (FileInfo) - Optional - Information about the cloud drive. - **uiConfig** (UiConfig) - Optional - UI settings. - **logDisabled** (bool) - Optional - Specifies whether to disable ARMS statistics. Default value: false. - **loginType** (LoginType) - Optional - The default logon method is to use a Alibaba Cloud Workspace account. - **networkAccessType** (string) - Optional - VPC logon is supported. ``` -------------------------------- ### Configure Camera Type Source: https://www.alibabacloud.com/help/en/agentbay/web-sdk-of-agentbay Use setLocalConfig to specify whether to use the front or rear camera on the client device. ```javascript // Front camera session.setLocalConfig('setCameraType', 1); // Rear camera session.setLocalConfig('setCameraType', 2); ``` -------------------------------- ### Event Handling API Source: https://www.alibabacloud.com/help/en/agentbay/web-sdk-of-agentbay API for registering event listeners to handle session lifecycle and runtime messages. ```APIDOC ## session.addHandle(name, callback) ### Description Registers a callback function for specific session events. ### Parameters - **name** (string) - Required - The type of event to listen for (e.g., 'getConnectionTicketInfo', 'onConnected', 'onDisConnected', 'onRuntimeMsg'). - **callback** (Function) - Required - The function to execute when the event occurs. ``` -------------------------------- ### Disable DesktopAssistant via uiConfig Source: https://www.alibabacloud.com/help/en/agentbay/web-sdk-of-agentbay Set the toolbar visibility to false during the session creation phase to disable the DesktopAssistant. ```javascript uiConfig: { toolbar: { visible: false, }, }, ``` -------------------------------- ### Business Control APIs Source: https://www.alibabacloud.com/help/en/agentbay/web-sdk-of-agentbay Various methods to control input, UI, and communication channels for the cloud phone session. ```APIDOC ## Business Control Methods ### Methods - **WebSDK.apiVersion** (string) - Returns the current SDK version. - **setInputEnabled(boolean)** - Enables or disables input operations. - **enableKeyBoard(boolean)** - Toggles mobile client keyboard visibility. - **setClipboardEnabled(boolean)** - Toggles clipboard control. - **setMicrophoneEnabled(boolean)** - Toggles microphone control. - **setTouchEnabled(boolean)** - Toggles touch control. - **setUiParams(UiConfig)** - Configures UI elements like toolbar visibility and rotation. ### Data Channel API - **session.addDataChannelListener(name, type, callback)** - Listens for messages on a custom data channel. - **session.sendDataChannelMessage(name, data)** - Sends data through a custom tunnel. ``` -------------------------------- ### User Information Structure Source: https://www.alibabacloud.com/help/en/agentbay/web-sdk-of-agentbay Defines the user's logon status information required for session authentication. ```APIDOC ## UserInfo ### Description The user's logon status information. You must specify one of the following parameters: authCode, ticket, or loginToken. ### Parameters #### Request Body - **authCode** (string) - Required - A one-time logon credential that has the highest priority. - **ticket** (string) - Required - For version 1.4.7 or later, you can directly pass in a ticket to establish a connection. - **loginToken** (string) - Required - The credential for logon with a convenience account. - **sessionId** (string) - Required - The SessionId that is gotten by calling GetLoginToken or GetStsToken. ``` -------------------------------- ### Listen for Lync Channel ADB Command Callback Source: https://www.alibabacloud.com/help/en/agentbay/web-sdk-of-agentbay Adds a listener to receive callbacks for ADB commands sent over the lync channel. The channel name must match the configured channel. ```javascript // Listen for the ADB command callback. session.addLyncListener('lync_adb_shell', 'onReceivedLyncData', data => console.log('data from lync_adb_shell', data)); ``` -------------------------------- ### Error Codes Reference Source: https://www.alibabacloud.com/help/en/agentbay/web-sdk-of-agentbay A list of common error codes encountered during cloud phone connection processes and their resolutions. ```APIDOC ## Error Codes Reference ### Common Error Codes | Error Code | Description | | :--- | :--- | | AccountNotAvailable | The domain account is locked, disabled, or has expired. | | ClientLockedForAliasFailed | Maximum incorrect attempts reached. Try again in 5 minutes. | | desktop-DesktopNetworkError | The network of this cloud phone is abnormal. Restart the cloud phone. | | desktop-InvalidClientIp.Policy | Access denied due to IT administrator IP whitelist policy. | | desktop-INSUFFICIENT_QUOTA | No temporary cloud phone available due to insufficient quota. | ``` -------------------------------- ### Configure and Send ADB Commands via Lync Channel Source: https://www.alibabacloud.com/help/en/agentbay/web-sdk-of-agentbay Configures the lync channel for sending ADB commands and sends a command with a unique identifier and operation type. Ensure OperationMap is defined. ```javascript // Configure lyncChannelConfig in sessionParam. lyncChannelConfig: [ { lyncChannelName: 'lync_adb_shell', } // Send an ADB command. session.value.sendLyncMessage( 'lync_adb_shell', JSON.stringify({ id: Date.now(), // The unique identifier of the command to be executed. cmd: OperationMap[type], }), ); ``` -------------------------------- ### Disconnection Error Codes Source: https://www.alibabacloud.com/help/en/agentbay/web-sdk-of-agentbay This section lists the error codes related to client disconnections and their corresponding explanations. ```APIDOC ## Disconnection Errors ### Description This section details the various error codes that indicate a disconnection event, along with their specific meanings. ### Error Codes | Code | Name | Description | |---|---|---| | 0 | ASP_CLIENT_DISCONNECT_CONNECT_ERROR | Disconnected. | | 1 | ASP_CLIENT_DISCONNECT_SOCKET_CLOSE | Socket closed. | | 2 | ASP_CLIENT_DISCONNECT_WEBRTC_CLOSE | WebRTC closed. | | 25 | | Ticket verification failed. If a user is disconnected and then uses the same ticket to request a connection again, this error is also triggered. | | 2001 | ASP_CLIENT_DISCONNECT_CLOUD_APP_STOP | The cloud application is closed. | | 2002 | ASP_CLIENT_DISCONNECT_CLIENT_PREEMPTION | The current cloud phone is preempted. | | 2003 | ASP_CLIENT_DISCONNECT_GUEST_SHUTDOWN_REBOOT | The guest is restarted. | | 2004 | | The current user is disconnected. | | 2027 | | The stream pulling mode is switched. | | 2200 | ASP_CLIENT_RTT_TIMEOUT | RTT timeout. | | 2201 | ASP_CLIENT_NET_ERROR_IO | Network I/O error. | | 2202 | ASP_CLIENT_UPDATE_TICKET_FAILED | Failed to update the ticket. | ``` -------------------------------- ### Enumeration Types Source: https://www.alibabacloud.com/help/en/agentbay/web-sdk-of-agentbay Definitions and descriptions of various enumeration types used in the API. ```APIDOC ## Enumeration Types ### OpenType #### Description The method to start a cloud phone. #### Enumerations - **newTab**: Opens in a new tab. - **inline**: Opens in an embedded iframe page. - **urlScheme**: Supports opening with a local native client. You must install Alibaba Cloud Workspace client V6.2 or later for this option. ``` ```APIDOC ### ConnectType #### Description Specifies whether to start a cloud computer or a cloud phone. #### Enumerations - **app**: Starts a cloud phone. Currently, the app type is reused for cloud phones. When you connect to a cloud phone, set `connectType` to `app`. - **desktop**: Starts a cloud computer. ``` ```APIDOC ### ResourceType #### Description Specifies whether to open the local connection page or the Alibaba Cloud Workspace web client. #### Enumerations - **local**: Opens the local connection HTML page. For cloud phone integration, set this parameter to `local`. ``` ```APIDOC ### ReconnectType #### Description The UI of the reconnection prompt pop-up window. #### Enumerations - **simple**: A simple loading style. - **normal**: A countdown pop-up window. ``` ```APIDOC ### ResolutionType #### Description The default resolution for the initial connection. If the user has set a preferred resolution, that resolution is used instead. #### Enumerations - **A**: Speed-prioritized. The current window size. - **B**: Quality-prioritized. The current window size multiplied by window.devicePixelRatio. ``` ```APIDOC ### ChargeType #### Description The billing method of the cloud phone. #### Enumerations - **PostPaid**: Pay-as-you-go. Supported versions: 1.4.0 or later. - **PrePaid**: Subscription. Supported versions: 1.4.0 or later. ``` ```APIDOC ### Language #### Description The language setting. Default value: `zh-CN`. #### Enumerations - **zh-CN**: Simplified Chinese - **en-US**: English - **ja-JP**: Japanese ``` ```APIDOC ### LoginType #### Description The method to log on to a cloud phone. #### Enumerations - **aliyunLogin**: Log on with an Alibaba Cloud account. - **normalLogin**: Log on with a Alibaba Cloud Workspace account. Cloud phones support only `normalLogin`. ``` ```APIDOC ### SessionEventType #### Description The mapping of session event types. This includes descriptions of cloud phone events. #### Enumerations - **getConnectionTicketInfo**: The event of connecting to a cloud phone. Supported versions: 1.0.0 or later. - **onConnected**: The event of establishing a connection to a cloud phone. Supported versions: 1.0.0 or later. - **onDisConnected**: The event of disconnecting from a cloud phone. Supported versions: 1.0.0 or later. - **onRuntimeMsg**: A message sent from the runtime to the SDK. Supported versions: 1.1.0 or later. - **networkData**: Network performance parameters. Supported versions: 1.3.1 or later. - **onError**: Receives errors that occur during the connection process. Supported versions: 1.4.1 or later. ``` ```APIDOC ### ConnDecodeType #### Description The decoding type of the stream. #### Enumerations - **0**: Software decoding. Supported versions: 1.2.0 or later. - **1**: Hardware decoding. Supported versions: 1.2.0 or later. - **2**: WebRTC. Supported versions: 1.2.0 or later. ``` ```APIDOC ### Protocol Type #### Description The connection protocol type. #### Enumerations - **ASP**: Alibaba Cloud in-house ASP protocol. Cloud phones support only the ASP protocol. Supported versions: 1.3.0 or later. - **HDX**: Citrix protocol. Supported versions: 1.3.0 or later. ``` -------------------------------- ### Send Data Channel Message Source: https://www.alibabacloud.com/help/en/agentbay/web-sdk-of-agentbay Sends a message over a configured data channel. The message content must be a Uint8Array. ```javascript // Send a tunnel message. // Request parameters: channel name, message content. session.sendDataChannelMessage('wy_vdagent_default_dc', new Uint8Array([1, 2, 3, 4])); ``` -------------------------------- ### Stop Session Connection Source: https://www.alibabacloud.com/help/en/agentbay/web-sdk-of-agentbay Terminates an active session connection. Call this method to cleanly disconnect from the workspace. ```javascript session.stop(); ``` -------------------------------- ### onError Callback Structure Source: https://www.alibabacloud.com/help/en/agentbay/web-sdk-of-agentbay The onError callback is triggered when a connection process error occurs. It returns an object containing the error code, a message with a request ID, and the API endpoint that triggered the error. ```APIDOC ## onError Callback ### Description This callback receives connection process errors. The message parameter includes a requestId for tracking, and the api parameter identifies the specific request that failed. ### Response Format - **code** (string) - The specific error code identifier. - **message** (string) - Detailed error message containing the requestId. - **api** (string) - The name of the API request that reported the error. ### Response Example { "code": "desktop-DesktopNetworkError", "message": "The network of this cloud phone is abnormal. RequestId: 12345-abcde", "api": "connectCloudPhone" } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.