|
|
@@ -2,7 +2,7 @@
|
|
|
<view class="video_box" :style="'height:' + phoneHeight + 'px'">
|
|
|
<!-- 本地预览视图 -->
|
|
|
<view class="video_me" v-show="allUserViewObjectList.length > 0">
|
|
|
- <!-- <view class="video_me" v-if="videoShow"> -->
|
|
|
+ <!-- <view class="video_me" v-if="videoShow"> -->
|
|
|
<zego-local-view :viewMode="publisherViewModeIndex"
|
|
|
style="width: 150px; height: 200px; flex: 1; position: fixed; right: 0; top: 65px;">
|
|
|
</zego-local-view>
|
|
|
@@ -10,9 +10,9 @@
|
|
|
|
|
|
<!-- 服务器传来的预览图 -->
|
|
|
<view class="video_you" v-for="(item, index) in allUserViewObjectList" :key="item.streamID">
|
|
|
- <!-- <view class="video_you"> -->
|
|
|
+ <!-- <view class="video_you"> -->
|
|
|
<zego-remote-view v-if="item.streamID" :streamID="item.streamID" :viewMode="item.viewMode"
|
|
|
- style="width: 620px; height: 600px; flex: 1;">
|
|
|
+ style="width:600px;height: 600rpx;border: 1px solid #fff;">
|
|
|
</zego-remote-view>
|
|
|
</view>
|
|
|
|
|
|
@@ -24,7 +24,7 @@
|
|
|
</view>
|
|
|
<text class="video_view_txt">翻转镜头</text>
|
|
|
</view>
|
|
|
-
|
|
|
+
|
|
|
<!-- <view class="video_imgList2" v-if="CameraShow">
|
|
|
<view class="video_view" @click="closeCamera">
|
|
|
<image class="video_view_img" src="../../static/image/11.png" mode=""></image>
|
|
|
@@ -38,7 +38,7 @@
|
|
|
</view>
|
|
|
<text class="video_view_txt" style="margin: 0 0 0 30rpx;">开启</text>
|
|
|
</view> -->
|
|
|
-
|
|
|
+
|
|
|
<image @click="offVideo()" style="width: 50px; height: 50px; margin: 0 0 0 330rpx;"
|
|
|
src="../../static/image/10.png" mode=""></image>
|
|
|
</view>
|
|
|
@@ -53,11 +53,14 @@
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
+ import {
|
|
|
+ mapState
|
|
|
+ } from 'vuex'
|
|
|
import store from '@/store/index.js'; //需要引入store
|
|
|
let App = getApp();
|
|
|
// var API = App.globalData.socketTask;
|
|
|
var API = App.globalData;
|
|
|
-
|
|
|
+
|
|
|
import permision from "@/zego-express-video-uniapp/permission.js";
|
|
|
import ZegoExpressEngine from '@/zego-express-video-uniapp/lib/ZegoExpressEngine';
|
|
|
import {
|
|
|
@@ -65,7 +68,8 @@
|
|
|
ZegoRoomState,
|
|
|
ZegoUpdateType,
|
|
|
// ZegoViewMode,
|
|
|
- ZegoVideoCodecID
|
|
|
+ ZegoVideoCodecID,
|
|
|
+ ZegoRemoteDeviceState
|
|
|
} from '@/zego-express-video-uniapp/lib/ZegoExpressDefines'
|
|
|
import {
|
|
|
AppID,
|
|
|
@@ -73,6 +77,10 @@
|
|
|
} from '@/zego-express-video-uniapp/KeyCenter.js'
|
|
|
import ZegoLocalView from '@/zego-express-video-uniapp/zego-view/ZegoLocalView';
|
|
|
import ZegoRemoteView from '@/zego-express-video-uniapp/zego-view/ZegoRemoteView';
|
|
|
+
|
|
|
+ import {
|
|
|
+ assign
|
|
|
+ } from 'lodash-es';
|
|
|
export default {
|
|
|
data() {
|
|
|
return {
|
|
|
@@ -93,6 +101,7 @@
|
|
|
allUserViewObjectList: [],
|
|
|
|
|
|
CameraShow: true, // 镜头开启关闭
|
|
|
+ playerStreamID: 0,
|
|
|
}
|
|
|
},
|
|
|
components: {
|
|
|
@@ -101,18 +110,18 @@
|
|
|
},
|
|
|
|
|
|
watch: {
|
|
|
- allUserViewObjectList(val) {
|
|
|
- var that = this
|
|
|
- if (val.length > 0) {
|
|
|
- val.forEach((item) => {
|
|
|
- if (item.streamID) {
|
|
|
- this.tensile(item)
|
|
|
- return true
|
|
|
- }
|
|
|
- })
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
+ // allUserViewObjectList(val) {
|
|
|
+ // var that = this
|
|
|
+ // if (val.length > 0) {
|
|
|
+ // val.forEach((item) => {
|
|
|
+ // if (item.streamID) {
|
|
|
+ // this.tensile(item)
|
|
|
+ // return true
|
|
|
+ // }
|
|
|
+ // })
|
|
|
+
|
|
|
+ // }
|
|
|
+ // }
|
|
|
},
|
|
|
|
|
|
methods: {
|
|
|
@@ -130,12 +139,22 @@
|
|
|
// console.log(this.engine)
|
|
|
this.addListeners();
|
|
|
// console.log('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>' + that.videoObj.room_id)
|
|
|
- this.engine.loginRoom(that.videoObj.room_id, {
|
|
|
- userID: that.videoObj.room_id,
|
|
|
- userName: that.videoObj.room_id
|
|
|
+ const userID = (that.userid = that.videoObj.room_id + that.videoObj.user_id)
|
|
|
+ console.log(userID, that.userid)
|
|
|
+
|
|
|
+ await this.engine.loginRoom(that.videoObj.room_id, {
|
|
|
+ userID,
|
|
|
+ userName: that.videoObj.user_id + '-' +
|
|
|
+ that.videoObj.real_name
|
|
|
}, {
|
|
|
isUserStatusNotify: true
|
|
|
+ }).then(res => {
|
|
|
+ console.log(res, 'login room -------------')
|
|
|
+ }).catch(err => {
|
|
|
+ console.error(err, 'login room')
|
|
|
});
|
|
|
+
|
|
|
+
|
|
|
},
|
|
|
|
|
|
// 即构 - 翻转镜头
|
|
|
@@ -173,7 +192,7 @@
|
|
|
this.videoShow = !this.videoShow
|
|
|
// this.onPublish()
|
|
|
this.engine.startPreview();
|
|
|
- this.engine.startPublishingStream(this.videoObj.room_id);
|
|
|
+ this.engine.startPublishingStream(this.userid);
|
|
|
this.publishBtnName = "Stop Publishing";
|
|
|
console.log(this.videoShow)
|
|
|
},
|
|
|
@@ -186,18 +205,18 @@
|
|
|
|
|
|
// 房间状态变化通知
|
|
|
this.engine.on("roomStateUpdate", (roomID, state, errorCode, extendedData) => {
|
|
|
- // console.log('房间状态变化')
|
|
|
- if (state == "CONNECTED") {
|
|
|
+ console.log('房间状态变化', state)
|
|
|
+ if (state == ZegoRoomState.Connected) {
|
|
|
// 与房间连接成功,只有当房间状态是连接成功时,才能进行推流、拉流等操作。
|
|
|
// 接下来的“预览并推流”的代码写在这里
|
|
|
console.log("房间连接成功");
|
|
|
}
|
|
|
- if (state == "DISCONNECTED") {
|
|
|
+ if (state == ZegoRoomState.DisConnected) {
|
|
|
// 与房间断开了连接
|
|
|
console.log("与房间断开连接");
|
|
|
}
|
|
|
|
|
|
- if (state == "CONNECTING") {
|
|
|
+ if (state == ZegoRoomState.Connecting) {
|
|
|
// 与房间尝试连接中
|
|
|
console.log("与房间尝试连接中");
|
|
|
}
|
|
|
@@ -211,12 +230,28 @@
|
|
|
if (updateType == ZegoUpdateType.Add) {
|
|
|
console.log('进入了啊AAAAAAAAAA')
|
|
|
for (let user of userList) {
|
|
|
+ let payload = assign({
|
|
|
+ streamID: ''
|
|
|
+ }, user)
|
|
|
+
|
|
|
for (let stream of this.allStreamList) {
|
|
|
if (user.userID == stream.user.userID) {
|
|
|
- user.streamID = stream.streamID;
|
|
|
+ payload.streamID = stream.streamID
|
|
|
+
|
|
|
+ if (!this.playerStreamID) {
|
|
|
+ this.playerStreamID = stream.streamID;
|
|
|
+ this.tensile(payload)
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
- this.allUserViewObjectList.push(user);
|
|
|
+
|
|
|
+ const index = this.allUserViewObjectList.findIndex(item => item.userID === payload
|
|
|
+ .userID)
|
|
|
+ console.log('-----------------------all user view object list ', index, payload)
|
|
|
+ if (index === -1) {
|
|
|
+ this.allUserViewObjectList.push(payload);
|
|
|
+ }
|
|
|
}
|
|
|
} else if (updateType == ZegoUpdateType.Delete) {
|
|
|
this.allUserViewObjectList = this.allUserViewObjectList.filter((object) => {
|
|
|
@@ -257,11 +292,18 @@
|
|
|
for (let stream of streamList) {
|
|
|
if (object.userID == stream.user.userID) {
|
|
|
object.streamID = stream.streamID;
|
|
|
+ if (!this.playerStreamID) {
|
|
|
+ this.playerStreamID = stream.streamID
|
|
|
+
|
|
|
+ this.tensile(object)
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
this.allStreamList = this.allStreamList.concat(streamList);
|
|
|
console.log(this.allStreamList, '-------------')
|
|
|
+
|
|
|
} else if (updateType == ZegoUpdateType.Delete) {
|
|
|
for (let object of this.allUserViewObjectList) {
|
|
|
for (let stream of streamList) {
|
|
|
@@ -295,15 +337,48 @@
|
|
|
|
|
|
// 拉流后的事件回调
|
|
|
this.engine.on("playerStateUpdate", (streamID, state, errorCode, extendedData) => {
|
|
|
- console.log('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>' + '拉流后的事件触发了')
|
|
|
+ console.warn('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>' + '拉流后的事件触发了start')
|
|
|
+ console.warn(streamID, state, errorCode, extendedData, this.playerStreamID)
|
|
|
+ console.warn('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>' + '拉流后的事件触发end')
|
|
|
+ })
|
|
|
+
|
|
|
+ this.engine.on('playerRecvVideoFirstFrame', (streamID) => {
|
|
|
+ console.warn('playerRecvVideoFirstFrame- 拉流端视频接收首帧回调', streamID)
|
|
|
+ })
|
|
|
+
|
|
|
+ this.engine.on('playerRenderVideoFirstFrame', (streamID) => {
|
|
|
+ console.warn('playerRenderVideoFirstFrame- 拉流端渲染完视频首帧回调', streamID)
|
|
|
+ })
|
|
|
+
|
|
|
+ this.engine.on('publisherStateUpdate', (streamID, state, errorCode, extendedData) => {
|
|
|
+ console.warn('publisherStateUpdate 推流状态回调', streamID, state, errorCode, extendedData)
|
|
|
+ })
|
|
|
+
|
|
|
+ this.engine.on('publisherCapturedVideoFirstFrame', (channel) => {
|
|
|
+ console.warn('publisherCapturedVideoFirstFrame 推流端视频采集首帧回调', channel)
|
|
|
+ })
|
|
|
+
|
|
|
+ this.engine.on('remoteCameraStateUpdate', (streamID, state) => {
|
|
|
+
|
|
|
+ console.warn('remoteCameraStateUpdate 远端摄像头设备状态通知', streamID, state)
|
|
|
+
|
|
|
+
|
|
|
})
|
|
|
},
|
|
|
|
|
|
tensile(item) {
|
|
|
+ console.warn('---------------------------- 拉流start -----------------------')
|
|
|
console.log(this.allStreamList)
|
|
|
- console.log(item)
|
|
|
+ console.log(item, item.streamID)
|
|
|
console.log(this.allUserViewObjectList)
|
|
|
+ // 拉流点击快于推流时,需要等流更新后重新拉
|
|
|
+ // startPlayingStream 在 play.js文件
|
|
|
+ // this.startPlayingStream(this.playStreamID);
|
|
|
this.engine.startPlayingStream(item.streamID)
|
|
|
+ console.warn('---------------------------- 拉流start1 -----------------------', this.playerStreamID)
|
|
|
+
|
|
|
+ console.warn('---------------------------- 拉流start end -----------------------')
|
|
|
+
|
|
|
},
|
|
|
|
|
|
// 停止拉流
|
|
|
@@ -322,16 +397,20 @@
|
|
|
console.log('开始推流了啊', this.isPublishingStream)
|
|
|
// 开始推流
|
|
|
this.engine.startPreview();
|
|
|
-
|
|
|
+
|
|
|
// 设置编码格式
|
|
|
// let videoConfig = {};
|
|
|
// videoConfig.codecID = ZegoVideoCodecID.VP8;
|
|
|
// this.engine.setVideoConfig(videoConfig);
|
|
|
// 设置编码格式
|
|
|
-
|
|
|
+
|
|
|
// this.engine.startPublishingStream(this.videoObj.room_id);
|
|
|
console.log(this.userid)
|
|
|
- this.engine.startPublishingStream(this.userid);
|
|
|
+ this.engine.startPublishingStream(this.userid).then(res => {
|
|
|
+ console.log(res, 'start publish stream ------------------1')
|
|
|
+ }).catch(err => {
|
|
|
+ console.error(err)
|
|
|
+ });;
|
|
|
// this.videoShow = true
|
|
|
}
|
|
|
this.isPublishingStream = !this.isPublishingStream;
|
|
|
@@ -442,9 +521,9 @@
|
|
|
}
|
|
|
|
|
|
.video_you {
|
|
|
- background: #000;
|
|
|
- width: 620px;
|
|
|
- height: 600px;
|
|
|
+ background: #f00;
|
|
|
+ width: 1200rpx;
|
|
|
+ height: 600rpx;
|
|
|
position: absolute;
|
|
|
right: 0;
|
|
|
bottom: 0;
|