yarek
yarek

Reputation: 12054

webrtc: createAnswer works on chrome but fires an error with firefox

function createPeerConnection() {
  try {
    pc = new RTCPeerConnection(null, pc_constraints);
    pc.onicecandidate = handleIceCandidate;
    pc.onaddstream = handleRemoteStreamAdded;
    pc.onremovestream = handleRemoteStreamRemoved;
    console.log('Created RTCPeerConnnection');
  } catch (e) {
    console.log('Failed to create PeerConnection, exception: ' + e.message);
    alert('Cannot create RTCPeerConnection object.');
      return;
  }

  try {
      // Reliable Data Channels not yet supported in Chrome
      sendChannel = pc.createDataChannel("sendDataChannel",
        {reliable: false});
      sendChannel.onmessage = handleMessage;
      trace('Created send data channel');
    } catch (e) {
      alert('Failed to create data channel. ' +
            'You need Chrome M25 or later with RtpDataChannel enabled');
      trace('createDataChannel() failed with exception: ' + e.message);
    }
    sendChannel.onopen = handleSendChannelStateChange;
    sendChannel.onclose = handleSendChannelStateChange;
    pc.ondatachannel = gotReceiveChannel;
}

    function doAnswer() {
      console.log('Sending answer to peer.');
      pc.createAnswer(setLocalAndSendMessage, null, sdpConstraints);
    }

I got error:

TypeError: Argument 2 of mozRTCPeerConnection.createAnswer is not an object.

Upvotes: 0

Views: 1581

Answers (2)

pmeyer
pmeyer

Reputation: 890

how about this? Its what the guys @ xsockets use...

pc.createAnswer(setLocalAndSendMessage,function (ex) { self.onerror(ex); }, sdpConstraints);

Upvotes: 0

cereallarceny
cereallarceny

Reputation: 4983

The following code should work in Firefox:

function doAnswer() {
  console.log('Sending answer to peer.');

  pc.createAnswer(setLocalAndSendMessage, handleCreateAnswerError, sdpConstraints);
}

function setLocalAndSendMessage(sessionDescription) {
  sessionDescription.sdp = preferOpus(sessionDescription.sdp);
  pc.setLocalDescription(sessionDescription);

  console.log('setLocalAndSendMessage sending message' , sessionDescription);

  sendMessage(sessionDescription);
}

function handleCreateAnswerError(error) {
  console.log('createAnswer() error: ', e);
}

The reason why this fails in Firefox can be found in the documentation for createAnswer. The issue is that Firefox won't let you pass null for the error handler. All this requires is that you write your own and then pass it into createAnswer. Don't pass null, you should actually be passing a function (object) to do something with the error.

Sorry for the late response, better late than never!

Upvotes: 1

Related Questions