<script> tag. After loading, obtain all external APIs through the global variable window.TcccUserCall.sdkAppId and userId query parameters to the URL. Use the same values as those passed in createUser.<script src="https://connect.tencentcloud.com/sdk/tccc-user-call-sdk.umd.js?sdkAppId=your_sdkAppId&userId=your_userId"></script><script>const { createUser, TcccSipError, ErrorCode } = window.TcccUserCall;</script>
Term | Type | Description |
createUser | Function | Factory function for creating user instances. |
TcccSipError | Class | Unified error class of the SDK. All exceptions are instances of this class or its subclasses. |
ErrorCode | Object | Constant object for error codes, used to determine specific error types. |
async function start () {const sdkAppId = 20000000;const userId = 'xxx';const audioChannelId = 'xxx';// 1. Call the service provider's backend API to obtain the userSig.// Refer to the Node.js example in "Preliminary Preparation".const response = await fetch('https://example.api.com/genUserSig?userId=' + encodeURIComponent(userId), {method: 'GET',});if (!response.ok) {throw new Error(`HTTP error! Status code: ${response.status}`);}const { userSig } = await response.json();// 2. Create a user instance.const { createUser, TcccSipError, ErrorCode } = window.TcccUserCall;const user = createUser({sdkAppId,userId,userSig,});// 3. Listen for the ready event.user.on('ready', () => {console.log('SDK is ready. You can initiate a call.');// 5. Initiate an audio call (call this after the ready event is triggered).makeCall(audioChannelId)});// 4. Initialize (establish a connection).user.init();async function makeCall(audioChannelId) {try {const session = await user.startAudioCall(audioChannelId);session.on('progress', (event) => {const { status_code, reason_phrase } = event.response;if (status_code === 180 || status_code === 183) {console.log('The line is ringing.', reason_phrase);}});session.on('accepted', () => {console.log('The other party has answered the call.');});session.on('ended', (event) => {console.log('Call ended', event.cause);});session.on('failed', (event) => {console.error('Call failed', event.cause);});} catch (err) {if (err instanceof TcccSipError) {console.error('Call error [' + err.code + ']: ' + err.message);}}}// 6. When outbound calls are no longer needed (for example, when the page is terminated), call cleanup to release resources.async function cleanup() {await user.unInit();}}start();
TcccSipUser instance at a time. To create a new instance, you must first call the unInit() method of the current instance to terminate it. Otherwise, a User.InstanceExists error will be thrown.Parameter | Type | Required | Description |
sdkAppId | number | Yes | SDKAppId of Tencent Cloud Contact Center. |
userId | string | Yes | The business-side user ID cannot be empty and cannot contain the @ character. If an email address is used as the user identifier, replace it with a URL-safe identifier. |
userSig | string | Yes | |
userClientData | string | No | If the ClientData parameter is specified when the CreateUserSig API is called to obtain the userSig, it must be passed in as well. For details, see Reference. |
TcccSipUser - a user instance object.const user = createUser({sdkAppId: 1400000000, // The type is number.userId: 'your_userId',userSig: 'your_userSig',});
createUser() and is responsible for managing the connection with the server, initiating calls, and so on.user.init(): Promise<void>ready event is triggered for the first time.user.unInit(): Promise<void>createUser().user.updateUserSig(userSig, userClientData): voidcode is User.InvalidUserSig, you can call this method to update the signature and then initiate the call again.Parameter | Type | Required | Description |
userSig | string | Yes | |
userClientData | string | No | If the ClientData parameter is specified when the CreateUserSig API is called to obtain the userSig, it must be passed in as well. For details, see Reference. |
try {await user.startAudioCall('xxx');} catch (err) {if (err.code === ErrorCode.User.InvalidUserSig) {user.updateUserSig('new userSig');// Initiate the call again after the update.}}
user.startAudioCall(audioChannelId): Promise<Session>ready event is triggered.User.CallInProgress error. You must wait for the current call to end or proactively call session.terminate() to hang up before initiating a new call.Parameter | Type | Required | Description |
audioChannelId | string | Yes |
Promise<Session> - resolves to a call session object. For details, see the Session (Call Session) section.try {const session = await user.startAudioCall('xxx');} catch (err) {if (err.code === ErrorCode.User.CallInProgress) {console.error('A call is already in progress.');}}
user.on(eventName, callback).Field | Type | Description |
attempts | number | Current number of connection attempts. |
Field | Type | Description |
error | boolean | Indicates whether the disconnection is abnormal. |
code | number | Disconnection status code (optional). |
reason | string | Disconnection reason description (optional). |
Session is a call session object returned by user.startAudioCall(). It provides call control methods and call status events.session.terminate(): voidsession.terminate();
session.muteAudio(mute): Promise<void>Parameter | Type | Description |
mute | boolean | true mutes, false unmutes. |
await session.muteAudio(true); // Mute the audio.await session.muteAudio(false); // Unmute the audio.
session.sendDTMFTone(tone, options?): Promise<void>Parameter | Type | Required | Description |
tone | string | Yes | A single DTMF key character, with a value range of 0-9, #, and *. |
options.duration | number | No | DTMF signal duration (ms). |
options.interToneGap | number | No | Interval from the next DTMF signal (ms). |
await session.sendDTMFTone('1');await session.sendDTMFTone('#');
session.isMuted(): { audio: boolean }const { audio } = session.isMuted();console.log('Muted:', audio);
session.isEnded(): booleansession.isInProgress(): booleansession.isEstablished(): booleansession.on(eventName, callback).response in the event object parameters is an object that contains the following fields:Field | Type | Description |
response.status_code | number | SIP status code, for example, 180 indicates ringing and 183 indicates session progress. |
response.reason_phrase | string | SIP status description, for example, 'Ringing' and 'Session Progress'. |
Field | Type | Description |
cause | string |
Field | Type | Description |
cause | string |
cause field in the ended and failed events:cause Value | Description |
Terminated | The call ended normally. |
Canceled | The caller canceled the call before the callee answered. |
Busy | The callee is busy. |
Rejected | The call was rejected. |
Not Found | The callee number does not exist. |
Unavailable | The callee is temporarily unavailable. |
No Answer | The callee did not answer. |
Expires | The call timed out. |
Request Timeout | Requests timed out. |
Connection Error | Network connection error. |
SIP Failure Code | Other SIP errors. |
Internal Error | Internal error. |
Address Incomplete | Incomplete number address. |
Authentication Error | Authentication error. |
Dialog Error | Dialog error. |
User Denied Media Access | The user denied media access permission. |
WebRTC Error | WebRTC error. |
RTP Timeout | RTP timeout (media stream interrupted). |
TcccSipError (or its subclasses).Attribute | Type | Description |
code | string | Error code, in the format of module.description, for example, User.NotReady. |
message | string | Human-readable error description. |
detail | object | undefined | Structured additional information (available for some error codes). |
fullMessage | string | Complete error chain information, with multiple layers of errors connected by line breaks. |
const { TcccSipError, ErrorCode } = window.TcccUserCall;try {await user.startAudioCall('xxx');} catch (err) {// Method 1: Use instanceof to check.if (err instanceof TcccSipError) {console.error(err.code, err.message);}// Method 2: Use ErrorCode constants for exact matching.if (err.code === ErrorCode.User.InvalidUserSig) {user.updateUserSig('new userSig');}// Method 3: View the complete error chain.if (err instanceof TcccSipError) {console.error(err.fullMessage);}}
Error code | Constant | Description |
User.InvalidUserId | ErrorCode.User.InvalidUserId | Invalid userId: it cannot be empty and cannot contain @. |
User.InstanceExists | ErrorCode.User.InstanceExists | A user instance already exists. Call unInit() to terminate it before creating a new instance. |
User.NotReady | ErrorCode.User.NotReady | The SDK is not ready yet. Initiate a call only after the ready event. |
User.Disconnected | ErrorCode.User.Disconnected | The WebSocket connection is disconnected. |
User.CallInProgress | ErrorCode.User.CallInProgress | A call is already in progress. |
User.InvalidUserSig | ErrorCode.User.InvalidUserSig | The userSig is invalid or has expired. |
User.Destroyed | ErrorCode.User.Destroyed | The instance has been terminated. Do not call unInit() again. |
detail field of some errors may contain RtcDetail information (see the description below).Error code | Constant | Description | detail |
Rtc.NotInRoom | ErrorCode.Rtc.NotInRoom | The user is not in the room and cannot perform operations such as muting. | - |
Rtc.Destroyed | ErrorCode.Rtc.Destroyed | The TRTC instance has been terminated. | - |
Rtc.PublishStopped | ErrorCode.Rtc.PublishStopped | Audio publishing failed or was stopped. | RtcDetail |
Rtc.JoinRoomFailed | ErrorCode.Rtc.JoinRoomFailed | Failed to enter the audio room. | RtcDetail |
Rtc.Trtc | ErrorCode.Rtc.Trtc | TRTC general error. | RtcDetail |
Rtc.KickedOut | ErrorCode.Rtc.KickedOut | Kicked out of the room (for example, due to duplicate login). | - |
Rtc.CheckDeviceFailed | ErrorCode.Rtc.CheckDeviceFailed | Device detection failed (other unknown reasons). | - |
Rtc.MicNotFound | ErrorCode.Rtc.MicNotFound | No microphone device detected. | RtcDetail |
Rtc.MicNotAllowed | ErrorCode.Rtc.MicNotAllowed | The user denied microphone permission. | RtcDetail |
Rtc.MicNotReadable | ErrorCode.Rtc.MicNotReadable | The microphone is not readable (it may be occupied by another application). | RtcDetail |
Rtc.MicTimeout | ErrorCode.Rtc.MicTimeout | Microphone capture timed out (the user did not respond to the authorization pop-up). | - |
Rtc.InsecureContext | ErrorCode.Rtc.InsecureContext | In a non-HTTPS environment, the browser prohibits access to the microphone. | - |
detail field may not exist. Even if it exists, the code and extraCode fields within it may not have values. If they do, refer to the TRTC error code documentation for their specific meanings.Field | Type | Description |
code | number | TRTC error code. |
extraCode | number | TRTC additional error code, used to further distinguish the cause. |
detail field of some errors may contain CgiDetail information (see the description below).Error code | Constant | Description | detail |
Cgi.BizError | ErrorCode.Cgi.BizError | Server-side business logic error (HTTP succeeds but the business response fails). | CgiDetail |
Cgi.Error | ErrorCode.Cgi.Error | Network request exception (timeout/network unreachable). | CgiDetail |
detail field may not exist. Even if it exists, the fields within it may not have values. When troubleshooting, provide the requestId to technical support.Field | Type | Description |
bizCode | string | Business error code returned by the server. |
httpStatus | number | HTTP response status code. |
requestId | string | Unique request identifier. Provide it to technical support when troubleshooting issues. |
code | string | Network-layer error code (for example, ERR_NETWORK). |
Error code | Constant | Description |
Session.TrtcClientNotExist | ErrorCode.Session.TrtcClientNotExist | The TRTC client instance does not exist. The call may not have been established yet or may have already ended. |
Error code | Constant | Description |
Dtmf.InvalidParam | ErrorCode.Dtmf.InvalidParam | The DTMF parameter is invalid (for example, tone is empty or not a single character). |
Dtmf.InvalidState | ErrorCode.Dtmf.InvalidState | The current call state does not allow sending DTMF (the call is not established). |
Dtmf.SendFailed | ErrorCode.Dtmf.SendFailed | Failed to send DTMF. |
Dtmf.Timeout | ErrorCode.Dtmf.Timeout | DTMF sending timed out. |
Dtmf.TransportError | ErrorCode.Dtmf.TransportError | DTMF transport layer error. |
Dtmf.DialogError | ErrorCode.Dtmf.DialogError | DTMF dialog error. |
Dtmf.ResponseError | ErrorCode.Dtmf.ResponseError | DTMF response error. |
localhost). Otherwise, the browser will block microphone access.createUser is called? The error code is User.InstanceExists.unInit() method of the existing instance to terminate it before creating a new one.startAudioCall is called? The error code is User.NotReady.ready event is triggered. The ready event indicates that the connection is established and the SDK is ready.Rtc.MicNotAllowed is reported?User.InvalidUserSig is reported?userSig has expired or the signature was calculated incorrectly. Check the backend signature generation logic, call user.updateUserSig() to update the signature, and then initiate the call again.Rtc.InsecureContext is reported?localhost for local development.startAudioCall again while a call is already in progress, the User.CallInProgress error is thrown.Esta página foi útil?
Você também pode entrar em contato com a Equipe de vendas ou Enviar um tíquete em caso de ajuda.
comentários