Encountered an issue when trying to establish the session description: An error occurred while attempting to set the remote answer SDP: Request was made in an inappropriate state

Using Angular JS to Get Room Id/Token from Server Side for WebSocket Connection Code Snippet Used in Application -

app.controller("videoCallingController",
["$scope", "$location", "$rootScope", "$localStorage", 'AuthenticationService', "CommonService", "videoService",
function ($scope, $location, $rootScope, $localStorage, AuthenticationService, CommonService, videoService) {

$scope.UserInfo = getLoggedInUserDetails();

if ($scope.UserInfo == null) {
    window.location.replace("/login.html#/");
}

$scope.offerConversationDetails = JSON.parse(localStorage.getItem('offerConversationDetails')); //$rootScope.offerConversationDetails;
$scope.IsCallBtn = false;
$scope.IsCallEnd = false;
$scope.IsRemoteStreaming = false;

//------- start custom Web socket ----------------
var ws;

function initWS(groupname) {

    //  var groupname = "TestRoom";


    ws = new WebSocket("wss://" + location.host + "/api/" + "api/Values/Get?id=" + groupname);


    ws.onopen = function () { };
    
    //Rest of the code goes here...

$scope.dragOptions = {
    start: function (e) {
        console.log("STARTING");
    },
    drag: function (e) {
        console.log("DRAGGING");
    },
    stop: function (e) {
        console.log("STOPPING");
    },
    container: 'container'
}

Answer №1

When serializing SDP, special characters may be included. To remove them, you can use the code snippet below:

// Code snippet to remove special characters
function maybeAddLineBreakToEnd(sdp) {
    var endWithLineBreak = new RegExp(/\n$/);
    if (!endWithLineBreak.test(sdp)) {
        return sdp + '\n';
    }
    return sdp;
}

function gotDescription(desc) {
    var offer = desc;
    offerSdpTextarea.value = desc.sdp;
    var sdp = offerSdpTextarea.value;
    sdp = maybeAddLineBreakToEnd(sdp);
    console.log(sdp);
    sdp = sdp.replace(/\n/g, '\r\n');
    offer.sdp = sdp;
    pc1.setLocalDescription(offer,
        onSetOfferSDPSuccess,
        onSetSDPError);
    trace('Modified Offer from localPeerConnection \n' + sdp);

    sendWS(JSON.stringify(offer));
}

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

Enhance Your User Experience with the Onsen UI Bluetooth Extension

Trying to integrate a Bluetooth plugin using Onsenui in Monaca IDE, but consistently encountering the error message: "bluetoothSerial not found." Looking to develop a service that necessitates the Bluetooth Serial plugin. Planning to simply utilize a .is ...

Using JavaScript, is there a way to modify a JSON parameter within an API?

My API provides JSON data structured like this: [{"NAME":"john","SURNAME":"johny","ADULT":"3","CHILD":"3","BABY":"0",}] In my JavaScript function, I need to send a request to a web service that will update the value of "BABY" from "0" to "1". Can this be ...

Challenges faced with react-bootstrap-autosuggest

After spending the entire day attempting to integrate the package from here into my create-react-app project upon ejection, I encountered the following error: Failed to compile. Error in ./~/react-bootstrap-autosuggest/lib/Autosuggest.js Module not found ...

Using a static value in the comparator is necessary for Array.find to function properly in Typescript

Looking to retrieve an item from an array: const device = this.selectedDevtype.devices.find(item => console.log(this.deviceID); return item.device_id === this.deviceID; }); console.log(device); When this.deviceID is logged, it shows "4", but t ...

Is it possible to dynamically assign trigger and target divs to bPopup?

On our ColdFusion page, we have a dynamic list of paired divs created using a loop over a query. For example, each pair consists of internshipHandleX and internshipHiddenX: <div id="internshipHidden#internship.currentrow#" class="hidden pop-up"> We ...

The specified container is not a valid DOM element

Recently, I decided to implement Redux into my React application. However, as I began setting everything up within my index.js file, I encountered an error message: https://i.sstatic.net/4kL2T.png. After some research, I learned that this error is related ...

Leveraging Ajax with PlayFramework Results

As stated in the PlayFramework Document 2.0 and PlayFramework Document 2.1, it is known that Play can return various responses such as: Ok() badRequest() created() status() forbidden() internalServerError() TODO However, when trying to send a response wi ...

Ways to display success message following JavaScript validation

I've been working on creating a form that displays a success message after JavaScript validation checks are successful. To show the success message, I'm utilizing Bootstrap alert. I split my code into two files - one for common validation functio ...

What is the method to retrieve a checkbox value within a datatable when employing pagination?

I recently came across an issue with my datatable where I had implemented a checkbox in the first column of each row. However, when I attempted to check the checkbox using an AJAX call, it only worked for the first page and not for any subsequent pages. H ...

When CSS is modified by inserting an extra div, it causes the positioning of other elements to shift towards

I'm currently working on adapting a method to make elements "sticky" for older browsers as discussed in this particular article. The basic idea involves implementing some JavaScript code that listens for scroll events. Upon detection of such an event ...

Detecting Android devices

Issue: My website functions properly on desktop but has a problem with the carousel images skewing on iPhones. To address this, I created a separate CSS styling for iPhone devices and used a JavaScript function found online to detect iPhones and iPads. Un ...

Refine the JSON data to only include the values you need

I've been spending a considerable amount of time on this challenge, but I'm facing difficulty in solving it. The issue at hand is that I have a JSON file that I am fetching from a URL, and my objective is to create a filter that displays only nam ...

What is the reason for the request body being undefined?

I have a JavaScript file named index.js that contains: const express = require('express'); const bodyParser = require('body-parser'); const cors = require('cors'); const db = require('./db'); const movieRouter = re ...

Axios is returning a 401 (Unauthorized) error when attempting to retrieve user data from a React frontend and pass it to DRF Social Oauth2. Strangely, the same process

Here are the contents of two files, LoginScreen.JS and login.JS. The LoginScreen.JS file contains a submit handler that submits user input, while we import the axios instance from login.JS. In addition, a working example from PostMan has been provided. lo ...

Before the async function, make sure to set the value using React's useState

Exploring the world of react context api for the very first time. Below is my react code utilizing the context api: const [valChanged, setValChanged] = useState(false); async function modalSave() { await setValChanged(true); // STEP 1 await o ...

Concealing functions within Accessors

I've recently started working on a website project utilizing the node.js/express stack and I am experimenting with developing in the functional programming style, which is quite new to me. One issue I encountered was related to the express method res. ...

After using browserify, when attempting to call the function in the browser, an Uncaught ReferenceError occurs

I am currently in the process of creating a compact NPM package. Here is a basic prototype: function bar() { return 'bar'; } module.exports = bar; This package is meant to be compatible with web browsers as well. To achieve this, I have inst ...

Inconsistent reliability of Loopback-context prompts the search for an alternative solution

After encountering some reliability issues with the loopback-context package, I decided to try an alternative approach. Instead of relying on setting the current user object in my middleware using loopback-context, I opted to fetch the accessToken from the ...

Webpage created from scratch encounters technical difficulties on mobile device browser

My website seems to be getting stuck at the beginning of a section, particularly on mobile browsers. You can check out the website here <section class="home-slider owl-carousel"> <div class="slider-item" style="background-image: url(images/bg ...

Using NodeJS to fetch external page data and return Javascript variable information

I need to retrieve the entire DOM of a specific page by sending a request, essentially crawling the website. The HTML directly includes a variable with some data, instead of it being in a separate script file. With my NodeJS backend, I am utilizing request ...