Realtime API WebRTC boltai integration
Yxax
async function createRealtimeSession(inStream, outEl, token) {
const pc = new RTCPeerConnection();
pc.ontrack = e => outEl.srcObject = e.streams[0];
pc.addTrack(inStream.getTracks()[0]);
const offer = await pc.createOffer();
await pc.setLocalDescription(offer);
const headers = { Authorization:
Bearer ${token}
, 'Content-Type': 'application/sdp' };const opts = { method: 'POST', body: offer.sdp, headers };
const resp = await fetch('api.openai.com/v1/realtime', opts);
await pc.setRemoteDescription({ type: 'answer', sdp: await resp.text() });
return pc;
}