Trying to extract the value of an event object from Google Chrome (WebRTC framework) has been a challenge for me. My current approach is as follows:
yourConnection.onicecandidate = function (event) {
console.log("onicecandidate called on my side with event: "
+ JSON.stringify(event, null, 4)); //that last line produces {}
var result = "";
for (var key in event) {
result += (key + " : " + event[key]);
}
console.log(result);
//...
}
Despite trying to use JSON.stringify, I have not been successful and instead, resort to iterating through the object properties manually...
candidate : [object RTCIceCandidate], NONE : 0, CAPTURING_PHASE : 1, AT_TARGET : 2, BUBBLING_PHASE : 3, MOUSEDOWN : 1, MOUSEUP : 2, MOUSEOVER : 4, MOUSEOUT : 8, MOUSEMOVE : 16, MOUSEDRAG : 32, CLICK : 64, DBLCLICK : 128, KEYDOWN : 256, KEYUP : 512, KEYPRESS : 1024, DRAGDROP : 2048, FOCUS : 4096, BLUR : 8192, SELECT : 16384, CHANGE : 32768, type : icecandidate, target : [object RTCPeerConnection], currentTarget : [object RTCPeerConnection], eventPhase : 2, bubbles : false, cancelable : false, defaultPrevented : false, timeStamp : 246.52, path : , srcElement : [object RTCPeerConnection], returnValue : true, cancelBubble : false, stopPropagation : function stopPropagation() { [native code] }, stopImmediatePropagation : function stopImmediatePropagation() { [native code] }, preventDefault : function preventDefault() { [native code] }, initEvent : function initEvent() { [native code] }, composed : false, composedPath : function composedPath() { [native code] },
My intention is to avoid complicating the process by delving into recursion for subproperties of the objects. Is there no simpler method to neatly display the properties of the object? Why does JSON.stringify yield an empty object?
Furthermore, why am I only able to iterate through an object using the `for each` loop, whereas...
for (var i = 0; i<event.length; i++) result += (event[i] + event[event[i]] );
...this method fails to iterate properly? As a newcomer to JavaScript, I may be overlooking something obvious, so apologies in advance.