Ver Fonte

bugfix: member count

able99 há 4 anos atrás
pai
commit
84ecc7136c
3 ficheiros alterados com 43 adições e 65 exclusões
  1. 28 42
      jhim/jhim.js
  2. 11 21
      jhlive/jhlive.nvue
  3. 4 2
      pagesMedia/liveDetail.nvue

+ 28 - 42
jhim/jhim.js

@@ -6,6 +6,7 @@ import LibGenerateTestUserSig from "./lib-generate-test-usersig-es.min";
 
 const EXPIRETIME = 604800;
 const LOGTAG = '--JHIM--:';
+const LOGTAGGROUP = '--JHIM-GROUP--:';
 
 class JhImGroup {
 	constructor(jhim, groupId, groupType, name ,avatar) {
@@ -21,15 +22,15 @@ class JhImGroup {
 		return this.jhim.ready && this.groupReady;
 	}
 	join(isOwner) {
-		console.log(LOGTAG + 'join', this.groupId, isOwner);
+		console.log(LOGTAGGROUP + 'join', this.groupId, isOwner);
 		
 		let join = () => {
-			console.log(LOGTAG + 'dojoin', this.groupId);
+			console.log(LOGTAGGROUP + 'dojoin', this.groupId);
 			return this.jhim.tim.joinGroup({
 				groupID: this.groupId,
 				type: TIM.TYPES.GRP_AVCHATROOM
 			}).then(res => {
-				console.log(LOGTAG + 'joinGrouped', res.data.status);
+				console.log(LOGTAGGROUP + 'joinGrouped', res.data.status);
 				switch (res.data.status) {
 					case TIM.TYPES.JOIN_STATUS_WAIT_APPROVAL: // 等待管理员同意
 						break;
@@ -44,7 +45,7 @@ class JhImGroup {
 		return this.jhim.tim.searchGroupByID(this.groupId).then(() => {
 			return join();
 		}, () => {
-			console.log(LOGTAG + 'createGroup');
+			console.log(LOGTAGGROUP + 'createGroup');
 			return this.jhim.tim.createGroup({
 				groupID: this.groupId,
 				name: this.groupId,
@@ -55,16 +56,20 @@ class JhImGroup {
 		});
 	}
 	exit(dismiss) {
-		console.log(LOGTAG + 'exit', this.groupId, dismiss);
-		return this.jhim.tim.quitGroup(this.groupId).then(() => {
-			this.groupReady = false;
-		}).then(()=>{
-			if(dismiss) {
-				return this.jhim.tim.dismissGroup(this.groupId);;
-			}else {
-				return Promise.resolve();
-			}
-		});
+		console.log(LOGTAGGROUP + 'exit', this.groupId, dismiss);
+		if(dismiss) {
+			return this.jhim.tim.dismissGroup(this.groupId).then(res=>{
+				this.groupReady = false;
+				console.log(LOGTAGGROUP+'dismissGroup', res);
+				return res;
+			});
+		}else {
+			return this.jhim.tim.quitGroup(this.groupId).then(res=>{
+				this.groupReady = false;
+				console.log(LOGTAGGROUP+'quitGroup', res);
+				return res;
+			});
+		}
 	}
 	getProfile() {
 		return this.jhim.tim.getGroupProfile({
@@ -136,7 +141,7 @@ class JhImGroup {
 	}
 }
 
-let instance = null;
+
 export default class JhIm {
 	static getInstance(userId, sdkAppID, secretKey, userSig) {
 		if (JhIm.instance) return JhIm.instance;
@@ -166,39 +171,20 @@ export default class JhIm {
 		this.TYPES = TIM.TYPES;
 		this.EVENT = TIM.EVENT;
 
-		this.tim.on(TIM.EVENT.MESSAGE_RECEIVED, event => {
-			console.log(LOGTAG + 'recv', event);
-			let msgs = [];
-			event.data.forEach(v => {
-				// https://imsdk-1252463788.file.myqcloud.com/IM_DOC/Web/Message.html
-				if (v.type == TIM.TYPES.MSG_TEXT) {
-					msgs.push(v);
-					msgs.push({
-						type: v.type,
-						name: v.nick,
-						avatar: v.avatar,
-						text: v.payload.text,
-						conversationType: v.conversationType,
-						time: v.time,
-					})
-				} else if (v.type == "TIMGroupTipElem") {
-					this.onIMGroupTipElem && this.onIMGroupTipElem(v.payload);
-				}
-			})
-
-			this.onIMMessageReceived && this.onIMMessageReceived(msgs);
-		}, this);
-
-		this.tim.on(TIM.EVENT.SDK_READY, event => {
+		this._readyCb = event => {
 			this.ready = true;
-		}, this);
-		this.tim.on(TIM.EVENT.SDK_NOT_READY, event => {
+		};
+		this.tim.on(TIM.EVENT.SDK_READY, this._readyCb);
+		this._notReadyCb = event => {
 			this.ready = false;
-		}, this);
+		};
+		this.tim.on(TIM.EVENT.SDK_NOT_READY, this._notReadyCb);
 
 		return this;
 	}
 	destory() {
+		this.tim.off(this._readyCb);
+		this.tim.off(this._notReadyCb);
 		this.tim = null;
 	}
 	on(name, cb) {

+ 11 - 21
jhlive/jhlive.nvue

@@ -134,19 +134,21 @@
 		},
 		methods: {
 			init() {
+				console.log(LOGTAG + 'init');
 				this.remoteUsers = [];
 				uni.setKeepScreenOn({
 					keepScreenOn: true
 				});
 			},
 			destroy() {
+				console.log(LOGTAG + 'destroy');
 				uni.setKeepScreenOn({
 					keepScreenOn: false
 				});
 				this.exitRoom()
 			},
 			enterRoom() {
-				if (!this.$refs.liveView) {
+				if (!this.$refs.liveView||!this.$refs.liveView.enterRoom) {
 					console.log(LOGTAG + 'no jhlive');
 					uni.showToast({
 						title: '直播组件初始化失败',
@@ -182,35 +184,23 @@
 					this.beautifyLevel ? 0 : 0,
 				);
 			},
-			handleLiveEvent(event) {
-				if (event.eventName == 'onRemoteUserEnterRoom' && !this.remoteUsers.find(v => v == event.eventData)) {
-					this.remoteUsers.push(event.eventData);
-					this.$emit('onRemoteUser', this.remoteUsers);
-				} else if (event.eventName == 'onRemoteUserLeaveRoom') {
-					this.remoteUsers = this.remoteUsers.filter(v => v != event.eventData);
-					this.$emit('onRemoteUser', this.remoteUsers);
-				} else if (event.eventName == 'onError') {
-					this.$emit('onError', event.eventData.msg);
-					uni.showToast({
-						title: event.eventData.msg,
-						duration: 2000
-					});
-				}
-			},
-			onError: (e) => {
+			onError(e) {
+				console.log(LOGTAG + 'onError', e);
 				uni.showToast({
 					title: e.detail,
 					duration: 2000
 				});
 				this.$emit('onError', e.detail);
 			},
-			onRemoteUserEnterRoom: (e) => {
-				if (this.remoteUsers.find(v => v == e.detail)) {
+			onRemoteUserEnterRoom(e) {
+				console.log(LOGTAG + 'onRemoteUserEnterRoom', e);
+				if (!this.remoteUsers.find(v => v == e.detail)) {
 					this.remoteUsers.push(e.detail);
-					this.$emit('onRemoteUser', this.remoteUsers);
 				}
+				this.$emit('onRemoteUser', this.remoteUsers);
 			},
-			onRemoteUserLeaveRoom: (e) => {
+			onRemoteUserLeaveRoom(e) {
+				console.log(LOGTAG + 'onRemoteUserLeaveRoom', e);
 				this.remoteUsers = this.remoteUsers.filter(v => v != e.detail);
 				this.$emit('onRemoteUser', this.remoteUsers);
 			},

+ 4 - 2
pagesMedia/liveDetail.nvue

@@ -188,7 +188,9 @@
 				}))];
 			},
 			onImGroupTip(e) {
-				this.subtitle = e[0].payload.userIDList.length + '人在观看';
+				this.jhimgroup.getProfile().then(v=>{
+					this.subtitle = v.memberCount + '人在观看';
+				});
 			},
 			onImGroupReady(e) {
 				this.imStatus = e?'':'登录中...';
@@ -208,7 +210,7 @@
 				this.jhimgroup.off(this.onImCustomMessage);
 				this.jhimgroup.off(this.onImGroupTip);
 				this.jhimgroup.offReady(this.onImGroupReady);
-				this.jhimgroup.exit(this.isAuthor).then(()=>this.jhim.logout());
+				this.jhimgroup.exit(this.isAuthor).then(()=>this.jhim.logout().then(()=>this.jhim.destroy()));
 				this.$refs.jhlive && this.$refs.jhlive.exitRoom();
 			},
 			onBtnClick(index, item) {