zego-express-engine-reactnative
Version:
React Native Zego Express Video for Android & iOS
700 lines • 127 kB
JavaScript
import { ZegoExpressEngineImpl } from './impl/ZegoExpressEngineImpl';
export default class ZegoExpressEngine {
/**
* Engine singleton instance
*/
static instance() {
return ZegoExpressEngineImpl.getInstance();
}
/**
* Create ZegoExpressEngine singleton object and initialize SDK.
*
* Available since: 2.14.0
* Description: Create ZegoExpressEngine singleton object and initialize SDK.
* When to call: The engine needs to be created before calling other functions.
* Restrictions: None.
* Caution: The SDK only supports the creation of one instance of ZegoExpressEngine. If you need call [createEngine] multiple times, you need call [destroyEngine] before you call the next [createEngine]. Otherwise it will return the instance which created by [createEngine] you called last time.
*
* @param profile The basic configuration information is used to create the engine.
* @return engine singleton instance.
*/
static createEngineWithProfile(profile) {
return ZegoExpressEngineImpl.createEngineWithProfile(profile);
}
/**
* Destroy the ZegoExpressEngine singleton object and deinitialize the SDK.
*
* Available since: 1.1.0
* Description: Destroy the ZegoExpressEngine singleton object and deinitialize the SDK.
* When to call: When the SDK is no longer used, the resources used by the SDK can be released through this interface
* Restrictions: None.
* Caution: After using [createEngine] to create a singleton, if the singleton object has not been created or has been destroyed, you will not receive related callbacks when calling this function.
*/
static destroyEngine() {
return ZegoExpressEngineImpl.destroyEngine();
}
/**
* Set advanced engine configuration.
*
* Available since: 1.1.0
* Description: Used to enable advanced functions.
* When to call: Different configurations have different call timing requirements. For details, please consult ZEGO technical support.
* Restrictions: None.
*
* @param config Advanced engine configuration
*/
static setEngineConfig(config) {
return ZegoExpressEngineImpl.setEngineConfig(config);
}
/**
* Set room mode.
*
* Available since: 2.9.0
* Description: If you need to use the multi-room feature, please call this function to complete the configuration.
* When to call: Must be set before calling [createEngine] to take effect, otherwise it will fail.
* Restrictions: If you need to use the multi-room feature, please contact the instant technical support to configure the server support.
* Caution: None.
*
* @param mode Room mode. Description: Used to set the room mode. Use cases: If you need to enter multiple rooms at the same time for publish-play stream, please turn on the multi-room mode through this interface. Required: True. Default value: ZEGO_ROOM_MODE_SINGLE_ROOM.
*/
static setRoomMode(mode) {
return ZegoExpressEngineImpl.setRoomMode(mode);
}
/**
* Gets the SDK's version number.
*
* Available since: 1.1.0
* Description: If you encounter an abnormality during the running of the SDK, you can submit the problem, log and other information to the ZEGO technical staff to locate and troubleshoot. Developers can also collect current SDK version information through this API, which is convenient for App operation statistics and related issues.
* When to call: Any time.
* Restrictions: None.
* Caution: None.
*
* @return SDK version.
*/
static getVersion() {
return ZegoExpressEngineImpl.getVersion();
}
/**
* Uploads logs to the ZEGO server.
*
* Available since: 1.1.0
* Description: By default, SDK creates and prints log files in the App's default directory. Each log file defaults to a maximum of 5MB. Three log files are written over and over in a circular fashion. When calling this function, SDK will auto package and upload the log files to the ZEGO server.
* Use cases: Developers can provide a business “feedback” channel in the App. When users feedback problems, they can call this function to upload the local log information of SDK to help locate user problems.
* When to call: After [createEngine].
* Restrictions: The frequency limit is once per minute.
* Caution: 1.After calling this interface to upload logs, if you call [destroyEngine] or exit the App too quickly, there may be a failure.It is recommended to wait a few seconds, and then call [destroyEngine] or exit the App after receiving the upload success callback. 2.If you want to call before [createEngine], use the [submitLog] interface.
*/
uploadLog() {
return ZegoExpressEngineImpl.getInstance().uploadLog();
}
/**
* Call the experimental API.
*
* Available since: 2.7.0
* Description: ZEGO provides some technical previews or special customization functions in RTC business through this API. If you need to get the use of the function or the details, please consult ZEGO technical support.
* When to call: After [createEngine].
*
* @param params Parameters in the format of a JSON string, please consult ZEGO technical support for details.
* @return Returns an argument in the format of a JSON string, please consult ZEGO technical support for details.
*/
callExperimentalAPI(params) {
return ZegoExpressEngineImpl.getInstance().callExperimentalAPI(params);
}
/**
* Register event handler
*
* @param event event type.
* @param callback event callback.
*/
on(event, callback) {
return ZegoExpressEngineImpl.getInstance().on(event, callback);
}
/**
* Unregister event handler
*
* @param event event type.
* @param callback event callback.
*/
off(event, callback) {
return ZegoExpressEngineImpl.getInstance().off(event, callback);
}
/**
* Log in to the room by configuring advanced properties, and return the login result through the callback parameter. You must log in to the room before pushing or pulling the stream.
*
* Available since: 2.18.0
* Description: If the room does not exist, [loginRoom] creates and logs in the room. SDK uses the 'room' to organize users. After users log in to a room, they can use interface such as push stream [startPublishingStream], pull stream [startPlayingStream], send and receive broadcast messages [sendBroadcastMessage], etc. To prevent the app from being impersonated by a malicious user, you can add authentication before logging in to the room, that is, the [token] parameter in the ZegoRoomConfig object passed in by the [config] parameter.
* Use cases: In the same room, users can conduct live broadcast, audio and video calls, etc.
* When to call /Trigger: This interface is called after [createEngine] initializes the SDK.
* Restrictions: For restrictions on the use of this function, please refer to https://docs.zegocloud.com/article/7611 or contact ZEGO technical support.
* Caution:
* 1. Apps that use different appIDs cannot intercommunication with each other.
* 2. SDK supports startPlayingStream audio and video streams from different rooms under the same appID, that is, startPlayingStream audio and video streams across rooms. Since ZegoExpressEngine's room related callback notifications are based on the same room, when developers want to startPlayingStream streams across rooms, developers need to maintain related messages and signaling notifications by themselves.
* 3. It is strongly recommended that userID corresponds to the user ID of the business APP, that is, a userID and a real user are fixed and unique, and should not be passed to the SDK in a random userID. Because the unique and fixed userID allows ZEGO technicians to quickly locate online problems.
* 4. After the first login failure due to network reasons or the room is disconnected, the default time of SDK reconnection is 20min.
* Privacy reminder: Please do not fill in sensitive user information in this interface, including but not limited to mobile phone number, ID number, passport number, real name, etc.
* Related callbacks:
* 1. When the user starts to log in to the room, the room is successfully logged in, or the room fails to log in, the [onRoomStateChanged] (Not supported before 2.18.0, please use [onRoomStateUpdate]) callback will be triggered to notify the developer of the status of the current user connected to the room.
* 2. Different users who log in to the same room can get room related notifications in the same room (eg [onRoomUserUpdate], [onRoomStreamUpdate], etc.), and users in one room cannot receive room signaling notifications in another room.
* 3. If the network is temporarily interrupted due to network quality reasons, the SDK will automatically reconnect internally. You can get the current connection status of the local room by listening to the [onRoomStateChanged] (Not supported before 2.18.0, please use [onRoomStateUpdate]) callback method, and other users in the same room will receive [onRoomUserUpdate] callback notification.
* 4. Messages sent in one room (e.g. [setStreamExtraInfo], [sendBroadcastMessage], [sendBarrageMessage], [sendCustomCommand], etc.) cannot be received callback ((eg [onRoomStreamExtraInfoUpdate], [onIMRecvBroadcastMessage], [onIMRecvBarrageMessage], [onIMRecvCustomCommand], etc) in other rooms. Currently, SDK does not provide the ability to send messages across rooms. Developers can integrate the SDK of third-party IM to achieve.
* Related APIs:
* 1. Users can call [logoutRoom] to log out. In the case that a user has successfully logged in and has not logged out, if the login interface is called again, the console will report an error and print the error code 1002001.
* 2. SDK supports multi-room login, please call [setRoomMode] function to select multi-room mode before engine initialization, and then call [loginRoom] to log in to multi-room.
* 3. Calling [destroyEngine] will also automatically log out.
*
* @param roomID Room ID, a string of less 128 bytes in length.
* Caution:
* 1. room ID is defined by yourself.
* 2. Only support numbers, English characters and '~', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', '=', '-', '`', ';', '’', ',', '.', '<', '>', '\'.
* 3. If you need to communicate with the Web SDK, please do not use '%'.
* @param user User object instance, configure userID, userName. Note that the userID needs to be globally unique with the same appID, otherwise the user who logs in later will kick out the user who logged in first.
* @param config Advanced room configuration.
* @return The result of this login room
*/
loginRoom(roomID, user, config) {
return ZegoExpressEngineImpl.getInstance().loginRoom(roomID, user, config);
}
/**
* Exit the room of the specified room ID with callback.
*
* Available since: 1.1.0
* Description: This API will log out the room named roomID.
* Use cases: In the same room, users can conduct live broadcast, audio and video calls, etc.
* When to call /Trigger: After successfully logging in to the room, if the room is no longer used, the user can call the function [logoutRoom].
* Restrictions: None.
* Caution: 1. Exiting the room will stop all publishing and playing streams for user, and inner audio and video engine will stop, and then SDK will auto stop local preview UI. If you want to keep the preview ability when switching rooms, please use the [switchRoom] method. 2. If the user logs out to the room, but the incoming 'roomID' is different from the logged-in room name, SDK will return failure.
* Related callbacks: After calling this function, you will receive [onRoomStateChanged] (Not supported before 2.18.0, please use [onRoomStateUpdate]) callback notification successfully exits the room, while other users in the same room will receive the [onRoomUserUpdate] callback notification(On the premise of enabling isUserStatusNotify configuration).
* Related APIs: Users can use [loginRoom], [switchRoom] functions to log in or switch rooms.
*
* @param roomID Room ID, a string of up to 128 bytes in length.
* Caution:
* 1. Only support numbers, English characters and '~', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', '=', '-', '`', ';', '’', ',', '.', '<', '>', '\'.
* 2. If you need to communicate with the Web SDK, please do not use '%'.
* @return The result of this logout room
*/
logoutRoom(roomID) {
return ZegoExpressEngineImpl.getInstance().logoutRoom(roomID);
}
/**
* Switch the room with advanced room configurations.
*
* Available since: 1.15.0
* Description: Using this interface allows users to quickly switch from one room to another room.
* Use cases: if you need to quickly switch to the next room, you can call this function.
* When to call /Trigger: After successfully login room.
* Restrictions: None.
* Caution:
* 1. When this function is called, all streams currently publishing or playing will stop (but the local preview will not stop).
* 2. To prevent the app from being impersonated by a malicious user, you can add authentication before logging in to the room, that is, the [token] parameter in the ZegoRoomConfig object passed in by the [config] parameter. This parameter configuration affects the room to be switched over.
* 3. Multi-room mode is supported in version 3.5.0 (use the function [setRoomMode] to set ZegoRoomMode to ZEGO_ROOM_MODE_MULTI_ROOM).
* 4. If a Token is passed in for login when logging into the room [loginRoom], the [switchroom] interface must be used with the config parameter and the corresponding Token value passed in when switching rooms.
* Privacy reminder: Please do not fill in sensitive user information in this interface, including but not limited to mobile phone number, ID number, passport number, real name, etc.
* Related callbacks: When the user call the [switchRoom] function, the [onRoomStateChanged] (Not supported before 2.18.0, please use [onRoomStateUpdate]) callback will be triggered to notify the developer of the status of the current user connected to the room.
* Related APIs: Users can use the [logoutRoom] function to log out of the room.
*
* @param fromRoomID Current roomID.
* @param toRoomID The next roomID.
* @param config Advanced room configuration.
*/
switchRoom(fromRoomID, toRoomID, config) {
return ZegoExpressEngineImpl.getInstance().switchRoom(fromRoomID, toRoomID, config);
}
/**
* Renew token.
*
* Available since: 2.8.0
* Description: After the developer receives [onRoomTokenWillExpire], they can use this API to update the token to ensure that the subsequent RTC functions are normal.
* Use cases: Used when the token is about to expire.
* When to call /Trigger: After the developer receives [onRoomTokenWillExpire].
* Restrictions: None.
* Caution: The token contains important information such as the user's room permissions, publish stream permissions, and effective time, please refer to https://docs.zegocloud.com/article/11649.
* Related callbacks: None.
* Related APIs: None.
*
* @param roomID Room ID.
* @param token The token that needs to be renew.
*/
renewToken(roomID, token) {
return ZegoExpressEngineImpl.getInstance().renewToken(roomID, token);
}
/**
* Set room extra information.
*
* Available since: 1.13.0
* Description: The user can call this function to set the extra info of the room.
* Use cases: You can set some room-related business attributes, such as whether someone is Co-hosting.
* When to call /Trigger: After logging in the room successful.
* Restrictions: For restrictions on the use of this function, please refer to https://docs.zegocloud.com/article/7611 or contact ZEGO technical support.
* Caution: 'key' is non null. The length of key and value is limited, please refer to Restrictions. The newly set key and value will overwrite the old setting.
* Related callbacks: Other users in the same room will be notified through the [onRoomExtraInfoUpdate] callback function.
* Related APIs: None.
*
* @param roomID Room ID.
* @param key key of the extra info.
* @param value value if the extra info.
* @return Set room extra info execution result notification
*/
setRoomExtraInfo(roomID, key, value) {
return ZegoExpressEngineImpl.getInstance().setRoomExtraInfo(roomID, key, value);
}
/**
* Starts publishing a stream. Support multi-room mode.
*
* Available since: 1.1.0
* Description: Users push their local audio and video streams to the ZEGO RTC server or CDN, and other users in the same room can pull the audio and video streams to watch through the `streamID` or CDN pull stream address.
* Use cases: It can be used to publish streams in real-time connecting wheat, live broadcast and other scenarios.
* When to call: After [loginRoom].
* Restrictions: None.
* Caution:
* 1. Before start to publish the stream, the user can choose to call [setVideoConfig] to set the relevant video parameters, and call [startPreview] to preview the video.
* 2. Other users in the same room can get the streamID by monitoring the [onRoomStreamUpdate] event callback after the local user publishing stream successfully.
* 3. In the case of poor network quality, user publish may be interrupted, and the SDK will attempt to reconnect. You can learn about the current state and error information of the stream published by monitoring the [onPublisherStateUpdate] event.
* 4. To call [SetRoomMode] function to select multiple rooms, the room ID must be specified explicitly.
*
* @param streamID Stream ID, a string of up to 256 characters.
* Caution:
* 1. Stream ID is defined by you.
* 2. needs to be globally unique within the entire AppID. If in the same AppID, different users publish each stream and the stream ID is the same, which will cause the user to publish the stream failure. You cannot include URL keywords, otherwise publishing stream and playing stream will fails.
* 3. Only support numbers, English characters and '-', '_'.
* @param channel Publish stream channel.
* @param config Advanced publish configuration.
*/
startPublishingStream(streamID, channel, config) {
return ZegoExpressEngineImpl.getInstance().startPublishingStream(streamID, channel, config);
}
/**
* Stops publishing a stream (for the specified channel).
*
* Available since: 1.1.0
* Description: The user stops sending local audio and video streams, and other users in the room will receive a stream deletion notification.
* Use cases: It can be used to stop publish streams in real-time connecting wheat, live broadcast and other scenarios.
* When to call: After [startPublishingStream].
* Restrictions: None.
* Caution:
* 1. After stopping the streaming, other users in the same room can receive the delete notification of the stream by listening to the [onRoomStreamUpdate] callback.
* 2. If the user has initiated publish flow, this function must be called to stop the publish of the current stream before publishing the new stream (new streamID), otherwise the new stream publish will return a failure.
* 3. After stopping streaming, the developer should stop the local preview based on whether the business situation requires it.
*
* @param channel Publish stream channel.
*/
stopPublishingStream(channel) {
return ZegoExpressEngineImpl.getInstance().stopPublishingStream(channel);
}
/**
* Sets the extra information of the stream being published for the specified publish channel.
*
* Available since: 1.1.0
* Description: Use this function to set the extra info of the stream. The stream extra information is an extra information identifier of the stream ID. Unlike the stream ID, which cannot be modified during the publishing process, the stream extra information can be modified midway through the stream corresponding to the stream ID. Developers can synchronize variable content related to stream IDs based on stream additional information.
* When to call: After the engine is created [createEngine], Called before and after [startPublishingStream] can both take effect.
* Restrictions: None.
* Related callbacks: Users can obtain the execution result of the function through [ZegoPublisherSetStreamExtraInfoCallback] callback.
*
* @param extraInfo Stream extra information, a string of up to 1024 characters.
* @param channel Publish stream channel.
* @return Set stream extra information execution result notification.
*/
setStreamExtraInfo(extraInfo, channel) {
return ZegoExpressEngineImpl.getInstance().setStreamExtraInfo(extraInfo, channel);
}
/**
* Starts/Updates the local video preview (for the specified channel).
*
* Available since: 1.1.0
* Description: The user can see his own local image by calling this function.
* Use cases: It can be used for local preview in real-time connecting wheat, live broadcast and other scenarios.
* When to call: After [createEngine].
* Restrictions: None.
* Caution: 1. The preview function does not require you to log in to the room or publish the stream first. But after exiting the room, SDK internally actively stops previewing by default. 2. Local view and preview modes can be updated by calling this function again. The user can only preview on one view. If you call [startPreview] again to pass in a new view, the preview screen will only be displayed in the new view. 3. You can set the mirror mode of the preview by calling the [setVideoMirrorMode] function. The default preview setting is image mirrored. 4. When this function is called, the audio and video engine module inside SDK will start really, and it will start to try to collect audio and video.
* Note: This function is only available in ZegoExpressVideo SDK!
*
* @param view The view used to display the preview image. If the view is set to null, no preview will be made.
* @param channel Publish stream channel
*/
startPreview(view, channel) {
return ZegoExpressEngineImpl.getInstance().startPreview(view, channel);
}
/**
* Stops the local preview (for the specified channel).
*
* Available since: 1.1.0
* Description: This function can be called to stop the preview when the preview is not needed locally.
* Caution: Stopping the preview will not affect the publish stream and playing stream functions.
* Note: This function is only available in ZegoExpressVideo SDK!
*
* @param channel Publish stream channel
*/
stopPreview(channel) {
return ZegoExpressEngineImpl.getInstance().stopPreview(channel);
}
/**
* Sets up the video configurations (for the specified channel).
*
* Available since: 1.1.0
* Description: Set the video frame rate, bit rate, video capture resolution, and video encoding output resolution.
* Default value: The default video capture resolution is 360p, the video encoding output resolution is 360p, the bit rate is 600 kbps, and the frame rate is 15 fps.
* When to call: After [createEngine].
* Restrictions: It is necessary to set the relevant video configuration before [startPreview], and only support the modification of the encoding resolution, the bit rate and the frame rate after [startPreview].
* Caution: Developers should note that the wide and high resolution of the mobile end is opposite to the wide and high resolution of the PC. For example, in the case of 360p, the resolution of the mobile end is 360x640, and the resolution of the PC end is 640x360.
* Note: This function is only available in ZegoExpressVideo SDK!
*
* @param config Video configuration, the SDK provides a common setting combination of resolution, frame rate and bit rate, they also can be customized.
* @param channel Publish stream channel.
*/
setVideoConfig(config, channel) {
return ZegoExpressEngineImpl.getInstance().setVideoConfig(config, channel);
}
/**
* Gets the current video configurations (for the specified channel).
*
* This function can be used to get the specified publish channel's current video frame rate, bit rate, video capture resolution, and video encoding output resolution.
* Note: This function is only available in ZegoExpressVideo SDK!
*
* @param channel Publish stream channel
* @return Video configuration object
*/
getVideoConfig(channel) {
return ZegoExpressEngineImpl.getInstance().getVideoConfig(channel);
}
/**
* Sets the video mirroring mode (for the specified channel).
*
* Available since: 1.1.0
* Description: Set whether the local preview video and the published video have mirror mode enabled. For specific mirroring mode.
* When to call: After [createEngine].
* Restrictions: This setting only works if the SDK is responsible for rendering.
* Note: This function is only available in ZegoExpressVideo SDK!
*
* @param mirrorMode Mirror mode for previewing or publishing the stream.
* @param channel Publish stream channel.
*/
setVideoMirrorMode(mirrorMode, channel) {
return ZegoExpressEngineImpl.getInstance().setVideoMirrorMode(mirrorMode, channel);
}
/**
* Sets the video orientation (for the specified channel).
*
* Available since: 1.1.0
* Description: Set the video orientation.
* Use cases: When users use mobile devices to conduct live broadcasts or video calls, they can set different video directions according to the scene.
* When to call: After [createEngine].
* Restrictions: Currently only supports iOS and Android platforms.
* Note: This function is only available in ZegoExpressVideo SDK!
*
* @param orientation Video orientation.
* @param channel Publish stream channel.
*/
setAppOrientation(orientation, channel) {
return ZegoExpressEngineImpl.getInstance().setAppOrientation(orientation, channel);
}
/**
* Sets up the audio configurations for the specified publish channel.
*
* Available since: 1.3.4
* Description: You can set the combined value of the audio codec, bit rate, and audio channel through this function. If the preset value cannot meet the developer's scenario, the developer can set the parameters according to the business requirements.
* Default value: The default audio config refers to the default value of [ZegoAudioConfig].
* When to call: After the engine is created [createEngine], and before publishing [startPublishingStream].
* Restrictions: None.
* Related APIs: [getAudioConfig].
*
* @param config Audio config.
* @param channel Publish stream channel.
*/
setAudioConfig(config, channel) {
return ZegoExpressEngineImpl.getInstance().setAudioConfig(config, channel);
}
/**
* Gets the current audio configurations from the specified publish channel.
*
* Available since: 1.8.0
* Description: You can get the current audio codec, bit rate, and audio channel through this function.
* When to call: After the engine is created [createEngine].
* Restrictions: None.
* Related APIs: [setAudioConfig].
*
* @param channel Publish stream channel.
* @return Audio config.
*/
getAudioConfig(channel) {
return ZegoExpressEngineImpl.getInstance().getAudioConfig(channel);
}
/**
* Take a snapshot of the publishing stream for the specified publish channel.
*
* Available since: 1.17.0
* Description: Take a snapshot of the publishing stream.
* When to call: Called this function after calling [startPublishingStream] or [startPreview].
* Restrictions: None.
* Caution: The resolution of the snapshot is the encoding resolution set in [setVideoConfig]. If you need to change it to capture resolution, please call [setCapturePipelineScaleMode] to change the capture pipeline scale mode to [Post].
* Related callbacks: The screenshot result will be called back through [ZegoPublisherTakeSnapshotCallback].
* Related APIs: [takePlayStreamSnapshot].
* Note: This function is only available in ZegoExpressVideo SDK!
*
* @param channel Publish stream channel.
* @return Results of take publish stream snapshot.
*/
takePublishStreamSnapshot(channel) {
return ZegoExpressEngineImpl.getInstance().takePublishStreamSnapshot(channel);
}
/**
* Stops or resumes sending the audio part of a stream for the specified channel.
*
* Available since: 1.1.0
* Description: This function can be called when publishing the stream to realize not publishing the audio data stream. The SDK still collects and processes the audio, but send muted audio frame packets to the network.
* Use case: Users can call this interface when they do not want to publish any audio data. This interface does not affect [onBeforeAudioPrepAudioData].
* When to call: Called after the engine is created [createEngine] can take effect.
* Restrictions: None.
* Related callbacks: If you stop sending audio streams, the remote user that play stream of local user publishing stream can receive `Mute` status change notification by monitoring [onRemoteMicStateUpdate] callbacks.
* Related APIs: [mutePublishStreamVideo].
*
* @param mute Whether to stop sending audio streams, true means not to send audio stream, and false means sending audio stream. The default is false.
* @param channel Publish stream channel.
*/
mutePublishStreamAudio(mute, channel) {
return ZegoExpressEngineImpl.getInstance().mutePublishStreamAudio(mute, channel);
}
/**
* Stops or resumes sending the video part of a stream for the specified channel.
*
* Available since: 1.1.0
* Description: This function can be called when publishing the stream to realize not publishing the video stream. The local camera can still work normally, can capture, preview and process video images normally, but does not send the video data to the network.
* When to call: Called after the engine is created [createEngine] can take effect.
* Restrictions: None.
* Related callbacks: If you stop sending video streams locally, the remote user that play stream of local user publishing stream can receive `Mute` status change notification by monitoring [onRemoteCameraStateUpdate] callbacks.
* Related APIs: [mutePublishStreamAudio].
* Note: This function is only available in ZegoExpressVideo SDK!
*
* @param mute Whether to stop sending video streams, true means not to send video stream, and false means sending video stream. The default is false.
* @param channel Publish stream channel.
*/
mutePublishStreamVideo(mute, channel) {
return ZegoExpressEngineImpl.getInstance().mutePublishStreamVideo(mute, channel);
}
/**
* Sets the audio recording volume for stream publishing.
*
* Available since: 1.13.0
* Description: This function is used to perform gain processing based on the device's collected volume. The local user can control the sound level of the audio stream sent to the remote end.
* Default value: Default is 100.
* When to call: After creating the engine [createEngine].
* Restrictions: The capture volume can be dynamically set during publishing.
* Related APIs: Set the playing stream volume [setPlayVolume].
*
* @param volume The volume gain percentage, the range is 0 ~ 200, and the default value is 100, which means 100% of the original collection volume of the device.
*/
setCaptureVolume(volume) {
return ZegoExpressEngineImpl.getInstance().setCaptureVolume(volume);
}
/**
* Adds a target CDN URL to which the stream will be relayed from ZEGO RTC server.
*
* Available since: 1.1.0
* Description: Forward audio and video streams from ZEGO RTC servers to custom CDN content distribution networks with high latency but support for high concurrent pull streams.
* Use cases: 1. It is often used in large-scale live broadcast scenes that do not have particularly high requirements for delay. 2. Since ZEGO RTC server itself can be configured to support CDN(content distribution networks), this function is mainly used by developers who have CDN content distribution services themselves. 3. This function supports dynamic relay to the CDN content distribution network, so developers can use this function as a disaster recovery solution for CDN content distribution services.
* When to call: After calling the [createEngine] function to create the engine.
* Restrictions: When the [enablePublishDirectToCDN] function is set to true to publish the stream straight to the CDN, then calling this function will have no effect.
* Caution: Removing URLs retweeted to CDN requires calling [removePublishCdnUrl], calling [stopPublishingStream] will not remove URLs publish to CDN.
* Related APIs: Remove URLs that are re-pushed to the CDN [removePublishCdnUrl].
*
* @param streamID Stream ID.
* @param targetURL CDN relay address, supported address format is rtmp, rtmps.
* @return The execution result of update the relay CDN operation.
*/
addPublishCdnUrl(streamID, targetURL) {
return ZegoExpressEngineImpl.getInstance().addPublishCdnUrl(streamID, targetURL);
}
/**
* Deletes the specified CDN URL, which is used for relaying streams from ZEGO RTC server to CDN.
*
* Available since: 1.1.0
* Description: When a CDN forwarding address has been added via [addPublishCdnUrl], this function is called when the stream needs to be stopped.
* When to call: After calling the [createEngine] function to create the engine, When you don't need to continue publish to the CDN.
* Restrictions: When the [enablePublishDirectToCDN] function is set to true to publish the stream straight to the CDN, then calling this function will have no effect.
* Caution: This function does not stop publishing audio and video stream to the ZEGO ZEGO RTC server.
* Related APIs: Add URLs that are re-pushed to the CDN [addPublishCdnUrl].
*
* @param streamID Stream ID.
* @param targetURL CDN relay address, supported address format rtmp.
* @return The execution result of update the relay CDN operation.
*/
removePublishCdnUrl(streamID, targetURL) {
return ZegoExpressEngineImpl.getInstance().removePublishCdnUrl(streamID, targetURL);
}
/**
* Whether to directly push to CDN (without going through the ZEGO RTC server), for the specified channel.
*
* Available since: 1.5.0
* Description: Whether to publish streams directly from the client to CDN without passing through Zego RTC server.
* Use cases: It is often used in large-scale live broadcast scenes that do not have particularly high requirements for delay.
* Default value: The default is false, and direct push is not enabled.
* When to call: After creating the engine [createEngine], before starting to push the stream [startPublishingStream].
* Caution: The Direct Push CDN feature does not pass through the ZEGO Real-Time Audio and Video Cloud during network transmission, so you cannot use ZEGO's ultra-low latency audio and video services.
* Related APIs: Dynamic re-push to CDN function [addPublishCdnUrl], [removePublishCdnUrl].
*
* @param enable Whether to enable direct publish CDN, true: enable direct publish CDN, false: disable direct publish CDN.
* @param config CDN configuration, if null, use Zego's background default configuration.
* @param channel Publish stream channel.
*/
enablePublishDirectToCDN(enable, config, channel) {
return ZegoExpressEngineImpl.getInstance().enablePublishDirectToCDN(enable, config, channel);
}
/**
* Sends Supplemental Enhancement Information to the specified publish channel.
*
* Available since: 1.1.0
* Description: While pushing the stream to transmit the audio and video stream data, the stream media enhancement supplementary information is sent to synchronize some other additional information.
* Use cases: Generally used in scenes such as synchronizing music lyrics or precise video layout, you can choose to send SEI.
* When to call: After starting to push the stream [startPublishingStream].
* Restrictions: Do not exceed 30 times per second, and the SEI data length is limited to 4096 bytes.
* Caution: Since the SEI information follows the video frame, there may be frame loss due to network problems, so the SEI information may also be lost. In order to solve this situation, it should be sent several times within the restricted frequency.
* Related APIs: After the pusher sends the SEI, the puller can obtain the SEI content by monitoring the callback of [onPlayerRecvSEI].
*
* @param data SEI data.
* @param channel Publish stream channel.
*/
sendSEI(data, channel) {
return ZegoExpressEngineImpl.getInstance().sendSEI(data, channel);
}
/**
* Enables or disables hardware encoding.
*
* Available since: 1.1.0
* Description: Whether to use the hardware encoding function when publishing the stream, the GPU is used to encode the stream and to reduce the CPU usage.
* When to call: The setting can take effect before the stream published. If it is set after the stream published, the stream should be stopped first before it takes effect.
* Caution: Because hard-coded support is not particularly good for a few models, SDK uses software encoding by default. If the developer finds that the device is hot when publishing a high-resolution audio and video stream during testing of some models, you can consider calling this function to enable hard coding.
*
* @param enable Whether to enable hardware encoding, true: enable hardware encoding, false: disable hardware encoding.
*/
enableHardwareEncoder(enable) {
return ZegoExpressEngineImpl.getInstance().enableHardwareEncoder(enable);
}
/**
* Whether to enable H.265 encoding to automatically downgrade to H.264 encoding.
*
* Available since: 2.12.0
* Description: When using H.265 encoding to push the stream, whether to enable the strategy of automatically degrading H.265 encoding to H.264 encoding under abnormal circumstances.After enabling automatic downgrade, when H.265 encoding is not supported or H.265 encoding fails, the SDK will try to downgrade and use H.264 encoding to push the stream.After turning off automatic downgrade, when H.265 encoding is not supported or H.265 encoding fails, the direct streaming fails.
* Use cases: In the Co-hosting and Showroom Live Streaming scenarios, use H265 encoding to push the stream to save CDN traffic without degrading the picture quality.
* Default Value: When this interface is not called, the default is yes, which means that H.265 encoding is turned on and automatically downgraded to H.264 encoding.
* When to call: After creating the engine, call the [startPublishingStream] function before pushing the stream.
* Related callbacks: When the H.265 encoding is automatically downgraded to the H.264 encoding strategy, the [onPublisherVideoEncoderChanged] callback will be triggered when the encoding method changes.
* Caution: When downgrading from H.265 to H.264 encoding occurs during the streaming process, if you are recording local video or cloud recording, multiple recording files will be generated, which needs to be dealt with.
*
* @param enable Whether to enable H.265 coding automatically fallback to H.264 coding, true: enable, false: disable, and the default value is true
*/
enableH265EncodeFallback(enable) {
return ZegoExpressEngineImpl.getInstance().enableH265EncodeFallback(enable);
}
/**
* Whether the specified video encoding type is supported.
*
* Available since: 2.12.0 and above
* Description: Whether the specified video encoding is supported depends on the following aspects, whether the hardware model supports hard encoding, whether the performance of the hardware model supports soft encoding, and whether the SDK has the encoding module.
* When to call: After creating the engine.
* Caution: It is recommended that users call this interface to obtain H.265 encoding support capability before publish stream with H.265 encoding, if not supported, you can use other encodings for publish, such as H.264.On the mobile platform, the SDK only supports H.265 hardware encoding, and it is affected by the model and hardware capabilities.
*
* @param codecID Video codec id. Required: Yes.
* @return Whether the specified video encoding is supported.Value range: true means support, you can use this encoding format for publish; false means the is not supported, and the encoding format cannot be used for publish.
*/
isVideoEncoderSupported(codecID) {
return ZegoExpressEngineImpl.getInstance().isVideoEncoderSupported(codecID);
}
/**
* Set video capture source for the specified channel.
*
* Available since: 3.1.0
* Description: Set video capture source for switching between different video capture sources.
* Use cases: Typically used in educational scenarios that require switching between different video capture sources.
* When to call: After the engine is created [createEngine].
* Restrictions: None.
* Caution: 1. Main push channel ZegoPublishChannel.Main does not support using ZegoVideoSourceType.Player and ZegoVideoSourceType.MainPublishChannel video source type.
* 2. When using ZegoVideoSourceType.Player and ZegoVideoSourceType.MainPublishChannel video source type in aux publish channel ZegoPublishChannel.Aux, must ensure that physical device works on main publish channel ZegoPublishChannel.Main.
* 3. Preemptive video sources are not allowed to be used on multiple channels at the same time, such as ZegoVideoSourceType.Camera and ZegoVideoSourceType.ScreenCapture.
* 4. The other publish channel can copy the main publish channel only when the main publish channel uses internal video capture. A maximum of one copy is supported.
* 5. When using ZegoVideoSourceType.Player video source type, please ensure that the ZegoMediaPlayer instance is created successfully.
* Note: This function is only available in ZegoExpressVideo SDK!
*
* @param source Video capture source.
* @param channel Publish stream channel.
*/
setVideoSource(source, channel) {
return ZegoExpressEngineImpl.getInstance().setVideoSource(source, channel);
}
/**
* Set audio capture source for the specified channel.
*
* Available since: 3.1.0
* Description: Set audio capture source for switching between different audio capture sources.
* Use cases: Typically used in educational scenarios that require switching between different audio capture sources.
* When to call: After the engine is created [createEngine].
* Caution: 1. Main push channel ZegoPublishChannel.Main does not support using ZegoAudioSourceType.MediaPlayer and ZegoAudioSourceType.MainPublishChannel audio source type.
* 2. When using ZegoAudioSourceType.MediaPlayer and ZegoAudioSourceType.MainPublishChannel audio source type in aux publish channel ZegoPublishChannel.Aux, must ensure that physical device works on main publish channel ZegoPublishChannel.Main.
* 3. Preemptive audio sources are not allowed to be used on multiple channels at the same time, such as ZegoAudioSourceType.Microphone.
* 4. When using ZegoAudioSourceType.MediaPlayer audio source type, please ensure that the ZegoMediaPlayer instance is created successfully.
*
* @param source Audio capture source.
* @param channel Publish stream channel.
*/
setAudioSource(source, channel) {
return ZegoExpressEngineImpl.getInstance().setAudioSource(source, channel);
}
/**
* Enable video object segmentation.
*
* Available since: 3.6.0
* Description: Video object segmentation and transmission is a technology that separates the video object (in most cases, a person) in a rectangular video through an AI algorithm at the push end, transmits it in the RTC network, and renders it at the stream playing end.
* Use cases: Scenes where the object in the video needs to be separated from the background, such as mixed reality, multi-person interaction scenes, and so on.
* When to call: After the engine is created [createEngine].
* Restrictions: Enabling object segmentation is a time-consuming operation, and it is not necessary to turn it on and off frequently.
* Caution: This feature requires special braiding, please contact ZEGO Technical Support
* Related callbacks: When the object segmentation is turned on or off, the notification of the object segmentation state can be received through [onVideoObjectSegmentationStateChanged].
* Related APIs: Use [enableAlphaChannelVideoEncoder] to support the transparent background encoding of the divided object, and then publish the stream, you can render the object with a transparent background effect on the stream playing side.
* Note: This function is only available in ZegoExpressVideo SDK!
*
* @param enable Whether to enable video object segmentation, off by default.
* @param config The type of object segmentation.
* @param channel Publish stream channel.
*/
enableVideoObjectSegmentation(enable, config, channel) {
return ZegoExpressEngineImpl.getInstance().enableVideoObjectSegmentation(enable, config, channel);
}
/**
* Enable video encoder alpha channel support.
*
* Available since: 3.4.0
* Description: Enable the alpha channel support of the video encoder on the stream publishing end, and encode the split video body for streaming.
* Use cases: Scenes where the object in the video needs to be separated from the background, such as mixed reality, multi-person interaction scenes, and so on.
* When to call: After creating the engine.
* Note: This function is only available in ZegoExpressVideo SDK!
*
* @param enable Enable video encoder alpha channel support, off by default.
* @param alphaLayout Specify the layout position of the alpha channel data.
* @param channel Publish stream channel.
*/
enableAlphaChannelVideoEncoder(enable, alphaLayout, channel) {
return ZegoExpressEngineImpl.getInstance().enableAlphaChannelVideoEncoder(enable, alphaLayout, channel);
}
/**
* Starts playing a stream from ZEGO RTC server or from third-party CDN. Support multi-room mode.
*
* Available since: 1.1.0
* Description: Play audio and video streams from the ZEGO RTC server or CDN.
* Use cases: In real-time or live broadcast scenarios, developers can listen to the [onRoomStreamUpdate] event callback to obtain the new stream information in the room where they are located, and call this interface to pass in streamID for play streams.
* When to call: After [loginRoom].
* Restrictions: None.
* Caution: 1. The developer can update the player canvas by calling this function again (the streamID must be the same). 2. After the first play stream failure due to network reasons or the play stream is interrupted, the default time for SDK reconnection is 20min. 3. In the case of poor network quality, user play may be interrupted, the SDK will try to reconnect, and the current play status and error information can be obtained by listening to the [onPlayerStateUpdate] event. please refer to https://docs.zegocloud.com/faq/reconnect. 4. Playing the stream ID that does not exist, the SDK continues to try to play after calling this function. After the stream ID is successfully published, the audio and video stream can be actually played.
* Note: This function is only available in ZegoExpressVideo SDK!
*
* @param streamID Stream ID, a string of up to 256 characters.
* Caution:
* Only support numbers, English characters and '-', '_'.
* @param view The view used to display the play audio and video stream's image. When the view is set to [null], no video is displayed, only audio is played.
* @param config Advanced player configuration Room [roomID] in [ZegoPlayerConfig] is the login roomID.
*/
startPlayingStream(streamID, view, config) {
return ZegoExpressEngineImpl.getInstance().startPlayingStream(streamID, view, config);
}
/**
* Stops playing a stream.
*
* Available since: 1.1.0
* Description: Play audio and video streams from the ZEGO RTC server.
* Use cases: In the real-time scenario, developers can listen to the [onRoomStreamUpdate] event callback to obtain the delete stream information in the room where they