Commit 8aff9e91 authored by huanglu's avatar huanglu

feat: 直播

parent 0079538c
...@@ -10,6 +10,6 @@ module.exports = { ...@@ -10,6 +10,6 @@ module.exports = {
proxy: { proxy: {
...agentList ...agentList
}, },
publicPath: '/gk-online', publicPath: './',
outputDir: 'gk-online' outputDir: 'gk-online'
} }
...@@ -15,5 +15,3 @@ new Vue({ ...@@ -15,5 +15,3 @@ new Vue({
store, store,
render: (h) => h(App), render: (h) => h(App),
}).$mount('#app') }).$mount('#app')
console.log('===== main console')
import io from 'socket.io-client' import io from 'socket.io-client'
import axios from 'axios' import axios from 'axios'
const socketUrl = 'http://172.10.1.201:7001/' const socketUrl = 'ws://payx.jkwljy.com/socket.io'
const http = axios.create({ const http = axios.create({
baseURL: socketUrl, baseURL: socketUrl,
......
...@@ -21,21 +21,14 @@ export default { ...@@ -21,21 +21,14 @@ export default {
methods: { methods: {
}, },
async mounted() { async mounted() {
const { userId } = this.$route.query const { userId, roomId } = this.$route.query
console.log('mounted')
// eslint-disable-next-line no-underscore-dangle
const ok = await HWRTC.getAuthUserMedia()
if (!ok) {
this.$alert('无摄像头和和麦克风权限');
return;
}
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('123') await this.rtc.joinRoom(roomId)
this.rtc.subscribedStreamCb((streams) => { this.rtc.subscribedStreamCb((streams) => {
const stream = streams.find((itm) => itm.getUserId().includes('teacher')) console.log('subscribedStreamCb: ', streams)
const stream = streams.reverse().find((itm) => itm.getUserId().includes('teacher'))
if (stream) this.playStream = stream; if (stream) this.playStream = stream;
}) })
} }
} }
</script> </script>
......
...@@ -9,11 +9,11 @@ ...@@ -9,11 +9,11 @@
<el-input class="input" v-model="username" placeholder="请输入用户名"></el-input> <el-input class="input" v-model="username" placeholder="请输入用户名"></el-input>
</el-form-item> </el-form-item>
</el-col> </el-col>
<!-- <el-col :span="24"> <el-col :span="24">
<el-form-item label="输入房间号"> <el-form-item label="输入房间号">
<el-input class="input" v-model="roomId" placeholder="请输入房间号" type="number"></el-input> <el-input class="input" v-model="roomId" placeholder="请输入房间号"></el-input>
</el-form-item> </el-form-item>
</el-col> --> </el-col>
<!-- <el-col :span="24"> <!-- <el-col :span="24">
<el-form-item label="房间名"> <el-form-item label="房间名">
<el-input class="input" v-model="roomName" placeholder="请输入房间名"></el-input> <el-input class="input" v-model="roomName" placeholder="请输入房间名"></el-input>
...@@ -63,6 +63,10 @@ export default { ...@@ -63,6 +63,10 @@ export default {
}, },
methods: { methods: {
join() { join() {
if (!this.roomId) {
this.$alert('请填写房间号')
return
}
const joinObj = this.joinTypes.find((itm) => itm.title === this.joinType) const joinObj = this.joinTypes.find((itm) => itm.title === this.joinType)
let userId = null let userId = null
if (joinObj.value.includes('teacher')) { if (joinObj.value.includes('teacher')) {
...@@ -72,7 +76,7 @@ export default { ...@@ -72,7 +76,7 @@ export default {
} }
const routeName = joinObj.path const routeName = joinObj.path
socket.connect(userId, () => { socket.connect(userId, () => {
this.$router.push({ name: routeName, query: { userId }}) this.$router.push({ name: routeName, query: { userId, roomId: this.roomId }})
}) })
} }
}, },
......
...@@ -7,13 +7,13 @@ ...@@ -7,13 +7,13 @@
</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-row :gutter="8">
<el-col :span="24"> <el-col :span="24">
<el-form-item label="房间号"> <el-form-item label="房间号">
<el-input v-model="roomId" placeholder="Please input roomid" type='number'></el-input> <el-input v-model="roomId" placeholder="Please input roomid" type='number'></el-input>
</el-form-item> </el-form-item>
</el-col> </el-col>
</el-row> </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="麦克风">
...@@ -59,7 +59,7 @@ export default { ...@@ -59,7 +59,7 @@ export default {
rtc: null, rtc: null,
roomId: null, roomId: null,
micro: [], micro: [],
microId: '', microId: '123',
cameras: [], cameras: [],
camerId: '', camerId: '',
streams: [], streams: [],
...@@ -100,6 +100,8 @@ export default { ...@@ -100,6 +100,8 @@ export default {
}, },
async mounted() { async mounted() {
console.log('mounted') console.log('mounted')
const { roomId } = this.$route.query
this.roomId = roomId
// 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) {
...@@ -112,7 +114,6 @@ export default { ...@@ -112,7 +114,6 @@ export default {
console.log(this.cameras, this.micro) console.log(this.cameras, this.micro)
this.rtc.subscribedStreamCb((streams) => { this.rtc.subscribedStreamCb((streams) => {
this.streams = streams this.streams = streams
console.log('******: ', streams)
}) })
}, },
beforeDestroy() { beforeDestroy() {
......
<template> <template>
<div class="paint-main" ref="pain_main"> <div class="paint-main" ref="pain_main">
<img :src="videoBg" class="bg"/> <img :src="currentImg" class="bg"/>
<geek-draw-board ref="draw"
<geek-draw-board ref="draw" :paintType="paintType" class="draw-board" /> :points="paints[currentIndex]" :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>
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
<span class="itm" v-for="(itm, index) in replyList" <span class="itm" v-for="(itm, index) in replyList"
:key="index">{{ JSON.stringify(itm) }}</span> :key="index">{{ JSON.stringify(itm) }}</span>
</div> </div>
<el-dialog title="推流设置" <el-dialog title="推流设置"
width="400px" width="400px"
:visible.sync="modal"> :visible.sync="modal">
...@@ -38,12 +37,14 @@ ...@@ -38,12 +37,14 @@
<el-button type="primary" @click="modal = false">确定</el-button> <el-button type="primary" @click="modal = false">确定</el-button>
</p> </p>
</el-dialog> </el-dialog>
<el-button type="text" @click="preAction" class="pre">上一页</el-button>
<el-button type="text" @click="nextAction" class="next">下一页</el-button>
</div> </div>
</template> </template>
<script> <script>
import { GeekDrawBoard } from '@geek/geekui' import { GeekDrawBoard } from '@geek/geekui'
import Vue from 'vue' import Vue from 'vue'
import { videoBg } from '@/assets/images/index' import { videoBg, bg } from '@/assets/images/index'
import HWRTC from '@/utils/hwrtc' import HWRTC from '@/utils/hwrtc'
import socket from '@/utils/socket' import socket from '@/utils/socket'
...@@ -62,6 +63,10 @@ const streamTypes = [ ...@@ -62,6 +63,10 @@ const streamTypes = [
{ title: 'full', name: '全屏' }, { title: 'full', name: '全屏' },
] ]
const imgs = [
bg, videoBg
]
Vue.use(GeekDrawBoard) Vue.use(GeekDrawBoard)
export default { export default {
...@@ -80,9 +85,21 @@ export default { ...@@ -80,9 +85,21 @@ export default {
modal: false, modal: false,
rtc: null, rtc: null,
replyList: [], replyList: [],
paints: [] paints: [],
imgs,
currentIndex: 0
}; };
}, },
computed: {
currentImg() {
return imgs[this.currentIndex];
},
currentPaintData() {
const nn = this.points ? this.points[this.currentIndex] : [];
console.log(nn)
return nn
}
},
methods: { methods: {
changeTool(title) { changeTool(title) {
if (title === 'redo' || title === 'clear') { if (title === 'redo' || title === 'clear') {
...@@ -97,7 +114,7 @@ export default { ...@@ -97,7 +114,7 @@ export default {
this.modal = true this.modal = true
} }
if (action === 'publish') { if (action === 'publish') {
this.rtc.createScreenShareStream() this.rtc.createStream(this.mico, this.camera)
} }
if (action === 'ans') { if (action === 'ans') {
this.sendAnswerTag(); this.sendAnswerTag();
...@@ -121,10 +138,23 @@ export default { ...@@ -121,10 +138,23 @@ export default {
socket.onMsg((data) => { socket.onMsg((data) => {
this.replyList.push(data); this.replyList.push(data);
}) })
} },
preAction() {
const paintData = this.$refs.draw.getData()
this.paints[this.currentIndex] = paintData;
if (this.currentIndex === 0) this.currentIndex = 0;
else this.currentIndex -= 1;
},
nextAction() {
const paintData = this.$refs.draw.getData()
this.paints[this.currentIndex] = paintData;
if (this.currentIndex === this.imgs.length - 1) this.currentIndex = this.imgs.length - 1;
else this.currentIndex += 1;
},
}, },
async mounted() { async mounted() {
this.paintType = 'pencil' this.paintType = 'pencil'
const { roomId } = this.$route.query
const ok = await HWRTC.getAuthUserMedia() const ok = await HWRTC.getAuthUserMedia()
if (!ok) { if (!ok) {
this.$alert('无摄像头和和麦克风权限'); this.$alert('无摄像头和和麦克风权限');
...@@ -134,7 +164,7 @@ export default { ...@@ -134,7 +164,7 @@ export default {
this.cameras = await this.rtc.getCameras() this.cameras = await this.rtc.getCameras()
this.camera = (this.cameras[0] || {}).deviceId this.camera = (this.cameras[0] || {}).deviceId
this.micros = await this.rtc.getMicrophones() this.micros = await this.rtc.getMicrophones()
await this.rtc.joinRoom('123') await this.rtc.joinRoom(roomId)
this.isJoin = true this.isJoin = true
this.mico = (this.micros[0] || {}).deviceId this.mico = (this.micros[0] || {}).deviceId
this.registerMsgReceived() this.registerMsgReceived()
...@@ -147,6 +177,16 @@ export default { ...@@ -147,6 +177,16 @@ export default {
height: 100vh; height: 100vh;
width: 100vw; width: 100vw;
position: relative; position: relative;
.pre {
position: absolute;
top: 50%; left: 10px;
transform: translateY(-50%);
}
.next {
position: absolute;
top: 50%; right: 10px;
transform: translateY(-50%);
}
.bg { .bg {
height: 100vh; width: 100vw; height: 100vh; width: 100vw;
} }
...@@ -160,8 +200,8 @@ export default { ...@@ -160,8 +200,8 @@ export default {
.tools-wrap { .tools-wrap {
position: fixed; position: fixed;
left: 20px; left: 20px;
top: 50%; top: 10px;
transform: translateY(-50%); // transform: translateY(-50%);
display: flex; display: flex;
flex-flow: column; flex-flow: column;
align-items: center; align-items: center;
...@@ -188,6 +228,9 @@ export default { ...@@ -188,6 +228,9 @@ export default {
animation: reply 1.2s linear; animation: reply 1.2s linear;
} }
} }
::v-deep .el-button--text {
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#b743e50c382121813660574fcd0fa7e7bee2f124" resolved "http://git.jksxb.cn:8081/repository/geek/@geek/geekui/-/geekui-1.1.2.tgz#346611159cc7e8bd37784e5d24310a56adb69434"
integrity sha512-VyiXuzLEN7g+B43SnFm8k4GGH9CShN+cPx6MftVjpLM9Ha4Axgv1rBNgJ2HTmdnGECyXqBYgYVs/trQVLel64A== integrity sha512-wR4K6iz4HG1f937HAvloiS4dHp7GdvWBJnr+C8f7OxmLynDUqZGFAulYhQCwHfPodI3kUpRYkPxxM53oZiMtlg==
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