websocket消息支持 (#188)
* 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>
This commit is contained in:
12
src/api/msg/index.ts
Normal file
12
src/api/msg/index.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import request from '../request'
|
||||
|
||||
export function api_sendMsg(userSignature: string, data: any) {
|
||||
return request<{ status: string }>({
|
||||
url: '/user-msg',
|
||||
method: 'POST',
|
||||
headers: {
|
||||
userSignature,
|
||||
},
|
||||
data,
|
||||
})
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { AxiosInstance, AxiosRequestConfig, AxiosResponse, InternalAxiosRequestConfig } from 'axios'
|
||||
import axios from 'axios'
|
||||
import openModal from '@/components/ErrorModal'
|
||||
|
||||
class Request {
|
||||
private instance: AxiosInstance
|
||||
@@ -15,14 +16,10 @@ class Request {
|
||||
this.instance.interceptors.request.use(
|
||||
(config: InternalAxiosRequestConfig) => {
|
||||
// 在发送请求之前做些什么
|
||||
console.log('请求拦截器被触发')
|
||||
|
||||
return config
|
||||
},
|
||||
(error: any) => {
|
||||
// 对请求错误做些什么
|
||||
console.error('请求拦截器发生错误:', error)
|
||||
|
||||
return Promise.reject(error)
|
||||
},
|
||||
)
|
||||
@@ -31,15 +28,16 @@ class Request {
|
||||
this.instance.interceptors.response.use(
|
||||
(response: AxiosResponse) => {
|
||||
// 对响应数据做些什么
|
||||
console.log('响应拦截器被触发')
|
||||
const responseData = response.data
|
||||
|
||||
return responseData
|
||||
return response
|
||||
},
|
||||
(error: any) => {
|
||||
// 对响应错误做些什么
|
||||
console.error('响应拦截器发生错误:', error)
|
||||
|
||||
if (error.response && error.response.data) {
|
||||
const { code, msg } = error.response.data
|
||||
openModal({ title: code, desc: msg })
|
||||
return Promise.reject(error.response.data)
|
||||
}
|
||||
openModal({ title: '请求错误', desc: error.message })
|
||||
return Promise.reject(error)
|
||||
},
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user