Commit ff5e3f73 authored by 刘阳's avatar 刘阳

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

# Conflicts: # src/views/answer-screen/index.vue # src/views/home/index.vue
parents 62eb3bf2 376de221
...@@ -6764,11 +6764,6 @@ ...@@ -6764,11 +6764,6 @@
"version": "3.8.1", "version": "3.8.1",
"resolved": "http://git.jksxb.cn:8081/repository/geek/core-js/-/core-js-3.8.1.tgz", "resolved": "http://git.jksxb.cn:8081/repository/geek/core-js/-/core-js-3.8.1.tgz",
"integrity": "sha1-9RUjZorIopTRKFw7nbRAJf2mbUc=" "integrity": "sha1-9RUjZorIopTRKFw7nbRAJf2mbUc="
},
"jquery": {
"version": "3.5.1",
"resolved": "http://git.jksxb.cn:8081/repository/geek/jquery/-/jquery-3.5.1.tgz",
"integrity": "sha1-17TQjhv9uGrS8aPQOeoXMEcXq7U="
} }
} }
}, },
...@@ -7667,6 +7662,11 @@ ...@@ -7667,6 +7662,11 @@
"supports-color": "^7.0.0" "supports-color": "^7.0.0"
} }
}, },
"jquery": {
"version": "3.5.1",
"resolved": "http://git.jksxb.cn:8081/repository/geek/jquery/-/jquery-3.5.1.tgz",
"integrity": "sha1-17TQjhv9uGrS8aPQOeoXMEcXq7U="
},
"js-base64": { "js-base64": {
"version": "2.6.4", "version": "2.6.4",
"resolved": "https://registry.npm.taobao.org/js-base64/download/js-base64-2.6.4.tgz?cache=0&sync_timestamp=1596556044168&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fjs-base64%2Fdownload%2Fjs-base64-2.6.4.tgz", "resolved": "https://registry.npm.taobao.org/js-base64/download/js-base64-2.6.4.tgz?cache=0&sync_timestamp=1596556044168&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fjs-base64%2Fdownload%2Fjs-base64-2.6.4.tgz",
......
<template> <template>
<div class="geek-rtc-play" ref="player"></div> <div class="geek-rtc-play" ref="player">
</div>
</template> </template>
<script> <script>
export default { export default {
......
...@@ -125,9 +125,6 @@ export default class HWOnline { ...@@ -125,9 +125,6 @@ export default class HWOnline {
await stream.initialize() await stream.initialize()
this.localStream = stream; this.localStream = stream;
console.log('local stream: ', stream);
this.streams.push(stream)
this.subscribedCb(this.streams)
return stream return stream
} }
...@@ -169,6 +166,8 @@ export default class HWOnline { ...@@ -169,6 +166,8 @@ export default class HWOnline {
console.log('stream-added: ', event) console.log('stream-added: ', event)
const {stream} = event const {stream} = event
this.client.subscribe(stream, { video: true, audio: true}) this.client.subscribe(stream, { video: true, audio: true})
console.log('stream-added: addCb')
this.addCb(stream)
}) })
// 远端流删除事件,当取消选看远端用户或者原来已经选看的远端用户退出房间后会收到该事件通知。 // 远端流删除事件,当取消选看远端用户或者原来已经选看的远端用户退出房间后会收到该事件通知。
this.client.on('stream-removed', (event) => { this.client.on('stream-removed', (event) => {
...@@ -178,6 +177,7 @@ export default class HWOnline { ...@@ -178,6 +177,7 @@ export default class HWOnline {
this.streams.splice(index, 1) this.streams.splice(index, 1)
} }
this.subscribedCb && this.subscribedCb(this.streams); this.subscribedCb && this.subscribedCb(this.streams);
this.removeCb(stream)
}) })
// 远端流更新事件,当远端用户的流发生变化,例如添加或者移除音视频轨,视频轨规格变化时会收到该事件通知。 // 远端流更新事件,当远端用户的流发生变化,例如添加或者移除音视频轨,视频轨规格变化时会收到该事件通知。
this.client.on('stream-updated', (event) => { this.client.on('stream-updated', (event) => {
...@@ -218,6 +218,16 @@ export default class HWOnline { ...@@ -218,6 +218,16 @@ export default class HWOnline {
this.subscribedCb = cb this.subscribedCb = cb
} }
// add
addStream(cb) {
this.addCb = cb
}
// remove
removeStream(cb) {
this.removeCb = cb
}
// 有用户加入房间的回调 // 有用户加入房间的回调
userJoinCb(cb) { userJoinCb(cb) {
this.joinCb = cb this.joinCb = cb
......
<template> <template>
<div ref="gk_screen_std" class="gk-screen-std"> <div ref="gk_screen_std" class="gk-screen-std">
<div v-if="questionType === 1 || questionType === 2" ref="vd"> <div v-if="isChoice" ref="vd">
<geek-draw-board <geek-draw-board
ref="draw" ref="draw"
:points="paints[currentIndex]" :points="paints[currentIndex]"
...@@ -16,14 +16,9 @@ ...@@ -16,14 +16,9 @@
:key="itm.title" :key="itm.title"
>{{ itm.name }} >{{ itm.name }}
</el-button> </el-button>
<el-button @click="sendAnswer"
type="primary"
class="itm"
:disabled="disabled">提交
</el-button>
</div> </div>
</div> </div>
<div v-if="questionType === 0"> <div v-else>
<div class="ans-wrap"> <div class="ans-wrap">
<el-button <el-button
v-for="itm in Answers" v-for="itm in Answers"
...@@ -37,14 +32,10 @@ ...@@ -37,14 +32,10 @@
</el-button> </el-button>
</div> </div>
</div> </div>
<el-button v-if="questionType === 0 "
type="primary" <el-button type="primary" @click="sendChoose" :disabled="false" class="ans-commit">
@click="sendAnswer"
:disabled="disabled"
class="ans-commit">
提交 提交
</el-button> </el-button>
<div class="none" v-if="questionType === -1" >暂无题目作答,请等候老师发送</div>
</div> </div>
</template> </template>
...@@ -78,9 +69,8 @@ export default { ...@@ -78,9 +69,8 @@ export default {
paints: [], paints: [],
paintType: '', paintType: '',
currentIndex: '', currentIndex: '',
questionType: -1, isChoice: true,
paintTypes, paintTypes
getMsg: {}
}; };
}, },
methods: { methods: {
...@@ -96,22 +86,13 @@ export default { ...@@ -96,22 +86,13 @@ export default {
console.log(value); console.log(value);
this.currentAns = value; this.currentAns = value;
}, },
sendAnswer() { sendChoose() {
let msg = '' console.log('currentPaintData', this.$refs.draw.getImg());
if (this.questionType === 0) {
msg = this.currentAns
} else if (this.questionType === 1 || this.questionType === 2) {
msg = this.$refs.draw.getImg()
} else {
msg = ''
}
socket.sendGroupMsg( socket.sendGroupMsg(
{ {
payload: { type: 'answer',
type: this.questionType, message: this.currentAns,
answer: msg, questionType: ''
}
}, },
(data) => { (data) => {
console.log('回执', data); console.log('回执', data);
...@@ -121,22 +102,17 @@ export default { ...@@ -121,22 +102,17 @@ export default {
}, },
dealMsg(msg) { dealMsg(msg) {
console.log('msg', msg); console.log('msg', msg);
this.getMsg = msg if (msg && msg.from && msg.from.indexOf('teacher') > -1 && msg.type === 'question') {
// 42["msg",{"from":"teacher-1608135771425","type":"question", this.disabled = false;
// "payload":{"type":0,"title":"选择题"}}]
if (msg && msg.from && msg.from.indexOf('teacher') > -1 && msg.payload.type > -1) {
this.questionType = msg.payload.type
} }
console.log('msg', this.questionType);
} }
}, },
beforeDestroy() { beforeDestroy() {
this.getMsg = {} // socket.offMsg(this.dealMsg);
socket.offMsg(this.dealMsg);
}, },
mounted() { mounted() {
this.paintType = 'pencil'; this.paintType = 'pencil';
socket.onMsg(this.dealMsg); // socket.onMsg(this.dealMsg);
document.body.addEventListener('touchmove', (e) => { document.body.addEventListener('touchmove', (e) => {
e.preventDefault(); e.preventDefault();
}, { passive: false }); }, { passive: false });
...@@ -150,6 +126,7 @@ export default { ...@@ -150,6 +126,7 @@ export default {
display: flex; display: flex;
flex-flow: column; flex-flow: column;
align-items: center; align-items: center;
overflow: hidden;
.tools-wrap { .tools-wrap {
position: fixed; position: fixed;
left: 20px; left: 20px;
...@@ -166,7 +143,7 @@ export default { ...@@ -166,7 +143,7 @@ export default {
} }
} }
.draw-board { .draw-board {
height: 100vh; height: 80vh;
width: 100vw; width: 100vw;
background: #f5f5f5; background: #f5f5f5;
} }
...@@ -188,9 +165,5 @@ export default { ...@@ -188,9 +165,5 @@ export default {
font-size: 40px; font-size: 40px;
margin-top: 5vh; margin-top: 5vh;
} }
.none{
font-size: 26px;
margin-top: 40vh;
}
} }
</style> </style>
...@@ -76,7 +76,12 @@ export default { ...@@ -76,7 +76,12 @@ export default {
} }
const routeName = joinObj.path const routeName = joinObj.path
socket.connect(userId, () => { socket.connect(userId, () => {
this.$router.push({ name: routeName, query: { userId, roomId: this.roomId }}) this.$router.push({
name: routeName,
query: {
userId, roomId: this.roomId, username: this.username
}
})
}) })
} }
}, },
......
<template> <template>
<div class="home"> <div class="home">
<div class="player"> <div class="player">
<RtcPlayer :stream="mainStream" class="local-player" /> <div v-if="mainStream"
:id="mainStream.getType() === 'local' ? mainStream.getId() : `player_${mainStream.getId()}`"
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>
<div class="side"> <div class="side">
<el-form ref="form" label-width="80px" style="margin-top: 30px"> <el-form ref="form" label-width="80px" style="margin-top: 30px">
<!-- <el-row :gutter="8">
<el-col :span="24">
<el-form-item label="房间号">
<el-input v-model="roomId" placeholder="Please input roomid" type='number'></el-input>
</el-form-item>
</el-col>
</el-row> -->
<el-row :gutter="8"> <el-row :gutter="8">
<el-col :span="24"> <el-col :span="24">
<el-form-item label="麦克风"> <el-form-item label="麦克风">
...@@ -39,8 +34,9 @@ ...@@ -39,8 +34,9 @@
<el-button type="primary" @click="play">加入房间</el-button> <el-button type="primary" @click="play">加入房间</el-button>
</div> </div>
<div class="stream-pre"> <div class="stream-pre">
<RtcPlayer @click="clickItm(itm)" <div @click="clickItm(itm, index)"
class="item" v-for="(itm, index) in subStreams" :stream="itm" :key="index" /> class="item" v-for="(itm, index) in subStreams" :key="itm.getId()"
:id="itm.getType() === 'local' ? itm.getId() : `player_${itm.getId()}`" />
</div> </div>
</div> </div>
</div> </div>
...@@ -49,7 +45,6 @@ ...@@ -49,7 +45,6 @@
<script> <script>
// eslint-disable-next-line import/no-unresolved // eslint-disable-next-line import/no-unresolved
import HWRTC from '@/utils/hwrtc' import HWRTC from '@/utils/hwrtc'
import RtcPlayer from '@/components/rct-play'
export default { export default {
data() { data() {
...@@ -66,12 +61,12 @@ export default { ...@@ -66,12 +61,12 @@ export default {
streams: [], streams: [],
localStream: null, localStream: null,
isJoin: false, isJoin: false,
mainId: '' mainId: '',
mainStream: null,
} }
}, },
name: 'Home', name: 'Home',
components: { components: {
RtcPlayer
}, },
watch: { watch: {
microId(N, O) { microId(N, O) {
...@@ -79,19 +74,15 @@ export default { ...@@ -79,19 +74,15 @@ export default {
}, },
camerId(N, O) { camerId(N, O) {
if (N !== O && this.isJoin) this.localStream.switchDevice('video', N); if (N !== O && this.isJoin) this.localStream.switchDevice('video', N);
} },
}, },
computed: { computed: {
subStreams() { subStreams() {
const subs = (this.streams || []).filter((itm) => itm !== this.mainStream) const subs = (this.streams || []).filter((itm) => !this.mainStream
console.log('subs: **** ', subs) || itm.getId() !== this.mainStream.getId())
console.log('===: sub', subs)
return 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() {
...@@ -100,16 +91,40 @@ export default { ...@@ -100,16 +91,40 @@ export default {
this.localStream = await this.rtc.createStream(this.microId, this.camerId) this.localStream = await this.rtc.createStream(this.microId, this.camerId)
await this.rtc.publish(this.localStream) await this.rtc.publish(this.localStream)
this.isJoin = true this.isJoin = true
this.mainStream = this.localStream
this.streams.push(this.mainStream)
console.log('=====: ', this.localStream.getType())
this.$nextTick(() => {
this.playStream(this.mainStream)
})
} catch (error) { } catch (error) {
console.log('创建失败: ', error) console.log('创建失败: ', error)
} }
}, },
playStream(stream) {
// eslint-disable-next-line no-unused-expressions
const isLocal = stream.getType() === 'local';
if (isLocal) {
console.log('===== local : ', stream)
stream.play(stream.getId(), { muted: false, objectFit: 'cover' })
} else {
console.log('===== remote', stream)
stream.play(`player_${stream.getId()}`, { muted: false, objectFit: 'cover' })
}
},
fullPlayer() { fullPlayer() {
console.log('full') console.log('full')
// document.querySelector('#player').requestFullscreen() // document.querySelector('#player').requestFullscreen()
}, },
clickItm(itm) { async clickItm(itm) {
this.mainId = itm.getId() await this.mainStream.stop()
await itm.stop()
const tmp = this.mainStream
this.mainStream = itm;
this.$nextTick(() => {
this.playStream(this.mainStream)
this.playStream(tmp)
})
} }
}, },
async mounted() { async mounted() {
...@@ -126,8 +141,22 @@ export default { ...@@ -126,8 +141,22 @@ export default {
this.rtc = new HWRTC(userId || (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()
this.rtc.subscribedStreamCb((streams) => { // this.rtc.subscribedStreamCb((streams) => {
this.streams = streams // this.streams = streams
// })
this.rtc.addStream((stream) => {
this.streams.push(stream)
console.log('add: ', stream)
setTimeout(() => {
this.playStream(stream)
}, 100);
})
this.rtc.removeStream((stream) => {
const index = this.streams.findIndex((itm) => itm.getId() === stream.getId())
console.log('removeStream::::', stream)
if (index > -1) {
this.streams.splice(index, 1)
}
}) })
}, },
beforeDestroy() { beforeDestroy() {
......
...@@ -2,14 +2,25 @@ ...@@ -2,14 +2,25 @@
<div class="paint-main" ref="pain_main"> <div class="paint-main" ref="pain_main">
<img :src="currentImg" class="bg"/> <img :src="currentImg" class="bg"/>
<geek-draw-board ref="draw" <geek-draw-board ref="draw"
:points="paints[currentIndex]" :paintType="paintType" class="draw-board" /> :points="paints[currentIndex]" paintColor='#FFF' :paintType="paintType" class="draw-board" />
<div class="tools-wrap"> <div class="tools-wrap">
<el-button class="itm" type="info" @click="changeTool(itm.title)" <el-button class="itm" type="info" @click="changeTool(itm.title)"
v-for="itm in paintTypes" :key="itm.title">{{ itm.name }}</el-button> v-for="itm in paintTypes" :key="itm.title">{{ itm.name }}</el-button>
</div> </div>
<div class="stream-wrap"> <div class="stream-wrap">
<el-button class="itm" type="text" @click="steamAction(itm.title)" <template v-for="itm in streamTypes">
v-for="itm in streamTypes" :key="itm.title">{{ itm.name }}</el-button> <el-button class="itm" type="text" v-if="itm.type !== 'down'" @click="steamAction(itm.title)"
:key="itm.title">{{ itm.name }}</el-button>
<el-dropdown v-else :key="itm.title">
<span class="el-dropdown-link">
{{ itm.name }}
</span>
<el-dropdown-menu slot="dropdown">
<el-dropdown-item @click.native="startAnswer(op)" v-for="op in itm.options"
:key="op.title">{{op.title}}</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
</template>
</div> </div>
<div class="reply-wrap"> <div class="reply-wrap">
...@@ -66,10 +77,19 @@ const paintTypes = [ ...@@ -66,10 +77,19 @@ const paintTypes = [
] ]
const streamTypes = [ const streamTypes = [
{ title: 'ans', name: '学生答题' }, {
{ title: 'publish', name: '开始推流' }, title: 'ans',
{ title: 'unpublish', name: '停止推流' }, name: '学生答题',
{ title: 'setting', name: '设置' }, type: 'down',
options: [
{ title: '选择题', value: 0 },
{ title: '简答题', value: 1 },
{ title: '填空题', value: 2 }
]
},
// { title: 'publish', name: '开始推流' },
// { title: 'unpublish', name: '停止推流' },
// { title: 'setting', name: '设置' },
{ title: 'full', name: '全屏' }, { title: 'full', name: '全屏' },
] ]
...@@ -127,6 +147,9 @@ export default { ...@@ -127,6 +147,9 @@ export default {
} }
this.paintType = title this.paintType = title
}, },
startAnswer(opt) {
this.sendAnswerTag(opt.value, opt.title)
},
async steamAction(action) { async steamAction(action) {
if (action === 'setting') { if (action === 'setting') {
this.modal = true this.modal = true
...@@ -134,27 +157,27 @@ export default { ...@@ -134,27 +157,27 @@ export default {
if (action === 'publish') { if (action === 'publish') {
this.rtc.createStream(this.mico, this.camera) this.rtc.createStream(this.mico, this.camera)
} }
if (action === 'ans') {
this.sendAnswerTag();
}
if (action === 'full') { if (action === 'full') {
// eslint-disable-next-line no-unused-expressions // eslint-disable-next-line no-unused-expressions
this.$refs.pain_main && this.$refs.pain_main.requestFullscreen(); this.$refs.pain_main && this.$refs.pain_main.requestFullscreen();
} }
}, },
sendAnswerTag() { sendAnswerTag(type, title) {
this.replyList = [] this.replyList = []
socket.sendGroupMsg({ socket.sendGroupMsg({
type: 'question', type: 'question',
options: ['A', 'B', 'C', 'D'], payload: {
message: '请答题' type,
title,
}
}, (res) => { }, (res) => {
console.log('teacher send success: ', res); console.log('teacher send success: ', res);
}) })
}, },
registerMsgReceived() { registerMsgReceived() {
socket.onMsg((data) => { socket.onMsg((data) => {
this.replyList.push(data); const { type, payload } = data
if (type === 'answer') this.replyList.push(payload);
}) })
}, },
preAction() { preAction() {
...@@ -251,9 +274,15 @@ export default { ...@@ -251,9 +274,15 @@ export default {
animation: reply 1.2s linear; animation: reply 1.2s linear;
} }
} }
::v-deep .el-button--text { ::v-deep {
.el-button--text {
color: white; color: white;
} }
.el-dropdown {
margin-right: 20px;
color: white;
}
}
} }
@keyframes reply { @keyframes reply {
......
...@@ -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#bbe448fbefb1487d4b5f16596458d8062b79700f" resolved "http://git.jksxb.cn:8081/repository/geek/@geek/geekui/-/geekui-1.1.2.tgz#8ef29a981ee01139ee73a9389058619595df2a88"
integrity sha512-TBPYSECTJknnBs7dSNdQLM+rnoMItpC3HBILLr3YuQCUdvmJdRsbaxlMokfEKv6a3sceAPWHCsnqEl7S4N+2yw== integrity sha512-bQ5lvdCZfFb8gy4iNsphljJBA/eUgJe6vzrIF+u0JXlS+7aGCvO3nOIqbkUwEEUBJHZfiz/XzISy+59gJCobgw==
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