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