Open the price stream on the TV board with the TV key header.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -44,9 +44,9 @@ class AuthPriceStream extends EventTarget {
|
||||
onmessage: (() => void) | null = null
|
||||
private abort = new AbortController()
|
||||
|
||||
constructor(url: string) {
|
||||
constructor(url: string, tvKey = '') {
|
||||
super()
|
||||
void this.start(url)
|
||||
void this.start(url, tvKey)
|
||||
}
|
||||
|
||||
close() {
|
||||
@@ -54,10 +54,12 @@ class AuthPriceStream extends EventTarget {
|
||||
this.abort.abort()
|
||||
}
|
||||
|
||||
private async start(url: string) {
|
||||
private async start(url: string, tvKey = '') {
|
||||
try {
|
||||
const headers: Record<string, string> = { Accept: 'text/event-stream' }
|
||||
if (tvKey) headers['X-Tv-Key'] = tvKey
|
||||
const response = await fetch(url, {
|
||||
headers: { Accept: 'text/event-stream' },
|
||||
headers,
|
||||
cache: 'no-store',
|
||||
signal: this.abort.signal,
|
||||
})
|
||||
@@ -119,6 +121,7 @@ class AuthPriceStream extends EventTarget {
|
||||
|
||||
let eventSource: AuthPriceStream | null = null
|
||||
let subscribers = 0
|
||||
let tvStreamKey: string | null = null
|
||||
let stopped = false
|
||||
let getSetting: ((key: string) => unknown) | null = null
|
||||
let reconnectTimer: ReturnType<typeof setTimeout> | undefined
|
||||
@@ -655,7 +658,7 @@ function connect() {
|
||||
markConnectingLifecycle()
|
||||
|
||||
try {
|
||||
eventSource = new AuthPriceStream(url)
|
||||
eventSource = new AuthPriceStream(url, tvStreamKey || '')
|
||||
} catch (error) {
|
||||
console.warn('Price SSE connect failed', error)
|
||||
handleStreamLost()
|
||||
@@ -740,6 +743,22 @@ function unbindBrowserNetworkListeners() {
|
||||
window.removeEventListener('offline', onBrowserOffline)
|
||||
}
|
||||
|
||||
export function startTvPriceStream(
|
||||
settingGetter: (key: string) => unknown,
|
||||
key: string,
|
||||
) {
|
||||
const secret = key.trim()
|
||||
if (!secret) return
|
||||
tvStreamKey = secret
|
||||
startPriceSocket(settingGetter)
|
||||
}
|
||||
|
||||
export function stopTvPriceStream() {
|
||||
if (!tvStreamKey) return
|
||||
tvStreamKey = null
|
||||
stopPriceSocket()
|
||||
}
|
||||
|
||||
export function startPriceSocket(settingGetter: (key: string) => unknown) {
|
||||
getSetting = settingGetter
|
||||
subscribers += 1
|
||||
|
||||
Reference in New Issue
Block a user