 			self.onSetDescriptionFailureCallback(error: error)
 		}
 	}
+
+    /**
+     * Methods inherited from RTCStatsDelegate
+     */
+
+    func peerConnection(peerConnection: RTCPeerConnection!,
+        didGetStats stats: [AnyObject]!) {
+
+            var jsStats = [NSDictionary]()
+
+            for stat in stats as NSArray {
+                var jsValues = Dictionary<String,String>()
+
+                for pair in stat.values as! [RTCPair] {
+                    jsValues[pair.key] = pair.value;
+                }
+
+                jsStats.append(["reportId": stat.reportId, "type": stat.type, "timestamp": stat.timestamp, "values": jsValues]);
+
+            }
+
+        self.onGetStatsCallback(array: jsStats);
+    }
 }

import Foundation


class PluginRTCPeerConnection : NSObject, RTCPeerConnectionDelegate, RTCSessionDescriptionDelegate {
	var rtcPeerConnectionFactory: RTCPeerConnectionFactory
	var rtcPeerConnection: RTCPeerConnection!
	var pluginRTCPeerConnectionConfig: PluginRTCPeerConnectionConfig

		)
	}

func getStats(
        pluginMediaStreamTrack: PluginMediaStreamTrack?,
        callback: (data: NSArray) -> Void,
        errback: (error: NSError) -> Void
        ) {
            NSLog("PluginRTCPeerConnection#getStats()")

            self.onGetStatsCallback = { (array: NSArray) -> Void in
                callback(data: array)
            }

            if !self.rtcPeerConnection.getStatsWithDelegate(self,
                mediaStreamTrack: pluginMediaStreamTrack?.rtcMediaStreamTrack,
                statsOutputLevel: RTCStatsOutputLevelStandard) {
                    errback(error: NSError(domain: "Cannot get peer connection stats.", code: -1, userInfo: nil))
            }
    }

	func close() {
		NSLog("PluginRTCPeerConnection#close()")
