Search code examples
javascriptreactjstwiliotwilio-api

record video call in a room only when user enters record button in twilio


What I am trying to do is to record the video call between one and another user that is going on. The video record will be started once user click on record button. However, I am getting the following issue

Unable to fetch record↵Invalid RecordingSid parameter

I am using rails for api and reactjs for frontend. In rails side i did the following

def record
    @client = client_authenticate()
    puts params["room_sid"]
    # RM5XXXXXXX
    recording = @client.video.recordings(params["room_sid"]).fetch
    puts recording.track_name
end

front end side

const Controls = ({ handleLeaveRoom, handleMute, handleRecord, mute }) => (
  <Wrapper>
    <Icon icon={mute ? faMicrophoneSlash : faMicrophone} size="2x" onClick={handleMute} />
    <HangCall icon={faPhone} size="2x" onClick={handleLeaveRoom} />
    <Icon icon={faDesktop} size="2x" />
    <Icon icon={faCloud} size="2x" onClick={handleRecord} />
  </Wrapper>
);

const handleRecord = async () => {
    try {
      const response = await fetch(`${API_BASE}/twilio/record`, {
        method: "POST",
        body: JSON.stringify({ room_sid: room.activeRoom.sid }),
        headers: {
          "Content-Type": "application/json"
        }
      });
      console.log("requested");
      const jsonResponse = await response.json();
      console.log("jsonResponse", jsonResponse);
    } catch (e) {
      console.error("e", e);
    }
  }

In a nutshell, I want to record the ongoing video call when user hits the record button to the cloud but getting above issue. I send the sid which we get when we join the room.


Solution

  • Twilio developer evangelist here.

    I can find nothing in the documentation that says you can start a recording part way through a video. From what I can see, you need to create the room via the REST API and set the recordParticipantsOnConnect parameter to true and that will record a participant once they join.

    In your code, on the Rails side, you are trying to request a recording that doesn't yet exist using the Room SID, which is the identifier for the room not for a recording. That's why that request is failing.

    There's no API endpoint to start a recording part way through.