admin管理员组

文章数量:1182280

I’m working on a WebRTC-based real-time application where the frontend (browser) connects to OpenAI’s Realtime API via a signaling server hosted on Cloudflare Workers. The project uses the following Cloudflare Workers sample code for the signaling server:

The application works locally on localhost but fails in production when deployed to Cloudflare Workers. It seems it can't initiate the peer connection and it moves to a failed state. Retry to connect also doesn't work.

  1. Frontend (browser) generates an SDP offer and sends it to the /rtc-connect endpoint on the Worker.

peerConnection = new RTCPeerConnection();

dataChannel = peerConnection.createDataChannel('response');

peerConnection.createOffer().then((offer) => {
            peerConnection.setLocalDescription(offer);
            fetch('/rtc-connect', {
                method: 'POST',
                body: offer.sdp,
                headers: {
                    'Content-Type': 'application/sdp',
                },
            })
                .then((r) => r.text())
                .then((answer) => {
                    peerConnection.setRemoteDescription({
                        sdp: answer,
                        type: 'answer',
                    });
                })
                .catch((error) => console.error("Error in signaling:", error));
        });

本文标签: WebRTC Connection Fails with OpenAI Realtime API in ProductionStack Overflow