Browse Source

直播人数和直播互动

unknown 4 years ago
parent
commit
69a0548dcc
3 changed files with 569 additions and 23 deletions
  1. 213 20
      pagesGood/liveDetail.vue
  2. 0 0
      pagesGood/trtc-room/common/tim-wx.js
  3. 356 3
      pagesGood/trtc-room/trtc-room.vue

+ 213 - 20
pagesGood/liveDetail.vue

@@ -4,7 +4,7 @@
 		<view class="top_box" :style="{ top: btn_top, left: btn_left}">
 			<image class="top_box_img" :src="head_img" mode="aspectFill"></image>
 			<view class="top_box_text">
-				<text class="text_box_top">{{title}}</text><text class="text_box_bottom" style="display:none">{{user_name}}</text>
+				<view class="left_box"><text class="text_box_top">{{title}}</text><text class="text_box_bottom" >{{user_name}}</text></view>
 				<view class="tx_btn" @click="subTap()"><text class="iconfont tixingn">{{tixing_str}}</text></view>
 			</view>
 		</view>
@@ -36,7 +36,20 @@
 		<u-top-tips ref="uTips"></u-top-tips>
 		
 		
-		
+		<view class="talk_box" :style="{ left: btn_left}">
+			<view class="line_box" v-for="(item, index) in text_list" :key="index">
+			  <view class="talk_box_timp" >
+				<image :src="item.description"></image>
+				<text>{{item.extension}}:{{item.data}}</text>
+			  </view>
+			</view>
+		  </view>
+		  <view class="talk_input" :style="{ left: btn_left}">
+			<view class="talk_box_timp" style="width: 60%;height: 80rpx;padding: 10rpx;">
+			  <input placeholder="说点什么..." placeholder-style="color:#fff" :value="send_value" type='text' confirm-type="send" @confirm="sendsms_fun" @input="getVal"/>
+			 
+			</view>
+	    </view>
 	</view>
 </template>
 
@@ -54,6 +67,11 @@
 		},
 		data() {
 			return {
+				text_list:[
+				 //{description:'https://thirdwx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTJc8RKCs43SAHMkh1bxVR3WTCr0MRkPCQkhlPrhA6Zhib1l5BouSIW0g6su8ia1cNVKhC2IZmM5humA/132',extension:'1111',data:'323123'}
+				],
+				first_gx:true,
+				send_value:'',
 				videoType: '',
 				roomID: '',
 				userID: '',
@@ -72,7 +90,7 @@
 				btn_left:0,
 				btn_top:0,
 				title:"888",
-				user_name:'1',
+				user_name:'0',
 				head_img:"../static/images/loginLogo.png",
 				liveId: '',
 				tixing_str:'直播提醒'
@@ -108,7 +126,7 @@
 			 wx.getSystemInfo({
 			    success: res => {
 					this.setData({
-						btn_left: res.windowWidth - menuButtonObject.right+'rpx',
+						btn_left: res.windowWidth - menuButtonObject.right+'px',
 						btn_top:menuButtonObject.top+menuButtonObject.height+14+'rpx',
 						head_img:uni.getStorageSync("liveImgUrl"),
 						title:uni.getStorageSync("liveName"),
@@ -129,6 +147,12 @@
 			});
 		},
 		methods: {
+			getVal(e) {
+				let {
+					value
+				} = e.detail
+				this.send_value = value;
+			},
 			subTap: function() {
 			    let that = this;
 				if(that.tixing_str=="取消提醒"){
@@ -192,6 +216,46 @@
 			closeGoods() {
 				this.$refs.popup.close()
 			},
+			sendsms_fun:function(){
+				/*this.trtcComponent.sendGroupTextMessage({
+				  roomID: Number(this.data.roomID), // 房间 ID
+				  message: this.data.title,
+				})*/
+				if(Number(wx.getStorageSync('jy_time'))>(new Date()).valueOf()){
+				  wx.showToast({
+					  title: "禁言中,不能发言",
+					  icon: 'none'
+				  })
+				  return false;
+				}
+				
+				this.trtcComponent.sendGroupCustomMessage({
+				  roomID: Number(this.roomID), // 房间 ID
+				  payload: {
+					data: this.send_value,
+					description: uni.getStorageSync("userData").headImage,
+					extension: uni.getStorageSync("userData").userName
+				  }
+				})
+				var that=this;
+				console.log("new_log",uni.getStorageSync("userData"))
+				var temp={
+				  data: this.send_value,
+				  description: uni.getStorageSync("userData").headImage,
+				  extension: uni.getStorageSync("userData").userName
+				};
+				var data=that.text_list;
+				if(data.length==5){
+				  data.shift();
+				}
+				data.push(temp);
+				this.setData({
+				  text_list:data,
+				});
+				this.setData({
+				  send_value:'',
+				});
+			},
 			goToGoodDetails(item) {
 				uni.navigateTo({
 					url: '/pagesGood/goodDetails?goodId=' + item.productId
@@ -231,7 +295,14 @@
 					scene: "live",
 					maxBitrate: 2000,
 					minBitrate: 1500,
-					beautyLevel: 9 // 默认开启美颜
+					beautyLevel: 9, // 默认开启美颜
+					enableIM: true, // 用于组件内渲染
+					showIMPanel: false,
+					exitIMThrottle: false,
+					messageContent: '',
+					messageList: [], // 仅保留10条消息
+					maxMessageListLength: 10,
+					messageListScrollTop: 0
 				};
 				this.setData({
 					rtcConfig: this.rtcConfig
@@ -254,15 +325,27 @@
 						console.error('* room joinRoom 进房失败:', res);
 					});
 				});
+			},  
+			setNum:function(){
+				var that=this;
+				let promise = that.trtcComponent.tim.getGroupProfile({ groupID: this.roomID+"" });
+				promise.then(function(imResponse) {
+					that.setData({
+						user_name:(Number(imResponse.data.group.memberCount)-1)
+					})
+				  console.log(imResponse.data.group);
+				}).catch(function(imError) {
+				  console.warn('getGroupProfile error:', imError); // 获取群详细资料失败的相关信息
+				});
 			},
 			bindTRTCRoomEvent: function() {
 				const TRTC_EVENT = this.trtcComponent.EVENT;
 				this.timestamp = []; // 初始化事件订阅
 				this.trtcComponent.on(TRTC_EVENT.LOCAL_JOIN, event => {
 					let user_list=this.trtcComponent.getRemoteUserList();
-					this.setData({
+					/*this.setData({
 						user_name:user_list.length
-					})
+					})*/
 					console.log('* room LOCAL_JOIN', event); // 进房成功,触发该事件后可以对本地视频和音频进行设置
 					if (this.options.localVideo === true || this.options.template === '1v1') {
 						//this.trtcComponent.publishLocalVideo();
@@ -279,9 +362,9 @@
 				}); // 远端用户进房
 				this.trtcComponent.on(TRTC_EVENT.REMOTE_USER_JOIN, event => {
 					let user_list=this.trtcComponent.getRemoteUserList();
-					this.setData({
+					/*this.setData({
 						user_name:user_list.length
-					})
+					})*/
 					console.log('* room REMOTE_USER_JOIN ---  room.vue', event, this.trtcComponent.getRemoteUserList(), this.template);
 					this.timestamp.push(new Date()); // 1v1视频通话时限制人数为两人的简易逻辑,建议通过后端实现房间人数管理
 					// 2人以上同时进行通话请选择网格布局
@@ -317,9 +400,9 @@
 						}, 3000)
 					//}
 					let user_list=this.trtcComponent.getRemoteUserList();
-					this.setData({
+					/*this.setData({
 						user_name:user_list.length
-					})
+					})*/
 				}); // 远端用户推送视频
 				this.trtcComponent.on(TRTC_EVENT.REMOTE_VIDEO_ADD, event => {
 					console.log('* room REMOTE_VIDEO_ADD', event, this.trtcComponent.getRemoteUserList()); // 订阅视频
@@ -375,6 +458,67 @@
 				this.trtcComponent.on(TRTC_EVENT.REMOTE_AUDIO_REMOVE, event => {
 					console.log('* room REMOTE_AUDIO_REMOVE', event, this.trtcComponent.getRemoteUserList());
 				});
+				this.trtcComponent.on(TRTC_EVENT.IM_READY, event => {
+				  console.log('* room IM_READY', event)
+				  var that=this;
+				  setTimeout(function(){
+					  if(that.first_gx){
+						  that.first_gx=false;
+						  that.setNum();
+					  }
+				  },1000)
+				  
+				})
+				this.trtcComponent.on(TRTC_EVENT.IM_MESSAGE_RECEIVED, event => {
+				  var that=this;
+				  if(event.data.data==undefined){
+					  return false;
+				  }
+				  if(event.data.data[0]==undefined){
+					  return false;
+				  }
+				  if(event.data.data[0].type=="TIMCustomElem"){
+					if(event.data.data[0].payload.description==0||event.data.data[0].payload.description==1||event.data.data[0].payload.description==2||event.data.data[0].payload.description==3){
+					  var user_id=wx.getStorageSync('uid');
+					  if(event.data.data[0].payload.data==user_id){
+						var jy_time=0;
+						if(event.data.data[0].payload.description==0){
+						  jy_time=(new Date()).valueOf()+5*60*1000;
+						}
+						if(event.data.data[0].payload.description==1){
+						  jy_time=(new Date()).valueOf()+10*60*1000;
+						}
+						if(event.data.data[0].payload.description==2){
+						  jy_time=(new Date()).valueOf()+30*60*1000;
+						}
+						if(event.data.data[0].payload.description==3){
+						  jy_time=(new Date()).valueOf()+60*60*1000;
+						}
+						wx.setStorageSync('jy_time', jy_time)
+					  }
+					  wx.showToast({
+						  title: event.data.data[0].payload.extension,
+						  icon: 'none'
+					  })
+					}else{
+					  var temp=event.data.data[0].payload;
+					  if(temp.data=="genxin"){
+						  setTimeout(function(){
+							  that.setNum();
+						  },3000)
+						  return false;
+					  }
+					  var data=that.text_list;
+					  if(data.length==5){
+						data.shift();
+					  }
+					  data.push(temp);
+					  this.setData({
+						text_list:data,
+					  });
+					}
+				  }
+				})
 			}
 		},
 	}
@@ -402,7 +546,7 @@
 			border-radius: 50%;
 			text-align: center;
 			line-height: 50px;
-
+			z-index: 100;
 			.iconzhibo-shangpin {
 				color: #FFFFFF;
 				font-size: 34px;
@@ -561,17 +705,15 @@
 		  padding-top: 2rpx;
 		}
 		.text_box_top{
-		 font-size: 34rpx;
-		     /* width: 100%; */
-		     display: block;
-		     height: 30rpx;
-		     float: left;
-		     margin-top: 19rpx;
-		     display: inline-block;
+		   font-size: 28rpx;
+		 display: block;
+		 height: 30rpx;
+		 
+		 margin-top: 6rpx;
 		}
 		.text_box_bottom{
 		  font-size: 22rpx;
-		  float: left;
+		  
 		  margin-top: 10rpx;
 		}
 		.tx_btn{
@@ -598,5 +740,56 @@
 		.tixingn:before {
 		  font-size: 60rpx;
 		}
+		.talk_box{
+		  z-index: 10;
+		position: absolute;
+		bottom: 170rpx;
+		left: 0rpx;
+		}
+		.line_box{
+		  width:100%
+		}
+		.talk_box_timp{
+		  display: inline-block;
+		border-radius: 60rpx;
+		background: rgba(0, 0, 0, 0.4);
+		margin-bottom: 10rpx;
+		}
+		.talk_box_timp image{
+		  width: 56rpx;
+		height: 56rpx;
+		border-radius: 60rpx;
+		float: left;
+		
+		}
+		.talk_box_timp text{
+		  float: left;
+		color: #fff;
+		padding-top: 6rpx;
+		padding-right: 50rpx;
+		font-size: 28rpx;
+		margin-left: 20rpx;
+		line-height: 45rpx;
+		}
+		.talk_input{
+		  z-index: 10;
+		position: absolute;
+		bottom: 38rpx;
+		left: 0rpx;
+		width:100%
+		}
+		.talk_box_timp input{
+		  float: left;
+		  color: #fff;
+		  padding-top: 6rpx;
+		  padding-right: 50rpx;
+		  font-size: 30rpx;
+		  margin-left: 20rpx;
+		  line-height: 45rpx;
+		  line-height: 34rpx;  
+		}
+		.left_box{
+			display: inline-block;
+		}
 	}
 </style>

File diff suppressed because it is too large
+ 0 - 0
pagesGood/trtc-room/common/tim-wx.js


+ 356 - 3
pagesGood/trtc-room/trtc-room.vue

@@ -478,9 +478,11 @@ import { setData } from '@/pagesGood/debug/GenerateTestUserSig';
 import UserController from './controller/user-controller';
 import Pusher from './model/pusher';
 import { EVENT } from './common/constants';
+import TIM from './common/tim-wx';
 import Event from './utils/event';
 import * as ENV from './utils/environment';
 const TAG_NAME = 'TRTC-ROOM';
+const IM_GROUP_TYPE = TIM.TYPES.GRP_CHATROOM // TIM.TYPES.GRP_CHATROOM 体验版IM无数量限制,成员20个, TIM.TYPES.GRP_AVCHATROOM IM体验版最多10个,升级后无限制
 
 export default {
 	data() {
@@ -504,7 +506,14 @@ export default {
 			remoteVolumeList: [],
 			appVersion: ENV.APP_VERSION,
 			libVersion: ENV.LIB_VERSION,
-			debugMode: ''
+			debugMode: '',
+			enableIM: true, // 用于组件内渲染
+			showIMPanel: false,
+			exitIMThrottle: false,
+			messageContent: '',
+			messageList: [], // 仅保留10条消息
+			maxMessageListLength: 10,
+			messageListScrollTop: 0,
 		};
 	},
 
@@ -518,7 +527,14 @@ export default {
 				userID: '',
 				userSig: '',
 				template: '',
-				debugMode: ''
+				debugMode: '',
+				enableIM: true, // 用于组件内渲染
+				showIMPanel: false,
+				exitIMThrottle: false,
+				messageContent: '',
+				messageList: [], // 仅保留10条消息
+				maxMessageListLength: 10,
+				messageListScrollTop: 0
 			})
 		}
 	},
@@ -608,12 +624,16 @@ export default {
 		 */
 		enterRoom: function(params) {
 			return new Promise((resolve, reject) => {
-				console.log(TAG_NAME, 'enterRoom');
+				console.log(TAG_NAME, 'enterRoom'); 
 				console.log(TAG_NAME, 'params', params);
 				console.log(TAG_NAME, 'config', this.config);
 				console.log(TAG_NAME, 'pusher', this.pusher); // 1. 补齐进房参数,校验必要参数是否齐全
 
 				console.log('进房......', params, this.config, this.pusher);
+				if (this.config.enableIM && this.config.sdkAppID) {
+					this._initIM(this.config,params.roomID)
+				 // this._loginIM({ ...this.config, roomID: params.roomID })
+				}
 				if (params) {
 					Object.assign(this.pusher, params);
 					Object.assign(this.config, params);
@@ -658,6 +678,7 @@ export default {
 				this.pusher.reset();
 				this.status.isPush = false;
 				const result = this.userController.reset();
+				this._exitIM();
 				this.setData(
 					{
 						pusher: this.pusher,
@@ -2302,6 +2323,338 @@ export default {
 					})
 					.catch(() => {});
 			}
+		},
+		//  ______  __       __        ______             __                                              __
+		//  |      \|  \     /  \      |      \           |  \                                            |  \
+		//   \$$$$$$| $$\   /  $$       \$$$$$$ _______  _| $$_     ______    ______   _______    ______  | $$
+		//    | $$  | $$$\ /  $$$        | $$  |       \|   $$ \   /      \  /      \ |       \  |      \ | $$
+		//    | $$  | $$$$\  $$$$        | $$  | $$$$$$$\\$$$$$$  |  $$$$$$\|  $$$$$$\| $$$$$$$\  \$$$$$$\| $$
+		//    | $$  | $$\$$ $$ $$        | $$  | $$  | $$ | $$ __ | $$    $$| $$   \$$| $$  | $$ /      $$| $$
+		//   _| $$_ | $$ \$$$| $$       _| $$_ | $$  | $$ | $$|  \| $$$$$$$$| $$      | $$  | $$|  $$$$$$$| $$
+		//  |   $$ \| $$  \$ | $$      |   $$ \| $$  | $$  \$$  $$ \$$     \| $$      | $$  | $$ \$$    $$| $$
+		//   \$$$$$$ \$$      \$$       \$$$$$$ \$$   \$$   \$$$$   \$$$$$$$ \$$       \$$   \$$  \$$$$$$$ \$$
+		
+		getCountNum(params) {
+			let promise = this.tim.getGroupProfile({ groupID: this.config.roomID+"" });
+			promise.then(function(imResponse) {
+				return imResponse.data.group.memberCount;
+			  console.log(imResponse.data.group);
+			}).catch(function(imError) {
+			  console.warn('getGroupProfile error:', imError); // 获取群详细资料失败的相关信息
+			});
+		},
+		/**
+		 * 初始化 IM SDK
+		 * @param {Object} config sdkAppID
+		 */
+		sendGroupCustomMessage(params) {
+		      if (!this.tim) {
+		        console.warn(TAG_NAME, '未开启IM功能,该方法无法使用', params)
+		        return
+		      }
+		      console.log(TAG_NAME, 'sendGroupCustomMessage', params)
+		      const message = this.tim.createCustomMessage({
+		        to: params.roomID + '',
+		        conversationType: TIM.TYPES.CONV_GROUP,
+		        payload: params.payload,
+		      })
+		      const promise = this.tim.sendMessage(message)
+		      promise.then(function(imResponse) {
+		        // 发送成功
+		        console.log(TAG_NAME, 'sendMessage success', imResponse)
+		      }).catch(function(imError) {
+		        // 发送失败
+		        console.warn(TAG_NAME, 'sendMessage error:', imError)
+		      })
+		      return promise
+		},
+		_initIM(config,roomId) {
+		  if (!config.enableIM || !config.sdkAppID || this.tim) {
+			return
+		  }
+		  console.log(TAG_NAME, '_initIM', config)
+		  // 初始化 sdk 实例
+		  const tim = TIM.create({
+			SDKAppID: config.sdkAppID,
+		  })
+		  // 0 普通级别,日志量较多,接入时建议使用
+		  // 1 release级别,SDK 输出关键信息,生产环境时建议使用
+		  // 2 告警级别,SDK 只输出告警和错误级别的日志
+		  // 3 错误级别,SDK 只输出错误级别的日志
+		  // 4 无日志级别,SDK 将不打印任何日志
+		  if (config.debugMode) {
+			tim.setLogLevel(1)
+		  } else {
+			tim.setLogLevel(4)
+		  }
+		  // 取消监听
+		  tim.off(TIM.EVENT.SDK_READY, this._onIMReady)
+		  tim.off(TIM.EVENT.MESSAGE_RECEIVED, this._onIMMessageReceived)
+		  tim.off(TIM.EVENT.SDK_NOT_READY, this._onIMNotReady)
+		  tim.off(TIM.EVENT.KICKED_OUT, this._onIMKickedOut)
+		  tim.off(TIM.EVENT.ERROR, this._onIMError)
+		  // 监听事件
+		  tim.on(TIM.EVENT.SDK_READY, this._onIMReady, this)
+		  tim.on(TIM.EVENT.MESSAGE_RECEIVED, this._onIMMessageReceived, this)
+		  tim.on(TIM.EVENT.SDK_NOT_READY, this._onIMNotReady, this)
+		  tim.on(TIM.EVENT.KICKED_OUT, this._onIMKickedOut, this)
+		  tim.on(TIM.EVENT.ERROR, this._onIMError, this)
+		  this.tim = tim
+		  wx.tim = tim
+		  this._loginIM({ ...this.config, roomID: roomId })
+		},
+		_loginIM(params) {
+		  if (!this.tim) {
+			return
+		  }
+		  console.log(TAG_NAME, '_loginIM', params)
+		  var that=this;
+		  setTimeout(function(){
+			  that.sendGroupCustomMessage({
+			    roomID: Number(that.config.roomID), // 房间 ID
+			    payload: {
+			  	data: 'genxin',
+			  	description: 'genxin',
+			  	extension: 'genxin'
+			    }
+			  })
+		  },2000)
+		  return this.tim.login({
+			userID: params.userID,
+			userSig: params.userSig,
+		  })
+		},
+		_logoutIM() {
+		  if (!this.tim) {
+			return
+		  }
+		  console.log(TAG_NAME, '_logoutIM')
+		  return this.tim.logout()
+		},
+		_exitIM() {
+			this.sendGroupCustomMessage({
+			  roomID: Number(this.config.roomID), // 房间 ID
+			  payload: {
+				data: 'genxin',
+				description: 'genxin',
+				extension: 'genxin'
+			  }
+			})
+			var that=this;
+		    setTimeout(function(){
+				// 方法需要调用限制,否则重复解散群 退群会有warn
+				if (that.config.exitIMThrottle || !that.tim) {
+							return
+				}
+				that.config.exitIMThrottle = true
+				const userList = that.getRemoteUserList()
+				const roomID = that.config.roomID
+				const userID = that.config.userID
+				that._searchGroup({ roomID }).then((imResponse) => {
+							// 查询群资料,判断是否为群主
+							if (imResponse.data.group.ownerID === userID && userList.length === 0) {
+							  // 如果 userList 为 0 群主可以解散群,并登出IM
+							  that._dismissGroup({ roomID }).then(()=>{
+								that.config.exitIMThrottle = false
+								that._logoutIM()
+							  }).catch((imError) => {
+								that.config.exitIMThrottle = false
+								that._logoutIM()
+							  })
+							} else if (imResponse.data.group.ownerID === userID) {
+							  that.config.exitIMThrottle = false
+							  // 群主不能退群只能登出
+							  that._logoutIM()
+							} else {
+							  // 普通成员退群并登出IM
+							  that._quitGroup({ roomID }).then(()=>{
+								that.config.exitIMThrottle = false
+								that._logoutIM()
+							  }).catch((imError) => {
+								that.config.exitIMThrottle = false
+								that._logoutIM()
+							  })
+							}
+				}).catch((imError) => {
+							that.config.exitIMThrottle = false
+							// 查询异常直接登出
+							that._logoutIM()
+				})
+			},2000)
+		},
+		_searchGroup(params) {
+		  if (!this.tim) {
+			return
+		  }
+		  console.log(TAG_NAME, '_searchGroup', params)
+		  const tim = this.tim
+		  const promise = tim.searchGroupByID(params.roomID + '')
+		  promise.then(function(imResponse) {
+			// const group = imResponse.data.group // 群组信息
+			console.log(TAG_NAME, '_searchGroup success', imResponse)
+		  }).catch(function(imError) {
+			console.warn(TAG_NAME, '_searchGroup fail,TIM 报错信息不影响后续逻辑,可以忽略', imError) // 搜素群组失败的相关信息
+		  })
+		  return promise
+		},
+		/**
+		 * 创建 AVchatroom
+		 * @param {*} params roomID
+		 * @returns {Promise}
+		 */
+		_createGroup(params) {
+		  if (!this.tim) {
+			return
+		  }
+		  console.log(TAG_NAME, '_createGroup', params)
+		  const promise = this.tim.createGroup({
+			groupID: params.roomID + '',
+			name: params.roomID + '',
+			type: IM_GROUP_TYPE,
+		  })
+		  promise.then((imResponse) => { // 创建成功
+			console.log(TAG_NAME, '_createGroup success', imResponse.data.group) // 创建的群的资料
+		  }).catch((imError) => {
+			console.warn(TAG_NAME, '_createGroup error', imError) // 创建群组失败的相关信息
+		  })
+		  return promise
+		},
+		/**
+		 * 进入 AVchatroom
+		 * @param {*} params roomID
+		 * @returns {Promise}
+		 */
+		_joinGroup(params) {
+		  if (!this.tim) {
+			return
+		  }
+		  console.log(TAG_NAME, '_joinGroup', params)
+		  const promise = this.tim.joinGroup({ groupID: params.roomID + '', type: IM_GROUP_TYPE })
+		  promise.then((imResponse) => {
+			switch (imResponse.data.status) {
+			  case TIM.TYPES.JOIN_STATUS_WAIT_APPROVAL: // 等待管理员同意
+				break
+			  case TIM.TYPES.JOIN_STATUS_SUCCESS: // 加群成功
+			  case TIM.TYPES.JOIN_STATUS_ALREADY_IN_GROUP: // 已经在群中
+				// console.log(imResponse.data.group) // 加入的群组资料
+				// wx.showToast({
+				//   title: '进群成功',
+				// })
+				console.log(TAG_NAME, '_joinGroup success', imResponse)
+				break
+			  default:
+				break
+			}
+		  }).catch((imError) => {
+			console.warn(TAG_NAME, 'joinGroup error', imError) // 申请加群失败的相关信息
+		  })
+		  return promise
+		},
+		_quitGroup(params) {
+		  if (!this.tim) {
+			return
+		  }
+		  console.log(TAG_NAME, '_quitGroup', params)
+		  const promise = this.tim.quitGroup(params.roomID + '')
+		  promise.then((imResponse) => {
+			console.log(TAG_NAME, '_quitGroup success', imResponse)
+		  }).catch((imError) => {
+			console.warn(TAG_NAME, 'quitGroup error', imError)
+		  })
+		  return promise
+		},
+		_dismissGroup(params) {
+		  if (!this.tim) {
+			return
+		  }
+		  console.log(TAG_NAME, '_dismissGroup', params)
+		  const promise = this.tim.dismissGroup(params.roomID + '')
+		  promise.then((imResponse) => {
+			console.log(TAG_NAME, '_dismissGroup success', imResponse)
+		  }).catch((imError) => {
+			console.warn(TAG_NAME, '_dismissGroup error', imError)
+		  })
+		  return promise
+		},
+		_onIMReady(event) {
+		  console.log(TAG_NAME, 'IM.READY', event)
+		  this._emitter.emit(EVENT.IM_READY, event)
+		  const roomID = this.config.roomID
+		  // 查询群组是否存在
+		  this._searchGroup({ roomID }).then((res) => {
+			// console.log(TAG_NAME, 'searchGroup', res)
+			// 存在直接进群
+			this._joinGroup({ roomID })
+		  }).catch(() => {
+			// 不存在则创建,如果是avchatroom 创建后进群
+			this._createGroup({ roomID }).then((res) => {
+			  // 进群
+			  this._joinGroup({ roomID })
+			}).catch((imError)=> {
+			  if (imError.code === 10021) {
+				console.log(TAG_NAME, '群已存在,直接进群', event)
+				this._joinGroup({ roomID })
+			  }
+			})
+		  })
+		  // 收到离线消息和会话列表同步完毕通知,接入侧可以调用 sendMessage 等需要鉴权的接口
+		  // event.name - TIM.EVENT.IM_READY
+		},
+		_onIMMessageReceived(event) {
+		  // 收到推送的单聊、群聊、群提示、群系统通知的新消息,可通过遍历 event.data 获取消息列表数据并渲染到页面
+		  console.log(TAG_NAME, 'IM.MESSAGE_RECEIVED', event)
+		  // messageList 仅保留10条消息
+		  const messageData = event.data
+		  const roomID = this.config.roomID + ''
+		  const userID = this.config.userID + ''
+		  for (let i = 0; i < messageData.length; i++) {
+			const message = messageData[i]
+			// console.log(TAG_NAME, 'IM.MESSAGE_RECEIVED', message, this.config, TIM.TYPES.MSG_TEXT)
+			if (message.to === roomID + '' || message.to === userID) {
+			  // 遍历messageData 获取当前room 或者当前user的消息
+			  console.log(TAG_NAME, 'IM.MESSAGE_RECEIVED', message, message.type, TIM.TYPES.MSG_TEXT)
+			  if (message.type === TIM.TYPES.MSG_TEXT) {
+				/*this._pushMessageList({
+				  name: message.from,
+				  message: message.payload.text,
+				})*/
+			  } else {
+				if (message.type === TIM.TYPES.MSG_GRP_SYS_NOTICE && message.payload.operationType === 2) {
+				  // 群系统通知
+				  /*this._pushMessageList({
+					name: '系统通知',
+					message: `欢迎 ${userID}`,
+				  })*/
+				}
+				// 其他消息暂不处理
+			  }
+			}
+		  }
+		  this._emitter.emit(EVENT.IM_MESSAGE_RECEIVED, event)
+		},
+		_onIMNotReady(event) {
+		  console.log(TAG_NAME, 'IM.NOT_READY', event)
+		  this._emitter.emit(EVENT.IM_NOT_READY, event)
+		  // 收到 SDK 进入 not ready 状态通知,此时 SDK 无法正常工作
+		  // event.name - TIM.EVENT.IM_NOT_READY
+		},
+		_onIMKickedOut(event) {
+		  console.log(TAG_NAME, 'IM.KICKED_OUT', event)
+		  this._emitter.emit(EVENT.IM_KICKED_OUT, event)
+		  // 收到被踢下线通知
+		  // event.name - TIM.EVENT.KICKED_OUT
+		  // event.data.type - 被踢下线的原因,例如 :
+		  //    - TIM.TYPES.KICKED_OUT_MULT_ACCOUNT 多实例登录被踢
+		  //    - TIM.TYPES.KICKED_OUT_MULT_DEVICE 多终端登录被踢
+		  //    - TIM.TYPES.KICKED_OUT_USERSIG_EXPIRED 签名过期被踢。使用前需要将SDK版本升级至v2.4.0或以上。
+		},
+		_onIMError(event) {
+		  console.log(TAG_NAME, 'IM.ERROR', event)
+		  this._emitter.emit(EVENT.IM_ERROR, event)
+		  // 收到 SDK 发生错误通知,可以获取错误码和错误信息
+		  // event.name - TIM.EVENT.ERROR
+		  // event.data.code - 错误码
+		  // event.data.message - 错误信息
 		}
 	}
 };

Some files were not shown because too many files changed in this diff