-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
41 lines (35 loc) · 1.24 KB
/
index.ts
File metadata and controls
41 lines (35 loc) · 1.24 KB
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
39
40
41
/* eslint-disable no-console */
import { Buffer } from 'node:buffer'
import { writeFile } from 'node:fs/promises'
import { createClient, createWs } from 'tosu-api'
async function main() {
const http = createClient({ baseUrl: 'http://127.0.0.1:24050' })
const jsonV2Data = (await http.GET('/json/v2')).data!
console.log('Current beatmap: ', jsonV2Data.beatmap)
const currBgBlob = (
await http.GET('/files/beatmap/background', {
parseAs: 'arrayBuffer',
})
).data!
await writeFile('background.png', Buffer.from(currBgBlob))
console.log('Current background image saved as background.png')
const ws = createWs('ws://127.0.0.1:24050', '/websocket/v2', {})
ws.addEventListener('open', () => {
console.log('WebSocket connection opened')
})
ws.addEventListener('error', (event) => {
console.error('WebSocket error:', event)
})
ws.addEventListener('close', (event) => {
console.log('WebSocket connection closed:', event)
})
ws.addEventListener('parseError', (event) => {
console.error('WebSocket parse error:', event.detail.error)
})
ws.addEventListener('message', async (event) => {
console.log('Received current beatmap from WebSocket:', event.detail.data.beatmap)
ws.stop()
})
ws.start()
}
main()