|
@@ -1,6 +1,6 @@
|
|
|
<template>
|
|
|
<div class="ue-wrapper">
|
|
|
- <div class="connect-status" v-show="connectStatus!=='连接成功'">连接状态:{{ connectStatus }}</div>
|
|
|
+ <div class="connect-status" v-show="connectStatus !== '连接成功'">连接状态:{{ connectStatus }}</div>
|
|
|
<div ref="videoContainerRef" class="video-container"></div>
|
|
|
<dialog id="login-dialog" data-bs-theme="dark">
|
|
|
<h2 class="mb-3 fs-6">登录以获取场景资源</h2>
|
|
@@ -23,8 +23,9 @@
|
|
|
</template>
|
|
|
|
|
|
<script setup>
|
|
|
-import { onMounted, ref, getCurrentInstance } from 'vue'
|
|
|
+import { onMounted, ref, getCurrentInstance, onBeforeUnmount } from 'vue'
|
|
|
import axios from 'axios';
|
|
|
+import baseUrl from '@/utils/peer-stream'
|
|
|
|
|
|
const { proxy } = getCurrentInstance()
|
|
|
|
|
@@ -77,6 +78,8 @@ const sendDataChannelCommand = (command) => {
|
|
|
// Call the send method on the custom peer-stream element
|
|
|
(peerStreamRef.value).emitMessage((JSON.parse(command)));
|
|
|
console.log('Sending command:', command);
|
|
|
+ } else {
|
|
|
+ console.warn('Send failed, stream is not connected:', command);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -90,44 +93,39 @@ const loginMsg = ref('')
|
|
|
function handleLogin(e) {
|
|
|
e.preventDefault();
|
|
|
console.log(form.value)
|
|
|
- const baseUrl = 'http://10.1.161.53:3000'
|
|
|
- axios.post(`${baseUrl}/auth/login`, form.value)
|
|
|
- .then(response => {
|
|
|
- if (response.status === 201) {
|
|
|
- localStorage.setItem('token', response.data.access_token);
|
|
|
- // 获取场景列表
|
|
|
- axios({
|
|
|
- method: 'get',
|
|
|
- url: baseUrl + '/scenePermission',
|
|
|
- headers: {
|
|
|
- 'Authorization': `Bearer ${localStorage.getItem('token')}`
|
|
|
- }
|
|
|
- }).then(res => {
|
|
|
- if(res.data) {
|
|
|
- const targetScene = res.data.find(row => row.name === "低空经济")
|
|
|
- if(!targetScene) {
|
|
|
- loginMsg.value = '未发现场景资源'
|
|
|
- return
|
|
|
+ axios.post(`http://${baseUrl}/auth/login`, form.value)
|
|
|
+ .then(response => {
|
|
|
+ if (response.status === 201) {
|
|
|
+ localStorage.setItem('token', response.data.access_token);
|
|
|
+ // 获取场景列表
|
|
|
+ axios({
|
|
|
+ method: 'get',
|
|
|
+ url: `http://${baseUrl}/scenePermission`,
|
|
|
+ headers: {
|
|
|
+ 'Authorization': `Bearer ${localStorage.getItem('token')}`
|
|
|
}
|
|
|
- wsConnect(targetScene.scene_id, targetScene.permission, localStorage.getItem('token'));
|
|
|
- // 添加全局调用监听
|
|
|
- proxy.$bus.on('callUE', (command) => {
|
|
|
- sendDataChannelCommand(command)
|
|
|
- })
|
|
|
- // 关闭弹窗和页面loading
|
|
|
- const dialog = document.getElementById('login-dialog')
|
|
|
- dialog.close()
|
|
|
- proxy.$bus.emit('toggleLoading', false)
|
|
|
- }
|
|
|
- })
|
|
|
- } else {
|
|
|
+ }).then(res => {
|
|
|
+ if (res.data) {
|
|
|
+ const targetScene = res.data.find(row => row.name === "低空经济")
|
|
|
+ if (!targetScene) {
|
|
|
+ loginMsg.value = '未发现场景资源'
|
|
|
+ return
|
|
|
+ }
|
|
|
+ wsConnect(targetScene.scene_id, targetScene.permission, localStorage.getItem('token'));
|
|
|
+ // 关闭弹窗和页面loading
|
|
|
+ const dialog = document.getElementById('login-dialog')
|
|
|
+ dialog.close()
|
|
|
+ proxy.$bus.emit('toggleLoading', false)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ loginMsg.value = '登录失败'
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch((e) => {
|
|
|
+ console.log(e)
|
|
|
loginMsg.value = '登录失败'
|
|
|
- }
|
|
|
- })
|
|
|
- .catch((e) => {
|
|
|
- console.log(e)
|
|
|
- loginMsg.value = '登录失败'
|
|
|
- })
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
onMounted(() => {
|
|
@@ -144,6 +142,15 @@ onMounted(() => {
|
|
|
// setTimeout(() => {
|
|
|
// proxy.$bus.emit('toggleLoading', false)
|
|
|
// }, 1000);
|
|
|
+
|
|
|
+ // 添加全局调用监听
|
|
|
+ proxy.$bus.on('callUE', (command) => {
|
|
|
+ sendDataChannelCommand(command)
|
|
|
+ })
|
|
|
+})
|
|
|
+
|
|
|
+onBeforeUnmount(() => {
|
|
|
+ proxy.$bus.off('callUE')
|
|
|
})
|
|
|
|
|
|
</script>
|