Skip to content

Instantly share code, notes, and snippets.

@dmurawsky
Created October 1, 2021 14:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmurawsky/32da84ea400317914758e1f2dec49f1c to your computer and use it in GitHub Desktop.
Save dmurawsky/32da84ea400317914758e1f2dec49f1c to your computer and use it in GitHub Desktop.
export const saveLiveSwitchRecording = async (
recordingId: string,
channelId: string,
fileName: string,
type: "video" | "audio"
) => {
const file = makeLiveSwitchRecordingFile(recordingId, channelId, fileName);
const format = fileName.substring(fileName.indexOf(".") + 1);
const writeStream = file.createWriteStream({
metadata: {
contentType: `${type}/${format}`,
},
});
const readStream = await axios.get(`https://api.liveswitch.io/recordings/${recordingId}/url?api-version=1.0`, {
headers: {
"X-API-Key": getEnvVar("LIVESWITCH_API_KEY"),
},
responseType: "stream",
});
const pipedStreams = readStream.data.pipe(writeStream);
return new Promise((resolve, reject) => {
pipedStreams.on("error", (err: string) => {
reject(err);
});
pipedStreams.on("finish", () => {
// TODO : Do something useful
resolve("true");
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment