ChatRoomManager.java
30.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
package com.chudiangameplay.android.manager;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;
import com.chudiangameplay.android.MyApplication;
import com.chudiangameplay.android.R;
import com.chudiangameplay.android.bean.RoomMicInfoV2;
import com.chudiangameplay.android.bean.Room_MaiWeiInfo;
import com.chudiangameplay.android.bean.Room_MsgInfo;
import com.chudiangameplay.android.bean.Room_PaiDui_UserInfo;
import com.chudiangameplay.android.bean.Room_RoomInfo;
import com.chudiangameplay.android.bean.UserInfo;
import com.chudiangameplay.android.constant.Constants;
import com.chudiangameplay.android.dialog.CommDialog;
import com.chudiangameplay.android.dialog.Room_pwd_Dialog;
import com.chudiangameplay.android.event.Event_RoomManage_Change;
import com.chudiangameplay.android.event.Event_Room_RoomChanged;
import com.chudiangameplay.android.interface_.CommCallBack;
import com.chudiangameplay.android.interface_.OkHttpCallBack;
import com.chudiangameplay.android.responce.BaseResponce;
import com.chudiangameplay.android.responce.CommBooleanResponce;
import com.chudiangameplay.android.responce.RoomMicInfoV2Response;
import com.chudiangameplay.android.responce.Room_GetMaiWeiInfoResponce;
import com.chudiangameplay.android.tool.CommToast;
import com.chudiangameplay.android.tool.Log;
import com.chudiangameplay.android.ui.activity.RoomDetailActivity_PaiDan;
import com.google.gson.Gson;
import com.lzy.okgo.OkGo;
import org.greenrobot.eventbus.EventBus;
import java.util.ArrayList;
import java.util.List;
import io.agora.AgoraAPIOnlySignal;
import io.agora.IAgoraAPI;
import io.agora.rtc.IRtcEngineEventHandler;
import io.agora.rtc.RtcEngine;
import io.agora.rtm.ErrorInfo;
import io.agora.rtm.ResultCallback;
import io.agora.rtm.RtmCallManager;
import io.agora.rtm.RtmChannel;
import io.agora.rtm.RtmChannelListener;
import io.agora.rtm.RtmChannelMember;
import io.agora.rtm.RtmClient;
import io.agora.rtm.RtmClientListener;
import io.agora.rtm.RtmMessage;
import io.agora.rtm.RtmStatusCode;
/**
* Created by Administrator on 2018/8/22.
*/
public class ChatRoomManager {
private static final String TAG = ChatRoomManager.class.getName();
Context mContext;
public RtcEngine mRtcEngine;
public RtmClient mRtmClient;
private RtmChannel mRtmChannel; //声网RTM房间
private RtmChannelListener mRtmChannelListener;
public Room_RoomInfo roomInfo;
public UserInfo userInfo;
public Room_MaiWeiInfo zhuchiMaiWei;
public boolean isOpenMic = false; //是否开启麦克风
public List<Room_MsgInfo> msgInfoList = new ArrayList<>(); //消息列表
public List<Room_MaiWeiInfo> maiweiList; //麦位列表
private static ChatRoomManager mInstance;
public static ChatRoomManager getInstance() {
if (mInstance == null) {
synchronized (ChatRoomManager.class) {
if (mInstance == null) {
mInstance = new ChatRoomManager();
}
}
}
return mInstance;
}
private ChatRoomManager() {
mContext = MyApplication.context;
}
//初始化聊天室
public void init(IRtcEngineEventHandler mRtcEventHandler, final RtmChannelListener mRtmChannelListener, Room_RoomInfo roomInfo, UserInfo userInfo) {
this.roomInfo = roomInfo;
this.userInfo = userInfo;
try {
if (mRtcEngine == null) {
mRtcEngine = RtcEngine.create(mContext, Constants.ChatRoom_AppId, mRtcEventHandler); //初始化
mRtcEngine.setChannelProfile(io.agora.rtc.Constants.CHANNEL_PROFILE_LIVE_BROADCASTING); //设置频道
mRtcEngine.enableAudioVolumeIndication(200, 3); // 灵敏度[0, 10]
mRtcEngine.joinChannel(null, roomInfo.roomNo, "", Integer.parseInt(UserManager.getUserInfo(mContext).userId)); // 加入直播室
} else {
mRtcEngine.addHandler(mRtcEventHandler);
}
} catch (Exception e) {
}
try {
if (mRtmClient == null) {
mRtmClient = RtmClient.createInstance(mContext, Constants.ChatRoom_AppId,
new RtmClientListener() {
@Override
public void onConnectionStateChanged(int state, int reason) {
Log.d(TAG, "on connection state changed to "
+ state + " reason: " + reason);
if (state == RtmStatusCode.ConnectionState.CONNECTION_STATE_ABORTED) {
loginRtmClient(mRtmChannelListener);
} else if (state == RtmStatusCode.ConnectionState.CONNECTION_STATE_RECONNECTING) {
CommToast.showToast(mContext, "网络连接不稳定 请检查网络");
}
}
@Override
public void onMessageReceived(RtmMessage rtmMessage, String peerId) {
String msg = rtmMessage.getText();
Log.d(TAG, "Receives message: " + msg
+ " from " + peerId);
}
@Override
public void onTokenExpired() {
}
});
} else {
mRtmClient.logout(null);
}
loginRtmClient(mRtmChannelListener);
} catch (Exception e) {
Log.d(TAG, "RTM SDK init fatal error!");
throw new RuntimeException("You need to check the RTM init process.");
}
}
public String getRoomNumber() {
if (roomInfo != null) {
return roomInfo.roomNo;
} else {
return null;
}
}
public String getTemplate() {
if (roomInfo != null) {
return roomInfo.template;
} else {
return null;
}
}
public void getChannelPeopleNum(final CommCallBack callBack) {
if (mRtmChannel != null) {
mRtmChannel.getMembers(new ResultCallback<List<RtmChannelMember>>() {
@Override
public void onSuccess(List<RtmChannelMember> rtmChannelMembers) {
callBack.onResult(rtmChannelMembers.size());
}
@Override
public void onFailure(ErrorInfo errorInfo) {
}
});
}
}
public void loginRtmClient(final RtmChannelListener mRtmChannelListener) {
mRtmClient.login(null, UserManager.getUserInfo(mContext).userId, new ResultCallback<Void>() {
@Override
public void onSuccess(Void responseInfo) {
// loginStatus = true;
Log.d(TAG, "login success!");
if (roomInfo != null) {
ChatRoomManager.getInstance().joinChannel(roomInfo.roomNo, mRtmChannelListener);
}
}
@Override
public void onFailure(ErrorInfo errorInfo) {
// loginStatus = false;
Log.d(TAG, "login failure!");
}
});
}
//加入房间
private RtmChannel joinChannel(String channelId, final RtmChannelListener mRtmChannelListener) {
try {
mRtmChannel = mRtmClient.createChannel(channelId, mRtmChannelListener);
mRtmChannel.join(new ResultCallback<Void>() {
@Override
public void onSuccess(Void responseInfo) {
Log.d(TAG, "Successfully joins the channel!");
ChatRoomManager.this.mRtmChannelListener = mRtmChannelListener;
}
@Override
public void onFailure(ErrorInfo errorInfo) {
Log.d(TAG, "join channel failure! errorCode = "
+ errorInfo.getErrorCode());
}
});
if (userInfo != null) {
mRtmClient.getRtmCallManager().createLocalInvitation(userInfo.userId).setChannelId(channelId);
}
} catch (RuntimeException e) {
Log.e(TAG, "Fails to create channel. Maybe the channel ID is invalid," +
" or already in use. See the API reference for more information.");
}
return mRtmChannel;
}
//房间发送消息
public void sendChannelMessage(String msg) {
if (mRtmChannel == null) {
return;
}
final RtmMessage message = mRtmClient.createMessage();
message.setText(msg);
mRtmChannel.sendMessage(message, new ResultCallback<Void>() {
@Override
public void onSuccess(Void aVoid) {
Log.d(TAG, "sendMessage onSuccess");
if (ChatRoomManager.this.mRtmChannelListener != null) {
ChatRoomManager.this.mRtmChannelListener.onMessageReceived(message, null);
}
}
@Override
public void onFailure(ErrorInfo errorInfo) {
Log.d(TAG, "sendMessage onFailure "
+ " errorInfo: " + errorInfo.toString());
}
});
}
//离开直播室
public void leaveChannel() {
if (mRtcEngine != null) {
mRtcEngine.leaveChannel();
mRtcEngine = null;
}
if (mRtmChannel != null) {
mRtmChannel.leave(null);
mRtmChannel.release();
mRtmChannel = null;
}
if (mRtmClient != null) {
mRtmClient.logout(null);
mRtmClient.release();
mRtmClient = null;
}
// if (m_agoraAPI != null) {
// m_agoraAPI.logout();
// m_agoraAPI.destroy();
// m_agoraAPI = null;
// }
}
public void joinCharRoom(final Context mContext, final String roomNo) {
if (!UserManager.isLogin(mContext)) {
UserManager.showLogin(mContext);
return;
}
//判断是否已有打开聊天室
if (roomInfo != null) {
//已在聊天室,并且在同一个房间, 直接跳到房间
if (TextUtils.equals(roomInfo.roomNo, roomNo)) {
toRoom(mContext, roomNo, "");
} else {
//不是同一个房间, 先关掉 再打开一个新的房间
closeRoom(new CommCallBack() {
@Override
public void onResult(Object obj) {
checkNeedPassword(mContext, roomNo);
}
});
}
} else {
//不在聊天室
checkNeedPassword(mContext, roomNo);
}
}
public static RoomDetailActivity_PaiDan roomActivity;
//检查密码
private static void checkNeedPassword(final Context mContext, final String roomNo) {
//判断是否需要密码
API_RoomManager.room_need_password(mContext, roomNo, new OkHttpCallBack() {
@Override
public void onSuccess(BaseResponce baseResponce) {
if (BaseResponce.Status_Success.equals(baseResponce.status)) {
CommBooleanResponce roomInfoResponce = (CommBooleanResponce) baseResponce;
if (roomInfoResponce.data) {
//需要密码,弹窗
final Room_pwd_Dialog dialog = new Room_pwd_Dialog(mContext, R.style.myDialog);
dialog.setIntputCallBack(new CommCallBack() {
@Override
public void onResult(Object obj) {
final String pwd = (String) obj;
//检查密码
API_RoomManager.room_check_password(mContext, roomNo, pwd, new OkHttpCallBack() {
@Override
public void onSuccess(BaseResponce baseResponce) {
if (BaseResponce.Status_Success.equals(baseResponce.status)) {
dialog.dismissWithAnim();
toRoom(mContext, roomNo, pwd);
} else {
CommToast.showToast(mContext, baseResponce.msg);
}
}
@Override
public void onFailure(BaseResponce baseResponce) {
CommToast.showToast(mContext, "网络连接失败,请重试");
}
});
}
});
dialog.show();
} else {
//不需要密码
toRoom(mContext, roomNo, "");
}
} else {
CommToast.showToast(mContext, baseResponce.msg);
}
}
@Override
public void onFailure(BaseResponce baseResponce) {
CommToast.showToast(mContext, "网络请求失败,请重试");
}
});
}
private static void toRoom(Context mContext, String roomNo, String password) {
Intent intent = new Intent(mContext, RoomDetailActivity_PaiDan.class);
intent.putExtra("roomNo", roomNo);
intent.putExtra("password", password);
if (mContext instanceof Service) {
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}
mContext.startActivity(intent);
}
CommCallBack closeRoomCallBack;
//关闭房间
public synchronized void closeRoom(final CommCallBack callBack) {
if (roomInfo == null) {
if (callBack != null) {
callBack.onResult(null);
}
return;
}
try {
closeRoomCallBack = callBack;
room_quit(roomInfo.roomNo, new CommCallBack() {
@Override
public void onResult(Object obj) {
closeRoomCallback();
}
});
} catch (Exception e) {
}
}
public void closeRoomCallback() {
if (closeRoomCallBack != null) {
closeRoomCallBack.onResult(null);
}
if (roomActivity != null) {
roomActivity.finishChatRom(null);
}
roomInfo = null;
zhuchiMaiWei = null;
userInfo = null;
msgInfoList.clear();
leaveChannel(); //关闭声网聊天室
//发送关闭事件
Event_Room_RoomChanged event_room_roomChanged = new Event_Room_RoomChanged();
event_room_roomChanged.type = 1;
EventBus.getDefault().post(event_room_roomChanged);
}
//消息基础信息
private Room_MsgInfo getBaseMsg() {
Room_MsgInfo msgInfo = new Room_MsgInfo();
try {
msgInfo.account = userInfo.userId;
msgInfo.nickName = userInfo.nickname;
msgInfo.headPortraitsUrl = userInfo.headPortraitsUrl;
if ("1".equals(userInfo.roomRole)) //房间角色(1:房主,2:管理,3:主持)
{
msgInfo.owner = Room_MsgInfo.KHSmallMessageOwnerHomeowner;
} else if ("2".equals(userInfo.roomRole)) {
msgInfo.owner = Room_MsgInfo.KHSmallMessageOwnerManage;
} else if ("3".equals(userInfo.roomRole)) {
msgInfo.owner = Room_MsgInfo.KHSmallMessageOwnerHost;
} else {
msgInfo.owner = Room_MsgInfo.KHSmallMessageOwnerOther;
}
} catch (Exception e) {
}
return msgInfo;
}
//发送普通事件消息
private void sendCommAction(int type, RoomMicInfoV2 receiveModel) {
Room_MsgInfo msgInfo = getBaseMsg();
msgInfo.messageType = type;
msgInfo.receiveModel = receiveModel;
sendChannelMessage(new Gson().toJson(msgInfo));
}
//发送上下麦信息
public void sendAction_maiwai(int type, Room_MaiWeiInfo info, RoomMicInfoV2 receiveModel, boolean isExitRoom) {
Room_MsgInfo msgInfo = getBaseMsg();
msgInfo.messageType = type; // Room_MsgInfo.KHSmallMessageTypeUserUpper; //上麦
msgInfo.seatIndex = info.index;
msgInfo.nickName = info.micUser.nickname;
msgInfo.account = info.micUser.userId;
msgInfo.headPortraitsUrl = info.micUser.headPortraitsUrl;
msgInfo.emblemSimpleUrl = info.micUser.emblemSimpleUrl;
msgInfo.memberEmblem = info.micUser.memberEmblem;
msgInfo.isExitRoom = isExitRoom;
if ("1".equals(info.micUser.roomRole)) //房间角色(1:房主,2:管理,3:主持)
{
msgInfo.owner = Room_MsgInfo.KHSmallMessageOwnerHomeowner;
} else if ("2".equals(info.micUser.roomRole)) {
msgInfo.owner = Room_MsgInfo.KHSmallMessageOwnerManage;
} else if ("3".equals(info.micUser.roomRole)) {
msgInfo.owner = Room_MsgInfo.KHSmallMessageOwnerHost;
} else {
msgInfo.owner = Room_MsgInfo.KHSmallMessageOwnerOther;
}
msgInfo.receiveModel = receiveModel;
sendChannelMessage(new Gson().toJson(msgInfo));
}
public void sendAction_maiwai(int type, Room_MaiWeiInfo info, RoomMicInfoV2 receiveModel) {
sendAction_maiwai(type, info, receiveModel, false);
}
public void sendAction_maiwai(int type, Room_PaiDui_UserInfo info, RoomMicInfoV2 receiveModel) {
Room_MsgInfo msgInfo = getBaseMsg();
msgInfo.messageType = type; // Room_MsgInfo.KHSmallMessageTypeUserUpper; //上麦
msgInfo.seatIndex = TextUtils.isEmpty(info.micIndex) ? -1 : Integer.valueOf(info.micIndex);
msgInfo.nickName = info.nickname;
msgInfo.account = info.userId;
msgInfo.headPortraitsUrl = info.headPortraitsUrl;
msgInfo.emblemSimpleUrl = info.emblemSimpleUrl;
msgInfo.memberEmblem = info.memberEmblem;
if ("1".equals(info.roomRole)) //房间角色(1:房主,2:管理,3:主持)
{
msgInfo.owner = Room_MsgInfo.KHSmallMessageOwnerHomeowner;
} else if ("2".equals(info.roomRole)) {
msgInfo.owner = Room_MsgInfo.KHSmallMessageOwnerManage;
} else if ("3".equals(info.roomRole)) {
msgInfo.owner = Room_MsgInfo.KHSmallMessageOwnerHost;
} else {
msgInfo.owner = Room_MsgInfo.KHSmallMessageOwnerOther;
}
msgInfo.receiveModel = receiveModel;
sendChannelMessage(new Gson().toJson(msgInfo));
}
public void sendAction_maiwai(int type, UserInfo info, RoomMicInfoV2 receiveModel) {
Room_MsgInfo msgInfo = getBaseMsg();
msgInfo.messageType = type; // Room_MsgInfo.KHSmallMessageTypeUserUpper; //上麦
msgInfo.seatIndex = TextUtils.isEmpty(info.isAtRoomIndex) ? -1 : Integer.valueOf(info.isAtRoomIndex);
msgInfo.nickName = info.nickname;
msgInfo.account = info.userId;
msgInfo.headPortraitsUrl = info.headPortraitsUrl;
msgInfo.emblemSimpleUrl = info.emblemSimpleUrl;
msgInfo.memberEmblem = info.memberEmblem;
if ("1".equals(info.roomRole)) //房间角色(1:房主,2:管理,3:主持)
{
msgInfo.owner = Room_MsgInfo.KHSmallMessageOwnerHomeowner;
} else if ("2".equals(info.roomRole)) {
msgInfo.owner = Room_MsgInfo.KHSmallMessageOwnerManage;
} else if ("3".equals(info.roomRole)) {
msgInfo.owner = Room_MsgInfo.KHSmallMessageOwnerHost;
} else {
msgInfo.owner = Room_MsgInfo.KHSmallMessageOwnerOther;
}
msgInfo.receiveModel = receiveModel;
sendChannelMessage(new Gson().toJson(msgInfo));
}
public void sendAction_RoomInfo(int type, RoomMicInfoV2 receiveModel) {
Room_MsgInfo msgInfo = getBaseMsg();
msgInfo.messageType = type;
msgInfo.receiveModel = receiveModel;
sendChannelMessage(new Gson().toJson(msgInfo));
}
//发送刷新麦位信息
// private Room_MsgInfo sendLeave() {
// Room_MsgInfo msgInfo = new Room_MsgInfo();
// try {
// msgInfo.messageType = Room_MsgInfo.KHSmallMessageTypeRefreshSeat;
//// if (m_agoraAPI != null)
//// m_agoraAPI.messageChannelSend(roomInfo.roomNo, new Gson().toJson(msgInfo), "");
// sendChannelMessage(new Gson().toJson(msgInfo));
// } catch (Exception e) {
//
// }
// return msgInfo;
// }
//获取角色 名称
public static String getRoleName(String owan) {
String text = "";
if ("1".equals(owan)) //房间角色(1:房主,2:管理,3:主持)
{
text = "房";
} else if ("2".equals(owan)) {
text = "管";
} else if ("3".equals(owan)) {
text = "主";
}
return text;
}
//是否是管理员
public static boolean isManager(String roomRole) {
if ("1".equals(roomRole) || "2".equals(roomRole) || "3".equals(roomRole)) {
return true;
} else {
return false;
}
}
public boolean isOwnerOrAdmin() {
if (userInfo != null) {
if ("1".equals(userInfo.roomRole) || "2".equals(userInfo.roomRole)) {
return true;
} else {
return false;
}
} else {
return false;
}
}
public boolean isManager() {
if (userInfo != null) {
return isManager(userInfo.roomRole);
} else {
return false;
}
}
public boolean isRoomOwner() {
if (userInfo != null) {
return "1".equals(userInfo.roomRole);
} else {
return false;
}
}
//设置角色文字 和背景
public static void setRoomRoleTextAndBg(TextView textView, String roomRole) {
textView.setText(getRoleName(roomRole));
textView.setBackgroundResource(getBackgroundResource(roomRole));
}
//获取角色 对应的文字背景
public static int getBackgroundResource(String roomRole) {
int resource = -1;
if ("1".equals(roomRole)) {
resource = R.drawable.shape_round2dp_ff576a;
} else if ("2".equals(roomRole)) {
resource = R.drawable.shape_round2dp_3f95ff;
} else if ("3".equals(roomRole)) {
resource = R.drawable.shape_round2dp_9549ef;
}
return resource;
}
public static int TYPE_PAIDAN = 0; //派单
public static int TYPE_YULE = 1; //娱乐
public static int getRoomType(String template) {
int type = -1;
if ("1".equals(template)) { // 1 派单 2娱乐
type = TYPE_PAIDAN;
} else if ("2".equals(template)) {
type = TYPE_YULE;
}
return type;
}
//获取老板位index
public static int getBossSeatIndex(String template) {
int index = -1;
if ("1".equals(template)) { // 1 派单 2娱乐
index = 1;
} else if ("2".equals(template)) {
index = 8;
}
return index;
}
public Room_MaiWeiInfo getMicInfoById(String userId) {
if (maiweiList != null && maiweiList.size() > 0) {
for (Room_MaiWeiInfo info : maiweiList) {
if (info.micUser != null && TextUtils.equals(userId, info.micUser.userId)) {
return info;
}
}
}
return null;
}
//退出房间
public void room_quit(final String roomNo, final CommCallBack callBack) {
if (!UserManager.isLogin(mContext)) {
return;
}
if (roomInfo == null) return;
//发送信令消息
if (userInfo == null) return;
API_RoomManager.room_quit(mContext, roomNo, new OkHttpCallBack<RoomMicInfoV2Response>() {
@Override
public void onSuccess(RoomMicInfoV2Response baseResponce) {
if (BaseResponce.Status_Success.equals(baseResponce.status) && baseResponce.data != null) {
if (maiweiList != null && maiweiList.size() > 0) {
for (int i = 0; i < maiweiList.size(); i++) {
//判断自己在不在麦位
if (maiweiList.get(i).micUser != null && userInfo != null && TextUtils.equals(maiweiList.get(i).micUser.userId, userInfo.userId)) {
//自己在麦位上, 就发下麦信息
sendAction_maiwai(Room_MsgInfo.KHSmallMessageTypeUserDown, maiweiList.get(i), baseResponce.data, true); //发送下麦消息
// if (callBack != null) {
// callBack.onResult(null);
// }
return;
}
}
}
sendCommAction(Room_MsgInfo.KHSmallMessageTypeRefreshSeat, baseResponce.data);
if (callBack != null) {
callBack.onResult(null);
}
}
}
@Override
public void onFailure(BaseResponce baseResponce) {
CommToast.showToast(mContext, "网络请求失败,请重试");
}
});
}
//聊天室封禁
public void room_room_banned(final String userId, String roomNo, final CommCallBack callBack) {
API_RoomManager.room_room_banned(mContext, roomNo, userId, new OkHttpCallBack() {
@Override
public void onSuccess(BaseResponce baseResponce) {
CommToast.showToast(mContext, baseResponce.msg);
if (BaseResponce.Status_Success.equals(baseResponce.status)) {
//刷新麦位
Event_RoomManage_Change eventRoomRoleChange = new Event_RoomManage_Change();
Room_PaiDui_UserInfo info = new Room_PaiDui_UserInfo();
info.userId = userId;
eventRoomRoleChange.userInfo = info;
eventRoomRoleChange.type = "聊天室封禁";
EventBus.getDefault().post(eventRoomRoleChange);
// getData();
if (callBack != null) {
callBack.onResult(null);
}
}
}
@Override
public void onFailure(BaseResponce baseResponce) {
}
});
}
//聊天室解除封禁
public void room_room_lift_bann(String userId, String roomNo, final CommCallBack callBack) {
API_RoomManager.room_room_lift_ban(mContext, roomNo, userId, new OkHttpCallBack() {
@Override
public void onSuccess(BaseResponce baseResponce) {
CommToast.showToast(mContext, baseResponce.msg);
if (BaseResponce.Status_Success.equals(baseResponce.status)) {
// getData();
if (callBack != null) {
callBack.onResult(null);
}
}
}
@Override
public void onFailure(BaseResponce baseResponce) {
}
});
}
//抱用户上麦
public void shangmai(final Context mContext, final String roomNo, final UserInfo userInfo, final CommCallBack callBack) {
CommDialog.showCommDialog(mContext, null, "确定", "再考虑一下", "是否确定上麦", null, new View.OnClickListener() {
@Override
public void onClick(View v) {
postShangmai(mContext, roomNo, userInfo, callBack);
}
});
}
public void postShangmai(final Context mContext, final String roomNo, final UserInfo userInfo, final CommCallBack callBack) {
OkGo.getInstance().cancelTag(API_RoomManager.TAG_HOLD_UP);
API_RoomManager.room_holdup(mContext, roomNo, "", userInfo.userId, null, new OkHttpCallBack<RoomMicInfoV2Response>() {
@Override
public void onSuccess(RoomMicInfoV2Response baseResponce) {
if (BaseResponce.Status_Success.equals(baseResponce.status)) {
//刷新麦位
// getMaiWeiInfo();
if (baseResponce != null && baseResponce.data != null) {
if (baseResponce.data != null && baseResponce.data.roomMicInfos != null && baseResponce.data.roomMicInfos.size() > 0) {
for (Room_MaiWeiInfo info : baseResponce.data.roomMicInfos) {
if (info.micUser != null && TextUtils.equals(userInfo.userId, info.micUser.userId)) {
ChatRoomManager.getInstance().sendAction_maiwai(Room_MsgInfo.KHSmallMessageTypeUserUpper, info,
baseResponce.data); //发送上下麦消息
}
}
}
if (callBack != null) {
callBack.onResult(null);
}
}
} else {
CommToast.showToast(mContext, baseResponce.msg);
}
}
@Override
public void onFailure(BaseResponce baseResponce) {
}
});
}
//下麦
public void room_hold_status(final String roomNo, final Room_MaiWeiInfo maiWeiInfo, final CommCallBack callBack) {
if (!UserManager.isLogin(mContext)) return;
if (maiWeiInfo == null || maiWeiInfo.micUser == null) return;
OkGo.getInstance().cancelTag(API_RoomManager.TAG_HOLD_STATUS);
API_RoomManager.room_hold_status(mContext, roomNo, maiWeiInfo.index + "", "-1", maiWeiInfo.micUser.userId, new OkHttpCallBack<RoomMicInfoV2Response>() {
@Override
public void onSuccess(RoomMicInfoV2Response info) {
if (info != null && BaseResponce.Status_Success.equals(info.status)) {
if (info != null && info.data != null) {
try {
if (maiWeiInfo != null && maiWeiInfo.micUser != null) {
ChatRoomManager.getInstance().sendAction_maiwai(Room_MsgInfo.KHSmallMessageTypeUserDown, maiWeiInfo,
info.data); //发送下麦消息
if (callBack != null) {
callBack.onResult(null);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
@Override
public void onFailure(BaseResponce baseResponce) {
}
});
}
}