Only getting Blob with different sizes in Websocket

marsonya
Hi, I am able to successfully connect to the Websocket and receiving text messages.
But, I am not getting ticks properly. I am continuously (more than a few times in a second) getting the following message that the parser is not able to parse:

data: Blob {
size: 560 // this keeps changing
type: ""
}
  • marsonya
    I am not using any client directly. I have copied the Parser from NodeJS NPM Client.

    onMessage: (message) => {
    console.log(message);
    this.connected = true;
    if(message.data instanceof ArrayBuffer) {
    console.log(message.data.byteLength)
    if(message.data.byteLength > 2) {
    const parsedData = this.parseBinary(message.data);
    this.updatePrices(parsedData);
    console.log('binary message', parsedData);
    }
    }else {
    const parsedText = this.parseTextMessage(message.data)
    if(parsedText) {
    console.log('text message', parsedText);
    }
    }
    }


    The code is not passing "if(message.data instanceof ArrayBuffer) {"
  • marsonya
    @sujith , please help me
  • sujith
    The tick data is in binary. You can read more about it from the API documentation.
  • marsonya
    marsonya edited January 8
    @sujith I understand that. And I am following the exact thing written in Kite NPM Package
    https://github.com/zerodha/kiteconnectjs/blob/master/lib/ticker.ts#L400

    The problem is message.data is coming as undefined.

    But I am getting empty Blob messages. I would really appreciate if you can nudge me in the right direction.
  • marsonya
    Issue resolved. I had to convert the Blob data to Array buffer using const buffer = await blob.arrayBuffer();
    Thanks :)
This discussion has been closed.