* Release (#162) * feat: ✨ websocket server demo * feat: ✨ ws server demo dev * feat: ✨ ws server and mobile page * feat: ✨ 手机端发送消息 * feat: ✨ 手机网页发送消息 * 添加了抽奖中和抽奖完成时的音效 * feat: ✨ 自定义设置弹幕服务器地址 * feat: ✨ ws not done * fix: 🐛 fix pr-185 #185 为播放音效添加控制 * feat: ✨ server worker demo not done * feat: ✨ websocket server * feat: ✨ 全局接收websocket消息并存储到indexdb中 --------- Co-authored-by: Silence@2024 <707261624@qq.com>
51 lines
1.3 KiB
Vue
51 lines
1.3 KiB
Vue
<script setup lang="ts">
|
|
import { onMounted, onUnmounted, ref, shallowRef, watch } from 'vue'
|
|
import { useToast } from 'vue-toast-notification'
|
|
import { api_sendMsg } from '@/api/msg'
|
|
import { getOriginUrl, getUniqueSignature } from '@/utils/auth'
|
|
|
|
const toast = useToast()
|
|
const mobileUrl = shallowRef<string>('')
|
|
const wsQuery = ref<{ userSignature: string }>({
|
|
userSignature: '',
|
|
})
|
|
|
|
function connectUserMsg() {
|
|
api_sendMsg(wsQuery.value.userSignature, `hello world ${wsQuery.value.userSignature}`).then((res: any) => {
|
|
toast.open({
|
|
message: res.msg || '发送成功',
|
|
type: 'success',
|
|
position: 'top-right',
|
|
})
|
|
})
|
|
}
|
|
|
|
async function getFinger() {
|
|
const userSignature = await getUniqueSignature()
|
|
wsQuery.value.userSignature = userSignature
|
|
return userSignature
|
|
}
|
|
async function setMobileUrl() {
|
|
const originUrl = getOriginUrl()
|
|
const userSignature = await getFinger()
|
|
mobileUrl.value = `${originUrl}/log-lottery/mobile?userSignature=${userSignature}`
|
|
}
|
|
onMounted(() => {
|
|
getFinger()
|
|
setMobileUrl()
|
|
})
|
|
|
|
onUnmounted(() => {
|
|
})
|
|
</script>
|
|
|
|
<template>
|
|
<div class="flex flex-col gap-3">
|
|
<button class="btn btn-primary btn-sm w-32" @click="connectUserMsg">
|
|
connectUserMsg
|
|
</button>
|
|
</div>
|
|
</template>
|
|
|
|
<style lang="scss" scoped></style>
|