The method JSON.stringify results in an empty curly braces object ´

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.

Answer №1

Chances are, the event does not have a WebIDL JSON serializer. If you're focusing solely on onicecandidate, then you can use JSON.stringify on the event.candidate (note that it may be absent to indicate the end of candidates) -- make sure to refer to the example in the WebRTC specification

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Challenges in handling asynchronous data within static JSON objects in Angular2

I have a service set up with some static objects that are being utilized in my UI. fetchRulesVariables() fetchRuleVariables() { let variables = [ { name: 'Credit Funding Type', id: 1, multiple: ...

The 'dataTable' function in JavaScript is malfunctioning within a React environment

I'm currently working on integrating the dataTable plug-in from JavaScript into a React environment. However, when attempting to implement the syntax as shown below: $('#example').DataTable( { data: dataSet, columns: [ ...

Troubles with retrieving Array data for a JavaScript column chart

I am currently developing a Flask app in Python and utilizing render_template to send back 2 arrays, "names" and "deals", to my HTML file. I have confirmed that these arrays are working correctly based on the code snippet below that I tested, which display ...

The implementation of async await within a switch case statement is failing to function properly

Is it possible to wait for the resolution of a promise within a switch case statement by using the keyword await? I am facing an issue with my Angular component where the following code is causing crashes in my application. switch (this.status) { ...

Error in retrieving JSONP request

My goal is to send a request to the following URL: https://en.wikipedia.org/w/api.php?action=opensearch&search=apple&limit=5&namespace=0&format=json I want to use JSONP for this. The function I intend to utilize for making this request i ...

The schema encountered an error due to the absence of the save method

My current goal is to allow a logged in user to visit any user's URL and follow them. However, I'm encountering an issue: TypeError: Object { _id: 54bd6b90b7d4cc8c10b40cbd, name: 'Johnny', username: 'batman', __v: 0, ...

Retrieving the HTML ID attribute of an anchor link within a form and sending it to the backend server

I am currently working on a project that involves a form containing an anchor link tag with a dynamic ID. I am utilizing this anchor link tag to submit the form via Javascript. However, I am facing difficulty in fetching the ID of the same anchor link tag, ...

After implementing the ng-repeat directive, the div element vanishes

I've been working on fetching data from a Json API and displaying it on user event. However, I'm facing an issue where the div disappears whenever I apply the ng-repeat property to it. Despite searching through various tutorials and documentation ...

Bring a div box to life using AngularJS

Struggling to animate a div-Box in AngularJS? Despite trying multiple examples, the animation just won't cooperate. I'm aiming to implement a feature where clicking on a button triggers a transition animation to display the search form. I under ...

Fast screening should enhance the quality of the filter options

Looking to enhance the custom filters for a basic list in react-admin, my current setup includes: const ClientListsFilter = (props: FilterProps): JSX.Element => { return ( <Filter {...props}> <TextInput label="First Name" ...

Issue with AJAX and Jquery auto form update functionality malfunctioning

On my form page, here is the code snippet: <form action="/register-process" method="post" id="form1"> <script type="text/javascript"> jQuery(document).ready(function($) { $(document).on('focusout', '#dateenglish', function ...

difficulties encountered while generating json file using arrays

I am attempting to save this playlist file, similar to the one shown below, in an albums.json file but am encountering difficulties. I also want this json object to be unique. If anyone can provide guidance on the right way forward, I would greatly appreci ...

Can you explain the contrast between JSON and XML formats?

Can you explain the distinction between JSON and XML? ...

What is the reason for the function to return 'undefined' when the variable already holds the accurate result?

I have created a function that aims to calculate the digital root of a given number. Despite my efforts, I am encountering an issue where this function consistently returns undefined, even though the variable does hold the correct result. Can you help me ...

I intend to extract the long_name value from the JSON data using AngularJS

I have been attempting to retrieve the long_name from the JSON data below using angular js, but unfortunately I am unable to successfully fetch it. CODE: { "results" : [ { "address_components" : [ { "long_name ...

How to work with multiple selections in React material-ui Autocomplete

I'm currently using Material-ui Autocomplete in multiple selection mode. My goal is to retrieve all the selected values when the form is submitted. Although I found a solution on how to get individual values through the onChange event handler from thi ...

Using PHP for Salesforce API integration

My apologies for my lack of familiarity with salesforce API terminologies. I've recently started developing a connector to interact with salesforce, and I've hit a roadblock. I have a specific requirement where every time a new entry is added to ...

Using Jquery to Display Page Content Upon Form Submission

When it comes to submitting a form, I usually have two options - using Ajax or submitting it normally. Submitting via Ajax will only show the response without displaying the POST page, while submitting the form will take you to the POST page where the PO ...

How to stop a div from shifting downwards with CSS

Within my Web Application, I have implemented HTML code that displays different texts above input fields based on certain conditions. However, the issue I am facing is that the input fields are being shifted down by the text. I want the input fields to al ...

The countdown feature is failing to update despite using the SetInterval function

My goal is to develop a countdown application using Atlassian Forge that takes a date input and initiates the countdown based on the current date. For instance, if I input "After 3 days from now," I am expecting the result to continuously update every seco ...