Commit 7c3ee642 authored by huanglu's avatar huanglu

feat: update

parent 8aff9e91
......@@ -65,13 +65,13 @@ export default class HWOnline {
this.client = client;
}
joinRoom(roomId) {
joinRoom(roomId, role) {
const ctimeDst = 7200000
const ctime = Math.floor((ctimeDst + new Date().getTime()) / 1000).toString()
const message = `${this.appId}+${roomId}+${this.userId}+${ctime}`
return this._joinRoom(roomId, {
userId: this.userId,
role: 0,
role,
ctime,
userName: `${this.userId}`,
signature: CryptoJS.HmacSHA256(message, this.appId).toString(),
......@@ -115,14 +115,19 @@ export default class HWOnline {
video: !!cameraId,
cameraId,
});
stream.setScreenProfile({
width: 1920,
height: 1080
});
// stream.setVideoProfile({
// height: 1080,
// width: 1980,
// // bitrate: 2400
// });
stream.setVideoProfile('720p_1');
await stream.initialize()
await this.publish(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
}
......
import io from 'socket.io-client'
import axios from 'axios'
const socketUrl = 'ws://payx.jkwljy.com/socket.io'
const socketUrl = 'wss://172.10.1.201:7001/'
const http = axios.create({
baseURL: socketUrl,
......
......@@ -23,10 +23,10 @@ export default {
async mounted() {
const { userId, roomId } = this.$route.query
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) => {
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;
})
}
......
......@@ -6,7 +6,7 @@
<el-row :gutter="10">
<el-col :span="24">
<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-col>
<el-col :span="24">
......@@ -39,7 +39,7 @@
</template>
<script>
import socket from '@/utils/socket'
// import socket from '@/utils/socket'
const joinTypes = [
{title: '学生大屏', value: 'student', path: 'big-screen'},
......@@ -54,7 +54,7 @@ export default {
components: {},
data() {
return {
username: '',
userId: '',
roomId: '1234',
roomName: '',
joinType: '学生大屏',
......@@ -63,21 +63,21 @@ export default {
},
methods: {
join() {
if (!this.roomId) {
if (!this.roomId || !this.userId) {
this.$alert('请填写房间号')
return
}
const joinObj = this.joinTypes.find((itm) => itm.title === this.joinType)
let userId = null
if (joinObj.value.includes('teacher')) {
userId = `teacher-${new Date().getTime()}`
} else {
userId = `${new Date().getTime()}`
}
// let userId = null
// if (joinObj.value.includes('teacher')) {
// userId = `teacher-${new Date().getTime()}`
// } else {
// userId = `${new Date().getTime()}`
// }
const routeName = joinObj.path
socket.connect(userId, () => {
this.$router.push({ name: routeName, query: { userId, roomId: this.roomId }})
})
// socket.connect(userId, () => {
this.$router.push({ name: routeName, query: { userId: this.userId, roomId: this.roomId }})
// })
}
},
mounted() {
......
<template>
<div class="home">
<div class="player">
<RtcPlayer :stream="localStream" class="local-player" />
<RtcPlayer :stream="mainStream" class="local-player" />
<el-button v-if="isJoin" type="primary"
@click.native="fullPlayer" class="full-screen">全屏</el-button>
</div>
......@@ -38,9 +38,10 @@
<div class="operation">
<el-button type="primary" @click="play">加入房间</el-button>
</div>
</div>
<div class="stream-pre">
<RtcPlayer class="item" v-for="(itm, index) in streams" :stream="itm" :key="index" />
<div class="stream-pre">
<RtcPlayer @click="clickItm(itm)"
class="item" v-for="(itm, index) in subStreams" :stream="itm" :key="index" />
</div>
</div>
</div>
</template>
......@@ -57,14 +58,15 @@ export default {
show: true,
output: '',
rtc: null,
roomId: null,
roomId: '',
micro: [],
microId: '123',
microId: '',
cameras: [],
camerId: '',
streams: [],
localStream: null,
isJoin: false
isJoin: false,
mainId: ''
}
},
name: 'Home',
......@@ -79,39 +81,51 @@ export default {
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: {
async play() {
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.play('player', { muted: false, objectFit: 'contain' })
await this.rtc.publish(this.localStream)
this.isJoin = true
} catch (error) {
console.log('创建失败: ', error)
}
},
join() {
this.rtc.joinRoom(this.roomId)
},
fullPlayer() {
console.log('full')
document.querySelector('#player').requestFullscreen()
// document.querySelector('#player').requestFullscreen()
},
clickItm(itm) {
this.mainId = itm.getId()
}
},
async mounted() {
console.log('mounted')
const { roomId } = this.$route.query
const { roomId, userId } = this.$route.query
this.roomId = roomId
this.userId = userId
// eslint-disable-next-line no-underscore-dangle
const ok = await HWRTC.getAuthUserMedia()
if (!ok) {
this.$alert('无摄像头和和麦克风权限');
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.micro = await this.rtc.getMicrophones()
console.log(this.cameras, this.micro)
this.rtc.subscribedStreamCb((streams) => {
this.streams = streams
})
......@@ -133,19 +147,17 @@ export default {
position: relative;
.side {
width: 20vw;
}
.stream-pre {
position: absolute;
top: 10px;
left: 0;
width: calc(100% - 20vw);
overflow: auto;
display: flex;
flex-flow: row;
.item {
margin-left: 10px;
width: 300px;
height: 220px;
flex-flow: column;
align-items: stretch;
.stream-pre {
flex: 1;
overflow: auto;
margin-top: 20px;
.item {
width: 100%;
height: 220px;
}
}
}
.operation {
......
......@@ -2,7 +2,7 @@
<div class="paint-main" ref="pain_main">
<img :src="currentImg" class="bg"/>
<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">
<el-button class="itm" type="info" @click="changeTool(itm.title)"
v-for="itm in paintTypes" :key="itm.title">{{ itm.name }}</el-button>
......@@ -45,8 +45,8 @@
import { GeekDrawBoard } from '@geek/geekui'
import Vue from 'vue'
import { videoBg, bg } from '@/assets/images/index'
import HWRTC from '@/utils/hwrtc'
import socket from '@/utils/socket'
// import HWRTC from '@/utils/hwrtc'
// import socket from '@/utils/socket'
const paintTypes = [
{ title: 'pencil', name: '铅笔', width: 20 },
......@@ -56,10 +56,19 @@ const paintTypes = [
]
const streamTypes = [
{ title: 'ans', name: '学生答题' },
{ title: 'publish', name: '开始推流' },
{ title: 'unpublish', name: '停止推流' },
{ title: 'setting', name: '设置' },
{
title: 'ans',
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: '全屏' },
]
......@@ -95,8 +104,8 @@ export default {
return imgs[this.currentIndex];
},
currentPaintData() {
const nn = this.points ? this.points[this.currentIndex] : [];
console.log(nn)
const nn = (this.paints || [])[this.currentIndex]
console.log('currentPaintData : ', nn)
return nn
}
},
......@@ -114,7 +123,8 @@ export default {
this.modal = true
}
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') {
this.sendAnswerTag();
......@@ -126,18 +136,18 @@ export default {
},
sendAnswerTag() {
this.replyList = []
socket.sendGroupMsg({
type: 'question',
options: ['A', 'B', 'C', 'D'],
message: '请答题'
}, (res) => {
console.log('teacher send success: ', res);
})
// socket.sendGroupMsg({
// type: 'question',
// options: ['A', 'B', 'C', 'D'],
// message: '请答题'
// }, (res) => {
// console.log('teacher send success: ', res);
// })
},
registerMsgReceived() {
socket.onMsg((data) => {
this.replyList.push(data);
})
// socket.onMsg((data) => {
// this.replyList.push(data);
// })
},
preAction() {
const paintData = this.$refs.draw.getData()
......@@ -154,19 +164,6 @@ export default {
},
async mounted() {
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()
}
}
......
......@@ -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#346611159cc7e8bd37784e5d24310a56adb69434"
integrity sha512-wR4K6iz4HG1f937HAvloiS4dHp7GdvWBJnr+C8f7OxmLynDUqZGFAulYhQCwHfPodI3kUpRYkPxxM53oZiMtlg==
resolved "http://git.jksxb.cn:8081/repository/geek/@geek/geekui/-/geekui-1.1.2.tgz#bbe448fbefb1487d4b5f16596458d8062b79700f"
integrity sha512-TBPYSECTJknnBs7dSNdQLM+rnoMItpC3HBILLr3YuQCUdvmJdRsbaxlMokfEKv6a3sceAPWHCsnqEl7S4N+2yw==
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