tencent cloud

Feedback

Last updated: 2022-09-26 12:04:32
    This document describes how to enter a TRTC room. Only after entering an audio/video room can a user subscribe to the audio/video streams of other users in the room or publish his or her own audio/video streams.
    
    
    You will encounter two types of objects while using the TRTC web SDK:
    Client object, which represents a local client. The Client class provides APIs for room entry, local stream publishing, remote stream subscription, etc.
    Stream object, which represents an audio/video stream object. There are local stream objects (LocalStream) and remote stream objects (RemoteStream). The Stream class provides APIs for stream-related actions, including audio/video playback control.
    

    Step 1. Create a client object

    Create a client object using TRTC.createClient(). Set the parameters as follows:
    Parameter
    Description
    Notes
    Data Type
    Example
    Default Value
    Remarks
    mode
    The application scenario.
    The rtc mode is for one-to-one audio/video calls or conferences with up to 300 participants.
    The live mode is for live streaming to up to 100,000 people.
    string
    rtc
    rtc
    -
    SDKAppID
    The application ID.
    You can view your application ID in the TRTC console. If you don’t have an application yet, click Create application to create one.
    Number
    1400000123
    -
    Required
    userId
    The user ID.
    It can contain only letters, digits, underscores, and hyphens.
    Note: In TRTC, a user cannot use the same user ID to enter the same room on two different devices at the same time.
    String
    denny or 123321
    -
    Required
    userSig
    The authentication ticket needed to enter a room.
    For how to calculate UserSig, see UserSig.
    String
    eJyrVareCeYrSy1SslI...
    -
    Required
    useStringRoomId
    Whether to use string type room IDs.
    Specifies whether to use room IDs whose data type is string.
    boolean
    true
    false
    -
    For more information on the parameters, see TRTC.createClient().
    // Create a client object in the call mode
    const client = TRTC.createClient({
    mode: 'rtc',
    sdkAppId,
    userId,
    userSig
    });
    
    // Create a client object in the live streaming mode
    const client = TRTC.createClient({
    mode: 'live',
    sdkAppId,
    userId,
    userSig
    });
    

    Step 2. Enter a room

    Call Client.join() to enter a TRTC room. Below are the request parameters:
    Parameter
    Description
    Notes
    Data Type
    Example
    Default Value
    Remarks
    roomId
    The room ID.
    The data type is number by default. If you want to use string type room IDs, set the useStringRoomId parameter of createClient() to true.
    A numeric room ID must be an integer from 1 to 4294967294.
    A string type room ID cannot be longer than 64 bytes and can contain only the following characters:
    Letters (a-z and A-Z), digits (0-9), spaces, and !#$%&()+-:;<=.>?@[]^_{}|~,
    number/string
    3364 or class-room
    -
    Required
    role
    The user role.
    This parameter is required only if mode is set to live. Two roles are supported currently: anchor and audience.
    string
    anchor
    audience
    -
    For more information on the parameters, see Client.join().
    // Using the Promise syntax
    client
    .join({ roomId })
    .then(() => {
    console.log('Entered the room successfully');
    })
    .catch(error => {
    console.error('Failed to enter the room. Please try again later.' + error);
    });
    
    // We recommend you use the async/await syntax
    try {
    await client.join({ roomId });
    console.log('Entered the room successfully');
    } catch (error) {
    console.error('Failed to enter the room. Please try again later.' + error);
    }
    
    // Enter the room as an anchor
    try {
    await client.join({
    roomId,
    role: 'anchor'
    });
    console.log('Entered the room successfully');
    } catch (error) {
    console.error('Failed to enter the room. Please try again later.' + error);
    }
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support