1.重构实时消息WebSocket连接
2.MySQL备份
This commit is contained in:
@@ -35,33 +35,6 @@ export const getUrl = (): string => {
|
||||
return value == 'getCurrentDomain' ? window.location.protocol + '//' + window.location.host : value
|
||||
}
|
||||
|
||||
/**
|
||||
* Webman Push 在 API 上的 HTTP 根地址(私有频道 POST /plugin/webman/push/auth 等)。
|
||||
* 与 VITE_AXIOS_BASE_URL 一致;开发环境为空时用当前页面源,配合 Vite 对 /plugin 的代理。
|
||||
*/
|
||||
export function getPushHttpBase(): string {
|
||||
const api = getUrl()
|
||||
if (api) {
|
||||
return api.replace(/\/$/, '')
|
||||
}
|
||||
return window.location.protocol + '//' + window.location.host
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载 push.js 的绝对 URL:文件放在 web/public/plugin/webman/push/,随 dist 与后台同源发布,
|
||||
* 不依赖 API 站点是否暴露 /plugin/webman/push/push.js。
|
||||
*/
|
||||
export function getPushScriptUrl(): string {
|
||||
let base = import.meta.env.BASE_URL
|
||||
if (typeof base !== 'string' || base === '') {
|
||||
base = '/'
|
||||
}
|
||||
if (!base.endsWith('/')) {
|
||||
base = base + '/'
|
||||
}
|
||||
return window.location.origin + base + 'plugin/webman/push/push.js'
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据运行环境获取基础请求URL的端口
|
||||
*/
|
||||
|
||||
@@ -1,84 +0,0 @@
|
||||
/**
|
||||
* 后台推送频道测试:加载官方 push.js 并订阅频道、监听文档约定事件
|
||||
*/
|
||||
|
||||
import { getPushHttpBase, getPushScriptUrl } from '/@/utils/axios'
|
||||
|
||||
const DOC_EVENTS = [
|
||||
'period.tick',
|
||||
'period.locked',
|
||||
'period.opened',
|
||||
'period.payout',
|
||||
'jackpot.hit',
|
||||
'bet.accepted',
|
||||
'bet.settled',
|
||||
'wallet.changed',
|
||||
'notice.popout',
|
||||
'withdraw.review_required',
|
||||
]
|
||||
|
||||
export async function loadPushJs(): Promise<void> {
|
||||
if ((window as any).Push) {
|
||||
return
|
||||
}
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
const script = document.createElement('script')
|
||||
script.src = getPushScriptUrl()
|
||||
script.onload = () => resolve()
|
||||
script.onerror = () => reject(new Error('load push.js failed'))
|
||||
document.head.appendChild(script)
|
||||
})
|
||||
}
|
||||
|
||||
export type PushTestLogLine = { t: number; event: string; payload: string }
|
||||
|
||||
export function startPushChannelListener(options: {
|
||||
url: string
|
||||
app_key: string
|
||||
channel: string
|
||||
/** 私有频道需走 /plugin/webman/push/auth */
|
||||
usePrivateAuth: boolean
|
||||
onLog: (line: PushTestLogLine) => void
|
||||
onConnected: (ok: boolean) => void
|
||||
}): { disconnect: () => void } {
|
||||
const PushCtor = (window as any).Push
|
||||
const cfg: anyObj = { url: options.url, app_key: options.app_key }
|
||||
if (options.usePrivateAuth) {
|
||||
cfg.auth = `${getPushHttpBase()}/plugin/webman/push/auth`
|
||||
}
|
||||
const client = new PushCtor(cfg)
|
||||
const ch = client.subscribe(options.channel)
|
||||
|
||||
const pushLog = (event: string, data: unknown) => {
|
||||
let payload = ''
|
||||
try {
|
||||
payload = typeof data === 'string' ? data : JSON.stringify(data)
|
||||
} catch {
|
||||
payload = String(data)
|
||||
}
|
||||
options.onLog({ t: Date.now(), event, payload })
|
||||
}
|
||||
|
||||
ch.on('pusher:subscription_succeeded', () => {
|
||||
options.onConnected(true)
|
||||
pushLog('pusher:subscription_succeeded', {})
|
||||
})
|
||||
|
||||
for (const ev of DOC_EVENTS) {
|
||||
ch.on(ev, (data: unknown) => {
|
||||
options.onConnected(true)
|
||||
pushLog(ev, data)
|
||||
})
|
||||
}
|
||||
|
||||
return {
|
||||
disconnect: () => {
|
||||
try {
|
||||
client.disconnect()
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
options.onConnected(false)
|
||||
},
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user