Commit 7c3ee642 authored by huanglu's avatar huanglu

feat: update

parent 8aff9e91
...@@ -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
} }
......
import io from 'socket.io-client' import io from 'socket.io-client'
import axios from 'axios' import axios from 'axios'
const socketUrl = 'ws://payx.jkwljy.com/socket.io' const socketUrl = 'wss://172.10.1.201:7001/'
const http = axios.create({ const http = axios.create({
baseURL: socketUrl, baseURL: socketUrl,
......
...@@ -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;
}) })
} }
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
<el-row :gutter="10"> <el-row :gutter="10">
<el-col :span="24"> <el-col :span="24">
<el-form-item label="用户名"> <el-form-item label="用户名">
<el-input class="input" v-model="username" placeholder="请输入用户名"></el-input> <el-input class="input" v-model="userId" placeholder="请输入用户名"></el-input>
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :span="24"> <el-col :span="24">
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
</template> </template>
<script> <script>
import socket from '@/utils/socket' // import socket from '@/utils/socket'
const joinTypes = [ const joinTypes = [
{title: '学生大屏', value: 'student', path: 'big-screen'}, {title: '学生大屏', value: 'student', path: 'big-screen'},
...@@ -54,7 +54,7 @@ export default { ...@@ -54,7 +54,7 @@ export default {
components: {}, components: {},
data() { data() {
return { return {
username: '', userId: '',
roomId: '1234', roomId: '1234',
roomName: '', roomName: '',
joinType: '学生大屏', joinType: '学生大屏',
...@@ -63,21 +63,21 @@ export default { ...@@ -63,21 +63,21 @@ export default {
}, },
methods: { methods: {
join() { join() {
if (!this.roomId) { if (!this.roomId || !this.userId) {
this.$alert('请填写房间号') this.$alert('请填写房间号')
return 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')) {
userId = `teacher-${new Date().getTime()}` // userId = `teacher-${new Date().getTime()}`
} else { // } else {
userId = `${new Date().getTime()}` // userId = `${new Date().getTime()}`
} // }
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: this.userId, roomId: this.roomId }})
}) // })
} }
}, },
mounted() { mounted() {
......
<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 class="item" v-for="(itm, index) in streams" :stream="itm" :key="index" /> <RtcPlayer @click="clickItm(itm)"
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,21 +147,19 @@ export default { ...@@ -133,21 +147,19 @@ export default {
position: relative; position: relative;
.side { .side {
width: 20vw; width: 20vw;
} display: flex;
flex-flow: column;
align-items: stretch;
.stream-pre { .stream-pre {
position: absolute; flex: 1;
top: 10px;
left: 0;
width: calc(100% - 20vw);
overflow: auto; overflow: auto;
display: flex; margin-top: 20px;
flex-flow: row;
.item { .item {
margin-left: 10px; width: 100%;
width: 300px;
height: 220px; height: 220px;
} }
} }
}
.operation { .operation {
text-align: center; text-align: center;
} }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<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" /> :paints="currentPaintData" :key="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>
...@@ -45,8 +45,8 @@ ...@@ -45,8 +45,8 @@
import { GeekDrawBoard } from '@geek/geekui' import { GeekDrawBoard } from '@geek/geekui'
import Vue from 'vue' import Vue from 'vue'
import { videoBg, bg } 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'
const paintTypes = [ const paintTypes = [
{ title: 'pencil', name: '铅笔', width: 20 }, { title: 'pencil', name: '铅笔', width: 20 },
...@@ -56,10 +56,19 @@ const paintTypes = [ ...@@ -56,10 +56,19 @@ const paintTypes = [
] ]
const streamTypes = [ const streamTypes = [
{ title: 'ans', name: '学生答题' }, {
{ title: 'publish', name: '开始推流' }, title: 'ans',
{ title: 'unpublish', name: '停止推流' }, name: '学生答题',
{ title: 'setting', name: '设置' }, actions: [
{ title: '选择题', value: 0 },
{ title: '简答题', value: 1 },
{ title: '填空题', value: 2 },
],
type: 'drown'
},
// { title: 'publish', name: '开始推流' },
// { title: 'unpublish', name: '停止推流' },
// { title: 'setting', name: '设置' },
{ title: 'full', name: '全屏' }, { title: 'full', name: '全屏' },
] ]
...@@ -95,8 +104,8 @@ export default { ...@@ -95,8 +104,8 @@ export default {
return imgs[this.currentIndex]; return imgs[this.currentIndex];
}, },
currentPaintData() { currentPaintData() {
const nn = this.points ? this.points[this.currentIndex] : []; const nn = (this.paints || [])[this.currentIndex]
console.log(nn) console.log('currentPaintData : ', nn)
return nn return nn
} }
}, },
...@@ -114,7 +123,8 @@ export default { ...@@ -114,7 +123,8 @@ export default {
this.modal = true this.modal = true
} }
if (action === 'publish') { if (action === 'publish') {
this.rtc.createStream(this.mico, this.camera) const stream = await this.rtc.createStream(this.mico, this.camera)
await this.rtc.publish(stream)
} }
if (action === 'ans') { if (action === 'ans') {
this.sendAnswerTag(); this.sendAnswerTag();
...@@ -126,18 +136,18 @@ export default { ...@@ -126,18 +136,18 @@ export default {
}, },
sendAnswerTag() { sendAnswerTag() {
this.replyList = [] this.replyList = []
socket.sendGroupMsg({ // socket.sendGroupMsg({
type: 'question', // type: 'question',
options: ['A', 'B', 'C', 'D'], // options: ['A', 'B', 'C', 'D'],
message: '请答题' // message: '请答题'
}, (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); // this.replyList.push(data);
}) // })
}, },
preAction() { preAction() {
const paintData = this.$refs.draw.getData() const paintData = this.$refs.draw.getData()
...@@ -154,19 +164,6 @@ export default { ...@@ -154,19 +164,6 @@ export default {
}, },
async mounted() { async mounted() {
this.paintType = 'pencil' this.paintType = 'pencil'
const { roomId } = this.$route.query
const ok = await HWRTC.getAuthUserMedia()
if (!ok) {
this.$alert('无摄像头和和麦克风权限');
return;
}
this.rtc = new HWRTC(`teacher${(new Date().getTime() / 1000).toFixed(0)}`);
this.cameras = await this.rtc.getCameras()
this.camera = (this.cameras[0] || {}).deviceId
this.micros = await this.rtc.getMicrophones()
await this.rtc.joinRoom(roomId)
this.isJoin = true
this.mico = (this.micros[0] || {}).deviceId
this.registerMsgReceived() this.registerMsgReceived()
} }
} }
......
...@@ -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