mediasoup-client TypeError: Cannot read property '_createTransport' of null at createRecvTransport

747 Views Asked by At

I've got an error in mediasoup-client while executing "device.createRecvTransport" in the Redux SAGA (I know this is not the best practice, but no choice).

"device.createRecvTransport" is actually an abstraction which holds a webRTC RTCPeerConnection instance. When I call it, it throws this error.

TypeError: Cannot read property '_createTransport' of null at createRecvTransport

the code:

function* createRecvTransport(device: Device) {
  const {
    id,
    iceParameters,
    iceCandidates,
    dtlsParameters,
    sctpParameters
  } = yield sendRequest({
    action: 'createWebRtcTransport',
    data: {
      forceTcp: false,
      producing: false,
      consuming: true
    }
  });

  const recvTransport: Transport = yield call(device.createRecvTransport, {
    id,
    iceParameters,
    iceCandidates,
    dtlsParameters,
    sctpParameters,
    iceServers: []
  });
}

the Device is declared with function

function* initDevice() {
  const handlerName = detectDevice();
  const device = new Device({
    handlerName
  });

  const routerRtpCapabilities = yield sendRequest({
    action: 'getRouterRtpCapabilities'
  });

  device.load({ routerRtpCapabilities });
}

"device.createSendTransport" method also works, the only issue is with creating Receive Transport. The method "router.createWebRtcTransport" get executed in the mediasoup router and it returns data before executing "createRecvTransport" in client side.

1

There are 1 best solutions below

0
On BEST ANSWER

Seems the problem is with the "yield call" expression. As the "device.createRecvTransport" isn't an async (handled with promise) function, it shouldn't be executed using "yield call".

When I removed "yield call", it fixed.