0

How to I retrieve call duration when someone leaves a call?

I am trying to use getStats() but I am only being returned a state value.

console.log("this.room.getStats() ", this.room.getStats());

returns:

this.room.getStats()  
Promise { <state>: "pending" }
atw
  • 5,428
  • 10
  • 39
  • 63

1 Answers1

1

Twilio developer evangelist here.

Maybe something like

const stats = await this.room.getStats();
const remoteTrackStats = kind === 'audio'
    ? stats[0].remoteAudioTrackStats[0]
    : stats[0].remoteVideoTrackStats[0]
const bytesReceived = remoteTrackStats.bytesReceived;
const timestamp = remoteTrackStats.timestamp;

Let me know if this helps at all!

lizziepika
  • 3,231
  • 1
  • 14
  • 23
  • Thanks so much for the answer but I am not getting an array back form getStats(). I am only getting a hash with state: pending in it and nothing else. I am testing locally on my development environment, maybe I need to use https instead of http. – atw Jun 25 '20 at 21:23
  • I will accept this answer but maybe I should mention that I needed to be configured for HTTPS in my development environment. – atw Jun 26 '20 at 11:47
  • Also, can you confirm that timestamp is actually the call duration? – atw Jun 26 '20 at 15:54