Commit d2636bf8 authored by 刘阳's avatar 刘阳

Merge branch 'master' of https://dev.jiuaoedu.com/huanglu/gk-online-teacher

# Conflicts: # src/utils/socket.js # src/views/home/index.vue # src/views/paint-screen/index.vue
parents 4ea699c8 776a6ce8
......@@ -65,13 +65,13 @@ export default class HWOnline {
this.client = client;
}
joinRoom(roomId) {
joinRoom(roomId, role) {
const ctimeDst = 7200000
const ctime = Math.floor((ctimeDst + new Date().getTime()) / 1000).toString()
const message = `${this.appId}+${roomId}+${this.userId}+${ctime}`
return this._joinRoom(roomId, {
userId: this.userId,
role: 0,
role,
ctime,
userName: `${this.userId}`,
signature: CryptoJS.HmacSHA256(message, this.appId).toString(),
......@@ -115,14 +115,19 @@ export default class HWOnline {
video: !!cameraId,
cameraId,
});
stream.setScreenProfile({
width: 1920,
height: 1080
});
// stream.setVideoProfile({
// height: 1080,
// width: 1980,
// // bitrate: 2400
// });
stream.setVideoProfile('720p_1');
await stream.initialize()
await this.publish(stream)
this.localStream = stream;
// stream.play(this.elId,{ muted: false, objectFit: 'contain' }) // 播放本地流
console.log('local stream: ', stream);
this.streams.push(stream)
this.subscribedCb(this.streams)
return stream
}
......
......@@ -23,10 +23,10 @@ export default {
async mounted() {
const { userId, roomId } = this.$route.query
this.rtc = new HWRTC(userId || (new Date().getTime() / 1000).toFixed(0));
await this.rtc.joinRoom(roomId)
await this.rtc.joinRoom(roomId, 2)
this.rtc.subscribedStreamCb((streams) => {
console.log('subscribedStreamCb: ', streams)
const stream = streams.reverse().find((itm) => itm.getUserId().includes('teacher'))
const stream = streams.find((itm) => itm.getUserId().includes('teacher'))
if (stream) this.playStream = stream;
})
}
......
<template>
<div class="home">
<div class="player">
<RtcPlayer :stream="localStream" class="local-player" />
<RtcPlayer :stream="mainStream" class="local-player" />
<el-button v-if="isJoin" type="primary"
@click.native="fullPlayer" class="full-screen">全屏</el-button>
</div>
......@@ -38,9 +38,10 @@
<div class="operation">
<el-button type="primary" @click="play">加入房间</el-button>
</div>
</div>
<div class="stream-pre">
<RtcPlayer class="item" v-for="(itm, index) in streams" :stream="itm" :key="index" />
<div class="stream-pre">
<RtcPlayer @click="clickItm(itm)"
class="item" v-for="(itm, index) in subStreams" :stream="itm" :key="index" />
</div>
</div>
</div>
</template>
......@@ -57,14 +58,15 @@ export default {
show: true,
output: '',
rtc: null,
roomId: null,
roomId: '',
micro: [],
microId: '123',
microId: '',
cameras: [],
camerId: '',
streams: [],
localStream: null,
isJoin: false
isJoin: false,
mainId: ''
}
},
name: 'Home',
......@@ -79,39 +81,51 @@ export default {
if (N !== O && this.isJoin) this.localStream.switchDevice('video', N);
}
},
computed: {
subStreams() {
const subs = (this.streams || []).filter((itm) => itm !== this.mainStream)
console.log('subs: **** ', subs)
return subs
},
mainStream() {
const main = (this.streams || []).find((itm) => itm.getId() === this.mainId)
console.log('main: **** ', main)
return main
}
},
methods: {
async play() {
try {
await this.rtc.joinRoom(this.roomId)
await this.rtc.joinRoom(`${this.roomId}`, 0)
this.localStream = await this.rtc.createStream(this.microId, this.camerId)
// this.localStream.play('player', { muted: false, objectFit: 'contain' })
await this.rtc.publish(this.localStream)
this.isJoin = true
} catch (error) {
console.log('创建失败: ', error)
}
},
join() {
this.rtc.joinRoom(this.roomId)
},
fullPlayer() {
console.log('full')
document.querySelector('#player').requestFullscreen()
// document.querySelector('#player').requestFullscreen()
},
clickItm(itm) {
this.mainId = itm.getId()
}
},
async mounted() {
console.log('mounted')
const { roomId } = this.$route.query
const { roomId, userId } = this.$route.query
this.roomId = roomId
this.userId = userId
// eslint-disable-next-line no-underscore-dangle
const ok = await HWRTC.getAuthUserMedia()
if (!ok) {
this.$alert('无摄像头和和麦克风权限');
return;
}
this.rtc = new HWRTC((new Date().getTime() / 1000).toFixed(0));
this.rtc = new HWRTC(userId || (new Date().getTime() / 1000).toFixed(0));
this.cameras = await this.rtc.getCameras()
this.micro = await this.rtc.getMicrophones()
console.log(this.cameras, this.micro)
this.rtc.subscribedStreamCb((streams) => {
this.streams = streams
})
......@@ -133,19 +147,17 @@ export default {
position: relative;
.side {
width: 20vw;
}
.stream-pre {
position: absolute;
top: 10px;
left: 0;
width: calc(100% - 20vw);
overflow: auto;
display: flex;
flex-flow: row;
.item {
margin-left: 10px;
width: 300px;
height: 220px;
flex-flow: column;
align-items: stretch;
.stream-pre {
flex: 1;
overflow: auto;
margin-top: 20px;
.item {
width: 100%;
height: 220px;
}
}
}
.operation {
......
......@@ -881,8 +881,8 @@
"@geek/geekui@^1.1.2":
version "1.1.2"
resolved "http://git.jksxb.cn:8081/repository/geek/@geek/geekui/-/geekui-1.1.2.tgz#346611159cc7e8bd37784e5d24310a56adb69434"
integrity sha512-wR4K6iz4HG1f937HAvloiS4dHp7GdvWBJnr+C8f7OxmLynDUqZGFAulYhQCwHfPodI3kUpRYkPxxM53oZiMtlg==
resolved "http://git.jksxb.cn:8081/repository/geek/@geek/geekui/-/geekui-1.1.2.tgz#bbe448fbefb1487d4b5f16596458d8062b79700f"
integrity sha512-TBPYSECTJknnBs7dSNdQLM+rnoMItpC3HBILLr3YuQCUdvmJdRsbaxlMokfEKv6a3sceAPWHCsnqEl7S4N+2yw==
dependencies:
"@geek/geek-editor" "^1.0.7"
cos-js-sdk-v5 "^0.5.27"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment