Spaces:
Sleeping
Sleeping
jacobinathanialpeterson
commited on
Commit
·
53cfa3e
1
Parent(s):
b48c8b5
Update static/script.js
Browse files- static/script.js +23 -4
static/script.js
CHANGED
@@ -4,7 +4,26 @@ myRoomId = "123"
|
|
4 |
const DELAYTIME = 500
|
5 |
let DATA;
|
6 |
|
7 |
-
function
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
const controller = new AbortController();
|
9 |
const abortSignal = controller.signal;
|
10 |
fetch(url, {
|
@@ -12,7 +31,7 @@ function postMessage(url="https://jacobinathanialpeterson-chatbox2.hf.space/post
|
|
12 |
headers: {
|
13 |
'Content-Type': 'application/json'
|
14 |
},
|
15 |
-
body: JSON.stringify({nameInput: document.getElementById("nameInputBox").value, messageInput: document.getElementById("messageInputBox").value, roomIdInput:
|
16 |
signal: abortSignal
|
17 |
})
|
18 |
.then(response => { if (!response.ok) { throw new Error('Network response was not ok.') } return response.json() })
|
@@ -22,7 +41,7 @@ function postMessage(url="https://jacobinathanialpeterson-chatbox2.hf.space/post
|
|
22 |
.catch(error => { if (error.name === 'AbortError') { console.log('Fetch aborted:', error.message) } else { console.error('Error fetching data:', error.message) }});
|
23 |
}
|
24 |
|
25 |
-
function getMessages(url="https://jacobinathanialpeterson-chatbox2.hf.space/messages") {
|
26 |
const controller = new AbortController();
|
27 |
const abortSignal = controller.signal;
|
28 |
fetch(url, {
|
@@ -30,7 +49,7 @@ function getMessages(url="https://jacobinathanialpeterson-chatbox2.hf.space/mess
|
|
30 |
headers: {
|
31 |
'Content-Type': 'application/json'
|
32 |
},
|
33 |
-
body: JSON.stringify({roomIdInput:
|
34 |
signal: abortSignal
|
35 |
})
|
36 |
.then(response => { if (!response.ok) { throw new Error('Network response was not ok.') } return response.json() })
|
|
|
4 |
const DELAYTIME = 500
|
5 |
let DATA;
|
6 |
|
7 |
+
function createRoom(roomId, url="https://jacobinathanialpeterson-chatbox2.hf.space/createRoom") {
|
8 |
+
const controller = new AbortController();
|
9 |
+
const abortSignal = controller.signal;
|
10 |
+
fetch(url, {
|
11 |
+
method: 'POST',
|
12 |
+
headers: {
|
13 |
+
'Content-Type': 'application/json'
|
14 |
+
},
|
15 |
+
body: JSON.stringify({roomIdInput: roomId}),
|
16 |
+
signal: abortSignal
|
17 |
+
})
|
18 |
+
.then(response => { if (!response.ok) { throw new Error('Network response was not ok.') } return response.json() })
|
19 |
+
.then(data => {
|
20 |
+
controller.abort();
|
21 |
+
})
|
22 |
+
.catch(error => { if (error.name === 'AbortError') { console.log('Fetch aborted:', error.message) } else { console.error('Error fetching data:', error.message) }});
|
23 |
+
|
24 |
+
}
|
25 |
+
|
26 |
+
function postMessage(roomId, url="https://jacobinathanialpeterson-chatbox2.hf.space/postMessage") {
|
27 |
const controller = new AbortController();
|
28 |
const abortSignal = controller.signal;
|
29 |
fetch(url, {
|
|
|
31 |
headers: {
|
32 |
'Content-Type': 'application/json'
|
33 |
},
|
34 |
+
body: JSON.stringify({nameInput: document.getElementById("nameInputBox").value, messageInput: document.getElementById("messageInputBox").value, roomIdInput: roomId}),
|
35 |
signal: abortSignal
|
36 |
})
|
37 |
.then(response => { if (!response.ok) { throw new Error('Network response was not ok.') } return response.json() })
|
|
|
41 |
.catch(error => { if (error.name === 'AbortError') { console.log('Fetch aborted:', error.message) } else { console.error('Error fetching data:', error.message) }});
|
42 |
}
|
43 |
|
44 |
+
function getMessages(roomId, url="https://jacobinathanialpeterson-chatbox2.hf.space/messages") {
|
45 |
const controller = new AbortController();
|
46 |
const abortSignal = controller.signal;
|
47 |
fetch(url, {
|
|
|
49 |
headers: {
|
50 |
'Content-Type': 'application/json'
|
51 |
},
|
52 |
+
body: JSON.stringify({roomIdInput: roomId}),
|
53 |
signal: abortSignal
|
54 |
})
|
55 |
.then(response => { if (!response.ok) { throw new Error('Network response was not ok.') } return response.json() })
|