File size: 1,095 Bytes
dad7400
 
 
 
 
 
 
 
e6b5231
dad7400
 
 
 
 
e6b5231
 
 
dad7400
e6b5231
dad7400
 
 
 
 
e6b5231
 
 
dad7400
e6b5231
dad7400
 
 
 
 
e6b5231
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const API = "/api/negotiate";

export async function getScenarios() {
  const res = await fetch(API + "/scenarios");
  if (!res.ok) throw new Error("Failed to fetch scenarios");
  return res.json();
}

export async function startNegotiation(data) {
  const res = await fetch(API + "/start", {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify(data),
  });
  if (!res.ok) throw new Error((await res.json()).error);
  return res.json();
}

export async function sendResponse(sessionId, response) {
  const res = await fetch(API + "/respond", {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({ sessionId, response }),
  });
  if (!res.ok) throw new Error((await res.json()).error);
  return res.json();
}

export async function acceptOffer(sessionId) {
  const res = await fetch(API + "/accept", {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({ sessionId }),
  });
  if (!res.ok) throw new Error((await res.json()).error);
  return res.json();
}