PK匹配计时优化,静音某个用户

This commit is contained in:
chenguilong
2022-11-24 16:31:05 +08:00
committed by fengshuo
parent f8a5546b33
commit f43b2d67de
16 changed files with 135 additions and 19 deletions

View File

@@ -0,0 +1,22 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "anchor_pk_mute_other@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "anchor_pk_mute_other@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 834 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@@ -0,0 +1,22 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "anchor_pk_open_other@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "anchor_pk_open_other@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 919 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@@ -19,6 +19,11 @@ NS_ASSUME_NONNULL_BEGIN
静音
*/
- (BOOL)muteRemote:(BOOL)mute;
/**
静音某个用户
userId: 用户ID
*/
- (BOOL)muteRemote:(BOOL)mute userId:(NSString *)userId;
/**
上下麦(说话)
*/

View File

@@ -100,6 +100,11 @@
return YES;
}
- (BOOL)muteRemote:(BOOL)mute userId:(NSString *)userId {
[self.engine muteRemoteAudio:userId mute:mute];
return YES;
}
- (void)broadcast:(BOOL)on {
[self.engine switchRole:on ? TRTCRoleAnchor : TRTCRoleAudience];
if (on) {

View File

@@ -115,6 +115,10 @@ typedef NS_ENUM(NSInteger, BackMusicPlayState) {
///退出跨房通话
- (void)disconnectOtherRoom;
/// 静音某个人
/// @param userId 用户id
- (void)muteOne:(BOOL)mute userId:(NSString *)userId;
/// 播放背景音乐
/// @param filePath 音频文件的地址
/// @param musicId TRTC自己要的

View File

@@ -107,6 +107,12 @@
[self.engine disconnectOtherRoom];
}
///
/// @param userId id
- (void)muteOne:(BOOL)mute userId:(NSString *)userId {
[self.engine muteRemote:mute userId:userId];
}
- (void)destory {
[self.engine destory];
}

View File

@@ -20,7 +20,8 @@ NS_ASSUME_NONNULL_BEGIN
- (void)handleMatchTimeOutMessage;
///PK匹配中计时
- (void)openCountdownWithTime:(long)time;
/// - Parameter startTime: 开始时间
- (void)openCountdownWithTime:(long)startTime;
@end

View File

@@ -14,6 +14,7 @@
#import "XPMacro.h"
#import "Api+AnchorPk.h"
#import "RoomInfoModel.h"
#import "Timestamp.h"
@interface XPAnchorPKMatchView()
///host
@@ -136,8 +137,28 @@
}
#pragma mark -
- (void)openCountdownWithTime:(long)time {
__block long tempTime = time; //
- (void)openCountdownWithTime:(long)startTime {
__block long tempTime;
[Timestamp getInternetDateWithSuccess:^(NSTimeInterval timeInterval) {
timeInterval = timeInterval * 1000;
tempTime = (timeInterval - startTime) / 1000;
if (tempTime < 0) {
tempTime = 0;
}
[self handleCountTime:tempTime];
} failure:^(NSError * _Nonnull error) {
NSDate *datenow = [NSDate date];
long time2 = (long)([datenow timeIntervalSince1970]*1000);
tempTime = (time2 - startTime) / 1000;
if (tempTime < 0) {
tempTime = 0;
}
[self handleCountTime:tempTime];
}];
}
- (void)handleCountTime:(long)time {
__block long tempTime = time;
if (self.timer == nil) {
@kWeakify(self);
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);

View File

@@ -8,7 +8,7 @@
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@class XPAnchorPkPanelView, AcrossRoomPKPanelModel;
@class XPAnchorPkPanelView, AcrossRoomPKPanelModel, AttachmentModel;
@protocol XPAnchorPkPanelViewDelegate <NSObject>
///展示用户卡片
@@ -33,6 +33,8 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic,weak) id<XPAnchorPkPanelViewDelegate> delegate;
///重置数据
- (void)resetAcrossPKViewData;
///更新对方麦状态
- (void)updateOtherMicStatus:(AttachmentModel *)attachment;
@end

View File

@@ -20,9 +20,11 @@
#import "XCHUDTool.h"
#import "AccountInfoStorage.h"
#import "NSArray+Safe.h"
#import "RtcManager.h"
///Model
#import "UserInfoModel.h"
#import "AcrossRoomPKPanelModel.h"
#import "AttachmentModel.h"
///View
#import "XPAnchorPKPanelUserView.h"
///Api
@@ -117,6 +119,23 @@
self.pkPanelInfo = nil;
}
///
- (void)updateOtherMicStatus:(AttachmentModel *)attachment {
NSNumber *micStatus = attachment.data[@"aMicStatus"];
NSNumber *aUid = attachment.data[@"aUid"];
self.otherMicButton.selected = !micStatus.boolValue;
[[RtcManager instance] muteOne:!micStatus.boolValue userId:[NSString stringWithFormat:@"%@", aUid]];
if (!micStatus.boolValue) {
[XCHUDTool showErrorWithMessage:@"主播已关闭对方房间的声音"];
self.otherMicButton.hidden = NO;
} else {
self.otherMicButton.hidden = YES;
}
if ([self.pkPanelInfo.cUid isEqualToString:[AccountInfoStorage instance].getUid]) {
self.otherMicButton.hidden = NO;
}
}
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
UIView *view = [super hitTest:point withEvent:event];
return view == self?nil:view;
@@ -501,8 +520,13 @@
self.otherNickLabel.text = pkPanelInfo.aNick;
self.redNickLabel.text = pkPanelInfo.cNick;
self.followButton.hidden = [pkPanelInfo.cUid isEqualToString:[AccountInfoStorage instance].getUid];
self.otherMicButton.hidden = ![pkPanelInfo.cUid isEqualToString:[AccountInfoStorage instance].getUid];
if (pkPanelInfo.aMicStatus == AnchorPKOtherMicStatus_Close) {
self.otherMicButton.hidden = NO;
} else {
self.otherMicButton.hidden = ![pkPanelInfo.cUid isEqualToString:[AccountInfoStorage instance].getUid];
}
self.otherMicButton.selected = pkPanelInfo.aMicStatus == AnchorPKOtherMicStatus_Close;
[[RtcManager instance] muteOne:pkPanelInfo.aMicStatus == AnchorPKOtherMicStatus_Close userId:pkPanelInfo.aUid];
} else {
self.redCountLabel.text = @"0";
self.blueCountLabel.text = @"0";
@@ -524,8 +548,10 @@
#pragma mark - private
- (void)onAnchorPkMuteMic:(UIButton *)sender {
if (![self.pkPanelInfo.cUid isEqualToString:[AccountInfoStorage instance].getUid]) {
return;
}
[Api anchorPKMuteOtherMic:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
} micStatus:sender.selected ? @"1" : @"0" roundId:[NSString stringWithFormat:@"%ld", self.pkPanelInfo.roundId] roomUid:self.pkPanelInfo.cUid];
}
@@ -696,9 +722,10 @@
- (UIButton *)otherMicButton {
if (!_otherMicButton) {
_otherMicButton = [[UIButton alloc] init];
[_otherMicButton setImage:[UIImage imageNamed:@"room_position_mute_Anchor"] forState:UIControlStateNormal];
[_otherMicButton setImage:[UIImage imageNamed:@"room_position_mute_Anchor"] forState:UIControlStateSelected];
[_otherMicButton setImage:[UIImage imageNamed:@"anchor_pk_open_other"] forState:UIControlStateNormal];
[_otherMicButton setImage:[UIImage imageNamed:@"anchor_pk_mute_other"] forState:UIControlStateSelected];
[_otherMicButton addTarget:self action:@selector(onAnchorPkMuteMic:) forControlEvents:UIControlEventTouchUpInside];
_otherMicButton.hidden = YES;
}
return _otherMicButton;
}

View File

@@ -470,10 +470,7 @@
NSDictionary *dict = noti.object;
NSNumber *startTime = dict[@"matchPkStartTime"];
self.delegate.getRoomInfo.pkMatchStartTime = [startTime longLongValue];
NSDate *datenow = [NSDate date];
long time2 = (long)([datenow timeIntervalSince1970]*1000);
long aTime = (time2 - self.delegate.getRoomInfo.pkMatchStartTime) / 1000;
[self.anchorPKMatchView openCountdownWithTime:aTime];
[self.anchorPKMatchView openCountdownWithTime:[startTime longValue]];
}
}
@@ -851,6 +848,7 @@
case Custom_Message_Sub_AnchorPK_Panel://PK
{
[self.anchorPKMatchView removeFromSuperview];
self.delegate.getRoomInfo.pkMatchStartTime = nil;
if (!self.anchorPKPanelView.superview) {
[self addSubview:self.anchorPKPanelView];
[self.anchorPKPanelView mas_makeConstraints:^(MASConstraintMaker *make) {
@@ -907,9 +905,9 @@
[self.anchorPKMatchView handleMatchTimeOutMessage];
}
break;
case Custom_Message_Sub_AnchorPK_MuteOtherMic:///PK
case Custom_Message_Sub_AnchorPK_MuteOtherMic:///PK
{
[self.anchorPKPanelView updateOtherMicStatus:attachment];
}
break;
default:
@@ -1436,6 +1434,7 @@
self.delegate.getRoomInfo.pkRoomId = nil;
self.delegate.getRoomInfo.pkState = nil;
self.delegate.getRoomInfo.winUid = nil;
self.delegate.getRoomInfo.pkMatchStartTime = nil;
}
#pragma mark -
@@ -1815,10 +1814,7 @@
make.left.mas_equalTo(0);
make.width.height.mas_equalTo(52);
}];
NSDate *datenow = [NSDate date];
long time2 = (long)([datenow timeIntervalSince1970]*1000);
long aTime = (time2 - self.delegate.getRoomInfo.pkMatchStartTime) / 1000;
[self.anchorPKMatchView openCountdownWithTime:aTime];
[self.anchorPKMatchView openCountdownWithTime:self.delegate.getRoomInfo.pkMatchStartTime];
}
}

View File

@@ -382,7 +382,12 @@ UIKIT_EXTERN NSString * const kRoomGiftEffectUpdateNotificationKey;
case RoomMoreMenuType_Room_Anchor_PK_Open:
{
if (self.hostDelegate.getRoomInfo.pkMatchStartTime) {//PK
[self.presenter requestCancelMatchRandomPK:roomUid];
TTAlertConfig *config = [[TTAlertConfig alloc] init];
config.message = @"取消匹配?";
[TTPopup alertWithConfig:config confirmHandler:^{
[self.presenter requestCancelMatchRandomPK:roomUid];
} cancelHandler:^{
}];
} else {
[self dismissViewControllerAnimated:NO completion:nil];
XPAnchorPKSelectTypeController *selectVc = [[XPAnchorPKSelectTypeController alloc] initWithRoomUid:roomUid];