gigswar commited on
Commit
8f4abac
·
verified ·
1 Parent(s): cb29e48

Create static/interview.js

Browse files
Files changed (1) hide show
  1. static/interview.js +41 -0
static/interview.js ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ let localStream;
2
+ let remoteStream;
3
+ let peerConnection;
4
+ let startButton = document.getElementById("startInterview");
5
+ let localVideo = document.getElementById("localVideo");
6
+ let remoteVideo = document.getElementById("remoteVideo");
7
+
8
+ // Start the interview (WebRTC setup)
9
+ startButton.addEventListener("click", startInterview);
10
+
11
+ async function startInterview() {
12
+ // Get the candidate's local video stream (camera)
13
+ localStream = await navigator.mediaDevices.getUserMedia({ video: true, audio: true });
14
+ localVideo.srcObject = localStream;
15
+
16
+ // Set up peer connection
17
+ peerConnection = new RTCPeerConnection();
18
+
19
+ // Add local stream to the connection
20
+ localStream.getTracks().forEach(track => peerConnection.addTrack(track, localStream));
21
+
22
+ // Listen for remote stream
23
+ peerConnection.ontrack = (event) => {
24
+ remoteStream = event.streams[0];
25
+ remoteVideo.srcObject = remoteStream;
26
+ };
27
+
28
+ // Create and send an offer to establish the WebRTC connection
29
+ let offer = await peerConnection.createOffer();
30
+ await peerConnection.setLocalDescription(offer);
31
+
32
+ // Send the offer to the bot's signaling server (could be FastAPI backend or WebSocket)
33
+ // You'll need to implement the signaling server here (sending and receiving messages)
34
+ sendOfferToBot(offer);
35
+ }
36
+
37
+ // This is a placeholder function to send the offer to the bot (e.g., using WebSocket)
38
+ function sendOfferToBot(offer) {
39
+ // Implement your signaling server here (e.g., via WebSocket or HTTP)
40
+ console.log("Sending offer to bot:", offer);
41
+ }