Marvelous Ikechi
Marvelous Ikechi

Reputation: 2043

Call doesn't drop after calling track.stop

I am using RNwebrtc to initiate a call for my application. The call gets to work on both ends, however, calling this end function executes successfully, but the communication channel remains open. What I mean is, the mics are still open that users can still speak to each other. Here's a sample of my code:

  const endCall = useCallback(async () => {
    const pc = peerConnectionRef.current;
    if (pc) {
      pc.getTransceivers().forEach(transceiver => {
        transceiver.stop();
      });
      pc.close();
      peerConnectionRef.current = null;
    }

    if (localStreamRef.current) {
      localStreamRef.current.getTracks().forEach(track => {
        console.log('Stopping local track:', track);
        track.stop();
      });
      localStreamRef.current = null;
    }

    if (remoteStreamRef.current) {
      remoteStreamRef.current.getTracks().forEach(track => {
        console.log('Stopping remote track:', track);
        track.stop();
      });
      remoteStreamRef.current = null;
    }

    console.log('Local stream after end call:', localStreamRef.current);
    console.log('Remote stream after end call:', remoteStreamRef.current);

    const callDoc = doc(collection(firestore, 'calls'), partyId);
    await updateDoc(callDoc, {callEnded: true, callStarted: false});

    setIsConnected(false);
    setCallEnded(true);
  }, [firestore, partyId]);

Upvotes: 0

Views: 26

Answers (0)

Related Questions