mirror of
https://github.com/orionprotocol/sdk.git
synced 2026-03-22 21:59:44 +03:00
Fix broken PriceFeed
This commit is contained in:
@@ -109,11 +109,19 @@ export default class PriceFeedSubscription<T extends SubscriptionType = Subscrip
|
||||
this.ws.onmessage = (e) => {
|
||||
const { data } = e;
|
||||
|
||||
// const isBufferArray = Array.isArray(data);
|
||||
// const isArrayBuffer = data instanceof ArrayBuffer;
|
||||
const isBuffer = Buffer.isBuffer(data);
|
||||
if (!isBuffer) throw new Error('Not a buffer');
|
||||
const dataString = data.toString();
|
||||
// Convert data to string
|
||||
|
||||
let dataString: string;
|
||||
if (typeof data === 'string') {
|
||||
dataString = data;
|
||||
} else if (Buffer.isBuffer(data)) {
|
||||
dataString = data.toString();
|
||||
} else if (Array.isArray(data)) {
|
||||
dataString = Buffer.concat(data).toString();
|
||||
} else { // ArrayBuffer
|
||||
dataString = Buffer.from(data).toString();
|
||||
}
|
||||
|
||||
if (dataString === 'pong') return;
|
||||
const json: unknown = JSON.parse(dataString);
|
||||
const subscription = subscriptions[type];
|
||||
|
||||
Reference in New Issue
Block a user