CloudHub JSSDK
- Overview
- CloudHubRTC
- CloudHubRTCObject
- Client
- ClientEvent
- ClientLiveTranscoding
- ClientChannelMediaRelayConfig
- Stream
- StreamEvent
- DeviceManager
- constant
- The Client interface provides major functions for a voice/video call, such as joining a channel and publishing a stream.
- The Client object is created by the
createClient
method and represents the local client.
Base
init
Initializes a Client Object
This method initializes the client object.
init(appId: string, options?:object, onSuccess?: function, onFailure?: function): void
// example:
client.init(appId, {}, function() {
console.log("client initialized");
}, function(err) {
console.log("client init failed", err);
});
Parameters | Type | Description |
---|---|---|
appId | string | Pass in the App ID for your project. |
options | object | Configuration item. |
onSuccess | function | The callback when the method succeeds. |
onFailure | function | The callback when the method fails. |
renewToken
Renews the Token
This method renews your token.
If the Token mechanism is enabled, the token used after a while will be invalid. Trigger Client.on(‘token-privilege-will-expire’) When the callback is called to reagent, then the method updates token, otherwise the SDK cannot establish a connection with the server.
renewToken(token:string, onSuccess?:function, onFailure?:function): void
// example:
client.renewToken(<token>, function(){
console.info("renewToken success");
}, function(errflag){
console.error("renewToken fail", errflag);
});
Parameters | Type | Description |
---|---|---|
token | string | Incoming Token from your service side 1. cloudHub recommends that you use a valid token (high security requirements) to join the channel. 2. For the build of token, see Token build documentation. 3. If you need to use a valid token (high security requirements) to join the channel, contact cloudHub’s business personnel to turn it on. 4. Token has an expiration time and is received Client.on(‘token-privilege-will-expire’)Update Token after the callback. 5. token There is an expiration time, received Client.on(‘request-token’)After the callback, join the channel with the new token. |
onSuccess | function | The callback when the method succeeds. |
onFailure | function | The callback when the method fails.The callback parameter carries the errflag parameter. errflag has the following values:* “ERR_INVALID_TOKEN” Not valid token* “ERR_TOKEN_EXPIRED” token Expired * “ERR_REFUSED” Other errors |
Note: Token is generated by a combination of authkey, secretkey, channel, userid, and expiretime, so make sure that the newly generated token uses the authkey, secretkey, channel, and userid unchanged.
event
off
Unbinds Events
This method removes the events attached by the Client.on() method.
off(eventType: string, listener: function): void
// example:
client.on("stream-published", function processStreamPublished(evt) {
console.log("Stream Published");
evt.stream.play("divId");
client.off("stream-published", processStreamPublished);
}
Parameters | Type | Description |
---|---|---|
eventType | string | The event to be removed. |
listener | function | The function to be removed. |
on
Make event binding.
For more information about the events that currently support binding and the role of the events Client event documentation
on(eventType: string, listener: function): void
// example:
client.on('first-audio-frame-decode', function (evt) {
// The callback of the first frame of the remote audio has been decoded.
// This callback is triggered when the local subscription to the remote stream is successful and the first frame of audio decoding is completed.
console.log('first-audio-frame-decode', evt);
})
Parameters | Type | Description |
---|---|---|
eventType | string | The event to bind |
listener | function | The event listener to bind |
offAll
Unbind all events under Type.
offAll(eventType: string): void
// example:
client.offAll("stream-network-quality");
channel
setChannelConfig
Set channel configuration, you can modify the ‘coding mode’ and ‘channel usage scene’ before entering the channel
client.setChannelConfig({
codec: 'vp8',
mode: 'live',
});
Parameters | Type | Description |
---|---|---|
codec | string | Optional, encoded in “vp8” and “h264” and defaulted to “vp8”. Note:: 1 channel can only support 1 encoding method, and the 1st user entering the channel determines how the channel is encoded. |
mode | string | Optional, channel usage scenarios, there are communication scenes rtc and live scenes live , the default is rtc .live : Live scene with two user roles, the host and the audience, which can be set up through the Client.setClementRole method. The host can send and receive voice/video streams, while viewers can only receive voice/video and cannot send.rtc : A communication scenario for common one-on-one calls or group chats where any user in a channel can send or receive voice/video streams.Note:: 1)Only 1 usage scenario can be supported for 1 channel, and the channel usage scenario is determined by the 1st user entering the channel. 2)We recommend that 1 channel always use only 1 usage scenario, do not use 1 channel today, use live scene tomorrow, and use the new channel if you need to replace the scene. 3)The communication scenario (“rtc”) does not allow access to too many users, the default channel 1 channel under the communication scenario (“rtc”) allows 100 people to enter, and if you need to adjust the number of users contact cloudHub business personnel. 4)Specify the usage scenario for the channel by specifying mode when createClient. |
joinChannel
Join cloudHubRTC channels.
This method allows users to join the CloudHubRTC channel. When the method is successfully called to join the channel, it is triggered locally Client.on(“signal-connected”) and Client.on(“signal-connection-state-change”) Callback.
In a communication scenario, the remote side is triggered Client.on(“peer-join”) Callback
In a live scenario, the user role that joins the channel is the anchor and the remote end is triggered Client.on(“peer-join”) Callback, if it is the audience, the far end does not trigger Client.on(“peer-join”) Callback.
joinChannel(token: string | null, channelId: string, uid: string | null, options?: object, onSuccess?: function, onFailure?: function): void
// example:
client.joinChannel(<token>, "1024", "userid", {}, function(uid) {
console.log("client" + uid + "joined channel");
// Create a local stream
//……
}, function(err) {
console.error("client join failed", err);
// Error handling
});
Parameters | Type | Description |
---|---|---|
token | string | Incoming Token from your service side 1. cloudHub recommends that you use a valid token (high security requirements) to join the channel. 2. For the build of token, see Token build documentation. 3. If you need to use a valid token (high security requirements) to join the channel, contact cloudHub’s business personnel to turn it on. 4. Token has an expiration time and is received Client.on(‘token-privilege-will-expire’)Update Token after the callback. 5. token There is an expiration time, received Client.on(‘request-token’)After the callback, join the channel with the new token. |
channelId | string | The string that identifies the call channel supports the following character set range: * 26 lowercase letters a-z * 26 capital letters A-Z * 10 numbers 0-9 * Special characters:-_ Note: We recommend that 1 channel always use only 1 usage scenario, do not use 1 channel in today’s communication scene, use live scene tomorrow, and use the new channel if you need to replace the scene. |
uid | string | Specifies the user’s ID. High security requirements: Incoming Token from your service side. Note: ASCII characters, which need to be guaranteed to be unique. If you do not specify (that is, set to null/undefined) or set to 0, the SDK automatically assigns one and returns it in the onSuccess callback method. |
options | object | Configuration items, as follows: userproperties?:object User-defined properties. For example, a nickname is passed on to a nickname:{nickname:“My name”} |
onSuccess | function | The method calls the callback function that was executed when it succeeded, and the callback carries the argument uid uid:string 用户 id |
onFailure | function | Failed callback, callback parameter errflag、message。 * message: error message. * errflag: Error identification, possible errors are as follows: 1. “CHANNEL_NO_SPECIFICATION”: parameter channel Non-compliant and contains unsupported characters. 2. “INVALID_ARG”: Invalid parameters. 3. “CLIENT_NOT_INIT”: There is no initialization Client。 4. “EMPTY_SIGNAL_ADDR_LIST”: There is no signaling server address to connect to. 5. “JOIN_CHANNEL_FAIL”: Failed to join the channel. 6. “JOIN_AUTH_FAIL”: Joining the channel to verify permissions failed. 7. “CHANNEL_MODE_MISMATCH”:Channel modes don’t match, for example, the channel scene is a call scene (mode is live), but CreateClient is passed on as a live scene (for rtc). 8. “ERR_INVALID_APP_ID”: Invalid appId. 9. “ERR_INVALID_TOKEN”: Invalid token. 10. “ERR_TOKEN_EXPIRED”: token Expired. 11. “ERR_ENTERPRISE_CONCURRENT_POINTS_EXCEED_LIMIT”: Enterprise concurransion points exceed the limit. 12. “ERR_REFUSED”: Other errors. |
Note:
- Locally triggered when joining a channel is successful Client.on(“signal-connected”) Call back, see for details Client event documentation。
- When the signaling channel connection is successful (locally triggered Client.on(“signal-connected”) Callback).The signaling channel may be disconnected due to network reasons, the SDK automatically reconnects, and the reconnection is successful and triggered locally Client.on(“signal-connected”)Callback.
- Do not engage in any communication behavior during the signaling channel disconnect(pubMsg、delMsg).It is recommended that the interface appear floating layer, do not let the user on the interface until the signaling channel connection is restored.
leaveChannel
Leave the CloudHubRTC channel.
When the method is called to leave the channel, it is triggered locally Client.on(“signal-connection-state-change”) Callback.
In a communication scenario, the remote side is triggered Client.on(“peer-leave”) Callback.
In a live scenario, the user role that leaves the channel is the anchor and the remote end is triggered Client.on(“peer-leave”) Callback, if the audience is far from the distal end Client.on(“peer-leave”) Callback.
leaveChannel(): void
// example:
client.leaveChannel()
Audio and video
publish
Publish the local audio and video stream.
This method is issued to the server.
After issuing audio and video streams, the local will trigger Client.on(“stream-published”) Torch; distal trigger Client.on(“stream-added”) Callback.
In the live broadcast scene, if the user’s role is the audience (audience),Automatically switch into an anchor when calling Publish(host) Role, Local trigger Client.on(“client-role-changed”) Tune, distal trigger Client.on(“peer-join”).
publish(stream: Stream, options?:object, onFailure?: function): void
// example:
client.publish(stream, {}, function(err) {
console.log(err);
// Code logic to handle release failures
})
Parameters | Type | Description |
---|---|---|
stream | Stream | Local audio and video flow object |
options | object | Reserved configuration items, currently pass {} |
onFailure | function | Methods The callback function performed when the call fails, the possible errors are as follows: * “STREAM_ALREADY_PUBLISHED”: The stream has been released. * “INVALID_LOCAL_STREAM”:Incoming stream format illegally. * “STREAM_NOT_INITED”: Local flow is not initialized. * “SIGNAL_NOT_CONNECT”: Not currently not in the channel, it may be no channel or network fluctuation caused temporary disconnection. * “PUBLISH_STREAM_LIMIT”: The maximum number of lotuses issued is exceeded. * “PUBLISH_NOT_PERMISSION”: No permission release. * “PUB_SETREMOTEDESC_FAIL”:Browser setRemoteDescription Failed, about setRemoteDescription Note: Trigger Client.on(‘stream-publish-failure’) The callback, the callback trigger indicates that this stream failed, and the SDK will not automatically re-release. |
Note:
- SDK has an automatic re-release policy. Once triggered, it is triggered. Client.on(“stream-reconnect-start”) and Client.on(“stream-reconnect-end”), For details, please see Client event documentation 的 stream-reconnect-start 和 stream-reconnect-end。
- Redistribution may be caused by the following reasons:
- “PUB_ACK_FAILED”: Release ACK failure, general is in release process connection lost [note: this failure SDK automatically republish ]
- “PUB_TIMEOUT”: Publish timeout [Note: SDK will automatically republish].
- “PUB_CONNECTION_FAILED”: Media transfer channel establishment failed after publishing [Note: SDK will automatically republish].
- “PUB_CONNECTION_INSTABILITY”: The stream has been successfully published, but the media transfer channel is unstable and needs to be forced to republish [Note: the SDK will automatically republish].
- “PUB_CONNECTION_ICE_DISCONNECTED”: The stream has been successfully published, but the media transfer channel is disconnected [Note: the SDK will automatically republish].
- “PUB_APP_HIDDEN_CATON”: After successful publishing, the APP lags because it is re-displayed after hiding the APP (pressing the Home button) [SDK will automatically re-publish].
- “PUB_UNDEFINED_FAIL”: Undefined publish failed [Note: SDK will automatically re-publish].
- “PUB_SDK_FORCE_RECONN”: Switching devices / switching resolutions because the browser version is too low requires a forced republish [Note: the SDK will automatically republish].
- The sdk auto-release will first unpublish the stream and then republish it, so if the stream is republished after it has already been successfully published the remote will trigger the Client.on(“stream-removed”) callback, the local will trigger the Client.on(“stream-unpublished”) Callback. if the republishing succeeds locally it will trigger the Client.on(“stream-published”) callback, the remote end will trigger the Client.on(“stream-added”) Callback.
- The SDK release has a comment of “SDK will automatically republish”, it will be automatically released after failure, if you don’t want to call unpublish anymore.
- It is recommended to call the unpublish method when the failure reason is “PUBLISH_STREAM_LIMIT”.
- Because of the SDK re-release mechanism, Client.on(“stream-removed”), Client.on(“stream-unpublished”), Client.on(“stream-published”), Client.on(“stream- added”) It may be triggered multiple times. After successful publishing, the re-publishing is successful for simple reasons. For example, the client (“stream-unpublished”) will be triggered locally and Client.(“stream-published”) will be started after the client starts, and the remote will trigger Client.on(“stream -unpublished”) -removed") Trigger Client.on(“stream- added”) after the start.
subscribe
Subscribe to remote audio and video streams.
This method receives remote audio and video streams from the server.
After subscribing to the remote audio and video stream, the Client.on(“stream-subscribed”) callback will be triggered locally. If the subscription stream contains audio, it will also trigger Client.on(“first-audio-frame-decode”) callback; if the subscription stream contains video, it will also trigger Client.on(“first-video-frame-decode”) Callback.
subscribe(stream: Stream, options?:object, onFailure?: function): void
// example:
client.subscribe(stream, {}, function(err) {
console.error("stream subscribe failed", err);
// Code logic to handle subscription failures
})
Parameters | Type | Description |
---|---|---|
stream | Stream | Remote audio and video stream object |
options | object | Reserved configuration items, just pass {} now |
onFailure | function | The callback function to be executed when the method fails. Here are some common errors: 1. “STREAM_ALREADY_SUBSCRIBED”: The stream is already subscribed. 2. “STREAM_NOT_YET_PUBLISHED”: The specified stream has not been published yet. 3. “INVALID_REMOTE_STREAM”: The format of the incoming stream is illegal. 4. “SIGNAL_NOT_CONNECT”: Not currently in the channel. It may be that you have not joined the channel or the network is temporarily disconnected due to network fluctuations. 5. “SUBSCRIBE_NOT_PERMISSION”: No permission to subscribe. 6. “SUB_SETREMOTEDESC_FAIL”: Browser setRemoteDescription failed, About setRemoteDescription Note: will trigger the Client.on(‘stream-subscribe-failure’) callback. If the callback is triggered, it means the subscription has failed and the SDK will not automatically Re-subscribe. |
Note:
The SDK has an automatic re-subscription strategy. Once the automatic re-subscription is triggered, Client.on(“stream-reconnect-start”) and Client.on(“stream-reconnect-end”) will be triggered. For details, please see “Client Event Document “ stream-reconnect-start and stream-reconnect-end.
Re-subscription may be triggered by the following reasons:
- “SUB_ACK_FAILED”: ACK subscription failed, usually due to disconnection during the subscription process [Note: SDK will automatically re-subscribe].
- “SUB_TIMEOUT”: Subscription timeout [Note: SDK will automatically re-subscribe].
- “SUB_CONNECTION_FAILED”: Media transmission channel establishment failed after subscribing [Note: SDK will automatically resubscribe].
- “SUB_CONNECTION_INSTABILITY”: The stream has been subscribed successfully, but the media transmission channel is unstable, and it needs to be forced to resubscribe [Note: SDK will automatically resubscribe].
- “SUB_CONNECTION_ICE_DISCONNECTED”: The stream has been subscribed successfully, but the media transmission channel is disconnected [Note: SDK will automatically resubscribe].
- “SUB_APP_HIDDEN_CATON”: After the subscription is successful, the app is hidden (for example, press the Home button) and then the app is redisplayed, causing a freeze [Note: SDK will automatically re-subscribe].
- “SUB_UNDEFINED_FAIL”: Undefined subscription failed [Note: SDK will automatically resubscribe].
The automatic re-subscription of SDK will first unsubscribe this stream, and the Client.on(“stream-unsubscribed”) callback will be triggered locally, and then subscribe. If the re-subscription is successful, the Client.on(“stream-subscribed”) callback will be triggered locally. If the subscription stream contains audio, it will also trigger Client.on(“first-audio-frame-decode”) callback; if the subscription stream contains video, it will also trigger Client.on(“first-video-frame-decode”) Callback.
There is a comment marked “SDK will automatically resubscribe”, the SDK will automatically resubscribe after failure, if you don’t want to subscribe, please call the unsubscribe method.
Because of the SDK re-subscription mechanism, Client.on(“stream-unsubscribed”) and Client.on(“stream-subscribed”) may be triggered multiple times. For example, after the subscription is successful, the client will be triggered if the re-subscription is successful due to link reasons. on(“stream-unsubscribed”) and Client.on(“stream-subscribed”).
unpublish
Unpublish local audio and video streams.
This method cancels the release of local audio and video streams. After unpublishing the audio and video stream, the remote site will trigger the Client.on(“stream-removed”) callback, and the local site will trigger the Client.on(“stream-unpublished”) callback.
In the live broadcast scenario, if the user’s role is the host, after calling unpublish, if there is no local stream release, it will automatically switch to the audience role, and the local will trigger Client.on(“client-role-changed”) Callback, the remote end will trigger Client.on(“peer-leave”).
unpublish(stream: Stream, options?:object, onSuccess?: function, onFailure?: function): void
// example:
client.unpublish(stream, {}, function(){
console.log("unpublish success");
}, function(err) {
console.log(err);
//……
})
Parameters | Type | Description |
---|---|---|
stream | Stream | Local audio and video stream object. |
options | object | Reserved configuration items, just pass {} now |
onSuccess | function | Unpublished successfully. |
onFailure | function | The callback function to be executed when the method fails, the following are some possible errors: 1. “STREAM_NOT_YET_PUBLISHED”: The specified stream has not been published yet. 2. “INVALID_LOCAL_STREAM”: The format of the incoming stream is illegal. 3. “SIGNAL_NOT_CONNECT”: Not currently in the channel, it may be that you have not joined the channel or the network fluctuates causing the connection to be temporarily disconnected. |
unsubscribe
Unsubscribe the remote audio and video stream.
unsubscribe(stream: Stream, options?:object, onSuccess?: function, onFailure?: function): void
// example:
client.unsubscribe(stream, {}, function(){
console.log("unsubscribe success");
}, function(err) {
console.log(err);
//……
})
Parameters | Type | Description |
---|---|---|
stream | Stream | Remote audio and video stream object. |
options | object | Reserved configuration items, just pass {} now |
onSuccess | function | Successfully canceled the subscription. |
onFailure | function | The callback function to be executed when the method fails. Here are some possible errors: 1. “INVALID_REMOTE_STREAM”: The format of the incoming stream object is illegal. 2. “SIGNAL_NOT_CONNECT”: Currently not in the channel, it may be that you have not joined or the network fluctuates causing the connection to be temporarily disconnected. 3. “NO_SUCH_REMOTE_STREAM”: The remote stream to be unsubscribed was not found. 4. “STREAM_NOT_YET_SUBSCRIBED”: There is no subscription for this stream. |
getRemoteAudioStats
Obtain audio statistics of the remote subscribed stream.
getRemoteAudioStats(onCallback: function): void
// example:
client.getRemoteAudioStats((remoteAudioStatsMap) => {
console.log("remoteAudioStatsMap", remoteAudioStatsMap);
});
enableAudioVolumeIndicator
Enable speaker volume alert.
This method allows the SDK to periodically return the volume reminder of the published/subscribed stream.
After enabling this method, the SDK will trigger the “stream-volume-indicator” callback to return the volume prompt every interval milliseconds, regardless of whether there is anyone speaking in the channel. Only return volume prompts whose stream Type is video (stream.getType() === “video”)
enableAudioVolumeIndicator(interval?:number): void
// example:
client.enableAudioVolumeIndicator(2000); // Triggers "volume-indicator" every two seconds retrace
client.on("stream-volume-indicator", function(evt){
console.log("stream-volume-indicator", evt);
});
Parameters | Type | Description |
---|---|---|
interval | number | How long to trigger the “stream-volume-indicator” callback to return the volume prompt, the unit is milliseconds, and the default is 300. Note: When the interval is-1, it means that the speaker volume prompt is not enabled. |
getLocalAudioStats
Obtain audio statistics of the locally published stream.
getLocalAudioStats(onCallback: function): void
//example:
client.getLocalAudioStats((localAudioStats) => {
console.log("localAudioStats:", localAudioStats);
});
Parameters | Type | Description |
---|---|---|
onCallback | function | Contains the callback of the audio statistics data of the local release stream. The callback parameter carries the LocalAudioStatsMap. LocalAudioStatsMap: For details, see CloudHubRTC data object document LocalAudioStatsMap description |
Note:
- Some statistics need to be counted after the stream-published event, which may take 0-3 seconds to return.
- Edge browser does not support.
getLocalVideoStats
getLocalVideoStats(onCallback: function): void
//example:
client.getLocalVideoStats((localVideoStats) => {
console.log("localVideoStats:", localVideoStats);
});
Get the video statistics of the local publishing stream.
Parameters | Type | Description |
---|---|---|
onCallback | function | Contains the callback of the video statistics data of the local release stream. The callback parameter carries the LocalVideoStatsMap. LocalVideoStatsMap: For details, see LocalVideoStatsMap description of CloudHubRTC data object document |
Note:
- Some statistics need to be counted after the stream-published event, which may take 0-3 seconds to return.
- Edge browser does not support.
getRemoteVideoStats
Method function: Obtain the video statistics data of the remote subscribed stream.
getRemoteVideoStats(onCallback: function): void
// example:
client.getRemoteVideoStats((remoteVideoStatsMap) => {
console.log("remoteVideoStatsMap", remoteVideoStatsMap);
});
Parameters | Type | Description |
---|---|---|
onCallback | function | Contains the callback of the audio statistics data of the remote subscription stream. The callback parameter carries the RemoteVideoStatsMap. RemoteVideoStatsMap: For details, see RemoteVideoStatsMap description of CloudHubRTC data object document |
Note:
- Statistical data needs to be counted after the stream-subscribed event, and it may take 0-3 seconds to return.
- Edge browser does not support.
enableMultiStream
Method function: Whether to enable multi-stream mode.
enableMultiStream(bEnable:boolean): void
// example:
client.enableMultiStream(true)
Parameters | Type | Description |
---|---|---|
bEnable | boolean | Whether to enable multi-stream mode. 1. true: use multi-stream mode 2. false: use single-stream mode |
Note:
Multi-stream mode means that multiple device streams can be released.
When you need to enable the multi-stream mode, please call the enableMultiStream method to enable it before joiningChannel.
The enableMultiStream method will be invalid after joinChannel is called.
Does not support multi-stream mode and single-stream mode to switch within the channel.
The mobile terminal does not support multi-stream mode, that is, multiple device streams cannot be published.
information
sendChatMsg
Method function: Send chat messages. Client.on(“recv-chat-msg”) callback will be triggered after receiving the chat message.
sendChatMsg(message:string, toId: string, extraData?:object): void
// example:
client.sendChatMsg("this is chat msg", CloudHubRTC.CONSTANTS.MSG_TO_ALLUSER, {"key1":"value1", "key2":"value2"});
Parameters | Type | Description |
---|---|---|
message | string | The sent chat message. |
toId | string | Specify who to send to, the default is YSRTC.CONSTANTS.MSG_TO_ALLUSER. |
Note:
- When there are too many chat messages sent within 1 second, the chat messages may be discarded, generally 20-100 messages per second.
- CloudHub will filter sensitive words for chat messages.
pubMsg
Send a signaling message. Client.on(“recv-pub-msg”) callback will be triggered after receiving “send signaling message”.
pubMsg(msgName: string, msgId:string, toId:string, data:object, save?:boolean,associatedMsgID?:string): void
//example:
client.pubMsg("msgname", "msgid", CloudHubRTC.CONSTANTS.MSG_TO_ALLUSER, {testdata: 1}, true);
Parameters | Type | Description |
---|---|---|
msgName | string | Signaling name. |
msgId | string | Signaling message ID. |
toId | string | Specify who to send to, the default is CloudHubRTC.CONSTANTS.MSG_TO_ALLUSER. For the possible values of toId, please see “Constant Declaration and Supplementary Explanation——Send Message” |
data | object | Signaling data. |
save | boolean | Whether to save the signaling, the default is false. Note: 1. If the message is not saved, you do not need to use delMsg to delete the message 2. If the message is not saved, the message will only be notified to people in the channel, and those who come in later Will not receive this message |
associatedMsgID | string | The associated message ID, the default is “”. Note: 1. Assuming that a message is associated with a message whose msgId is “parent-msg”, then when the “parent-msg” message is deleted, the a message is also deleted Delete, the signaling server will push the “parent-msg” message to be deleted, but will not push a message to be deleted (ie: deleting the parent node will only push the deleted message of the parent node, not the deleted child node Message, the client needs to remove the child node’s message after receiving the notification of the parent node’s delete message). For example, when msgId is “child-msg” and associated with msgId is “parent-msg” and the message with msgId is “parent-msg” is deleted, the client will receive a delete message notification with msgId as “parent-msg” (ie : Client.on(“recv-del-msg”) callback) will be triggered without receiving the delete message notification with msgId as “child-msg”. |
Note: In the live broadcast scene, it is recommended that only some people (hosts or authorized viewers, etc.) be able to send pubMsg, and not everyone can actively send pubMsg [for example: a channel with 100,000 people and an audience of 99,000 people, then these people There should not be the ability to actively send pubMsg, but the anchor should be authorized to a certain audience, this audience can send pubMsg].
delMsg
Delete the signaling message. Client.on(“recv-del-msg”) callback will be triggered after receiving the “delete signaling message”.
delMsg(msgName: string, msgId:string, toId:string): void
// example:
client.delMsg("msgname", "msgid", CloudHubRTC.CONSTANTS.MSG_TO_ALLUSER);
Parameters | Type | Description |
---|---|---|
msgName | string | Signaling name. |
msgId | string | Signaling message ID. |
toId | string | Specify who to send to, the default is CloudHubRTC.CONSTANTS.MSG_TO_ALLUSER. For the possible values of toId, please see “Constant Declaration and Supplementary Description-Sending Message” |
Note: In the live broadcast scene, it is recommended that only some people (hosts or authorized viewers, etc.) be able to send delMsg, and not everyone can actively send delMsg [for example: a channel with 100,000 people and an audience of 99,000 people, then these people There should not be the ability to actively send delMsg, but the anchor should be authorized to a certain audience, this audience can send delMsg].
Signaling
getSignalConnectionState
getSignalConnectionState(): string
Obtain the connection status between the SDK and the signaling server. Calling this method will return the connection status between the SDK and the signaling server. There are 3 types of connection status between the SDK and the signaling server:
- DISCONNECTED: The connection is disconnected. This status indicates that the SDK is in any of the following stages:
- Call Client.joinChannel to join the initial stage of the channel
- The phase of leaving the channel after calling Client.leaveChannel
- CONNECTING: Connecting. It is in this state when calling Client.joinChannel or automatically reconnecting when the connection is interrupted.
- CONNECTED: Connected. This status indicates that the user has joined the channel and can publish or subscribe to media streams in the channel.
Note:
- When the status changes to DISCONNECTED, it is necessary to clear the data cached in the UI layer, such as stream list, user list, UI interface, channel closed connection, etc. [Note: This state is usually triggered when the user calls leaveChannel or is kicked out of the channel, and will truly disconnect from the server and will not reconnect]
- When a signal-reconnect event is received (ie: the state is CONNECTING), the data cached in the UI layer, such as stream list, user list, UI interface, etc., need to be cleared. [Note: This state generally means that the current network is disconnected from the server and will be reconnected, and the server can be reconnected when the network is restored]
Parameters | Type | Description |
---|---|---|
onCallback | function | Contains the callback of the audio statistics data of the remote subscription stream. The callback parameter carries RemoteAudioStatsMap. RemoteAudioStatsMap: For details, see the RemoteAudioStatsMap description of “CloudHubRTC Data Object Document” |
Note:
- Statistical data needs to be counted after the stream-subscribed event, and it may take 0-3 seconds to return.
- Edge browser does not support.
User
evictUser
Kick the user out of the channel.
evictUser(uid:string, reason?:string): void
// example:
client.evictUser("uid", "reason");
Parameters | Type | Description |
---|---|---|
uid | string | ID of the user to be kicked out of the channel |
reason | string | Reason for kicking out the channel |
setProperty
Change the user’s custom user attributes. This method changes the properties of a user and notifies the specified user in the channel of the property change. The specified user will receive the Client.on(“user-properties-update”) callback.
setProperty(uid: string, properties: object, toId?: string): void
// example:
client.setProperty("userid", {key1:value1}, CloudHubRTC.CONSTANTS.MSG_TO_ALLUSER);
Parameters | Type | Description |
---|---|---|
uid | string | ID of the user whose attribute was changed |
properties | object | The changed user properties object. |
toId | string | Specify who to send to, the default is CloudHubRTC.CONSTANTS.MSG_TO_ALLUSER. The possible values of toId can be found in “Constant Declaration and Supplementary Description-Sending Message” |
Note:
- The setProperty interface is called in the live broadcast scene. If the changed person is an audience, the custom user property change will not be notified, that is, Client.on(“user-properties-update”) will not trigger the callback.
- Viewers are not recommended to call the setProperty interface in the live broadcast scene.
setClientRole
Set user roles.
This method is only applicable to live broadcast scenes.
In the live broadcast scenario, you can call this method to set the user role.
Before joining the channel, users can set their own roles through this method.
After joining the channel, the user can switch roles through this method:
- In the live broadcast scenario, call Client.setClientRole to switch the host to the audience, and all local streams will be automatically unpublished.
- In a live broadcast scenario, if the user’s role is the host, after calling unpublish, if there is no local stream release, it will automatically switch to the audience role, and the local will trigger Client.on(“client-role-changed” ) Callback, the remote end will trigger Client.on(“peer-leave”).
- In a live broadcast scenario, if the user’s role is an audience, it will automatically switch to the host role when publish is called. The local will trigger the Client.on(“client-role-changed”) callback, and the remote will Trigger Client.on(“peer-join”).
If you call this method to switch user roles after joining a channel, after the switch is successful, Client.on(“client-role-changed”) callback will be triggered locally; and Client.on(“peer-join”) or Client will be triggered remotely .on(“peer-leave”) callback.
setClientRole(role:string, onCallback?:function): void
// example:
client.setClientRole("host", function(errinfo) {
if (!errinfo) {
console.log("setClientRole success");
} else {
console.log("setClientRole error", errinfo);
}
});
Parameters | Type | Description |
---|---|---|
role | string | User role, roles are “audience” |
onCallback | function | Callback function, the function carries the parameter errinfo, if errinfo is null/undefined, it means the setting is successful, otherwise the setting fails. |
Note: This method cannot be used in communication scenarios (mode set to rtc). By default, all users are in the host role.
Recording
startServerRecord
Start server-side recording.
The recording function needs to be turned on by contacting cloudHub business personnel. If it is not turned on, it will not be possible to call this interface to record. Will trigger the Client.on(“server-record-state-change”) callback.
startServerRecord(config?:object): void
// example:
client.startServerRecord({});
Parameters | Type | Description |
---|---|---|
config | object | Recording configuration items, the configuration items are as follows: recordChat?:boolean Whether to record chat messages, the default is false. |
Note: If you call startServerRecord twice (that is, call startServerRecord again without calling stopServerRecord), the first call will prevail.
stopServerRecord
Stop server-side recording.
Will trigger the Client.on(“server-record-state-change”) callback.
stopServerRecord(): void
// example:
client.stopServerRecord();
pauseServerRecord
Method function: Pause server-side recording.
Will trigger the Client.on(“server-record-state-change”) callback.
pauseServerRecord(): void
// example:
client.pauseServerRecord();
Parameters | Type | Description |
---|---|---|
url | string | Ingest URL. |
resumeServerRecord
Resume server-side recording.
Will trigger the Client.on(“server-record-state-change”) callback.
resumeServerRecord(): void
// example:
client.resumeServerRecord();
Parameters | Type | Description |
---|---|---|
url | string | Ingest URL. |
Push Stream
addPublishStreamUrl
Increase the bypass push address.
addPublishStreamUrl(url:string): void
// example:
client.removePublishStreamUrl("xxxx");
Parameters | Type | Description |
---|---|---|
url | string | Ingest URL. |
removePublishStreamUrl
Delete the bypass streaming address.
removePublishStreamUrl(url:string): void
Parameters | Type | Description |
---|---|---|
url | string | Ingest URL. |
setLiveTranscoding
Set up live streaming and transcoding.
setLiveTranscoding(liveTranscoding:LiveTranscoding): void
// example:
var liveTranscoding = {
"width": 640,
"height": 360,
"videoBitrate": 400,
"videoFramerate": 15,
"audioSampleRate": 48000,
"audioBitrate": 48,
"audioChannels": 1,
"audioCodecProfile": 0,
"videoGop": 30,
"videoCodecProfile": 100,
"streamCount": 1,
"backgroundColor": 0x000000,
"transcodingStreams": [{
"x": 0,
"y": 0,
"width": 640,
"height": 360,
"zOrder": 0,
"uid": "123456",
"type": "video",
"sourceID": "default_source_id"
}]
};
client.setLiveTranscoding(liveTranscoding);
Parameters | Type | Description |
---|---|---|
liveTranscoding | LiveTranscoding(object) | Settings for live transcoding. For details about LiveTranscoding, please refer to LiveTranscoding documentation Note: The liveTranscoding passed in each call to the setLiveTranscoding interface will overwrite the previous liveTranscoding. |
startChannelMediaRelay
Start cross-channel media stream forwarding.
startChannelMediaRelay(channelMediaRelayConfig:ChannelMediaRelayConfig): void
// example:
var channelMediaRelayConfig = client.produceChannelMediaRelayConfig();
channelMediaRelayConfig.setDestChannelInfo(
"destChannelName",
{
uid: "Relay_myChannelName_Requester_myuid"
}
);
client.startChannelMediaRelay(channelMediaRelayConfig);
Parameters | Type | Description |
---|---|---|
channelMediaRelayConfig | ChannelMediaRelayConfig | Cross-channel media forwarding configuration class instance. For details about ChannelMediaRelayConfig, please refer to ChannelMediaRelayConfig Description. Note: The channelMediaRelayConfig instance is generated by calling produceChannelMediaRelayConfig. |
Note: For events related to the stream forwarding state, please see the event description of client.on(“channel-media-relay-state”)
updateChannelMediaRelay
Update cross-channel media stream forwarding.
updateChannelMediaRelay(channelMediaRelayConfig:ChannelMediaRelayConfig): void
// example:
channelMediaRelayConfig.setDestChannelInfo(
"destChannelName2",
{
uid: "Relay_myChannelName_Requester_myuid"
}
);
client.updateChannelMediaRelay(channelMediaRelayConfig);
Parameters | Type | Description |
---|---|---|
channelMediaRelayConfig | ChannelMediaRelayConfig | Cross-channel media forwarding configuration class instance. For details about ChannelMediaRelayConfig, please refer to ChannelMediaRelayConfig Description”. Note: The channelMediaRelayConfig instance calls produceChannelMediaRelayConfig to generate. |
Note: For events related to the stream forwarding state, please see the event description of client.on(“channel-media-relay-state”)
stopChannelMediaRelay
Method effect: Stop the cross-channel media stream forwarding.
stopChannelMediaRelay(): void
// example:
client.stopChannelMediaRelay();
Note: For events related to the stream forwarding state, please see the event description of client.on(“channel-media-relay-state”)
produceChannelMediaRelayConfig
Production cross-channel media forwarding configuration examples. For details about ChannelMediaRelayConfig, see ChannelMediaRelayConfig
produceChannelMediaRelayConfig(): void
// example:
var channelMediaRelayConfig = client.produceChannelMediaRelayConfig();