var accessToken = '';
var accessManager = Twilio.AccessManager(accessToken);
var client = Twilio.Conversations.Client(accessManager);

function handleConversationStats(conversation) {
  var dialog = conversation._dialogs.values().next().value;
  var peerConnection = dialog.session.mediaHandler.peerConnection;
  var selector = null;
  var packets = 0;

  setInterval(function() {
    // Works in FireFox
    // peerConnection.getStats(selector, function(report) {
    //   for(var i in report) {
    //     var currentReport = report[i];
    //     if(currentReport.type === 'outboundrtp') {
    //       console.log(currentReport);
    //       packets += currentReport.packetsSent;
    //     }
    //   }
    //   console.log('Number of packets sent so far: ' + packets);
    // }, function(error) {
    //   console.log('Oh no I messed up: ' + error);
    // });

    // Works in Chrome
    peerConnection.getStats(function(report) {
      report = standardizeReport(report);
      console.log(report);

      for(var i in report) {
        var currentReport = report[i];
        if(currentReport.type === 'ssrc' && currentReport.packetsSent) {
          console.log(currentReport);
          packets += parseInt(currentReport.packetsSent, 10);
        }
      }
      console.log('Number of packets sent so far: ' + packets);
    }, selector, function(error) {
      console.log('Oh no I messed up: ' + error);
    });
  }, 5000);
}

function standardizeReport(response) {
  if(navigator.mozGetUserMedia) {
    return response;
  }

  var standardReport = {};
  response.result().forEach(function(report) {
    var standardStats = {
      id: report.id,
      type: report.type,
    };
    report.names().forEach(function(name) {
      standardStats[name] = report.stat(name);
    });
    standardReport[standardStats.id] = standardStats;
  });

  return standardReport;
}

function onInviteAccepted(conversation) {
  conversation.localMedia.attach('#local');

  conversation.on('participantConnected', function(participant) {
    participant.media.attach('#remote');

    handleConversationStats(conversation);
  });
}

client.listen().then(function () {
  client.on('invite', function(invite) {
    invite.accept().then(onInviteAccepted);
  });
});

console.log('Hello Keeyon, s_haha_n, Niko, Gutomaia jer_dude, NichtBela and sir_majestic');
console.log('Also hello to Devin, Brent, Manny and Mheetu');
console.log('zykO rules and Trohnics is my pizza brother');

@@ -128,16 +128,419 @@
 ager);%0A%0A
+function getStats(peerConnection, selector, successCb, failureCb) %7B%0A  if(navigator.mozGetUserMedia) %7B%0A    // User is using FireFox%0A    return peerConnection.getStats(selector, successCb, failureCb);%0A  %7D else %7B%0A    // User is using Chrome%0A    return peerConnection.getStats(function(response) %7B%0A      var report = standardizeReport(response);%0A      successCb(report);%0A    %7D, selector, failureCb);%0A  %7D%0A%7D%0A%0A
 function
@@ -800,24 +800,50 @@
  FireFox
-%0A    // 
+ and Chrome (I hope)%0A    getStats(
 peerConn
@@ -844,34 +844,26 @@
 erConnection
-.getStats(
+, 
 selector, fu
@@ -882,19 +882,16 @@
 t) %7B%0A   
- //
    for(v
@@ -907,27 +907,24 @@
 eport) %7B%0A   
- //
      var cur
@@ -947,27 +947,67 @@
 ort%5Bi%5D;%0A
+%0A
     
-//
+    if(navigator.mozGetUserMedia) %7B%0A   
      
+  
 if(curre
@@ -1041,26 +1041,25 @@
 rtp') %7B%0A    
-//
+ 
        conso
@@ -1089,17 +1089,16 @@
     
-//
        
+ 
 pack
@@ -1139,23 +1139,11 @@
     
-//
    
-  %7D%0A    //
    %7D
@@ -1151,372 +1151,23 @@
     
-//
    
-console.log('Number of packets sent so far: ' + packets);%0A    // %7D, function(error) %7B%0A    //   console.log('Oh no I messed up: ' + error);%0A    // %7D);%0A%0A    // Works in Chrome%0A    peerConnection.getStats(function(report) %7B%0A      report = standardizeReport(report);%0A      console.log(report);%0A%0A      for(var i in report) %7B%0A        var currentReport = report%5Bi%5D;%0A
+ %7D else %7B%0A  
     
@@ -1237,32 +1237,34 @@
 nt) %7B%0A          
+  
 console.log(curr
@@ -1277,32 +1277,34 @@
 ort);%0A          
+ 
+ 
 packets += parse
@@ -1339,16 +1339,28 @@
 t, 10);%0A
+          %7D%0A
         
@@ -1365,24 +1365,25 @@
   %7D%0A      %7D%0A
+%0A
       consol
@@ -1440,26 +1440,16 @@
 ;%0A    %7D,
- selector,
  functio

Implement browser-agnostic version of packets counter