From dd10ee2243fcfc1a0f6ae340c4c1732e5c5d1cf2 Mon Sep 17 00:00:00 2001
From: liuyg <376836862@qq.com>
Date: Thu, 12 Aug 2021 10:23:23 +0800
Subject: [PATCH] 视频1

---
 components/submit/submit.vue   |   33 ++++++++++++++--
 pages/videoCall/videoCall.nvue |   59 +++++++++++++++++++++++------
 store/mutations.js             |    4 +-
 store/index.js                 |    1 
 4 files changed, 78 insertions(+), 19 deletions(-)

diff --git a/components/submit/submit.vue b/components/submit/submit.vue
index d2cd28e..de25bbb 100644
--- a/components/submit/submit.vue
+++ b/components/submit/submit.vue
@@ -259,6 +259,9 @@
 			//开始音频
 			openAudio(val) { //Mains
 				// console.log(this.names)
+				// var socketOpen = false;
+
+
 				uni.navigateTo({
 					url: '../videoCall/videoCall?state=' + val + '&type=audio'
 				});
@@ -271,17 +274,37 @@
 			},
 			//开始视频
 			openVideo(val) { //Mains
+				// uni.onSocketOpen(function(res) {
+				// 	// socketOpen = true;
+				// 	console.log('持续连接成功')
+				// 	sendSocketMessage();
+				// });
+
+				// function sendSocketMessage() {
+				// 	var data = {
+				// 		name: this.$store.state.puserName,
+				// 		id: this.names[1],
+				// 		// id: state.puserID,
+				// 		type: 'video'
+				// 	}
+				// 	// if (socketOpen) {
+				// 	uni.sendSocketMessage({
+				// 		data: JSON.stringify(data)
+				// 	});
+				// 	// }
+				// }
+			
 				uni.navigateTo({
 					url: '../videoCall/videoCall?state=' + val + '&type=video' + '&myname=' + this.names[0] +
 						'&toname=' + this.names[1]
 				});
 			},
 			//接收视频
-			receiveVideo(val, room) { //Receiver
-				uni.navigateTo({
-					url: '../videoCall/videoCall?state=' + val + '&type=video' + '&room=' + room
-				});
-			}
+			// receiveVideo(val, room) { //Receiver
+			// 	uni.navigateTo({
+			// 		url: '../videoCall/videoCall?state=' + val + '&type=video' + '&room=' + room
+			// 	});
+			// }
 		},
 		mounted() {
 			// uni.onSocketMessage(function(res) {
diff --git a/pages/videoCall/videoCall.nvue b/pages/videoCall/videoCall.nvue
index 8ec3ad0..37ddd25 100644
--- a/pages/videoCall/videoCall.nvue
+++ b/pages/videoCall/videoCall.nvue
@@ -115,8 +115,8 @@
 				<text class="activetext">语音通话中</text>
 				<u-loading size="36" mode="flower"></u-loading>
 			</view>
-			
-			
+
+
 			<!-- 音视频基本开关 -->
 			<view class="videoshow_control position">
 				<!-- 音频开关 -->
@@ -206,8 +206,8 @@
 				userName: '111',
 				toName: '',
 				Otype: '',
-				
-				formName:''
+
+				formName: ''
 			}
 		},
 		// 页面初始加载(仅执行一次)
@@ -226,17 +226,52 @@
 			console.log(option.state);
 			if (option.state == "Mains") {
 				this.isMain = true;
+				var call = false;
 				// this.userName = 'faqiren';
-				this.userName = option.myname;
-				this.toName = option.toname;
-				setTimeout(res => {
-					//发起请求  给后端双方姓名
+				// setTimeout(res => {
+				//发起请求  给后端双方姓名
 
-					//得到返回值   开始视频  或者拒绝视频
-					this.join();
+				//得到返回值   开始视频  或者拒绝视频
+				// this.join();
+				uni.request({
+					url: this.$store.state.api + '/pushMsg/inviteVideoCall',
+					data: {
+						userId: option.toname,
+						name: this.$store.state.puserName,
+						type: 'video'
+					},
+					success(res) {
+						// if(res.data.res == 0){
+
+						// }
+						var d = res.data.data;
+						if (d.res == 0) {
+							console.log('对方不在线--退出');
+							call = false;
+							uni.navigateBack();
+						} else if (d.res == 1) {
+							console.log('对方在线-- 等待对方接受');
+							// call = true;
+							this.join();
+						}
+					}
+				})
 
 
-				}, 5000)
+				uni.onSocketMessage(function(res) {
+					console.log(res.data);
+					var data = JSON.parse(res.data)
+					// if (call && ) {
+
+					// }
+					if (data.type = 'close') {
+						console.log('对方已挂断');
+						this.closeAll();
+					}
+				});
+
+
+				// }, 5000)
 			} else if (option.state == "Receiver") {
 				this.userName = 'jieshouren';
 				this.formName = 'wo';
@@ -565,7 +600,7 @@
 				RtcModule.destroyRtc((res) => {
 					console.log("页面销毁", res.code);
 					console.log('成功关闭')
-					// uni.navigateBack();
+					uni.navigateBack();
 				});
 				// }
 				// });
diff --git a/store/index.js b/store/index.js
index aece5cf..2178b2a 100644
--- a/store/index.js
+++ b/store/index.js
@@ -35,6 +35,7 @@
 		logPath: '',
 		// piAPI: 'http://223.82.109.183:2080/api',
 		piAPI: 'http://223.82.109.183:2082/api',
+		api: 'http://192.168.0.111:83',
 		// piAPI: 'http://localhost:82/',
 		// piAPI: 'http://192.168.0.108:81',
 		puserName: '',
diff --git a/store/mutations.js b/store/mutations.js
index 664665e..9665061 100644
--- a/store/mutations.js
+++ b/store/mutations.js
@@ -73,13 +73,13 @@
 		uni.onSocketMessage(function(res) {
 			console.log(res.data);
 			var data  = JSON.parse(res.data)
-			// if (data.type == 'video') {
+			if (data.type == 'video') {
 				// this.receiveVideo('Receiver', );
 				console.log('进入接受 跳转',data.type)
 				uni.navigateTo({
 					url: '../videoCall/videoCall?state=Receiver&type=' + data.type +'&room=' + data.roomId
 				});
-			// }
+			}
 			// console.log('收到服务器内容:' + res.data);
 		});
 		

--
Gitblit v1.9.3