-
Notifications
You must be signed in to change notification settings - Fork 13
/
lcm.js
43 lines (37 loc) · 946 Bytes
/
lcm.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
37
38
39
40
41
42
43
import WebSocket from 'ws'
import fs from 'fs'
const ws = new WebSocket('ws://100.76.41.44:5000')
const prompts = [
'A beautiful sunset over the ocean',
'A cute puppy playing in the park',
'A futuristic city skyline at night'
]
let promptIndex = 0
ws.on('open', () => {
console.log('Connected to WebSocket server')
sendNextPrompt()
})
ws.on('message', (data) => {
const fileName = `image_${promptIndex}.png`
fs.writeFile(fileName, data, (err) => {
if (err) {
console.error(`Error writing file ${fileName}:`, err)
} else {
console.log(`Image saved as ${fileName}`)
promptIndex++
sendNextPrompt()
}
})
})
ws.on('close', () => {
console.log('Disconnected from WebSocket server')
})
function sendNextPrompt () {
if (promptIndex < prompts.length) {
const prompt = prompts[promptIndex]
const message = JSON.stringify({ prompt })
ws.send(message)
} else {
ws.close()
}
}