TRTCKaraokeRoom
is based on Tencent Real-Time Communication (TRTC) and Tencent Cloud Chat. With TRTCKaraoke:TRTCKaraokeRoom
is an open-source class depending on two closed-source Tencent Cloud SDKs. For the specific implementation process, see Karaoke (iOS).AVChatRoom
feature of the Chat SDK is used to implement chat rooms. The attribute APIs of IM are used to store room information such as the seat list, and invitation signaling is used to send requests to speak or invite others to speak.TRTCKaraokeRoom
API OverviewAPI | Description |
Gets a singleton object. | |
Terminates a singleton object. | |
Sets event callbacks. | |
Sets the thread where event callbacks are. | |
Logs in. | |
Logs out. | |
Sets profile. |
API | Description |
Creates a room (called by room owner). If the room does not exist, the system will automatically create a room. | |
Terminates a room (called by room owner). | |
Enters a room (called by listener). | |
Exits a room (called by listener). | |
Gets room list details. | |
Gets the user information of the specified userId . If the value is nil , the information of all users in the room is obtained. |
API | Description |
Starts music. | |
Stops music. | |
Pauses music. | |
Resumes music. |
API | Description |
Becomes a speaker (called by room owner or listener). | |
Becomes a listener (called by speaker). | |
Places a user in a seat (called by room owner). | |
Removes a speaker (called by room owner). | |
Mutes/Unmutes a seat (called by room owner). | |
Blocks/Unblocks a seat (called by room owner). |
API | Description |
Starts mic capturing. | |
Stops mic capturing. | |
Sets audio quality. | |
Mutes/Unmutes local audio. | |
Sets whether to play sound from the device’s speaker or receiver. | |
Sets mic capturing volume. | |
Sets playback volume. | |
Enables/Disables in-ear monitoring. |
API | Description |
Mutes/Unmutes a specified member. | |
Mutes/Unmutes all members. |
API | Description |
API | Description |
Broadcasts a text chat message in a room. This API is generally used for on-screen comments. | |
Sends a custom text chat message. |
API | Description |
Sends an invitation. | |
Accepts an invitation. | |
Declines an invitation. | |
Cancels an invitation. |
TRTCKaraokeRoomDelegate
API OverviewAPI | Description |
Callback for error. | |
Callback for warning. | |
Callback of log. |
API | Description |
The room was terminated. | |
The room information changed. | |
User volume |
API | Description |
All seat changes. | |
A user became a speaker or was made a speaker by the room owner. | |
A user became a listener or was made a listener by the room owner. | |
The room owner muted a seat. | |
Whether a user’s mic is muted | |
The room owner blocked a seat. |
API | Description |
A listener entered the room. | |
A listener exited the room. |
API | Description |
A text chat message was received. | |
A custom message was received. |
API | Description |
Receipt of an invitation. | |
Invitation accepted by invitee. | |
Invitation declined by invitee. | |
Invitation canceled by inviter. |
API | Description |
Music playback progress. | |
Music playback is ready. | |
Music playback was completed. |
/*** Get a `TRTCKaraokeRoom` singleton object** - returns: `TRTCKaraokeRoom` instance* - note: To terminate a singleton object, call {@link TRTCKaraokeRoom#destroySharedInstance()}.*/+ (instancetype)sharedInstance NS_SWIFT_NAME(shared());
TRTCKaraokeRoom
instance can no longer be used. You need to call sharedInstance again to get a new instance./*** Terminate the `TRTCKaraokeRoom` singleton object** - note: After the instance is terminated, the externally cached `TRTCKaraokeRoom` instance can no longer be used. You need to call {@link TRTCKaraokeRoom#sharedInstance()} again to get a new instance.*/+ (void)destroySharedInstance NS_SWIFT_NAME(destroyShared());
TRTCKaraokeRoomDelegate
to get different status notifications of TRTCKaraokeRoom./*** Set the event callbacks of the component** You can use `TRTCKaraokeRoomDelegate` to get different status notifications of `TRTCKaraokeRoom`.** - parameter delegate Callback API* - note: Callbacks in `TRTCKaraokeRoom` are sent to you in the main queue by default. If you need to specify a queue for event callbacks, use {@link TRTCKaraokeRoom#setDelegateQueue(queue)}.*/- (void)setDelegate:(id<TRTCKaraokeRoomDelegate>)delegate NS_SWIFT_NAME(setDelegate(delegate:));
setDelegate
is the delegate callback of TRTCKaraokeRoom
. /*** Set the queue for event callbacks** - parameter queue. The status notifications of `TRTCKaraokeRoom` will be sent to the queue you specify.*/- (void)setDelegateQueue:(dispatch_queue_t)queue NS_SWIFT_NAME(setDelegateQueue(queue:));
Parameter | Type | Description |
queue | dispatch_queue_t | The status notifications of TRTCKaraokeRoom are sent to the thread queue you specify. |
- (void)login:(int)sdkAppIDuserId:(NSString *)userIduserSig:(NSString *)userSigcallback:(ActionCallback _Nullable)callback NS_SWIFT_NAME(login(sdkAppID:userId:userSig:callback:));
Parameter | Type | Description |
sdkAppId | int | |
userId | String | The ID of the current user, which is a string that can contain only letters (a-z and A-Z), digits (0-9), hyphens (-), and underscores (_). |
userSig | String | Tencent Cloud's proprietary security signature. For how to calculate and use it, see FAQs > UserSig. |
callback | ActionCallback | The callback for login. The code is 0 if login succeeds. |
- (void)logout:(ActionCallback _Nullable)callback NS_SWIFT_NAME(logout(callback:));
Parameter | Type | Description |
callback | ActionCallback | The callback for logout. The code is 0 if logout succeeds. |
- (void)setSelfProfile:(NSString *)userName avatarURL:(NSString *)avatarURL callback:(ActionCallback _Nullable)callback NS_SWIFT_NAME(setSelfProfile(userName:avatarURL:callback:));
Parameter | Type | Description |
userName | String | The username. |
avatar | String | The address of the profile photo. |
callback | ActionCallback | The callback for profile configuration. The code is 0 if the operation succeeds. |
- (void)createRoom:(int)roomID roomParam:(RoomParam *)roomParam callback:(ActionCallback _Nullable)callback NS_SWIFT_NAME(createRoom(roomID:roomParam:callback:));
Parameter | Type | Description |
roomId | int | The room ID. You need to assign and manage room IDs in a centralized manner. Multiple roomID values can be aggregated into a room list. Currently, Tencent Cloud does not provide management services for room lists. Please manage your own room lists. |
roomParam | TRTCCreateRoomParam | Room information, such as room name, seat list information, and cover information. To manage seats, you must enter the number of seats in the room. |
callback | ActionCallback | The callback for room creation. The code is 0 if the operation succeeds. |
createRoom
to create a karaoke room, passing in room attributes (e.g., room ID, whether listeners need room owner’s permission to speak, number of seats).enterSeat
to become a speaker.onSeatListChanget
notification about the change of the seat list, and can update the change to the UI.onAnchorEnterSeat
notification that someone became a speaker, and mic capturing will be enabled automatically.- (void)destroyRoom:(ActionCallback _Nullable)callback NS_SWIFT_NAME(destroyRoom(callback:));
Parameter | Type | Description |
callback | ActionCallback | The callback for room termination. The code is 0 if the operation succeeds. |
- (void)enterRoom:(NSInteger)roomID callback:(ActionCallback _Nullable)callback NS_SWIFT_NAME(enterRoom(roomID:callback:));
Parameter | Type | Description |
roomId | int | The room ID. |
callback | ActionCallback | The callback for room entry. The code is 0 if the operation succeeds. |
roomId
and room information of multiple karaoke rooms.enterRoom
with the room ID passed in.onRoomInfoChange
notification about room attribute change from the component. The attributes can be recorded, and corresponding changes can be made to the UI, including room name, whether room owner’s permission is required for listeners to speak, etc.onSeatListChange
notification about the change of the seat list and can update the change to the UI.onAnchorEnterSeat
notification that someone became a speaker.- (void)exitRoom:(ActionCallback _Nullable)callback NS_SWIFT_NAME(exitRoom(callback:));
Parameter | Type | Description |
callback | ActionCallback | The callback for room exit. The code is 0 if the operation succeeds. |
roomInfo
when calling createRoom()
.- (void)getRoomInfoList:(NSArray<NSNumber *> *)roomIdList callback:(KaraokeInfoCallback _Nullable)callback NS_SWIFT_NAME(getRoomInfoList(roomIdList:callback:));
Parameter | Type | Description |
roomIdList | List<Integer> | The room ID list. |
callback | RoomInfoCallback | The callback of room details. |
userId
).- (void)getUserInfoList:(NSArray<NSString *> * _Nullable)userIDList callback:(KaraokeUserListCallback _Nullable)callback NS_SWIFT_NAME(getUserInfoList(userIDList:callback:));
Parameter | Type | Description |
userIdList | List<String> | The user IDs to query. If this parameter is null , the information of all users in the room is queried. |
userlistcallback | UserListCallback | The callback of user details. |
onMusicPrepareToPlay
notification.onMusicProgressUpdate
notification.onMusicCompletePlaying
notification.- (void)startPlayMusic:(int32_t)musicID originalUrl:(NSString *)originalUrl accompanyUrl:(NSString *)backingUrl NS_SWIFT_NAME(startPlayMusic(musicID:originalUrl:accompanyUrl:));
Parameter | Type | Description |
musicID | int32_t | The music ID. |
originalUrl | String | The absolute path of the vocal track. |
accompanyUrl | String | The absolute path of the instrumental track. |
onMusicCompletePlaying
notification.- (void)stopPlayMusic NS_SWIFT_NAME(stopPlayMusic());
onMusicProgressUpdate
notification will be paused.onMusicCompletePlaying
notification will be received.- (void)pausePlayMusic NS_SWIFT_NAME(pausePlayMusic());
onMusicPrepareToPlay
notification will be received.- (void)resumePlayMusic NS_SWIFT_NAME(resumePlayMusic());
onSeatListChange
notification and an onAnchorEnterSeat
notification.- (void)enterSeat:(NSInteger)seatIndex callback:(ActionCallback _Nullable)callback NS_SWIFT_NAME(enterSeat(seatIndex:callback:));
Parameter | Type | Description |
seatIndex | int | The number of the seat to be taken. |
callback | ActionCallback | The callback for the operation. |
sendInvitation
first to send a request and, after receiving onInvitationAccept
, call this API.onSeatListChange
notification and an onAnchorLeaveSeat
notification.- (void)leaveSeat:(ActionCallback _Nullable)callback NS_SWIFT_NAME(leaveSeat(callback:));
Parameter | Type | Description |
callback | ActionCallback | The callback for the operation. |
onSeatListChange
notification and an onAnchorEnterSeat
notification.- (void)pickSeat:(NSInteger)seatIndex userId:(NSString *)userId callback:(ActionCallback _Nullable)callback NS_SWIFT_NAME(pickSeat(seatIndex:userId:callback:));
Parameter | Type | Description |
seatIndex | int | The number of the seat to place the listener in. |
userId | String | The User ID. |
callback | ActionCallback | The callback for the operation. |
sendInvitation
first to send a request and, after receiving onInvitationAccept
, call pickSeat
.onSeatListChange
notification and an onAnchorLeaveSeat
notification.- (void)kickSeat:(NSInteger)seatIndex callback:(ActionCallback _Nullable)callback NS_SWIFT_NAME(kickSeat(seatIndex:callback:));
Parameter | Type | Description |
seatIndex | int | The number of the seat to remove the speaker from. |
callback | ActionCallback | The callback for the operation. |
onSeatListChange
notification and an onSeatMute
notification.- (void)muteSeat:(NSInteger)seatIndex isMute:(BOOL)isMute callback:(ActionCallback _Nullable)callback NS_SWIFT_NAME(muteSeat(seatIndex:isMute:callback:));
Parameter | Type | Description |
seatIndex | int | The number of the seat to mute/unmute. |
isMute | boolean | true : Mute; false : Unmute |
callback | ActionCallback | The callback for the operation. |
seatIndex
will call muteAudio
to mute/unmute his or her audio.onSeatListChange
notification and an onSeatClose
notification.- (void)closeSeat:(NSInteger)seatIndex isClose:(BOOL)isClose callback:(ActionCallback _Nullable)callback NS_SWIFT_NAME(closeSeat(seatIndex:isClose:callback:));
Parameter | Type | Description |
seatIndex | int | The number of the seat to block/unblock. |
isClose | boolean | true : Block; false : Unblock |
callback | ActionCallback | The callback for the operation. |
seatIndex
will leave the seat.- (void)startMicrophone;
- (void)stopMicrophone;
- (void)setAuidoQuality:(NSInteger)quality NS_SWIFT_NAME(setAuidoQuality(quality:));
Parameter | Type | Description |
quality | int |
- (void)muteLocalAudio:(BOOL)mute NS_SWIFT_NAME(muteLocalAudio(mute:));
Parameter | Type | Description |
mute | boolean |
- (void)setSpeaker:(BOOL)userSpeaker NS_SWIFT_NAME(setSpeaker(userSpeaker:));
Parameter | Type | Description |
useSpeaker | boolean | true : Speaker; false : Receiver |
- (void)setAudioCaptureVolume:(NSInteger)volume NS_SWIFT_NAME(setAudioCaptureVolume(volume:));
Parameter | Type | Description |
volume | int | The capturing volume. Value range: 0-100 (default: 100) |
- (void)setAudioPlayoutVolume:(NSInteger)volume NS_SWIFT_NAME(setAudioPlayoutVolume(volume:));
Parameter | Type | Description |
volume | int | The playback volume. Value range: 0-100 (default: 100) |
- (void)muteRemoteAudio:(NSString *)userId mute:(BOOL)mute NS_SWIFT_NAME(muteRemoteAudio(userId:mute:));
Parameter | Type | Description |
userId | String | The user ID. |
mute | boolean | true : Mute; false : Unmute |
- (void)muteAllRemoteAudio:(BOOL)isMute NS_SWIFT_NAME(muteAllRemoteAudio(isMute:));
Parameter | Type | Description |
isMute | boolean | true : Mute; false : Unmute |
- (void)setVoiceEarMonitorEnable:(BOOL)enable NS_SWIFT_NAME(setVoiceEarMonitor(enable:));
Parameter | Type | Description |
enable | boolean | true : Enable; false : Disable |
- (TXAudioEffectManager * _Nullable)getAudioEffectManager;
- (void)sendRoomTextMsg:(NSString *)message callback:(ActionCallback _Nullable)callback NS_SWIFT_NAME(sendRoomTextMsg(message:callback:));
Parameter | Type | Description |
message | String | A text chat message. |
callback | ActionCallback | The callback for the operation. |
- (void)sendRoomCustomMsg:(NSString *)cmd message:(NSString *)message callback:(ActionCallback _Nullable)callback NS_SWIFT_NAME(sendRoomCustomMsg(cmd:message:callback:));
Parameter | Type | Description |
cmd | String | A custom command word used to distinguish between different message types. |
message | String | A text chat message. |
callback | ActionCallback | The callback for the operation. |
- (NSString *)sendInvitation:(NSString *)cmduserId:(NSString *)userIdcontent:(NSString *)contentcallback:(ActionCallback _Nullable)callback NS_SWIFT_NAME(sendInvitation(cmd:userId:content:callback:));
Parameter | Type | Description |
cmd | String | Custom command of business |
userId | String | The user ID of the invitee. |
content | String | The content of the invitation. |
callback | ActionCallback | The callback for the operation. |
Parameter | Type | Description |
inviteId | String | The invitation ID. |
- (void)acceptInvitation:(NSString *)identifier callback:(ActionCallback _Nullable)callback NS_SWIFT_NAME(acceptInvitation(identifier:callback:));
Parameter | Type | Description |
id | String | The invitation ID. |
callback | ActionCallback | The callback for the operation. |
- (void)rejectInvitation:(NSString *)identifier callback:(ActionCallback _Nullable)callback NS_SWIFT_NAME(rejectInvitation(identifier:callback:));
Parameter | Type | Description |
id | String | The invitation ID. |
callback | ActionCallback | The callback for the operation. |
- (void)cancelInvitation:(NSString *)identifier callback:(ActionCallback _Nullable)callback NS_SWIFT_NAME(cancelInvitation(identifier:callback:));
Parameter | Type | Description |
id | String | The invitation ID. |
callback | ActionCallback | The callback for the operation. |
TRTCKaraokeRoomDelegate
Event Callback APIs- (void)onError:(int)codemessage:(NSString*)messageNS_SWIFT_NAME(onError(code:message:));
Parameter | Type | Description |
code | int | The error code. |
message | String | The error message. |
- (void)onWarning:(int)codemessage:(NSString *)messageNS_SWIFT_NAME(onWarning(code:message:));
Parameter | Type | Description |
code | int | Error code |
message | String | Warning message |
- (void)onDebugLog:(NSString *)messageNS_SWIFT_NAME(onDebugLog(message:));
Parameter | Type | Description |
message | String | Log information |
- (void)onRoomDestroy:(NSString *)messageNS_SWIFT_NAME(onRoomDestroy(message:));
Parameter | Type | Description |
message | String | Callback information |
roomInfo
is passed in by the room owner during room creation.- (void)onRoomInfoChange:(KaraokeInfo *)roomInfoNS_SWIFT_NAME(onRoomInfoChange(roomInfo:));
Parameter | Type | Description |
roomInfo | RoomInfo | Room information |
muteLocalAudio
, all members in the room will receive this callback.- (void)onUserMicrophoneMute:(NSString *)userId mute:(BOOL)muteNS_SWIFT_NAME(onUserMicrophoneMute(userId:mute:));
Parameter | Type | Description |
userId | String | The User ID. |
mute | boolean | Volume. Value range: 0-100 |
- (void)onUserVolumeUpdate:(NSArray<TRTCVolumeInfo *> *)userVolumes totalVolume:(NSInteger)totalVolumeNS_SWIFT_NAME(onUserVolumeUpdate(userVolumes:totalVolume:));
Parameter | Type | Description |
userVolumes | List | List of user volumes |
totalVolume | int | Total volume. Value range: 0-100 |
- (void)onSeatInfoChange:(NSArray<KaraokeSeatInfo *> *)seatInfolistNS_SWIFT_NAME(onSeatListChange(seatInfoList:));
Parameter | Type | Description |
seatInfoList | List<SeatInfo> | Full seat list |
- (void)onAnchorEnterSeat:(NSInteger)indexuser:(KaraokeUserInfo *)userNS_SWIFT_NAME(onAnchorEnterSeat(index:user:));
Parameter | Type | Description |
index | int | The seat taken |
user | UserInfo | Details of the user who took the seat |
- (void)onAnchorLeaveSeat:(NSInteger)indexuser:(KaraokeUserInfo *)userNS_SWIFT_NAME(onAnchorLeaveSeat(index:user:));
Parameter | Type | Description |
index | int | The seat previously occupied by the speaker |
user | UserInfo | Details of the user who took the seat |
- (void)onSeatMute:(NSInteger)indexisMute:(BOOL)isMuteNS_SWIFT_NAME(onSeatMute(index:isMute:));
Parameter | Type | Description |
index | int | The seat muted/unmuted |
isMute | boolean | true : Muted; false : Unmuted |
- (void)onSeatClose:(NSInteger)indexisClose:(BOOL)isCloseNS_SWIFT_NAME(onSeatClose(index:isClose:));
Parameter | Type | Description |
index | int | The seat blocked/unblocked |
isClose | boolean | true : Blocked; false : Unblocked |
- (void)onAudienceEnter:(KaraokeUserInfo *)userInfoNS_SWIFT_NAME(onAudienceEnter(userInfo:));
Parameter | Type | Description |
userInfo | UserInfo | Information of the listener who entered the room |
- (void)onAudienceExit:(KaraokeUserInfo *)userInfoNS_SWIFT_NAME(onAudienceExit(userInfo:));
Parameter | Type | Description |
userInfo | UserInfo | Information of the listener who exited the room |
- (void)onRecvRoomTextMsg:(NSString *)messageuserInfo:(KaraokeUserInfo *)userInfoNS_SWIFT_NAME(onRecvRoomTextMsg(message:userInfo:));
Parameter | Type | Description |
message | String | A text chat message. |
userInfo | UserInfo | Information of the sender |
- (void)onRecvRoomCustomMsg:(NSString *)cmdmessage:(NSString *)messageuserInfo:(KaraokeUserInfo *)userInfoNS_SWIFT_NAME(onRecvRoomCustomMsg(cmd:message:userInfo:));
Parameter | Type | Description |
command | String | Custom command word used to distinguish between different message types |
message | String | A text chat message. |
userInfo | UserInfo | Information of the sender |
- (void)onReceiveNewInvitation:(NSString *)identifierinviter:(NSString *)invitercmd:(NSString *)cmdcontent:(NSString *)contentNS_SWIFT_NAME(onReceiveNewInvitation(identifier:inviter:cmd:content:));
Parameter | Type | Description |
id | String | The invitation ID. |
inviter | String | The user ID of the inviter. |
cmd | String | A custom command word specified by business. |
content | UserInfo | Content specified by business |
- (void)onInviteeAccepted:(NSString *)identifierinvitee:(NSString *)inviteeNS_SWIFT_NAME(onInviteeAccepted(identifier:invitee:));
Parameter | Type | Description |
id | String | The invitation ID. |
invitee | String | The user ID of the invitee. |
- (void)onInviteeRejected:(NSString *)identifierinvitee:(NSString *)inviteeNS_SWIFT_NAME(onInviteeRejected(identifier:invitee:));
Parameter | Type | Description |
id | String | The invitation ID. |
invitee | String | The user ID of the invitee. |
- (void)onInvitationCancelled:(NSString *)identifierinvitee:(NSString *)invitee NS_SWIFT_NAME(onInvitationCancelled(identifier:invitee:));
Parameter | Type | Description |
id | String | The invitation ID. |
invitee | String | The user ID of the invitee. |
- (void)onMusicPrepareToPlay:(int32_t)musicIDNS_SWIFT_NAME(onMusicPrepareToPlay(musicID:));
Parameter | Type | Description |
musicID | int32_t | musicID passed in for playback |
- (void)onMusicProgressUpdate:(int32_t)musicIDprogress:(NSInteger)progress total:(NSInteger)totalNS_SWIFT_NAME(onMusicProgressUpdate(musicID:progress:total:));
Parameter | Type | Description |
musicID | int32_t | musicID passed in for playback |
progress | NSInteger | Current playback progress in ms |
total | NSInteger | Total duration in ms |
- (void)onMusicCompletePlaying:(int32_t)musicIDNS_SWIFT_NAME(onMusicCompletePlaying(musicID:));
Parameter | Type | Description |
musicID | int32_t | musicID passed in for playback |
Was this page helpful?