### Full Event Listener Setup Example Source: https://github.com/ezviz-openbiz/ezuikit-javascript-npm/blob/master/EZUIKitNative/EZUIKitNative集成文档.md Sets up listeners for 'connect', 'capturePicture', and 'stopSave' events, then initializes the player. ```javascript const native = new EZUIKit.EZUIKitNative({ container: "players-container" }); // 监听插件连接状态 native.eventEmitter.on('connect', (res) => { if (res.code === 0) { console.log('插件连接成功'); } else { console.error('插件连接失败', res); } }); // 监听截图事件 native.eventEmitter.on('capturePicture', (res) => { if (res.code === 0) { console.log('截图完成:', res.data.fileName); // 自动下载截图 const link = document.createElement('a'); link.download = res.data.fileName; link.href = res.data.base64; document.body.appendChild(link); link.click(); document.body.removeChild(link); } }); // 监听录制停止事件 native.eventEmitter.on('stopSave', (res) => { if (res.code === 0 && res.data) { console.log('录制完成:', res.data.url); } }); // 初始化播放器 native.init({ layout: { col: 4, row: 4 }, deviceList: [/* 设备配置 */] }); ``` -------------------------------- ### Complete EZUIKitNative Example Source: https://github.com/ezviz-openbiz/ezuikit-javascript-npm/blob/master/EZUIKitNative/EZUIKitNative集成文档.md A full HTML example demonstrating the setup and initialization of EZUIKitNative, including container preparation and player initialization upon successful plugin connection. ```html EZUIKitNative 示例
``` -------------------------------- ### Install ezuikit-js via npm Source: https://github.com/ezviz-openbiz/ezuikit-javascript-npm/blob/master/EZUIKitNative/EZUIKitNative集成文档.md Install the ezuikit-js dependency in your project using npm. ```javascript npm install ezuikit-js ``` -------------------------------- ### native.play(id, params) Source: https://github.com/ezviz-openbiz/ezuikit-javascript-npm/blob/master/EZUIKitNative/EZUIKitNative集成文档.md Starts playing the specified video or all videos. Can target a specific player by ID or index, or play all. ```APIDOC ## native.play(id, params) ### Description Starts playing the specified video or all videos. ### Method `native.play` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **id** (string | number) - Optional - The ID or index of the player to play. If omitted, all players will play. - **params** (any) - Optional - Playback parameters. ### Request Example ```javascript // Play a specific player by index native.play(0); // Play a specific player by ID native.play('player0'); // Play all players native.play(); ``` ### Response #### Success Response (200) No specific response body is documented. #### Response Example None ``` -------------------------------- ### Install ezuikit-js via yarn Source: https://github.com/ezviz-openbiz/ezuikit-javascript-npm/blob/master/EZUIKitNative/EZUIKitNative集成文档.md Install the ezuikit-js dependency in your project using yarn. ```javascript yarn add ezuikit-js ``` -------------------------------- ### Deploy to Docker Nginx Source: https://github.com/ezviz-openbiz/ezuikit-javascript-npm/blob/master/demos/with-docker-nginx/README.md Starts the Docker Compose services in detached mode to deploy to a Docker Nginx container. Access the application at http://localhost:8000. ```bash ## 部署到docker的nginx容器中 ## http://localhost:8000 docker-compose up -d ``` -------------------------------- ### Decoder Load Events Source: https://github.com/ezviz-openbiz/ezuikit-javascript-npm/blob/master/README.md Listen for events related to the decoder resource loading process, including start and completion. ```APIDOC ## Decoder Load Events ### Description Subscribes to `decoderLoad` to be notified when the decoder resources begin loading, and to `decoderLoaded` when the loading process is complete. ### Method `player.eventEmitter.on(EZUIKitPlayer.EVENTS.decoderLoad, () => { ... });` `player.eventEmitter.on(EZUIKitPlayer.EVENTS.decoderLoaded, () => { ... });` ### Parameters None ### Request Example ```javascript // Listen for decoder resource loading start player.eventEmitter.on(EZUIKitPlayer.EVENTS.decoderLoad, () => { console.log("Decoder loading started..."); }); // Listen for decoder resource loading completion player.eventEmitter.on(EZUIKitPlayer.EVENTS.decoderLoaded, () => { console.log("Decoder loading completed."); }); ``` ### Response None ``` -------------------------------- ### Listen for Decoder Load Events Source: https://github.com/ezviz-openbiz/ezuikit-javascript-npm/blob/master/README.md Handle events related to the decoder resource loading process. This includes events for when the decoder starts loading and when it finishes loading. ```javascript // 监听解码资源开始加载事件 player.eventEmitter.on(EZUIKitPlayer.EVENTS.decoderLoad, () => { // ... }); // 监听解码资源加载完成事件 player.eventEmitter.on(EZUIKitPlayer.EVENTS.decoderLoaded, () => { // ... }); ``` -------------------------------- ### Video Info Event Source: https://github.com/ezviz-openbiz/ezuikit-javascript-npm/blob/master/README.md Listen for video information events to get details about the video stream's format, resolution, and frame rate. ```APIDOC ## Video Info Event ### Description Subscribes to the `videoInfo` event to receive real-time information about the video stream, including format, resolution, and frame rate. This event can be continuously triggered if `streamInfoCBType` is set to 0 during initialization. ### Method `player.eventEmitter.on(EZUIKitPlayer.EVENTS.videoInfo, (info) => { ... });` ### Parameters None ### Event Data - **info** (VideoInfo) - An object containing video stream details: - **videoFormatName** (string) - The name of the video format. - **width** (number) - The width of the video. - **height** (number) - The height of the video. - **frameRate** (number) - The frame rate of the video. - **intervalOfIFrame** (number) - The interval of I-frames (average size of the last 5 GOPs). ### Request Example ```javascript player.eventEmitter.on(EZUIKitPlayer.EVENTS.videoInfo, (info) => { console.log("videoInfo", info); }); ``` ### Response None ``` -------------------------------- ### Audio Info Event Source: https://github.com/ezviz-openbiz/ezuikit-javascript-npm/blob/master/README.md Listen for audio information events to get details about the audio stream's format, channels, and sample rate. ```APIDOC ## Audio Info Event ### Description Subscribes to the `audioInfo` event to receive real-time information about the audio stream, such as format, channels, and sample rate. This event can be continuously triggered if `streamInfoCBType` is set to 0 during initialization. ### Method `player.eventEmitter.on(EZUIKitPlayer.EVENTS.audioInfo, (info) => { ... });` ### Parameters None ### Event Data - **info** (AudioInfo) - An object containing audio stream details: - **audioFormatName** (string) - The name of the audio format. - **audioChannels** (number) - The number of audio channels. - **audioBitsPerSample** (number) - The audio sample bit depth. - **audioSamplesRate** (number) - The audio sample rate. - **audioBitRate** (number) - The audio bitrate. ### Request Example ```javascript player.eventEmitter.on(EZUIKitPlayer.EVENTS.audioInfo, (info) => { console.log("audioInfo", info); }); ``` ### Response None ``` -------------------------------- ### EZUIKitNative Initialization (No-Plugin Mode) Source: https://github.com/ezviz-openbiz/ezuikit-javascript-npm/blob/master/EZUIKitNative/EZUIKitNative集成文档.md Demonstrates how to initialize EZUIKitNative in 'no-plugin' mode or when it's automatically selected due to device list constraints. It also shows how to access and control individual player instances. ```APIDOC ## Initialize EZUIKitNative in No-Plugin Mode ### Description Initializes EZUIKitNative, specifying the `mode` to `0` for no-plugin mode. This mode is also automatically used if `mode` is `1` (auto) and the `deviceList` count is 9 or less. The example shows how to access player instances via the `players` property and call methods on them, such as `changePlayUrl`. ### Constructor `new EZUIKit.EZUIKitNative(options)` ### Parameters #### Options - **container** (string) - The ID of the HTML element to contain the players. - **mode** (number) - Playback mode: `0` for no-plugin, `1` for auto, `2` for force-plugin. Defaults to `2`. - **deviceList** (Array) - A list of devices to play. Each object should contain: - **id** (string) - Unique identifier for the player. - **width** (string) - Width of the player. - **height** (string) - Height of the player. - **template** (string) - Player template (e.g., 'pcLive'). - **url** (string) - The playback URL. - **accessToken** (string) - Access token for playback. - **handleSuccess** (function) - Callback for successful playback. - **handleError** (function) - Callback for playback errors. ### Example ```javascript const native = new EZUIKit.EZUIKitNative({ container: "players-container", mode: 0, // 0: no-plugin, 1: auto, 2: force-plugin deviceList: [ { id: 'player0', width: '100%', height: '100%', template: 'pcLive', url: 'ezopen://open.ys7.com/设备序列号/通道号.live', accessToken: 'at.xxx', handleSuccess: () => { console.log('Playback successful'); }, handleError: (res) => { console.error('Playback failed', res); } } ] }); // Accessing and controlling a player instance native.players[0].changePlayUrl({ url: "ezopen://open.ys7.com/设备序列号/通道号.live" }); ``` ``` -------------------------------- ### native.init(options) Source: https://github.com/ezviz-openbiz/ezuikit-javascript-npm/blob/master/EZUIKitNative/EZUIKitNative集成文档.md Initializes the player and configures the device list. This is the primary function to set up the video playback environment. ```APIDOC ## native.init(options) ### Description Initializes the player and configures the device list. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **options** (object) - Required - Configuration options for initialization. - **deviceList** (array[EZUIKitPlayerParams]) - Required - List of devices to configure. - **id** (string) - Required - Unique identifier for the player. - **width** (string) - Required - Player width. - **height** (string) - Required - Player height. - **template** (string) - Required - Template type: 'pcLive' (live) or 'pcRec' (playback). - **url** (string) - Required - Playback URL (ezopen protocol). - **accessToken** (string) - Required - Access token. - **handleSuccess** (Function) - Optional - Callback for successful playback. - **handleError** (Function) - Optional - Callback for playback errors. - **handleInitSuccess** (Function) - Optional - Callback for successful initialization. - **stopSaveCallBack** (Function) - Optional - Callback for stop recording. - **layout** (object) - Optional - Layout configuration, takes precedence over instance creation. - **col** (number) - Number of columns in the layout. - **row** (number) - Number of rows in the layout. *Note: If the number of devices in `deviceList` exceeds the total number of layout slots, only the first `col * row` elements will be initialized.* ### Request Example ```javascript native.init({ layout: { col: 4, row: 4 }, deviceList: [ { id: 'player0', width: '100%', height: '100%', template: 'pcLive', url: 'ezopen://open.ys7.com/设备序列号/通道号.live', accessToken: 'at.xxx', handleSuccess: () => { console.log('播放成功'); }, handleError: (res) => { console.error('播放失败', res); } } ] }); ``` ### Response #### Success Response (200) No specific response body is documented. #### Response Example None ``` -------------------------------- ### Full EZUIKitNative Initialization and Usage Source: https://github.com/ezviz-openbiz/ezuikit-javascript-npm/blob/master/EZUIKitNative/EZUIKitNative集成文档.md Demonstrates the complete lifecycle of EZUIKitNative, from instantiation and initialization to API calls and destruction. ```javascript const native = new EZUIKit.EZUIKitNative({ container: "players-container", mode: 2, autoPlay: true }); //初始化播放 native.init({ layout: { col: 4, row: 4 }, deviceList: [ { id: 'player0', width: '100%', height: '100%', template: 'pcLive', url: 'ezopen://open.ys7.com/设备序列号/通道号.live', accessToken: 'at.xxx', handleSuccess: () => { console.log('播放成功'); }, handleError: (res) => { console.error('播放失败', res); } } ] }); // 调用指定播放器的API native.changePlayUrl("player2", { url :"ezopen://open.ys7.com/设备序列号/1.live" }) // 销毁所有播放器 native.destroy(); ``` -------------------------------- ### Player Initialization and Destruction Source: https://github.com/ezviz-openbiz/ezuikit-javascript-npm/blob/master/EZUIKitNative/EZUIKitNative集成文档.md Demonstrates the lifecycle of an EZUIKitNative instance, including initialization with player configurations and final destruction. ```APIDOC ## `new EZUIKit.EZUIKitNative(options)` and `native.destroy()` ### Description Initializes the EZUIKitNative instance with specified options and provides a method to clean up all resources upon completion. ### Initialization #### `new EZUIKit.EZUIKitNative(options)` - **Description**: Creates a new instance of EZUIKitNative. - **Parameters**: - **options** (object) - Required - Configuration object for the native instance. - **container** (string) - Required - The ID of the HTML element where players will be rendered. - **mode** (number) - Optional - Playback mode (e.g., 2 for multi-player grid). - **autoPlay** (boolean) - Optional - Whether to automatically start playback upon initialization. #### `native.init(config)` - **Description**: Initializes the player layout and devices within the EZUIKitNative instance. - **Parameters**: - **config** (object) - Required - Configuration for player initialization. - **layout** (object) - Required - Defines the grid layout for players (e.g., `{ col: 4, row: 4 }`). - **deviceList** (array) - Required - An array of device configurations for each player. - Each device object can include `id`, `width`, `height`, `template`, `url`, `accessToken`, `handleSuccess`, and `handleError` properties. ### Destruction #### `native.destroy()` - **Description**: Cleans up all resources associated with the EZUIKitNative instance, including stopping playback and releasing the plugin. ### Request Example ```javascript // Create a native instance const native = new EZUIKit.EZUIKitNative({ container: "players-container", mode: 2, autoPlay: true }); // Initialize players native.init({ layout: { col: 4, row: 4 }, deviceList: [ { id: 'player0', width: '100%', height: '100%', template: 'pcLive', url: 'ezopen://open.ys7.com/设备序列号/通道号.live', accessToken: 'at.xxx', handleSuccess: () => { console.log('Playback successful'); }, handleError: (res) => { console.error('Playback failed', res); } } ] }); // ... later, when done ... // Destroy all players native.destroy(); ``` ``` -------------------------------- ### Initialize Player After Plugin Connection Source: https://github.com/ezviz-openbiz/ezuikit-javascript-npm/blob/master/EZUIKitNative/EZUIKitNative集成文档.md Initialize the player once the plugin connection is successfully established. Initialization commands sent before connection may fail. ```javascript native.eventEmitter.on('connect', (res) => { if (res.code !== 0) { console.log(`插件连接断开: ${JSON.stringify(res)}`, 'error'); } else { console.log(`插件连接成功`, 'success'); // 初始化播放器 native.init({ layout: { col: 2, row: 2 }, deviceList: [ { id: 'player0', width: '100%', height: '100%', template: 'pcLive', url: 'ezopen://open.ys7.com/设备序列号/1.live', accessToken: 'your_access_token', staticPath: './ezuikit_static' } ] }); } }) ``` -------------------------------- ### Import EZUIKit SDK in HTML Source: https://github.com/ezviz-openbiz/ezuikit-javascript-npm/blob/master/EZUIKitNative/EZUIKitNative集成文档.md Include the EZUIKit SDK in your HTML file using a script tag. ```html ``` -------------------------------- ### Initialize EZUIKitNative Player Source: https://github.com/ezviz-openbiz/ezuikit-javascript-npm/blob/master/EZUIKitNative/EZUIKitNative集成文档.md Initializes the player with device list and layout configurations. Ensure deviceList contains valid EZUIKitPlayerParams. The layout parameter determines the grid size for displaying multiple players. ```javascript native.init({ layout: { col: 4, row: 4 }, deviceList: [ { id: 'player0', width: '100%', height: '100%', template: 'pcLive', url: 'ezopen://open.ys7.com/设备序列号/通道号.live', accessToken: 'at.xxx', handleSuccess: () => { console.log('播放成功'); }, handleError: (res) => { console.error('播放失败', res); } } ] }); ``` -------------------------------- ### Create Player Container Source: https://github.com/ezviz-openbiz/ezuikit-javascript-npm/blob/master/EZUIKitNative/EZUIKitNative集成文档.md Prepare a container element in your HTML to serve as the anchor for the plugin. ```html
``` -------------------------------- ### Initialize EZUIKitNative in Plugin Mode Source: https://github.com/ezviz-openbiz/ezuikit-javascript-npm/blob/master/EZUIKitNative/EZUIKitNative集成文档.md Creates an EZUIKitNative instance with the mode explicitly set to plugin (2). This mode is suitable for scenarios requiring more than 9 concurrent playback screens, such as multi-screen inspection or large display scenarios. ```javascript const native = new EZUIKit.EZUIKitNative({ container: "players-container", mode: 2 }); ``` -------------------------------- ### native.fullscreen() Source: https://github.com/ezviz-openbiz/ezuikit-javascript-npm/blob/master/EZUIKitNative/EZUIKitNative集成文档.md Enters full-screen mode for the entire plugin. Individual player full-screen can be toggled by double-clicking a player. ```APIDOC ## native.fullscreen() ### Description Enters full-screen mode for the entire plugin. ### Method `native.fullscreen` ### Parameters None ### Request Example ```javascript // Enter overall full-screen mode native.fullscreen(); ``` ### Response #### Success Response (200) No specific response body is documented. #### Response Example None ``` -------------------------------- ### Import EZUIKit SDK in JavaScript Source: https://github.com/ezviz-openbiz/ezuikit-javascript-npm/blob/master/EZUIKitNative/EZUIKitNative集成文档.md Import the EZUIKit SDK into your JavaScript project. ```javascript import EZUIKit from "ezuikit-js"; ``` -------------------------------- ### EZUIKitNative Constructor (Plugin Mode) Source: https://github.com/ezviz-openbiz/ezuikit-javascript-npm/blob/master/EZUIKitNative/EZUIKitNative集成文档.md Details the constructor for EZUIKitNative when using plugin mode, including its parameters and return value. ```APIDOC ## EZUIKitNative Constructor ### Description Creates an instance of EZUIKitNative. This documentation specifically covers the constructor parameters relevant to plugin mode. ### Method `new EZUIKit.EZUIKitNative(options)` ### Parameters #### Options - **container** (HTMLElement | string) - The DOM element or its ID that the plugin will attach to. Required. - **mode** (number) - Specifies the playback mode. `0`: No plugin, `1`: Auto, `2`: Force plugin. Defaults to `2`. - **autoPlay** (boolean) - Determines if playback should start automatically. Defaults to `false`. - **layout** (object) - Defines the grid layout for players. Defaults to a 4x4 grid. Can be modified later. Example: `{ col: 4, row: 4 }`. ### Return Value An EZUIKitNative instance. ### Example ```javascript const native = new EZUIKit.EZUIKitNative({ container: "players-container", mode: 2 // Force plugin mode }); ``` ``` -------------------------------- ### EZUIKit Player Control Functions Source: https://github.com/ezviz-openbiz/ezuikit-javascript-npm/blob/master/demos/base-demo/themeDataRec.html Provides essential functions to control the EZUIKit Player instance, including fullscreen, play, stop, capturing pictures, managing audio, recording, and talking. Ensure a player instance is initialized before calling these functions. ```javascript function fullscreen() { if (player) player.fullscreen(); } ``` ```javascript function play() { if (player) player.play(); } ``` ```javascript function stop() { if (player) player.stop() } ``` ```javascript function getOSDTime() { if (player) player.getOSDTime().then((data) => { console.log("getOSDTime 获取 数据", data) }) } ``` ```javascript function capturePicture() { if (player) player.capturePicture().then((data) => { console.log("capturePicture 获取 数据", data) }) } ``` ```javascript function openSound() { if (player) player.openSound() } ``` ```javascript function closeSound() { if (player) player.closeSound() } ``` ```javascript function startSave() { if (player) player.startSave().then((data) => { console.log("startSave 获取 数据", data) }) } ``` ```javascript function stopSave() { if (player) player.stopSave().then((data) => { console.log("stopSave 获取 数据", data) }) } ``` ```javascript function startTalk() { if (player) player.startTalk(); } ``` ```javascript function stopTalk() { if (player) player.stopTalk(); } ``` ```javascript function destroy() { if (player) player.destroy(); player = null } ``` -------------------------------- ### native.exitfullscreen() Source: https://github.com/ezviz-openbiz/ezuikit-javascript-npm/blob/master/EZUIKitNative/EZUIKitNative集成文档.md Exits the full-screen mode for the entire plugin. ```APIDOC ## native.exitfullscreen() ### Description Exits the full-screen mode for the entire plugin. ### Method `native.exitfullscreen` ### Parameters None ### Request Example ```javascript // Exit overall full-screen mode native.exitfullscreen(); ``` ### Response #### Success Response (200) No specific response body is documented. #### Response Example None ``` -------------------------------- ### EZUIKit Player Initialization with Theme Data Source: https://github.com/ezviz-openbiz/ezuikit-javascript-npm/blob/master/demos/base-demo/themeDataRec.html Initializes the EZUIKit Player with custom theme data, including header and footer button configurations. The `flattenToNested` function is used to process form data into a nested object structure suitable for player options. Ensure the 'video-container' ID exists in your HTML. ```javascript var player; function handleSubmit(form) { const formData = new FormData(form); let opt = {} for (const [key, value] of formData.entries()) { const obj = flattenToNested(key, value) opt[key] = value } opt = flattenToNested(opt) if (opt.themeData.header && opt.themeData.header.btnList && opt.themeData.header.btnList.length > 0) { for (let i = 0; i < opt.themeData.header.btnList.length; i++) { let btn = opt.themeData.header.btnList[i]; opt.themeData.header.btnList[i] = { ...btnList[btn.iconId], isrender: 1, } } } if (opt.themeData.footer && opt.themeData.footer.btnList && opt.themeData.footer.btnList.length > 0) { for (let i = 0; i < opt.themeData.footer.btnList.length; i++) { let btn = opt.themeData.footer.btnList[i]; opt.themeData.footer.btnList[i] = { ...btnList[btn.iconId], isrender: 1, } } } destroy() console.warn('EZUIKitPlayer options', opt) player = new EZUIKit.EZUIKitPlayer({ id: 'video-container', // 视频容器ID scaleMode: 1, // 默认 0 完全填充窗口,会有拉伸 1: 等比适配 2: 等比完全填充窗口, 超出隐藏 @sine 8.2.0 ...opt, env: { // https://open.ys7.com/help/1772?h=domain // domain默认是 https://open.ys7.com, 如果是私有化部署或海外的环境,请配置对应的domain // The default domain is https://open.ys7.com If it is a private deployment or overseas (outside of China) environment, please configure the corresponding domain domain: "https://open.ys7.com" } }); return false } ``` -------------------------------- ### Player initialization in HTML Source: https://github.com/ezviz-openbiz/ezuikit-javascript-npm/blob/master/skills/Ezuikit_Native_Skill.md This HTML snippet demonstrates how to initialize the EZUIKit Player component within a web page. It specifies the role as 'player' and targets a container element with the ID 'player-container'. ```html ``` -------------------------------- ### EZUikit Connection State Flow Source: https://github.com/ezviz-openbiz/ezuikit-javascript-npm/blob/master/skills/ezuikit_native_integration.md Illustrates the state transitions for WebSocket connections in EZUikit, from idle to closed, including retrying logic. ```text idle → connecting → connected → closed ↘ retrying → connecting → connected ↘ retrying → ... (最多 3 次后 → closed) ``` -------------------------------- ### Direct API Call Source: https://github.com/ezviz-openbiz/ezuikit-javascript-npm/blob/master/EZUIKitNative/EZUIKitNative集成文档.md EZUIKitNative instances support passing parameters to directly call specific player APIs. This allows for dynamic control over individual player instances within the native container. ```APIDOC ## `native.api(id, params)` ### Description Allows direct invocation of an API on a specific player instance identified by `id`, passing `params` to the API. ### Method `native.api(id: string, params: object)` ### Parameters #### Path Parameters - **id** (string) - Required - The identifier of the player instance to call the API on. - **params** (object) - Required - The parameters to pass to the specified API. ### Request Example ```javascript // Call the changePlayUrl method on the player with id 'player2', passing the URL parameter. native.changePlayUrl("player2", { url: "ezopen://open.ys7.com/AZ3754171/1.live" }); ``` ### Further Information For a list of available APIs and their specific parameters, refer to: https://open.ys7.com/help/4275 ``` -------------------------------- ### Open Sound Event Source: https://github.com/ezviz-openbiz/ezuikit-javascript-npm/blob/master/README.md Listen for the open sound event, which is triggered when the audio is turned on. ```APIDOC ## Open Sound Event ### Description Subscribes to the `openSound` event, which is emitted when the audio is turned on. The default volume is 0.8, and it cannot be changed at this time. ### Method `player.eventEmitter.on(EZUIKitPlayer.EVENTS.openSound, () => { ... });` ### Parameters None ### Request Example ```javascript player.eventEmitter.on(EZUIKitPlayer.EVENTS.openSound, () => { // Audio is now on }); ``` ### Response None ``` -------------------------------- ### Initialize EZUIKitNative in Non-Plugin Mode Source: https://github.com/ezviz-openbiz/ezuikit-javascript-npm/blob/master/EZUIKitNative/EZUIKitNative集成文档.md Initializes EZUIKitNative with mode set to non-plugin (0). This mode is also automatically used if the device list has 9 or fewer devices and the mode is set to auto (1). Players are managed by the EZUIKitNative instance's 'players' property. Usage, function calls, and event listening are identical to EZUIKitPlayer. ```javascript const native = new EZUIKit.EZUIKitNative({ container: "players-container", mode: 0, // 0:不使用插件,1:自动,2:强制使用插件 deviceList: [ { id: 'player0', width: '100%', height: '100%', template: 'pcLive', url: 'ezopen://open.ys7.com/设备序列号/通道号.live', accessToken: 'at.xxx', handleSuccess: () => { console.log('播放成功'); }, handleError: (res) => { console.error('播放失败', res); } } ] }); ``` -------------------------------- ### Listen for Plugin Connection Status Source: https://github.com/ezviz-openbiz/ezuikit-javascript-npm/blob/master/EZUIKitNative/EZUIKitNative集成文档.md Register a listener for the 'connect' event to monitor the plugin's connection status and log success or failure. ```javascript native.eventEmitter.on('connect', (res) => { if (res.code !== 0) { console.log(`插件连接失败: ${JSON.stringify(res)}`, 'error'); } else { console.log(`插件连接成功`, 'success'); } }) ``` -------------------------------- ### Listen for Open Sound Event Source: https://github.com/ezviz-openbiz/ezuikit-javascript-npm/blob/master/README.md Register a listener for the event that occurs when the sound is turned on. The default volume is 0.8 and cannot be changed. ```javascript // 监听打开声音事件, 默认音量是 0.8 暂时不支持更改 player.eventEmitter.on(EZUIKitPlayer.EVENTS.openSound, () => { // ... }); ``` -------------------------------- ### Event Listener Registration Source: https://github.com/ezviz-openbiz/ezuikit-javascript-npm/blob/master/EZUIKitNative/EZUIKitNative集成文档.md EZUIKitNative provides an EventEmitter for listening to various player events, such as 'capturePicture', 'connect', and 'stopSave'. Use the `on` method to register these listeners. ```APIDOC ## `native.eventEmitter.on(eventName, callback)` ### Description Registers a callback function to be executed when a specific event is triggered by the EZUIKitNative instance or its players. ### Method `native.eventEmitter.on(eventName: string, callback: function)` ### Parameters #### Path Parameters - **eventName** (string) - Required - The name of the event to listen for (e.g., 'capturePicture', 'connect', 'stopSave'). - **callback** (function) - Required - The function to execute when the event is triggered. The callback receives event-specific data as an argument. ### Event Details #### 'capturePicture' - **Description**: Triggered when a screenshot is taken (either by user action or programmatically via `capturePicture`). - **Callback Data**: `res` object containing `code` (0 for success), and `data` with `fileName` and `base64` image data on success. #### 'connect' - **Description**: Monitors the connection status of the native plugin. - **Callback Data**: `res` object with `eventType` ('connect'), `code` (0: connected, -1: disconnected, -2: connection failed), and `msg` (status description). #### 'stopSave' - **Description**: Triggered when video recording stops. - **Callback Data**: `res` object containing `code` (0 for success) and `data` with the `url` of the saved recording on success. ### Request Example ```javascript // Listen for the 'capturePicture' event native.eventEmitter.on('capturePicture', (res) => { if (res.code === 0) { console.log(`Screenshot callback, file name: ${res.data.fileName}, file data: ${res.data.base64}`); // Example: Auto-download the captured image const link = document.createElement('a'); link.download = res.data.fileName; link.href = res.data.base64; document.body.appendChild(link); link.click(); document.body.removeChild(link); } }); // Listen for the 'connect' event native.eventEmitter.on('connect', (res) => { if (res.code !== 0) { console.log(`Plugin connection failed: ${JSON.stringify(res)}`, 'error'); } else { console.log(`Plugin connected successfully`, 'success'); } }); ``` ### Further Information For a comprehensive list of all available events, refer to: https://open.ys7.com/help/4275 ``` -------------------------------- ### Create EZUIKitNative Instance by DOM Element Source: https://github.com/ezviz-openbiz/ezuikit-javascript-npm/blob/master/EZUIKitNative/EZUIKitNative集成文档.md Instantiate EZUIKitNative, specifying the container element using a DOM element reference. ```javascript // 通过DOM元素确定跟随锚点 const native = new EZUIKit.EZUIKitNative({ container: document.getElementById("players-container") // 容器DOM元素 }); ``` -------------------------------- ### Configure Player Logger Options Source: https://github.com/ezviz-openbiz/ezuikit-javascript-npm/blob/master/README.md Set logger options for the player. The options object can include name, level, and showTime properties to control logging behavior. ```typescript // interface LoggerOptions { // name?: string // level?: 'INFO' | 'LOG' | 'WARN' | 'ERROR', // showTime?: boolean // } player.setLoggerOptions(options); ``` -------------------------------- ### Call Player API with Parameters Source: https://github.com/ezviz-openbiz/ezuikit-javascript-npm/blob/master/EZUIKitNative/EZUIKitNative集成文档.md Invoke a specific API on a player instance by its ID, passing necessary parameters. ```javascript native.changePlayUrl("player2", { url :"ezopen://open.ys7.com/AZ3754171/1.live" }) ``` -------------------------------- ### native.reload() Source: https://github.com/ezviz-openbiz/ezuikit-javascript-npm/blob/master/EZUIKitNative/EZUIKitNative集成文档.md Resets the plugin window. ```APIDOC ## native.reload() ### Description Resets the plugin window. ### Method `native.reload` ### Parameters None ### Request Example ```javascript native.reload(); ``` ### Response #### Success Response (200) No specific response body is documented. #### Response Example None ``` -------------------------------- ### Logger Options Source: https://github.com/ezviz-openbiz/ezuikit-javascript-npm/blob/master/README.md Configure logging options for the player. This allows control over log level, name, and time display. ```APIDOC ## setLoggerOptions ### Description Sets the logging options for the player. This method allows you to configure the verbosity and format of log messages. ### Method `player.setLoggerOptions(options)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **options** (LoggerOptions) - Optional - An object containing logger configuration. - **name** (string) - Optional - A label for log messages. - **level** (string) - Optional - The logging level. Supported values: 'INFO', 'LOG', 'WARN', 'ERROR'. - **showTime** (boolean) - Optional - Whether to include timestamps in log messages. ### Request Example ```javascript const options = { name: 'MyPlayerLogger', level: 'INFO', showTime: true }; player.setLoggerOptions(options); ``` ### Response None ``` -------------------------------- ### Register and Remove Event Listener Source: https://github.com/ezviz-openbiz/ezuikit-javascript-npm/blob/master/EZUIKitNative/EZUIKitNative集成文档.md Demonstrates how to register an event listener using 'on' and subsequently remove it using 'off'. ```javascript const handler = (data) => { console.log('事件触发', data); }; // 注册监听 native.eventEmitter.on('connect', handler); // 移除监听 native.eventEmitter.off('connect', handler); ``` -------------------------------- ### Create EZUIKitNative Instance by ID Source: https://github.com/ezviz-openbiz/ezuikit-javascript-npm/blob/master/EZUIKitNative/EZUIKitNative集成文档.md Instantiate EZUIKitNative, specifying the container element by its ID. ```javascript // 通过id确定跟随锚点 const native = new EZUIKit.EZUIKitNative({ container: "players-container" // 容器ID }); ``` -------------------------------- ### Listen for Audio Information Events Source: https://github.com/ezviz-openbiz/ezuikit-javascript-npm/blob/master/README.md Monitor changes in audio information. To continuously receive audio information, set streamInfoCBType to 0 during initialization. ```javascript // interface AudioInfo { // audioFormatName:string // 音频格式名称 // audioChannels:number // 音频通道数 // audioBitsPerSample: number // 音频采样位数 // audioSamplesRate:number // 音频采样率 // audioBitRate: number // 音频码率 // } // 监听音频信息变化 player.eventEmitter.on(EZUIKitPlayer.EVENTS.audioInfo, (info) => { // {"audioFormat":8193,"audioFormatName":"AAC","audioChannels":1,"audioBitsPerSample":16,"audioSamplesRate":16000,"audioBitRate":32000} console.log("audioInfo", info); }); ``` -------------------------------- ### Listen for Video Clarity Change Events Source: https://github.com/ezviz-openbiz/ezuikit-javascript-npm/blob/master/README.md Subscribe to events indicating a change in video clarity. The event data includes the clarity name, level, and stream type. ```javascript // interface VideoLevelData { // "name": string, // 清晰度名称 // "level":2, // 清晰度级别 0 | 1 | 2 | 3 | 4 | 5 | 6 // "streamTypeIn":2 // 主子码流 1:主码流 2:子码流 // } // 监听截图事件 player.eventEmitter.on(EZUIKitPlayer.EVENTS.changeVideoLevel, (info) => { // {data: VideoLevelData} console.log("changeVideoLevel", info); }); ``` -------------------------------- ### Handle Playback Errors Source: https://github.com/ezviz-openbiz/ezuikit-javascript-npm/blob/master/EZUIKitNative/EZUIKitNative集成文档.md Configure the 'handleError' callback within the device configuration to manage playback failures. ```javascript { id: 'player0', url: 'ezopen://...', handleError: (res) => { console.error('播放失败', res); // 处理错误逻辑 } } ``` -------------------------------- ### Listen for Capture Picture Event Source: https://github.com/ezviz-openbiz/ezuikit-javascript-npm/blob/master/EZUIKitNative/EZUIKitNative集成文档.md Register a listener for the 'capturePicture' event to handle screenshot results, including downloading the image data. ```javascript native.eventEmitter.on('capturePicture', (res) => { if (res.code == 0) { console.log(`截图回调,文件名称:${res.data.fileName},文件数据:${res.data.base64}`); const link = document.createElement('a'); link.download = res.data.fileName; link.href = res.data.base64; document.body.appendChild(link); link.click(); document.body.removeChild(link); } }) ``` -------------------------------- ### Listen for Video Information Events Source: https://github.com/ezviz-openbiz/ezuikit-javascript-npm/blob/master/README.md Track changes in video information. To continuously receive video information, set streamInfoCBType to 0 during initialization. ```javascript // interface VideoInfo { // videoFormatName:string // 视频格式名称 // width:number // 视频宽 // height: number // 视频高 // frameRate:number // 帧率 // intervalOfIFrame: number // IFrame间隔 (统计最近 5 个 GOP 的平均大小) // } // 监听视频信息变化 player.eventEmitter.on(EZUIKitPlayer.EVENTS.videoInfo, (info) => { // {"videoFormat":5,"videoFormatName":"H265","width":3840,"height":2160,"frameRate":15,"intervalOfIFrame":0} console.log("videoInfo", info); }); ``` -------------------------------- ### Listen for connection and launch failure events Source: https://github.com/ezviz-openbiz/ezuikit-javascript-npm/blob/master/skills/Ezuikit_Native_Skill.md These TypeScript event listeners are used to monitor the connection status with the native plugin. The 'connect' event handles general connection failures, while 'launchFailed' is triggered after all retry attempts are exhausted. ```typescript native.on('connect', (data) => { if (data.code === -2) { console.log('插件连接失败,正在尝试唤起...'); } }); native.on('launchFailed', (data) => { console.log(`插件唤起失败,已重试 ${data.attempts} 次`); // 此处可展示安装引导 UI }); ``` -------------------------------- ### Listen for Screenshot Events Source: https://github.com/ezviz-openbiz/ezuikit-javascript-npm/blob/master/README.md Handle events triggered when a screenshot is taken. The event provides information including the file name and a base64 encoded image string. ```javascript // interface CapturePictureInfoDate { // fileName: string // 图片文件名称 // base64: string // base64图片字符串 // } // 监听截图事件 player.eventEmitter.on(EZUIKitPlayer.EVENTS.capturePicture, (info) => { // {data: CapturePictureInfoDate} console.log("capturePictureInfo", info); }); ``` -------------------------------- ### Reload EZUIKitNative Plugin Source: https://github.com/ezviz-openbiz/ezuikit-javascript-npm/blob/master/EZUIKitNative/EZUIKitNative集成文档.md Resets the plugin window, effectively reloading the player instances. ```javascript native.reload(); ``` -------------------------------- ### Manage Fullscreen Mode with EZUIKitNative Source: https://github.com/ezviz-openbiz/ezuikit-javascript-npm/blob/master/EZUIKitNative/EZUIKitNative集成文档.md Enables or disables fullscreen mode for the entire plugin. Individual player fullscreen can be toggled by double-clicking a player, and exited with ESC. ```javascript // 整体全屏 native.fullscreen(); ``` ```javascript // 退出整体全屏 native.exitfullscreen(); ``` -------------------------------- ### EZUIKit Player Button Configuration Object Source: https://github.com/ezviz-openbiz/ezuikit-javascript-npm/blob/master/demos/base-demo/themeDataRec.html Defines a mapping of icon IDs to button configurations for EZUIKit Player's header and footer. This object is used to dynamically assign properties like 'iconId', 'part', and 'isrender' to buttons based on their configuration. ```javascript const btnList = { // header deviceID: { "iconId": "deviceID", "part": "left", }, deviceName: { "iconId": "deviceName", "part": "left", }, cloudRecord: { "iconId": "cloudRecord", "part": "right", }, cloudRec: { "iconId": "cloudRec", "part": "right", }, rec: { "iconId": "rec", "part": "right", }, // footer play: { "iconId": "play", "part": "left", }, capturePicture: { "iconId": "capturePicture", "part": "left", }, sound: { "iconId": "sound", "part": "left", }, recordvideo: { "iconId": "recordvideo", "part": "left", }, zoom: { "iconId": "zoom", "part": "left", }, speed: { "iconId": "speed", "part": "right", }, webExpend: { "iconId": "webExpend", "part": "right", }, expend: { "iconId": "expend", "part": "right", }, fullscreen: { "iconId": "fullscreen", // 8.2.0 开始支持, 用来替换 webExpend "part": "right", }, } ``` -------------------------------- ### Listen for Stream Information Events Source: https://github.com/ezviz-openbiz/ezuikit-javascript-npm/blob/master/README.md Subscribe to stream information events. The behavior of this event depends on the initialization of streamInfoCBType. If set to 1, it triggers twice upon stream acquisition; if set to 0, it triggers continuously, potentially impacting performance. ```javascript // 监听流信息事件 player.eventEmitter.on(EZUIKitPlayer.EVENTS.streamInfoCB, (info) => { // 包括 视频信息 音频信息 console.log("streamInfoCB", info); }); ``` -------------------------------- ### Control Player in Non-Plugin Mode Source: https://github.com/ezviz-openbiz/ezuikit-javascript-npm/blob/master/EZUIKitNative/EZUIKitNative集成文档.md Accesses the first player instance from the 'players' array and calls the 'changePlayUrl' method to update the playback address. This demonstrates how to interact with individual players managed by the EZUIKitNative instance in non-plugin mode. ```javascript native.players[0].changePlayUrl({ url:"ezopen://open.ys7.com/设备序列号/通道号.live" }); ``` -------------------------------- ### Allow iframe to request fullscreen Source: https://github.com/ezviz-openbiz/ezuikit-javascript-npm/blob/master/FAQ.md Configure an iframe to allow fullscreen requests by setting the `allowfullscreen` attribute to true. This enables the iframe's `requestFullscreen()` method. ```html ``` -------------------------------- ### Change Video Level Event Source: https://github.com/ezviz-openbiz/ezuikit-javascript-npm/blob/master/README.md Listen for video level change events, which indicate a switch in video clarity. ```APIDOC ## Change Video Level Event ### Description Subscribes to the `changeVideoLevel` event, which is triggered when the video clarity is switched. The event data provides information about the new video level and stream type. ### Method `player.eventEmitter.on(EZUIKitPlayer.EVENTS.changeVideoLevel, (info) => { ... });` ### Parameters None ### Event Data - **info** (object) - Contains data related to the video level change: - **data** (VideoLevelData) - An object with video level details: - **name** (string) - The name of the video clarity level. - **level** (number) - The video clarity level (0-6). - **streamTypeIn** (number) - The stream type (1 for main stream, 2 for sub-stream). ### Request Example ```javascript player.eventEmitter.on(EZUIKitPlayer.EVENTS.changeVideoLevel, (info) => { console.log("changeVideoLevel", info); }); ``` ### Response None ``` -------------------------------- ### Destroy Event Source: https://github.com/ezviz-openbiz/ezuikit-javascript-npm/blob/master/README.md Listen for the destroy event, which is triggered when the player instance is being destroyed. ```APIDOC ## Destroy Event ### Description Subscribes to the `destroy` event, which is emitted when the player instance is being cleaned up and destroyed. This is useful for performing any necessary cleanup operations. ### Method `player.eventEmitter.on(EZUIKitPlayer.EVENTS.destroy, () => { ... });` ### Parameters None ### Request Example ```javascript player.eventEmitter.on(EZUIKitPlayer.EVENTS.destroy, () => { console.log("Player instance is being destroyed."); // Perform cleanup tasks here }); ``` ### Response None ```