Room Owner | Listener |
| |
TUIChatSalon
component and customize your own UI.TestChatSalon
and click Create.TUIChatSalon/Debug/GenerateTestUserSig.swift
.GenerateTestUserSig.swift
:UserSig
described in this document involves configuring SECRETKEY
in client code. In this method, SECRETKEY
may be easily decompiled and reversed, and if your key is disclosed, attackers can steal your Tencent Cloud traffic. Therefore, this method is suitable only for the local execution and debugging of the app.UserSig
distribution method is to integrate the calculation code of UserSig
into your server and provide an application-oriented API. When UserSig
is needed, your application can send a request to the business server for a dynamic UserSig
. For more information, see How do I calculate UserSig on the server?.TUIChatSalon/TUIChatSalonApp.xcworkspace
with Xcode (11.0 or above) and click the run button.Source
folder in the source code contains two subfolders: ui
and model
. The ui
subfolder contains UI code and UI-related logic. The table below lists the Swift files (folders) and the UI views they represent. You can refer to it when making UI changes.File or Folder | Description |
TRTCChatSalonEntryControl.swift | The initialization method for all view controllers. You can use the instance to quickly get a ViewController object. |
TRTCCreateChatSalonViewController | Logic for the room creation view |
TRTCChatSalonViewController | The main room views for room owner and listener |
Source
folder in the source code contains two subfolders: ui
and model
. The model
subfolder contains the reusable open-source component TUIChatSalon
. You can find the component's APIs in TRTCChatSalon.h
and use them to customize your own UI.
TUIChatSalon
depends on the TRTC SDK and IM SDK. Follow the steps below to integrate them into your project.pod 'TXIMSDK_iOS'pod 'TXLiteAVSDK_TRTC'
SDK | Download Page | Integration Guide |
TRTC SDK | ||
IM SDK |
Privacy > Microphone Usage Description
in info.plist
.TUIChatSalon
componentSource
, Resources
, and TXAppBasic
folders and the TUIChatSalon.podspec
file to your project directory.Podfile
and run pod install
to complete the import.pod 'TXAppBasic', :path => "TXAppBasic/"pod 'TXLiteAVSDK_TRTC'pod 'TUIChatSalon', :path => "./", :subspecs => ["TRTC"]
sharedInstance
class method of TUIChatSalon
to create an instance of the component.setDelegate
method to register event callbacks of the component.login
method to log in to the component. Set the key parameters as described below.Parameter | Description |
SDKAppID | |
userId | ID of the current user, which is a string that can contain letters (a-z and A-Z), digits (0-9), hyphens (-), and underscores (_). We recommend you set it based on your business account system. |
userSig | |
callback | Login callback. The code is `0` if login is successful. |
// Swift example// The class responsible for business logic in your codeclass YourController {// Calculate attributes to get a singleton object.var chatSalon: TRTCChatSalon {return TRTCChatSalon.shared()}// Other code logic......}// Set the `chatSalon` delegate.self.chatSalon.setDelegate(delegate: self)// Below is the calling method. We recommend that you use `weak self` in the closure to prevent circular references. The weak self part is not included in the sample code below.self.chatSalon.login(sdkAppID: sdkAppID, userID: userId, userSig: userSig) { [weak self] (code, message) inguard let `self` = self else { return }// Your callback business logic}
setSelfProfile
to set your nickname and profile photo.createRoom
to create a chat salon, passing in room-related parameters such as room ID, whether your consent is required for listeners to speak, and the room type.onAnchorEnterSeat
notification that someone becomes a speaker, and mic capturing will be enabled automatically.// 1. Set your nickname and profile photo.self.chatSalon.setSelfProfile(userName: userName, avatarUrl: avatarURL) { (code, message) in// Callback of the result}// 2. Create a room.let param = ChatSalonParam.init()param.roomName = "Room name"param.needRequest = true // Whether your consent is required for listeners to speakparam.coverUrl = "Cover URL"param.seatInfoList = []self.chatSalon.createRoom(roomID: yourRoomID, roomParam: param) { (code, message) inguard code == 0 else { return }// 3. Become a speaker.self.chatSalon.enterSeat { [weak self] (code, message) inguard let `self` = self else { return }if code == 0 {// Seat taken successfully} else {// Failed to take a seat}}}// 4. You receive an `onAnchorEnterSeat` notification after becoming a speaker.func onAnchorEnterSeat(user: ChatSalonUserInfo) {}
setSelfProfile
to set your nickname and profile photo.getRoomInfoList
to get short descriptions of the rooms, which are provided by room owners when they call createRoom
.getRoomInfoList
.enterRoom
with the room ID passed in to enter.onRoomInfoChange
notification about room change from the component. Record the room information, including room name, whether the room owner’s consent is required for listeners to speak, etc., and update it to the UI.onAnchorEnterSeat
notification that someone becomes a speaker.// 1. Set your nickname and profile photo.self.chatSalon.setSelfProfile(userName: userName, avatarUrl: avatarURL) { (code, message) in// Callback of the result}// 2. Get the room list from the backend. Suppose it is `roomList`.let roomList: [Int] = getRoomIDList() // The function you use to get the list of room IDs// 3. Call `getRoomInfoList` to get details of the rooms.self.chatSalon.getRoomInfoList(roomIdList: roomIdsInt) { (code, message, roomInfos: [ChatSalonInfo]) in// Refresh the UI after getting the result.}// 4. Pass in `roomId` to enter a room.self.chatSalon.enterRoom(roomID: roomInfo.roomID) { (code, message) in// Callback of the room entry resultif code == 0 {// Entered room}}// 5. After successful room entry, you receive an `onRoomInfoChange` notification.func onRoomInfoChange(roomInfo: ChatSalonInfo) {// Update the room name and other information.}// 6. You receive an `onAnchorEnterSeat` notification.func onAnchorEnterSeat(user: ChatSalonUserInfo) {// Handle the mic-on event.}
userId
of the listener to pickSeat
. All members in the room will receive an onAnchorEnterSeat
notification.userId
to kickSeat
. All members in the room will receive an onAnchorLeaveSeat
notification.onAnchorEnterSeat
.// 1. The room owner makes a listener speaker.self.chatSalon.pickSeat(userID: "123") { (code, message) in// 2. A callback is returned.}// 3. The room owner receives a notification that someone became a speaker, and can determine whether it is the listener he or she intended to make speaker.func onAnchorEnterSeat(user: ChatSalonUserInfo) {// Handle the mic-on event.}
enterSeat
. All members in the room will receive an onAnchorEnterSeat
notification.leaveSeat
. All members in the room will receive an onAnchorLeaveSeat
notification.onAnchorEnterSeat
.// 1. A listener calls an API to become a speaker.self.chatSalon.enterSeat { (code, message) in// 2. A callback is returned.}// 3. The listener receives a notification that someone became a speaker and can determine whether it is him/herself.func onAnchorEnterSeat(user: ChatSalonUserInfo) {// Handle the mic-on event.}
sendInvitation
, passing in information including the room owner’s userId
and custom command words. The API will return an inviteId
, which should be recorded.onReceiveNewInvitation
notification, and a window pops up on the UI asking the room owner whether to accept the request.acceptInvitation
with the inviteId
passed in to accept the request.onInviteeAccepted
notification and calls enterSeat
to become a speaker.// Listener// 1. A listener calls `sendInvitation` to request to speak.let inviteId = self.chatSalon.sendInvitation(cmd: "ENTER_SEAT", userID: ownerUserId, content: "1") { (code, message) in// Callback of the result}// 2. Place the user in the seat after the invitation is acceptedfunc onInviteeAccepted(identifier: String, invitee: String) {if identifier == selfID {self.chatSalon.enterSeat { (code, message) in// Callback of the result}}}// Room owner// 1. The room owner receives the request.func onReceiveNewInvitation(identifier: String, inviter: String, cmd: String, content: String) {if cmd == "ENTER_SEAT" {// 2. The room owner accepts the request.self.chatSalon.acceptInvitation(identifier: identifier, callback: nil)}}
sendInvitation
, passing in information including the listener's userId
and custom command words. The API will return an inviteId
, which should be recorded.onReceiveNewInvitation
notification, and a window pops up asking the listener whether to agree to speak.acceptInvitation
with the inviteId
passed in to accept the invitation.onInviteeAccepted
notification and calls pickSeat
to make the listener a speaker.// Room owner// 1. The room owner calls `sendInvitation` to invite user `123` to speak.let inviteId = self.chatSalon.sendInvitation(cmd: "PICK_SEAT", userID: ownerUserId, content: "2") { (code, message) in// Callback of the result}// 2. Place the user in the seat after the invitation is acceptedfunc onInviteeAccepted(identifier: String, invitee: String) {if identifier == selfID {self.chatSalon.pickSeat(userID: ) { (code, message) in// Callback of the result}}}// Listener// 1. The listener receives the invitation.func onReceiveNewInvitation(identifier: String, inviter: String, cmd: String, content: String) {if cmd == "PICK_SEAT" {// 2. The listener accepts the invitation.self.chatSalon.acceptInvitation(identifier: identifier, callback: nil)}}
sendRoomTextMsg
to send common text messages. All users in the room will receive an onRecvRoomTextMsg
callback.
IM has its default content moderation rules. Text messages that contain restricted terms will not be forwarded by the cloud.// Sender: send text messagesself.chatSalon.sendRoomTextMsg(message: message) { (code, message) in}// Recipient: listen for text messagesfunc onRecvRoomTextMsg(message: String, userInfo: ChatSalonUserInfo) {// Handling of the messages received}
sendRoomCustomMsg
to send custom (signaling) messages. All users in the room will receive an onRecvRoomCustomMsg
callback.
Custom messages are often used to transfer custom signals, e.g., to give and broadcast likes.// For example, a sender can customize commands to distinguish on-screen comments and likes.// For example, use "CMD_DANMU" to indicate on-screen comments and "CMD_LIKE" to indicate likes.self.chatSalon.sendRoomCustomMsg(cmd: “CMD_DANMU”, message: "hello world", callback: nil)self.chatSalon.sendRoomCustomMsg(cmd: "CMD_LIKE", message: "", callback: nil)// Recipient: listen for custom messagesfunc onRecvRoomCustomMsg(cmd: String, message: String, userInfo: ChatSalonUserInfo) {if cmd == "CMD_DANMU" {// An on-screen comment is received.}if cmd == "CMD_LIKE" {// A like is received.}}
Was this page helpful?