Commit 8aff9e91 authored by huanglu's avatar huanglu

feat: 直播

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