subscription fixes
This commit is contained in:
@@ -6,6 +6,7 @@ import FlexSearch from "flexsearch";
|
|||||||
import {useChartOrderStore} from "@/orderbuild.js";
|
import {useChartOrderStore} from "@/orderbuild.js";
|
||||||
import {useStore} from "@/store/store.js";
|
import {useStore} from "@/store/store.js";
|
||||||
import {subOHLC, unsubOHLC} from "@/blockchain/ohlcs.js";
|
import {subOHLC, unsubOHLC} from "@/blockchain/ohlcs.js";
|
||||||
|
import {socket} from "@/socket.js";
|
||||||
|
|
||||||
let feeDropdown = null
|
let feeDropdown = null
|
||||||
let widget = null
|
let widget = null
|
||||||
@@ -276,7 +277,7 @@ export const DataFeed = {
|
|||||||
}
|
}
|
||||||
const co = useChartOrderStore();
|
const co = useChartOrderStore();
|
||||||
co.selectedSymbol = symbolItem
|
co.selectedSymbol = symbolItem
|
||||||
const pool = symbolItem.pools[Math.trunc(symbolItem.pools.length/2)];
|
const pool = symbolItem.pools[0]; // choose the first-listed pool. server will adjust metadata accordingly.
|
||||||
// noinspection JSValidateTypes
|
// noinspection JSValidateTypes
|
||||||
co.selectedPool = pool
|
co.selectedPool = pool
|
||||||
updateFeeDropdown()
|
updateFeeDropdown()
|
||||||
@@ -342,9 +343,12 @@ export const DataFeed = {
|
|||||||
const chainId = useStore().chainId.value;
|
const chainId = useStore().chainId.value;
|
||||||
const poolAddr = useChartOrderStore().selectedPool[0];
|
const poolAddr = useChartOrderStore().selectedPool[0];
|
||||||
const period = tvResolutionToPeriodString(resolution);
|
const period = tvResolutionToPeriodString(resolution);
|
||||||
subscriptions[subscriberUID] = [chainId, poolAddr, period]
|
subscriptions[subscriberUID] = [chainId, poolAddr, period, onRealtimeCallback, onResetCacheNeededCallback]
|
||||||
const key = `${chainId}|${poolAddr}|${period}`;
|
const key = `${chainId}|${poolAddr}|${period}`
|
||||||
subscription_callbacks[key] = [onRealtimeCallback, onResetCacheNeededCallback]
|
if (key in subscriptionCallbacks)
|
||||||
|
subscriptionCallbacks[key].push(subscriberUID)
|
||||||
|
else
|
||||||
|
subscriptionCallbacks[key] = [subscriberUID]
|
||||||
console.log('sub', key)
|
console.log('sub', key)
|
||||||
subOHLC(chainId, poolAddr, period)
|
subOHLC(chainId, poolAddr, period)
|
||||||
},
|
},
|
||||||
@@ -356,7 +360,11 @@ export const DataFeed = {
|
|||||||
delete subscriptions[subscriberUID]
|
delete subscriptions[subscriberUID]
|
||||||
const key = `${chainId}|${poolAddr}|${period}`;
|
const key = `${chainId}|${poolAddr}|${period}`;
|
||||||
console.log('unsub',key)
|
console.log('unsub',key)
|
||||||
delete subscription_callbacks[key]
|
const remainingSubs = subscriptionCallbacks[key].filter((v)=>v!==subscriberUID)
|
||||||
|
if (remainingSubs.length===0)
|
||||||
|
delete subscriptionCallbacks[key]
|
||||||
|
else
|
||||||
|
subscriptionCallbacks[key] = remainingSubs
|
||||||
},
|
},
|
||||||
|
|
||||||
poolCallbackState : {lastBar:{'chain|pool|period':null}},
|
poolCallbackState : {lastBar:{'chain|pool|period':null}},
|
||||||
@@ -368,8 +376,26 @@ export const DataFeed = {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const key = `${chainId}|${poolPeriod}`;
|
const key = `${chainId}|${poolPeriod}`;
|
||||||
console.log('key lookup',key,subscription_callbacks[key])
|
const subscriptionUIDs = subscriptionCallbacks[key];
|
||||||
const [onRealtimeCallback, onResetCacheNeededCallback] = subscription_callbacks[key]
|
if (subscriptionUIDs===undefined) {
|
||||||
|
console.log('unsubbing abandoned subscription', poolPeriod)
|
||||||
|
socket.emit('unsubOHLCs', chainId, [poolPeriod])
|
||||||
|
return
|
||||||
|
}
|
||||||
|
function onRealtimeCallback() {
|
||||||
|
for (const subId of subscriptionUIDs) {
|
||||||
|
const [_chainId, _poolAddr, _period, _onRealtimeCallback, _onResetCacheNeededCallback] = subscriptions[subId]
|
||||||
|
_onRealtimeCallback(...arguments)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function onResetCacheNeededCallback() {
|
||||||
|
for (const subId of subscriptionUIDs) {
|
||||||
|
const [_chainId, _poolAddr, _period, _onRealtimeCallback, _onResetCacheNeededCallback] = subscriptions[subId]
|
||||||
|
_onResetCacheNeededCallback(...arguments)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let ohlc = ohlcs.at(-1);
|
let ohlc = ohlcs.at(-1);
|
||||||
console.log("poolCallBack ohlc:", new Date(Number(ohlc[0])*1000).toGMTString(), ohlc)
|
console.log("poolCallBack ohlc:", new Date(Number(ohlc[0])*1000).toGMTString(), ohlc)
|
||||||
for (let i = 0; i<ohlc.length; i++) if (ohlc[i]!=null) ohlc[i] = Number(ohlc[i])
|
for (let i = 0; i<ohlc.length; i++) if (ohlc[i]!=null) ohlc[i] = Number(ohlc[i])
|
||||||
@@ -417,4 +443,4 @@ export const DataFeed = {
|
|||||||
|
|
||||||
let defaultSymbol = null
|
let defaultSymbol = null
|
||||||
const subscriptions = {}
|
const subscriptions = {}
|
||||||
const subscription_callbacks = {}
|
const subscriptionCallbacks = {}
|
||||||
|
|||||||
Reference in New Issue
Block a user