Enrique GF
Enrique GF

Reputation: 1295

error on WEBRTC setRemoteDescription method

I´m doing this app with Vue and socket.io using WEBRTC, but when I try to use the method of RTCPeerConnection ,setRemoteDescription, passing the sdp parameter i receive this error

Uncaught (in promise) SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data

After the callee having received the offer on this kind of format:

offerWEBRTC: Object { type: "offer"
, sdp: "v=0\r\no=- 4541021516758240611 2 IN IP4 
127.0.0.1\r\ns=-\r\nt=0 0\r\na=group:BUNDLE 0 1\r\na=extmap-allow-mixed\r\na=msid-
semantic: WMS uNxCWJIzYxNdDeeaGvIfxsgNEMkADiu4dHZb\r\nm=audio 9 UDP/TLS/RTP/SAVPF 111 63 
103 104 9 0 8 106 105 13 110 112 113 126\r\nc=IN IP4 0.0.0.0\r\na=rtcp:9 IN IP4 
0.0.0.0\r\na=ice-ufrag:+J7I\r\na=ice-pwd:UdlojqyyLfe9hSJhL2H+i5Ww\r\na=ice-
options:trickle\r\na=fingerprint:sha-256 
1B:64:59:54:92:16:2A:0E:CF:8D:0C:14:45:36:A4:0B:49:9D:D5:7B:1A:9B:0E:BB:7D:9E:2D:13:8C:A8
:64:CE\r\na=setup:actpass\r\na=mid:0\r\na=extmap:1 urn:ietf:params:rtp-hdrext:ssrc-audio-
level\r\na=extmap:2 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-
time\r\na=extmap:3 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-
extensions-01\r\na=extmap:4 urn:ietf:params:rtp-
hdrext:sdes:mid\r\na=sendrecv\r\na=msid:uNxCWJIzYxNdDeeaGvIfxsgNEMkADiu4dHZb aeb4e1a9-
af4c-4847-95d9-74fa295d817b\r\na=rtcp-mux\r\na=rtpmap:111 opus/48000/2\r\na=rtcp-fb:111 
transport-cc\r\na=fmtp:111 minptime=10;useinbandfec=1\r\na=rtpmap:63 
red/48000/2\r\na=fmtp:63 111/111\r\na=rtpmap:103 ISAC/16000\r\na=rtpmap:104 
ISAC/32000\r\na=rtpmap:9 G722/8000\r\na=rtpmap:0 PCMU/8000\r\na=rtpmap:8 
PCMA/8000\r\na=rtpmap:106 CN/32000\r\na=rtpmap:105 CN/16000\r\na=rtpmap:13 
CN/8000\r\na=rtpmap:110 telephone-event/48000\r\na=rtpmap:112 telephone-
event/32000\r\na=rtpmap:113 telephone-event/16000\r\na=rtpmap:126 telephone-
event/8000\r\na=ssrc:3144952377 cname:Bp6iErLqqeidCIX2\r\na=ssrc:3144952377 
msid:uNxCWJIzYxNdDeeaGvIfxsgNEMkADiu4dHZb aeb4e1a9-af4c-4847-95d9-
74fa295d817b\r\na=ssrc:3144952377 
mslabel:uNxCWJIzYxNdDeeaGvIfxsgNEMkADiu4dHZb\r\na=ssrc:3144952377 label:aeb4e1a9-af4c-
4847-95d9-74fa295d817b\r\nm=video 9 UDP/TLS/RTP/SAVPF 96 97 98 99 100 101 102 121 127 120 
125 107 108 109 35 36 124 119 123 118 114 115 116\r\nc=IN IP4 0.0.0.0\r\na=rtcp:9 IN IP4 
0.0.0.0\r\na=ice-ufrag:+J7I\r\na=ice-pwd:UdlojqyyLfe9hSJhL2H+i5Ww\r\na=ice-
options:trickle\r\na=fingerprint:sha-256 .....
\r\n" }

In the callee side a method is initialised in order to handle that offer, and erogue an answer, thus inside that method i set this setRemoteDescription() one :



let myConnectionPeer: RTCPeerConnection = new RTCPeerConnection();

async answerHandler(payload:TypeOfMyPayload){
 await myConnectionPeer.setRemoteDescription(JSON.parse(payload.offerWEBRTC?.sdp))
    .......
}

If i don´t parse it the error would vary a little bit like :

RTCPeerConnection.setRemoteDescription: Argument 1 can't be converted to a dictionary.

But keep having that error. Any help would be amazing!!!

Upvotes: 0

Views: 895

Answers (1)

Enrique GF
Enrique GF

Reputation: 1295

Eventually despite of receive the data, that wasn´t a JSON as the method demanded, thus was necessary through the method Object.assign, parse the whole object to a JSON format...then all worked. If someone have this same issue hope this could help

Upvotes: 1

Related Questions