UserSig
in the console as shown below:
UserID
of administrator
. You can also create multiple admin accounts as needed. Note that you can create up to five admin accounts.No. | Live Room Status |
1 | To be started |
2 | On live |
3 | Paused |
4 | Ended |
5 | Played back |
No. | Characteristics |
1 | Users in a live room need to be notified in real time of the change of the live room status. |
2 | Users new to a live room need to get the current status of the live room. |
Implementation Scheme | Pros | Cons |
The business backend maintains the live room status and uses the IM server API to send custom group messages to notify users of the status. | When the live room status needs to be obtained frequently, storing the status on the business backend reduces the frequency to call the IM SDK, compared to storing the status in the IM group profile.This implementation scheme makes it possible to get the live room status when the IM SDK is not integrated. | The business backend needs to provide an extra module for reading and writing the live room status.Exceptions are more likely to occur when the live room data is obtained, as the data comes from both the business backend and IM group profile.Custom messages may be lost when sent. When there are a large number of messages, low-priority ones will be discarded first, which affects the display of the live room status. Therefore, we recommend you use high-priority custom messages. |
You can store the live room status through a custom group field or group attribute and notify group users through the callback for group attribute change of the client SDK. | You don't need to provide an extra module for reading and writing the live room status.Theoretically, the callback for group attribute change won't be lost.Live room data is obtained from the group profile, which serves as a unified data source that reduces exceptions. | You need to get the group profile frequently in the high-exposure module, which increases the pressure on IM.If the IM SDK module is not integrated, you need to call the IM server SDK on the business backend to get the group profile, and the number of calls is limited. |
lastMessage
) doesn't need to be managed.OnGroupInfoChange
in GroupListener
to get the changed group attribute.// Get the group profile from the clientV2TIMManager.getGroupManager().getGroupsInfo(groupIDList, new V2TIMValueCallback<List<V2TIMGroupInfoResult>>() {@Overridepublic void onSuccess(List<V2TIMGroupInfoResult> v2TIMGroupInfoResults) {// Obtained the group profile successfully}@Overridepublic void onError(int code, String desc) {// Failed to obtain the group profile}});// Modify the group profile on the clientV2TIMGroupInfo v2TIMGroupInfo = new V2TIMGroupInfo();v2TIMGroupInfo.setGroupID("Group ID of the group to be modified");v2TIMGroupInfo.setFaceUrl("http://xxxx");V2TIMManager.getGroupManager().setGroupInfo(v2TIMGroupInfo, new V2TIMCallback() {@Overridepublic void onSuccess() {// Modified the group profile successfully}@Overridepublic void onError(int code, String desc) {// Failed to modify the group profile}});
[[V2TIMManager sharedInstance] getGroupsInfo:@[@"groupA"] succ:^(NSArray<V2TIMGroupInfoResult *> *groupResultList) {// Obtained the group profile successfully} fail:^(int code, NSString *desc) {// Failed to obtain the group profile}];V2TIMGroupInfo *info = [[V2TIMGroupInfo alloc] init];info.groupID = @"Group ID of the group to be modified";info.faceURL = @"http://xxxx";[[V2TIMManager sharedInstance] setGroupInfo:info succ:^{// Modified the group profile successfully} fail:^(int code, NSString *desc) {// Failed to modify the group profile}];
// Get the group profileV2TimValueCallback<List<V2TimGroupInfoResult>> groupinfos = await groupManager.getGroupsInfo(groupIDList: ['groupid1']);// Modify the group profilegroupManager.setGroupInfo(info: V2TimGroupInfo.fromJson({"groupAddOpt":GroupAddOptTypeEnum.V2TIM_GROUP_ADD_AUTH// ...Other profiles}));// CallbackTencentImSDKPlugin.v2TIMManager.addGroupListener(listener: V2TimGroupListener(onGroupInfoChanged: ((groupID, changeInfos) {// The group information was changed.})));
// Get the group profilelet promise = tim.getGroupProfile({ groupID: 'group1', groupCustomFieldFilter: ['key1','key2'] });promise.then(function(imResponse) {console.log(imResponse.data.group);}).catch(function(imError){console.warn('getGroupProfile error:', imError); // Error information});// Modify the group profilelet promise = tim.updateGroupProfile({groupID: 'group1',name: 'new name', // Modify the group nameintroduction: 'this is introduction.', // Modify the group introduction// Starting from v2.6.0, group members can receive group messages about group custom field modifications and obtain related content. For more information, see Message.payload.newGroupProfile.groupCustomField.groupCustomField: [{ key: 'group_level', value: 'high'}] // Modify the group custom field});promise.then(function(imResponse) {console.log(imResponse.data.group) // Detailed group profile after modification}).catch(function(imError){console.warn('updateGroupProfile error:', imError); // Error information});// Starting from v2.6.2, the SDK supports muting and unmuting all. Currently, when all users are muted in a group, group notifications cannot be delivered.let promise = tim.updateGroupProfile({groupID: 'group1',muteAllMembers: true, // `true`: mute all; `false`: unmute all});promise.then(function(imResponse) {console.log(imResponse.data.group) // Detailed group profile after modification}).catch(function(imError){console.warn('updateGroupProfile error:', imError); // Error information});
Priority | Description |
High | High priority |
Normal | Medium priority |
Low | Low priority |
// Create a custom messageV2TIMMessage v2TIMMessage = V2TIMManager.getMessageManager().createCustomMessage("Custom one-to-one message".getBytes());// Set the message priority to highv2TIMMessage.setPriority(V2TIMMessage.V2TIM_PRIORITY_HIGH)// Send the messageV2TIMManager.getMessageManager().sendMessage(v2TIMMessage, "receiver_userID", null, V2TIMMessage.V2TIM_PRIORITY_NORMAL, false, null, new V2TIMSendCallback<V2TIMMessage>() {@Overridepublic void onProgress(int progress) {// The progress is not called back for the custom message.}@Overridepublic void onSuccess(V2TIMMessage message) {// The custom group message sent successfully}@Overridepublic void onError(int code, String desc) {// Failed to send the custom group message}});
// Create a text messageV2TIMMessage *message = [[V2TIMManager sharedInstance] createTextMessage:@"content"];// Send the message[V2TIMManager.sharedInstance sendMessage:messagereceiver:@"userID"groupID:nilpriority:V2TIM_PRIORITY_NORMALonlineUserOnly:NOofflinePushInfo:nilprogress:nilsucc:^{// The text message sent successfully}fail:^(int code, NSString *desc) {// Failed to send the text message}];
// Create a text messageV2TimValueCallback<V2TimMsgCreateInfoResult> createTextAtMessageRes = await TencentImSDKPlugin.v2TIMManager.getMessageManager().createTextAtMessage(text: "test",atUserList: [],);if(createTextAtMessageRes.code == 0){String id = createTextAtMessageRes.data.id;// Send the text messageV2TimValueCallback<V2TimMessage> sendMessageRes = await TencentImSDKPlugin.v2TIMManager.getMessageManager().sendMessage(id: id, receiver: "", groupID: "groupID");if(sendMessageRes.code == 0){// The message sent successfully}}
// Send the text message// 1. Create a message instance. The returned instance can be displayed on the screen.let message = tim.createTextMessage({to: 'user1',conversationType: TIM.TYPES.CONV_C2C,// Message priority, which applies to group chats and is supported by v2.4.2 or later. If messages in a group exceed the frequency limit, the backend will deliver high-priority messages first. For more information, see https://www.tencentcloud.com/document/product/269/3663?from_cn_redirect=1#.E6.B6.88.E6.81.AF.E4.BC.98.E5.85.88.E7.BA.A7.E4.B8.8E.E9.A2.91.E7.8E.87.E6.8E.A7.E5.88.B6.// Enumerated values supported: TIM.TYPES.MSG_PRIORITY_HIGH, TIM.TYPES.MSG_PRIORITY_NORMAL (default), TIM.TYPES.MSG_PRIORITY_LOW, TIM.TYPES.MSG_PRIORITY_LOWEST// priority: TIM.TYPES.MSG_PRIORITY_NORMAL,payload: {text: 'Hello world!'},// The read receipt feature is supported for one-to-one messages by v2.20.0 or later. To use it, purchase the Premium edition package and set `needReadReceipt` to `true` when creating a message.needReadReceipt: true// Message custom data (saved in the cloud, will be sent to the peer end, and can still be pulled after the app is uninstalled and reinstalled; supported from v2.10.2)// cloudCustomData: 'your cloud custom data'});// 2. Send the message.let promise = tim.sendMessage(message);promise.then(function(imResponse) {// The message sent successfullyconsole.log(imResponse);}).catch(function(imError){// The message failed to be sentconsole.warn('sendMessage error:', imError);});
99
included in the parameter.{"CallbackCommand": "Group.CallbackAfterSendMsg", // Callback command"GroupId": "@TGS#2J4SZEAEL", // Group ID"Type": "Public", // Group type"From_Account": "jared", // Sender"Operator_Account":"admin", // Request initiator"Random": 123456, // Random number"MsgSeq": 123, // Sequence number of the message"MsgTime": 1490686222, // Time of the message"OnlineOnlyFlag": 1, // The value is `1` if it is an online message and `0` (default) if it’s not. For audio-video groups, the value is `0`."MsgBody": [ // Message body. For more information, see the `TIMMessage` message object.{"MsgType": "TIMTextElem", // Text"MsgContent":{"Text": "red packet"}}],"CloudCustomData": "your cloud custom data"}
MsgBody
. For more information on all the fields, see Callback After Sending a Group Message.{"CallbackCommand": "State.StateChange","EventTime": 1629883332497,"Info": {"Action": "Login","To_Account": "testuser316","Reason": "Register"},"KickedDevice": [{"Platform": "Windows"},{"Platform": "Android"}]}
Info
, so as to count the online duration. For more information on all the fields, see State Change Callbacks.V2TIMMessageListGetOption option = new V2TIMMessageListGetOption();option.setGetType(V2TIMMessageListGetOption.V2TIM_GET_CLOUD_OLDER_MSG); // Pull older cloud messagesoption.setGetTimeBegin(1640966400); // Start from 2022-01-01 00:00:00option.setGetTimePeriod(1 * 24 * 60 * 60); // Pull the messages of the whole dayoption.setCount(Integer.MAX_VALUE); // Return all the messages within the time rangeoption.setGroupID(#you group id#); // Pull group messagesV2TIMManager.getMessageManager().getHistoryMessageList(option, new V2TIMValueCallback<List<V2TIMMessage>>() {@Overridepublic void onSuccess(List<V2TIMMessage> v2TIMMessages) {Log.i("imsdk", "success");}@Overridepublic void onError(int code, String desc) {Log.i("imsdk", "failure, code:" + code + ", desc:" + desc);}});
// Pull historical one-to-one messages// Set `lastMsg` to `nil` for the first pull// `lastMsg` can be the last message in the returned message list for the second pull.[V2TIMManager.sharedInstance getC2CHistoryMessageList:#your user id# count:20 lastMsg:nil succ:^(NSArray<V2TIMMessage *> *msgs) {// Record the `lastMsg` for the next pullV2TIMMessage *lastMsg = msgs.lastObject;NSLog(@"success, %@", msgs);} fail:^(int code, NSString *desc) {NSLog(@"fail, %d, %@", code, desc);}];
// Pull historical one-to-one messages// Set `lastMsgID` to `null` for the first pull// `lastMsgID` can be the ID of the last message in the returned message list for the second pull.TencentImSDKPlugin.v2TIMManager.getMessageManager().getC2CHistoryMessageList(userID: "userId",count: 10,lastMsgID: null,);
/ Pull the message list for the first time when a conversation is opened.let promise = tim.getMessageList({conversationID: 'C2Ctest', count: 15});promise.then(function(imResponse) {const messageList = imResponse.data.messageList; // Message listconst nextReqMessageID = imResponse.data.nextReqMessageID; // This parameter must be passed in for the next pulling by page.const isCompleted = imResponse.data.isCompleted; // It indicates whether all messages have been pulled.});// Pull down to see more messages.let promise = tim.getMessageList({conversationID: 'C2Ctest', nextReqMessageID, count: 15});promise.then(function(imResponse) {const messageList = imResponse.data.messageList; // Message listconst nextReqMessageID = imResponse.data.nextReqMessageID; // This parameter must be passed in for the next pulling by page.const isCompleted = imResponse.data.isCompleted; // It indicates whether all messages have been pulled.});
2TIMManager.getGroupManager().getGroupOnlineMemberCount("group_avchatroom", new V2TIMValueCallback<Integer>() {@Overridepublic void onSuccess(Integer integer) {// Obtained the number of online members in the audio-video group (AVChatRoom) successfully}@Overridepublic void onError(int code, String desc) {// Failed to obtain the number of online members in the audio-video group (AVChatRoom)}});
[[V2TIMManager sharedInstance] getGroupOnlineMemberCount:@"group_avchatroom" succ:^(NSInteger count) {// Obtained the number of online members in the audio-video group (AVChatRoom) successfully} fail:^(int code, NSString *desc) {// Failed to obtain the number of online members in the audio-video group (AVChatRoom)}];
groupManager.getGroupOnlineMemberCount(groupID: '');
// Get the number of online users in an audio-video group (supported from v2.8.0)let promise = tim.getGroupOnlineMemberCount('group1');promise.then(function(imResponse) {console.log(imResponse.data.memberCount);}).catch(function(imError){console.warn('getGroupOnlineMemberCount error:', imError); // Error information});
MuteAllMember
field of the group attribute as instructed in Modifying the Profile of a Group. To mute a specified user, set the group member attribute as instructed in Bulk Muting and Unmuting.// Mute the `userB` group member for one minuteV2TIMManager.getGroupManager().muteGroupMember("groupA", "userB", 60, new V2TIMCallback() {@Overridepublic void onSuccess() {// Muted the group member successfully}@Overridepublic void onError(int code, String desc) {// Failed to mute the group member}});// Mute all membersV2TIMGroupInfo info = new V2TIMGroupInfo();info.setGroupID("groupA");info.setAllMuted(true);V2TIMManager.getGroupManager().setGroupInfo(info, new V2TIMCallback() {@Overridepublic void onSuccess() {// Muted all successfully}@Overridepublic void onError(int code, String desc) {// Failed to mute all}});V2TIMManager.getInstance().addGroupListener(new V2TIMGroupListener() {@Overridepublic void onMemberInfoChanged(String groupID, List<V2TIMGroupMemberChangeInfo> v2TIMGroupMemberChangeInfoList) {// Listen for the muting of a group memberfor (V2TIMGroupMemberChangeInfo memberChangeInfo : v2TIMGroupMemberChangeInfoList) {// ID of the muted userString userID = memberChangeInfo.getUserID();// Muting durationlong muteTime = memberChangeInfo.getMuteTime();}}@Overridepublic void onGroupInfoChanged(String groupID, List<V2TIMGroupChangeInfo> changeInfos) {// Listen for the muting of allfor (V2TIMGroupChangeInfo groupChangeInfo : changeInfos) {if (groupChangeInfo.getType() == V2TIMGroupChangeInfo.V2TIM_GROUP_INFO_CHANGE_TYPE_SHUT_UP_ALL) {// Whether all members are mutedboolean isMuteAll = groupChangeInfo.getBoolValue();}}}});
// Mute the group member `user1` for one minute[[V2TIMManager sharedInstance] muteGroupMember:@"groupA" member:@"user1" muteTime:60 succ:^{// Muted the group member successfully} fail:^(int code, NSString *desc) {// Failed to mute the group member}];// Mute all membersV2TIMGroupInfo *info = [[V2TIMGroupInfo alloc] init];info.groupID = @"groupA";info.allMuted = YES;[[V2TIMManager sharedInstance] muteGroupMember:@"groupA" member:@"user1" muteTime:60 succ:^{// Muted all successfully} fail:^(int code, NSString *desc) {// Failed to mute all}];[[V2TIMManager sharedInstance] addGroupListener:self];- (void)onMemberInfoChanged:(NSString *)groupID changeInfoList:(NSArray <V2TIMGroupMemberChangeInfo *> *)changeInfoList {// Listen for the muting of a group memberfor (V2TIMGroupMemberChangeInfo *memberChangeInfo in changeInfoList) {// ID of the muted userNSString *userID = memberChangeInfo.userID;// Muting durationuint32_t muteTime = memberChangeInfo.muteTime;}}- (void)onGroupInfoChanged:(NSString *)groupID changeInfoList:(NSArray <V2TIMGroupChangeInfo *> *)changeInfoList {// Listen for the muting of allfor (V2TIMGroupChangeInfo groupChangeInfo in changeInfoList) {if (groupChangeInfo.type == V2TIM_GROUP_INFO_CHANGE_TYPE_SHUT_UP_ALL) {// Whether all members are mutedBOOL isMuteAll = groupChangeInfo.boolValue;}}}
// Mute the group member `userB` for ten minutesgroupManager.muteGroupMember(groupID: '',userID: 'userB',seconds: 10);// Mute all membersgroupManager.setGroupInfo(info: V2TimGroupInfo(isAllMuted: true,groupID: '',groupType: 'Public'));TencentImSDKPlugin.v2TIMManager.addGroupListener(listener: V2TimGroupListener(onMemberInfoChanged: (groupID, v2TIMGroupMemberChangeInfoList) {// The group member information is changed.},onGroupInfoChanged: (groupID,info){// Group profile modification}));
tim.setGroupMemberMuteTime(options);let promise = tim.setGroupMemberMuteTime({groupID: 'group1',userID: 'user1',muteTime: 600 // The user is muted for ten minutes. If the value is set to `0`, the user is unmuted.});promise.then(function(imResponse) {console.log(imResponse.data.group); // New group profileconsole.log(imResponse.data.member); // New group member profile}).catch(function(imError){console.warn('setGroupMemberMuteTime error:', imError); // Error information});// Set the period for muting a group member in the topiclet promise = tim.setGroupMemberMuteTime({groupID: 'topicID',userID: 'user1',muteTime: 600 // The user is muted for ten minutes. If the value is set to `0`, the user is unmuted.});promise.then(function(imResponse) {console.log(imResponse.data.group); // New group profileconsole.log(imResponse.data.member); // New group member profile}).catch(function(imError){console.warn('setGroupMemberMuteTime error:', imError); // Error information});// Starting from v2.6.2, the SDK supports muting and unmuting all. Currently, when all users are muted in a group, group notifications cannot be delivered.let promise = tim.updateGroupProfile({groupID: 'group1',muteAllMembers: true, // `true`: mute all; `false`: unmute all});promise.then(function(imResponse) {console.log(imResponse.data.group) // Detailed group profile after modification}).catch(function(imError){console.warn('updateGroupProfile error:', imError); // Error information});
List<String> userIDList = new ArrayList<>();userIDList.add("userB");V2TIMManager.getGroupManager().kickGroupMember("groupA", userIDList, "", new V2TIMValueCallback<List<V2TIMGroupMemberOperationResult>>() {@Overridepublic void onSuccess(List<V2TIMGroupMemberOperationResult> v2TIMGroupMemberOperationResults) {// Removed the member successfully}@Overridepublic void onError(int code, String desc) {// Failed to remove the member}});V2TIMManager.getInstance().addGroupListener(new V2TIMGroupListener() {@Overridepublic void onMemberKicked(String groupID, V2TIMGroupMemberInfo opUser,List<V2TIMGroupMemberInfo> memberList) {// A group member was removed.}});
[[V2TIMManager sharedInstance] kickGroupMember:@"groupA" memberList:@[@"user1"] reason:@"" succ:^(NSArray<V2TIMGroupMemberOperationResult *> *resultList) {// Removed the member successfully} fail:^(int code, NSString *desc) {// Failed to remove the member}];[[V2TIMManager sharedInstance] addGroupListener:self];- (void)onMemberKicked:(NSString *)groupID opUser:(V2TIMGroupMemberInfo *)opUser memberList:(NSArray<V2TIMGroupMemberInfo *>*)memberList {// A group member was removed.}
groupManager.kickGroupMember(groupID: '',memberList: []);
tim.deleteGroupMember(options);
{"CallbackCommand": "Group.CallbackBeforeSendMsg", // Callback command"GroupId": "@TGS#2J4SZEAEL", // Group ID"Type": "Public", // Group type"From_Account": "jared", // Sender"Operator_Account":"admin", // Request initiator"Random": 123456, // Random number"OnlineOnlyFlag": 1, // The value is `1` if it is an online message and `0` (default) if it’s not. For audio-video groups, the value is `0`."MsgBody": [ // Message body. For more information, see the `TIMMessage` message object.{"MsgType": "TIMTextElem", // Text"MsgContent":{"Text": "red packet"}}],"CloudCustomData": "your cloud custom data"}
MsgType
field in MsgBody
. For more information on the fields, see Callback Before Sending a Group Message.{"ActionStatus": "OK","ErrorInfo": "","ErrorCode": 0 // Different `ErrorCode` values have different meanings.}
ErrorCode | Description |
0 | Speaking is allowed, and messages can be delivered. |
1 | Speaking is denied, and the client returns 10016 . |
2 | Silent discarding is enabled, and the client returns messages normally. |
getGroupMemberList
API to get the list of online group members in a live room for display. As an audio-video group (AVChatRoom) has a large number of members, the feature of pulling the list of all the members is unavailable. The Premium edition and non-Premium edition differ in settings:getGroupMemberList
to pull the latest 30 group members.getGroupMemberList
to pull the latest 1,000 group members. This feature needs to be enabled in the IM console. If it is not enabled, only the latest 30 group members will be pulled, just as in the non-Premium edition.getGroupMemberList
and the onGroupMemberEnter
and onGroupMemberQuit
callbacks of the group listening. However, after users leave and re-enter the live room, only the latest 30 group members can be pulled.// Use the `filter` parameter to specify only the profile of the group owner is to be pulledint role = V2TIMGroupMemberFullInfo.V2TIM_GROUP_MEMBER_FILTER_OWNER;V2TIMManager.getGroupManager().getGroupMemberList("testGroup", role, 0,new V2TIMValueCallback<V2TIMGroupMemberInfoResult>() {@Overridepublic void onError(int code, String desc) {// Messages failed to be pulled}@Overridepublic void onSuccess(V2TIMGroupMemberInfoResult v2TIMGroupMemberInfoResult) {// Conversations pulled successfully}});
[[V2TIMManager sharedInstance] getGroupMemberList:@"groupA" filter:V2TIM_GROUP_MEMBER_FILTER_OWNER nextSeq:0 succ:^(uint64_t nextSeq, NSArray<V2TIMGroupMemberFullInfo *> *memberList) {// Conversations pulled successfully} fail:^(int code, NSString *desc) {// Messages failed to be pulled}];
// Use the `filter` parameter to specify only the profile of the group owner is to be pulled. You can also set `filter` to `All` to pull the profiles of all group members.groupManager.getGroupMemberList(count: 10,filter: GroupMemberFilterTypeEnum.V2TIM_GROUP_MEMBER_FILTER_ADMIN,nextSeq: '0',offset: 0,groupID: "",);
tim.getGroupMemberList(options);
AVChatRoom
) support on-screen comments, gifts, and like messages to build a friendly interaction experience.SDKAppID
will receive it.Message.nick
, and Message.avatar
fields are empty during message sending?getUserInfo
API to get the Message.nick
and Message.avatar
fields in the user's information and use them as the fields for message sending.
Was this page helpful?