forked from MinesJA/browser-board-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HTTPConn.js
36 lines (32 loc) · 950 Bytes
/
HTTPConn.js
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
class HTTPConn {
constructor(endpoint) {
this.endpoint = endpoint
}
getBoard() {
const route = `/board?id=${config.ID}`
fetch(this.endpoint + route, { method: 'GET' })
.then(response => response.arrayBuffer())
.then(bufferData => {
const pixelArray = new Uint8ClampedArray(bufferData)
canvas.setImageFromArray(pixelArray)
console.log('fetched board: ', pixelArray)
})
}
setTile(x, y, c) {
fetch(this.endpoint + `/tile?x=${x}&y=${y}&c=${c}&id=${config.ID}`, {
method: 'Post',
mode: 'no-cors'
})
.then(response => response)
.then(x => {
// console.log('%cJUST SET A TILE', 'color: purple', x.headers)
})
}
getGroupInfo() {
fetch(`${this.endpoint}/groups?id=${config.ID}`, { method: 'GET' })
.then(r => r.json())
.then(groupData => {
// console.log('%cGETTED GROUP! ', 'color: green', groupData)
})
}
}