Right now, I am in the process of developing a straightforward video chat service using WebRTC with Ajax as the signalling method.
Following the suggestion of another user on Stack Overflow, to ensure my understanding of a typical WebRTC application flow, I initially created a basic WebRTC video chat service where I displayed the offer or answer and ICE candidates on the screen. I manually copied this information into a text area in the other client's window to establish the connection successfully.
Once that was working correctly, I attempted to switch to using Ajax for signalling. However, I have encountered difficulties in getting it to function properly.
In my current setup, each time offer/answer or ICE candidate information is generated, I immediately create an Ajax object to store this data (after executing the JSON.stringify method) in a DB table. Both clients continuously check this DB table for any new information from the other client.
I have been closely monitoring console output, and it appears that a valid offer is always sent from one client to another. Despite successfully setting this offer as the remote description and creating an answer upon receiving it, every effort to set the local description of the "answerer" fails.
Could there be a specific reason for this issue? Below is a snippet of my code:
var i,
len;
for (i = 0, len = responseData.length; i < len; i += 1) {
message = JSON.parse(responseData[i]);
if (message.type === 'offer') {
makeAnswer(message);
}
// Code omitted,
}
...
makeAnswer = function (offer) {
pc.setRemoteDescription(new RTCSessionDescription(offer), function () {
pc.createAnswer(function (desc) {
// An answer is always properly generated here.
pc.setLocalDescription(desc, function () {
// This success callback function is never executed.
setPayload(JSON.stringify(pc.localDescription));
}, function () {
// I always end up here.
});
});
});
};
To summarize, I iterate through retrieved data from the DB, checking for both an offer and multiple candidate information gathered simultaneously. When encountering a message with the type property as 'offer,' I invoke the makeAnswer function. From there, I attempt to set the remote description to the received offer, create an answer, and assign the answer as the local description, but it consistently fails during this last step.
If anyone can provide guidance on why this issue may arise, I would greatly appreciate it.
Thank you for your help.