mirror of
https://github.com/Monadical-SAS/reflector.git
synced 2025-12-20 20:29:06 +00:00
Implemented API from code generated by OpenAPI
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import Peer from "simple-peer";
|
||||
import axios from "axios";
|
||||
|
||||
const API_URL = process.env.NEXT_PUBLIC_API_URL;
|
||||
import { DefaultApi } from "../api/apis/DefaultApi";
|
||||
import { Configuration } from "../api/runtime";
|
||||
|
||||
const useWebRTC = (stream, transcriptId) => {
|
||||
const [data, setData] = useState({
|
||||
@@ -13,29 +12,33 @@ const useWebRTC = (stream, transcriptId) => {
|
||||
if (!stream || !transcriptId) {
|
||||
return;
|
||||
}
|
||||
const url = `${API_URL}/v1/transcripts/${transcriptId}/record/webrtc`;
|
||||
|
||||
const apiConfiguration = new Configuration({
|
||||
basePath: process.env.NEXT_PUBLIC_API_URL,
|
||||
});
|
||||
const api = new DefaultApi(apiConfiguration);
|
||||
|
||||
let peer = new Peer({ initiator: true, stream: stream });
|
||||
|
||||
peer.on("signal", (data) => {
|
||||
if ("sdp" in data) {
|
||||
const rtcOffer = {
|
||||
sdp: data.sdp,
|
||||
type: data.type,
|
||||
const requestParameters = {
|
||||
transcriptId: transcriptId,
|
||||
rtcOffer: {
|
||||
sdp: data.sdp,
|
||||
type: data.type,
|
||||
},
|
||||
};
|
||||
|
||||
axios
|
||||
.post(url, rtcOffer, {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
})
|
||||
.then((response) => {
|
||||
const answer = response.data;
|
||||
api
|
||||
.transcriptRecordWebrtcV1TranscriptsTranscriptIdRecordWebrtcPost(
|
||||
requestParameters,
|
||||
)
|
||||
.then((answer) => {
|
||||
peer.signal(answer);
|
||||
})
|
||||
.catch((e) => {
|
||||
console.error("WebRTC signaling error:", e);
|
||||
.catch((err) => {
|
||||
console.error("WebRTC signaling error:", err);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user