Search code examples
angulartypescriptably-realtime

Getting started with ABLY


I added https://github.com/ably/ably-js to my project so that I can use typescript. Currently my document adds the currentBid information to the mongodb document with the corresponding auctionId. I'm trying to associate the auctionId with the currentBid value so that the correct value assigns to the correct auction using ABLY so I assigned the channel name to the auctionId with the currentBid value as the data. Here's my code below. Currently it does say publish succeeded in the ably Your app statistics summary and it does register the message according to it's message counter.

Right now on the channel.subscribe, the innerHTML turns into a JSON object on the screen when bid happens. Not sure how I'm gonna associate correct auctionId. How would I query the channels I publish?

The value that returns in innerHTML is If the currentBid is $205.00 and I bid $15.00 then the channel.subscribe I have outputs this:

The message.data value stays at $205.00 The value never updates to $220.00

channel.publish( this.auctionId, this.currentBid);


channel.subscribe(this.auctionId, function (message) {
      document.getElementById('currentBid').innerHTML = JSON.stringify(message.data);

    });

enter image description here


Solution

  • from the looks of it, it seems that you are publishing the new bid price on the channel 'feed' and the event name 'currentBid'. If that's true then any subscriptions to this channel would receive that new bid price in the data object. In your example, $15. In your front-end then you'll need to add this new bid price to your previous price and display that updated info in your HTML.

    In terms of the published messages, if you are wanting to debug what's coming through, you can make use of the dev console that you can find on your app dashboard. Just add the channel and event names and subscribe to it, you should see logs of all the messages being published to that channel.

    enter image description here

    P.S. It's not really ideal ever to share your API key publicly, consider replacing it with some dummy text in future :)

    Full disclaimer - I'm the Developer Advocate for Ably Realtime.