- From: Jan-Ivar Bruaroey <jib@mozilla.com>
- Date: Mon, 12 Aug 2013 21:39:27 -0400
- To: Harald Alvestrand <harald@alvestrand.no>
- CC: "public-webrtc@w3.org" <public-webrtc@w3.org>
On 8/12/13 4:21 AM, Harald Alvestrand wrote: > The union defeats our purpose, since it limits the legal forms of > stats to just those that made it into the union; we want to be able to > add new stats at will, including implementation-defined ones. Yes, good point, and this union trick didn't work anyway, as I mentioned in the followup. >> The second point was that getters apparently have name collision >> issues, and he was wondering if it would be better for our needs to >> return a (read-only) "Map-like" object >> http://dev.w3.org/2006/webapi/WebIDL/#MapClass like this: >> >> [MapClass(DOMString, AnyRTCStats)] >> interface RTCStatsReport {}; > > This seems like an interesting direction to go - would this be instead > of using Dictionary? It would be instead of the getter. We would still return dictionaries. > Which interfaces today utilize the [MapClass] extended attribute? (I > like to look at examples...) MapClass is very new. It is discussed here: - http://lists.w3.org/Archives/Public/public-script-coord/2013AprJun/0589.html - http://lists.w3.org/Archives/Public/public-script-coord/2013AprJun/0631.html The only "use" I found is http://dev.w3.org/csswg/css-variables/#the-CSSVariablesMap-interface My understanding is that any object is "map-like" if it implements the mentioned set of methods (or a subset for read-only objects) that let users treat the object like a map (associative array). Without waiting for [MapClass] extended attribute support, here's what I'm using: // [MapClass(DOMString, object)] interface RTCStatsReport { void forEach(RTCStatsReportCallback callbackFn, optional any thisArg); object get(DOMString key); boolean has(DOMString key); }; Example caller: pc2.getStats(null, function(stats) { var statsString = ''; var i = 0; stats.forEach(function(res) { statsString += '<h3>Report '; statsString += i; statsString += '</h3>'; statsString += dumpStats(res); } }); function dumpStats(obj) { var statsString = 'Timestamp:'; statsString += obj.timestamp; if (obj.id) { statsString += "<br>id "; statsString += obj.id; } if (obj.type) { statsString += " type "; statsString += obj.type; } if (obj.bytesReceived !== undefined) { statsString += " bytesReceived: "; statsString += obj.bytesReceived; statsString += "<br>"; } return statsString; } .: Jan-Ivar :.
Received on Tuesday, 13 August 2013 01:39:56 UTC